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

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

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.