1. 程式人生 > >DB2中如何檢視執行計劃

DB2中如何檢視執行計劃

[email protected]:~$  db2 "flush package cache dynamic"
DB20000I  The SQL command completed successfully.'

[email protected]:~$ db2 "SELECT NAME FROM T2 WHERE ID > 15" 

NAME                
--------------------
qing                
song                

  2 record(s) selected.

[email protected]
:~$ db2 "SELECT executable_id,STMT_EXEC_TIME,Total_cpu_time,varchar(stmt_text,50) as stmt_text FROM TABLE(MON_GET_PKG_CACHE_STMT ('D', NULL,NULL,-1)) AS T " EXECUTABLE_ID STMT_EXEC_TIME TOTAL_CPU_TIME STMT_TEXT ------------------------------------------------------------------- -------------------- -------------------- -------------------------------------------------- x'0100000000000000110100000000000000000000020020170630092845270960' 0 0 SELECT executable_id,STMT_EXEC_TIME,Total_cpu_time SQL0445W Value "SELECT executable_id,STMT_EXEC_TIME,Total_cpu_time,varchar(s" has been truncated. SQLSTATE=01004 x'0100000000000000100100000000000000000000020020170630092841223134' 0 73 SELECT NAME FROM T2 WHERE ID > 15 2 record(s) selected with 1 warning messages printed.
[email protected]
:~$ db2 "CALL EXPLAIN_FROM_SECTION(x'0100000000000000100100000000000000000000020020170630092841223134' , 'M', NULL, 0, 'INST105', ?, ?, ?, ?, ? )" Value of output parameters -------------------------- Parameter Name : EXPLAIN_SCHEMA Parameter Value : INST105 Parameter Name : EXPLAIN_REQUESTER Parameter Value : INST105 Parameter Name : EXPLAIN_TIME Parameter Value : 2017-06-30-09.29.03.900808 Parameter Name : SOURCE_NAME Parameter Value : SQLC2K26 Parameter Name : SOURCE_SCHEMA Parameter Value : NULLID Parameter Name : SOURCE_VERSION Parameter Value : Return Status = 0
[email protected]
:~$ db2exfmt -d sample -o packagecache.out1 DB2 Universal Database Version 10.5, 5622-044 (c) Copyright IBM Corp. 1991, 2012 Licensed Material - Program Property of IBM IBM DATABASE 2 Explain Table Format Tool Connecting to the Database. Connect to Database Successful. Enter up to 26 character Explain timestamp (Default -1) ==> Enter up to 128 character source name (SOURCE_NAME, Default %%) ==> Enter source schema (SOURCE_SCHEMA, Default %%) ==> Enter section number (0 for all, Default 0) ==> Output is in packagecache.out1. Executing Connect Reset -- Connect Reset was Successful. [email protected]:~$ more packagecache.out1 DB2 Universal Database Version 10.5, 5622-044 (c) Copyright IBM Corp. 1991, 2012 Licensed Material - Program Property of IBM IBM DATABASE 2 Explain Table Format Tool ******************** EXPLAIN INSTANCE ******************** DB2_VERSION: 10.05.8 FORMATTED ON DB: SAMPLE SOURCE_NAME: SQLC2K26 SOURCE_SCHEMA: NULLID SOURCE_VERSION: EXPLAIN_TIME: 2017-06-30-09.29.03.900808 EXPLAIN_REQUESTER: INST105 Database Context: ---------------- Parallelism: None CPU Speed: 1.298947e-07 Comm Speed: 100 Buffer Pool size: 1000 Sort Heap size: 256 Database Heap size: 1200 Lock List size: 4096 Maximum Lock List: 10 Average Applications: 1 Locks Available: 13107 Package Context: --------------- SQL Type: Dynamic Optimization Level: 5 Blocking: Block All Cursors Isolation Level: Cursor Stability ---------------- STATEMENT 1 SECTION 201 ---------------- QUERYNO: 0 QUERYTAG: CLP Statement Type: Select Updatable: No Deletable: No Query Degree: 1 Original Statement: ------------------ SELECT NAME FROM T2 WHERE ID > 15 Optimized Statement: ------------------- SELECT Q1.NAME AS "NAME" FROM INST105.T2 AS Q1 WHERE (15 < Q1.ID) Explain level: Explain from section Access Plan: ----------- Total Cost: 6.81246 Query Degree: 1 Rows RETURN ( 1) Cost I/O | 1 FETCH ( 2) 6.81246 NA /----+----\ 1 3 IXSCAN TABLE: INST105 ( 3) T2 0.00553156 Q1 NA | 3 INDEX: INST105 IDX2 Q1