Using global temporary tables in batch explain


(BMC.DB2.SPE2410)You can provide declarations of global temporary tables by using the ddname GLOBDDN. This allows the dynamic explain to run without a -204 error when the SQL statements refer to global temporary tables.

//GLOBDDL DD DISP=SHR,DSN=RDAGXR1.SQLIN(GLOBTBS)

To provide declarations of global temporary tables by using the ddname GLOBDDN, follow these steps:

  1. The input should be a flat file with FB 80.
  2. Terminate each SQL statement with a semicolon.
  3. Include the declaration of global temporary tables and insert statements in the file.
  4. When you run a large workload, if the same GTT name is used across many PACKAGES with unique declarations specific to each PACKAGE, it is beneficial to provide package-specific declarations, as shown in the following figure.
  5. Place the package-specific definitions at the bottom of the file, identified by –PKG/DBRM followed by the package name. You can use wildcards for PACKAGE versions.

    DECLARE GLOBAL TEMPORARY TABLE TEMPI LIKE
               SYSIBM.SYSTABLES ON COMMIT PRESERVE ROWS;
    SELECT NAME FROM SYSIBM.SYSTABLES;
    DECLARE GLOBAL TEMPORARY TABLE TEMP2 LIKE
               SYSIBM.SYSTABLESPACE ON COMMIT PRESERVE ROWS;
    DECLARE GLOBAL TEMPORARY TABLE TEMP3 LIKE
               SYSIBM.SYSDATABASE ON COMMIT PRESERVE ROWS;
    --PKG/DBRM GLOBPKG.%
      DECLARE GLOBAL TEMPORARY TABLE TEMP4 LIKE
                  SYSIBM.SYSCOLUMNS ON COMMIT PRESERVE ROWS;
      INSERT INTO TEMP4
                SELECT * FROM
                  SYSIBM.SYSCOLUMNS;
                 WHERE NAME LIKE "WORK%';
    --PKG/DBRM GLOBAYO.%
      DECLARE GLOBAL TEMPORARY TABLE TEMPS LIKE
                  SYSIBM.SYSINDEXES ON COMMIT PRESERVE ROWS;

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*