17.05 - Example: Defining and Using a Simple Join Index With an n -way Join Result - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Advanced SQL Engine
Teradata Database
Release Number
January 2021
Content Type
Programming Reference
Publication ID
English (United States)
Last Update

This statement creates a join index defined with a multiway join result:

    CREATE JOIN INDEX cust_order_join_line AS
    SELECT (l_orderkey, o_orderdate, c_nationkey, o_totalprice),
           (l_partkey, l_quantity, l_extendedprice, l_shipdate)
    FROM (lineitem 
    LEFT JOIN orders ON l_orderkey = o_orderkey)
    INNER JOIN customer ON o_custkey = c_custkey
    PRIMARY INDEX (l_orderkey);

The following query is provided as an example to show how the Optimizer uses the join index to process a query on the base tables for which it is defined. An EXPLAIN of the SELECT statement includes RETRIEVE step from join index table cust_order_join_line by way of an all-rows scan with a condition of ("cust_order_join_line.c_nationkey = 10").

    SELECT l_orderkey, o_orderdate, o_totalprice,
         l_partkey, l_quantity, l_extendedprice, l_shipdate
    FROM lineitem, orders, customer
    WHERE l_orderkey = o_orderkey 
    AND o_custkey = c_custkey 
    AND c_nationkey = 10;