如何解决创建一个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 举报,一经查实,本站将立刻删除。