简体   繁体   中英

What is the difference between volatile table and multiset volatile table?

I am looking at some SAS/Teradata code and confused on the below. This has a volatile table and a multiset volatile table. What is the difference between the two? Also, why does this specify WITH DATA PRIMARY INDEX? Also for the second one, why does this collect statistics?

  PROC SQL ;
CONNECT TO TERADATA (AUTHDOMAIN=IDWPRD SERVER= IDWPRD MODE=TERADATA);
EXECUTE(
CREATE VOLATILE TABLE REQ1_1_CODE_INS AS (
SELECT 
    ACCT_REF_NB, 
    CAST(NON_MNTR_TXN_PST_TS AS DATE) AS ADJ_DT,
    SRC_DATA_DT,
    NON_MNTR_TXN_SEQ_NB,
    SRC_CRE_USER_ID,
    PROC_TRAN_CD,
    PROC_TRCK_ID,
    MAX(CASE WHEN NON_MNTR_TXN_SBTP_CD = '0009' THEN TRIM(NEW_NON_MNTR_TXN_DTL_TX) ELSE NULL END) AS CARD_NB
FROM DWHMGR.PST_NON_MNTR_TXN
WHERE NON_MNTR_TXN_TP_CD ='255'
    AND CAST(NON_MNTR_TXN_PST_TS AS DATE) >= '2016-03-13'
    AND CAST(NON_MNTR_TXN_PST_TS AS DATE) <= '2017-11-09'
GROUP BY 1,2,3,4,5,6,7
HAVING TXN_DT <= ADD_MONTHS(ADJ_DT, -24) 
        OR UPPER(MRCH_NM) LIKE '%CHECK TO%' 
        OR UPPER(MRCH_NM) LIKE '%BALANCE TRANSFER%' 
)WITH DATA PRIMARY INDEX(ACCT_REF_NB) ON COMMIT PRESERVE ROWS;
) BY TERADATA;
CREATE TABLE UNIX.REQ1_1_CODE_INS AS SELECT * FROM CONNECTION TO TERADATA(SELECT * FROM REQ1_1_CODE_INS);

/* REFERENCE TABLE */

EXECUTE(
CREATE MULTISET VOLATILE TABLE _ACCTS_00 AS (
    SELECT DISTINCT ACCT_REF_NB FROM REQ1_1_CODE_INS
) WITH DATA PRIMARY INDEX(ACCT_REF_NB) ON COMMIT PRESERVE ROWS;
) BY TERADATA;
EXECUTE( COLLECT STATISTICS ON _ACCTS_00 PRIMARY INDEX(ACCT_REF_NB); ) BY TERADATA;

Volatile table is like work table in SAS, it just is there for particular session.

Teradata has 2 kinds of table, one is set table and another is multiset table. Set table does not allow row level duplicates, where multiset table allows row level duplicates. Default is set table if nothing is mentioned in create table statement.

Teradata also needs a primary index and needs to mentioned as with data primary index(index name). with data gets data another option is with no data

collect stats is big concept, basically it collects demographic data for primary index, which in return helps in future queries dependent on that index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM