Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Finding the table size alone? - response (4) by dnoeth

$
0
0

There's a quite unknown COLLECT DEMOGRAPHICS command (to be used by Index Wizard or Visual Explain) which estimates the size of each subtable per AMP.
You don't need a full Query Capture Database (QCD), it's enough to create a single table (copied from the QCD setup script):

CREATE SET TABLE DataDemographics
     (
      MachineName VARCHAR(30) CHARACTER SET UNICODE UPPERCASE NOT CASESPECIFIC NOT NULL,
      TableName VARCHAR(128) CHARACTER SET UNICODE UPPERCASE NOT CASESPECIFIC NOT NULL,
      DatabaseName VARCHAR(128) CHARACTER SET UNICODE UPPERCASE NOT CASESPECIFIC NOT NULL,
      DBSize INTEGER NOT NULL,
      CollectedTime TIMESTAMP(6) NOT NULL,
      AMPNumber INTEGER NOT NULL,
      ClusterNumber INTEGER NOT NULL,
      SubTableID SMALLINT NOT NULL,
      SubTableType VARCHAR(120) CHARACTER SET LATIN NOT CASESPECIFIC,
      RowCount DECIMAL(18,0) NOT NULL,
      AvgRowSize INTEGER NOT NULL,
      QueryID INTEGER,
      IndexName VARCHAR(128) CHARACTER SET UNICODE UPPERCASE NOT CASESPECIFIC,
      DemographicsID INTEGER)
PRIMARY INDEX ( MachineName ,TABLENAME ,DatabaseName );

Then you submit a

COLLECT DEMOGRAPHICS FOR mytable INTO mydatabase; 

Following query returns the approximate size per subtable:

SELECT
   DatabaseName
   ,TABLENAME
   ,SubTableId 
   ,SubTableType
   ,MIN(IndexName) AS IndexName
   ,SUM(RowCount * (AvgRowSize + 0.5)) AS SubTableSize
   ,100 * SubTableSize/CurrentPerm AS SubTablePercent
   ,SUM(SubTableSize) OVER (PARTITION BY DatabaseName, TABLENAME) AS CurrentPerm
FROM DataDemographics
GROUP BY 1,2,3,4
ORDER BY 1,2,3;

Caution: this is not including the size of a Fallback protected table, i.e. you need to add a join to dbc.TablesV and multiply the size times two when it's a Fallback table.


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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