Example: Collecting Statistics on Built-In Function Expressions - Teradata Vantage - Analytics Database

SQL Data Definition Language Syntax and Examples

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-11-06
dita:mapPath
jco1628111346878.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
mdr1472255012272
lifecycle
latest
Product Category
Teradata Vantage™

You can also collect statistics on constant expressions that refer to built-in functions.

The Optimizer remembers the materialized values for the CURRENT_TIMESTAMP, CURRENT_DATE and USER functions when statistics are collected and then substitutes the stored materialized values when the statistics are used.

For other built-in functions like SESSION and CURRENT_ROLE, the Optimizer substitutes the values based on the session parameters at the time the statistics are used. Even though the database allows you to specify any built-in functions, you should restrict your collecting of statistics to built-in functions other than CURRENT_TIMESTAMP, CURRENT_DATE and USER in the expressions.

In the following request, the Optimizer substitutes the value for CURRENT_DATE for the CASE expression and then remembers it. When the statistics are used for this expression, the Optimizer substitutes the saved value for CURRENT_DATE.

     COLLECT STATISTICS 
     COLUMN CASE WHEN CAST(o_orderdatetime AS DATE AT 0) = CURRENT_DATE 
                 THEN 'orders-today'
                 ELSE 'orders-old'
            END AS stats_orders_today_and_old
     ON orders;