17.05 - Example: Nullified EXPAND Operation - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)

This example shows how when an expanded column is not specified in the select list of a query, but a DISTINCT operator is specified, the EXPAND operation is nullified.

     CREATE SET TABLE df2.t1, NO FALLBACK, NO BEFORE JOURNAL,
                              NO AFTER JOURNAL, CHECKSUM = DEFAULT,
                              DEFAULT MERGEBLOCKRATIO (
       i  INTEGER,
       j  INTEGER,
       pd PERIOD(DATE) FORMAT 'yyyy-mm-dd')
     PRIMARY INDEX (i);

The first SELECT statement in this example does not specify the DISTINCT operator.

     EXPLAIN SELECT i,j
             FROM t1
             EXPAND ON pd AS expd BY INTERVAL '1' DAY;

An EXPLAIN shows an EXPAND ON t1.pd.

The following SELECT statement specifies the DISTINCT operator.

     SELECT DISTINCT i,j
             FROM t1
             EXPAND ON pd AS expd BY INTERVAL '1' day;

An EXPLAIN shows a SORT and elimination of duplicate rows. The DISTINCT operator makes the EXPAND ON step unnecessary.