银行数据库

请大家帮我看看为什么这个执行计划里面会有SORT??

$ db2expln -d remall -g -f "tune.sql" -terminal -z ";" DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009 Licensed Material - Program Property of IBM IBM DB2 Universal Database SQL and XQUERY Explain Tool DB2 Universal Databa...显示全部
$ db2expln -d remall -g -f "tune.sql" -terminal -z ";"

DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool

DB2 Universal Database Version 9.7, 5622-044 (c) Copyright IBM Corp. 1991, 2009
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL and XQUERY Explain Tool

******************** DYNAMIC ***************************************

==================== STATEMENT ==========================================

        Isolation Level          = Cursor Stability
        Blocking                 = Block Unambiguous Cursors
        Query Optimization Class = 5

        Partition Parallel       = No
        Intra-Partition Parallel = No

        SQL Path                 = "SYSIBM", "SYSFUN", "SYSPROC", "SYSIBMADM", 
                                   "SNDBUSR"


Statement:
  
  SELECT COUNT(1)
  from catentry a , catentdesc b 
  where a.CATENTRY_ID =b.CATENTRY_ID and a.markfordelete =0 and 
          b.published=1 and a.field5 like ?


Section Code Page = 1208

Estimated Cost = 326166.062500
Estimated Cardinality = 1.000000

Access Table Name = SNDBUSR.CATENTRY  ID = 2,1036
|  #Columns = 2
|  Skip Inserted Rows
|  Avoid Locking Committed Data
|  Currently Committed for Cursor Stability
|  May participate in Scan Sharing structures
|  Scan may start anywhere and wrap, for completion
|  Fast scan, for purposes of scan sharing management
|  Scan can be throttled in scan sharing management
|  Relation Scan
|  |  Prefetch: Eligible
|  Lock Intents
|  |  Table: Intent Share
|  |  Row  : Next Key Share
|  Sargable Predicate(s)
|  |  #Predicates = 2
|  |  Insert Into Sorted Temp Table  ID = t1
|  |  |  #Columns = 1
|  |  |  #Sort Key Columns = 1
|  |  |  |  Key 1: CATENTRY_ID (Descending)
|  |  |  Sortheap Allocation Parameters:
|  |  |  |  #Rows     = 7269.000000
|  |  |  |  Row Width = 12
|  |  |  Piped
Sorted Temp Table Completion  ID = t1
Access Temp Table  ID = t1
|  #Columns = 1
|  Relation Scan
|  |  Prefetch: Eligible
Nested Loop Join
|  Access Table Name = SNDBUSR.CATENTDESC  ID = 6,4
|  |  Index Scan:  Name = SNDBUSR.I_CATENTDESC_1  ID = 6
|  |  |  Regular Index (Not Clustered)
|  |  |  Index Columns:
|  |  |  |  1: PUBLISHED (Ascending)
|  |  |  |  2: CATENTRY_ID (Descending)
|  |  #Columns = 0
|  |  Skip Inserted Rows
|  |  Avoid Locking Committed Data
|  |  Currently Committed for Cursor Stability
|  |  #Key Columns = 2
|  |  |  Start Key: Inclusive Value
|  |  |  |  |  1: 1
|  |  |  |  |  2: ?
|  |  |  Stop Key: Inclusive Value
|  |  |  |  |  1: 1
|  |  |  |  |  2: ?
|  |  Index-Only Access
|  |  Index Prefetch: Eligible 1508
|  |  Lock Intents
|  |  |  Table: Intent Share
|  |  |  Row  : Next Key Share
|  |  Sargable Index Predicate(s)
|  |  |  Predicate Aggregation
|  |  |  |  Column Function(s)
Aggregation Completion
|  Column Function(s)
Return Data to Application
|  #Columns = 1

End of section


Optimizer Plan:

         Rows   
       Operator 
         (ID)   
         Cost   
               
          1    
         n/a   
        RETURN 
         ( 1)  
        326166 
          |    
          1    
         n/a   
        GRPBY  
         ( 2)  
        326166 
         |     
       5058.74 
         n/a   
       NLJOIN  
        ( 3)   
       326166  
      /       --
  7268.39         * 
    n/a          |        
  TBSCAN       806224     
   ( 4)    Index:         
  307756   SNDBUSR        
    |      I_CATENTDESC_1 
  7268.39 
    n/a   
   SORT   
   ( 5)   
  307756  
    |     
  7268.39 
    n/a   
  TBSCAN  
   ( 6)   
  307753  
    |     
  806227  
   n/a    
 Table:   
 SNDBUSR  
 CATENTRY 

我这段SQL好像不该有排序呀。但为什么存取计划里面会有SORT这样的操作呢?很纳闷,请大家讲解一下~

附件:

附件图标a.rar (6.71 KB)

收起
参与50

查看其它 48 个回答智长老的回答

智长老智长老数据库管理员IBM ISSC
db2会排序RID,减少在同一页的行的反复读取,以降低I/O成本
IT分销/经销 · 2012-03-07
浏览1251

回答者

智长老
数据库管理员IBM ISSC

智长老 最近回答过的问题

回答状态

  • 发布时间:2012-03-07
  • 关注会员:1 人
  • 回答浏览:1251
  • X社区推广