17.10 - 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

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1144-171K
Language
English (United States)

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;