创建一个Teradata SQL收集统计信息语句

问题描述

代码使用teradata sql PIVOT函数和DBC表来生成teradata sql Collect Stats语句。只需复制代码,并在出现提示时输入数据库名称和表名称即可。将返回collect stats语句。

/**********************************************************************************************************************************************************************************
                                  CODE GENERATOR FOR "COLLECT STATS STATEMENTS'" FOR NEW teraDATA TABLES 
                                                                                              written by Margaretha Du Toit
                                  
                                 ****  IMPORTANT ****
For existing tables,the collect stats statement MUST be generated by the following code :       
     SHOW STATS ON YourDatabase.YourTable e.g.   SHOW STATS ON MyDatabase.MyTable   
     You may then use the code returned by teradata and add your changes to the existing code. 
     It is very important that you use the current stats in production as this has been collected over time
           and will be lost if you do not include the columns referenced in production

                                *** FOR NEW DEVELOPMENT ***
For NEW tables in ONLY,you can use the code below to generate a collect stats statement 
The sql is generated by hardcoding code and fetching values from DBC.Indices                              
To use this code,the table must FirsT be created in the DEVELOPMENT database                                                                                    
You can extract for a single table or for multiple tables using this code by replacing the table name/s in #001 and #002 in the sql code below
The DBA's may suggest different columns for stats to be collected on based on performance and skew

Once you have run this sql,you can copy the result and paste in in your sql Editor Screen and then run the collect stats 
    statement/s before you send it to the DBA's
********************************************************************************************************************************************************************************************/

SELECT disTINCT
-- Please do not disturb the code below as it formats the collect stats statement
'COLLECT STATISTICS USING NO SAMPLE 
AND NO THRESHOLD DAYS 
AND NO THRESHOLD PERCENT 
'||
B.Individual_Indeces||'
COLUMN(' ||OREPLACE( XMLAGG(TRIM(COALESCE(A.ColumnName,-1)||' ')) (varchar(1000)),' ',',') ||')
'||'ON '||
UPPER(TRIM(A.DatabaseName))||'.'||UPPER(TRIM(A.TableName))||';'
as CollectStatsstatement 
FROM    DBC.Indices A

INNER JOIN
(
SELECT 
DatabaseName,TableName,XMLAGG(TRIM(COALESCE( 'COLUMN('||TRIM(ColumnName)||'),-1)||' ')) (VARCHAR(1000)) as Individual_Indeces
FROM    DBC.Indices
WHERE UPPER(DatabaseName)= '?PLEASE_ENTER_YOUR_DATABASE_NAME'  -- Replace with your Database
-- #001
-- For a single table use below code and replace with you Table Name
AND UPPER(TableName) = '?PLEASE_ENTER_YOUR_TABLE_NAME' -- For a mutiple tables use below code below and replace with you Table Names
-- AND UPPER(TableName) IN ( 'ACCOUNT_PARTY','AGREEMENT','EVENT')
GROUP BY 1,2
) B

ON A.DatabaseName = B.DatabaseName
AND A.TableName = B.TableName

WHERE  UPPER(TRIM(A.DatabaseName)) =  '?PLEASE_ENTER_YOUR_DATABASE_NAME'  -- Replace with your Database
-- #002
-- For a single table use below code below and replace with you Table Name
AND UPPER(TRIM(A.TableName)) = '?PLEASE_ENTER_YOUR_TABLE_NAME'
-- For a mutiple tables use below code  below and replace with you Table Names
-- AND UPPER(A.TableName) IN ( 'ACCOUNT_PARTY','EVENT')

GROUP BY   A.DatabaseName,A.TableName,B.Individual_Indeces

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...