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

SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
ncd1596241368722.ditamap
dita:ditavalPath
hoy1596145193032.ditaval
dita:id
B035-1144
lifecycle
previous
Product Category
Teradata Vantage™

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;