Quantcast
Channel: Teradata Downloads
Viewing all articles
Browse latest Browse all 780

Extracting table and column statistics

$
0
0
AttachmentSize
TeradataColumnStatistics.zip5.38 KB

Statistics provides valuable information to the optimizer to make decisions on generating optimal explain plan.  The information about the statistics can be obtained by using the “Help Statistics” command however the displayed data cannot be used to join with other tables.  The article provides a java stored procedure and DDL which extracts the output of "Help Statistics" at Table and Column level and capture the data into tables. 

The captured data in the tables helps with:

  1. Identifying old and stale statistics
  2. Understand the data demographics in more detail
  3. The data could be joined to DBQLObjTBL  for further analysis
  4. The data could be used to generate test data
  5. The data could be exported
  6. Better understand the explain plan there is a detailed explanation of how the statistics are used in Teradata Manual “SQL Request and Transaction Processing”

Environment

The code was built and tested on:

  • TD 13.10
  • Linux 64-bit
  • JDK 1.5

Installation & usage

  1. Three files are provided in TeradataColumnStatistics.zip
    1. TeradataColumnStatistics.java(Java code)
    2. TeradataColumnStatistics.sql  (DDL to hold the table and column statistics)
    3. TeradataColumnStatistics.jar(JAR file of the compiled Java code)
  2. Download the above files (always copy or move the TeradataColumnStatistics.jarfile in binary mode).
  3. Make sure that the user has privileges to call SQLJ.INSTALL_JARand CREATE EXTERNAL PROCEDURE.
  4. Create the two table provided in TeradataColumnStatistics.sql
  5. Use bteq to execute the below commands:
    CALL SQLJ.INSTALL_JAR('CJ!/tmp/TeradataColumnStatistics.jar', 'TeradataColumnStatistics', 0); 
    
    /** Where /tmp is the directory the TeradataColumnStatistics.jar file resides */ 
    
    REPLACE PROCEDURE TableColumnStatistics
    
    ( INOUT db VARCHAR(32),INOUT tab VARCHAR(32) )
    
    LANGUAGE JAVA MODIFIES SQL DATA
    
    PARAMETER STYLE JAVA
    
    EXTERNAL NAME 'TeradataColumnStatistics:TeradataColumnStatistics.main';
  6. To execute the JSP in bteq:
    CALL RETAIL.TableColumnStatistics('RETAIL','ITEM'); 
    
    /** RETAIL is the database name and ITEM is the table name */
  7. Check the tables Help_Col_Statsand Help_Tab_Statsfor the data contents.

The java code could also be compiled on the Linux box

$/opt/teradata/jvm64/jdk5/bin/javac TeradataColumnStatistics.java

$/opt/teradata/jvm64/jdk5/bin/jar -cf TeradataColumnStatistics.jar TeradataColumnStatistics.class

Teradata Manual SQL External Routine Programming; Chapter 5 - Java External Stored Procedures discusses more about building and using Java stored procedures

Ignore ancestor settings: 
0
Channel: 
Apply supersede status to children: 
0

Viewing all articles
Browse latest Browse all 780

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>