Attachment | Size |
---|---|
![]() | 5.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:
- Identifying old and stale statistics
- Understand the data demographics in more detail
- The data could be joined to DBQLObjTBL for further analysis
- The data could be used to generate test data
- The data could be exported
- 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
-
Three files are provided in TeradataColumnStatistics.zip
TeradataColumnStatistics.java
(Java code)TeradataColumnStatistics.sql
(DDL to hold the table and column statistics)TeradataColumnStatistics.jar
(JAR file of the compiled Java code)
-
Download the above files (always copy or move the
TeradataColumnStatistics.jar
file in binary mode). -
Make sure that the user has privileges to call
SQLJ.INSTALL_JAR
andCREATE EXTERNAL PROCEDURE.
-
Create the two table provided in
TeradataColumnStatistics.sql
-
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';
-
To execute the JSP in bteq:
CALL RETAIL.TableColumnStatistics('RETAIL','ITEM'); /** RETAIL is the database name and ITEM is the table name */
-
Check the tables
Help_Col_Stats
andHelp_Tab_Stats
for 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:
Tags:
Apply supersede status to children:
0