How to calculate the query execution time in Teradata

DBC Tables in Teradata – Data dictionary of Teradata

Teradata stores the log of each and every SQL query data in the data dictionary tables. Those meta data tables are present in the DBC database. From these tables,We can get the table level details such as column information, index information, table size,database size and so on. Similarly it provides query execution level details such as query run time time, Impact CPU, CPU consumption, execution plan and so on.

DBC.DBQLogTbl ( view name – DBC.QryLogV )

For each query execution, it maintains the log in DBC.DBQLogTble. The corresponding view name for this table is DBC.QryLogv. It provides enough information to investigate the query performance in Teradata. We can fetch those query level details using either query band or the corresponding user name or query id. Few important columns in this table are AMPCPUTime, MaxAMPCPUTime, FirstRespTime, StartTime and QueryText.

Calculate the query run time in Teradata using DBC.QryLogv

In order to find the query execution time , we need to subtract the Start time from the First Response Time in the DBC.QryLogv. Since those columns contains the timestamp, we have applied Extract function and other time calculation to get the query run time in seconds and minutes as below.

FirstRespTime:

The timestamp when the first response packet is sent to the client unless the request is held by TASM to meet the minimum response time. In this case, it is the timestamp when the first response packet is ready to be sent to the client.

StartTime:

The timestamp when the query is submitted.

Output : Query execution time and other CPU metrics

DBC Query log table in Teradata
DBC Query log table in Teradata

Recommended Articles