please let me know any tweaks to query would elimante the sort..
Quote:
|
Why did you do that? A unique constraint (a PK is just that) is already implemented by a unique index. So this seems to be work for no good reason. If it is intended to get the PCTFREE and the ALLOW REVERSE SCANS option in there, don't create the PK on the table in the CREATE TABLE statement. Create the table, then the index, then add the PK constraint.
|
I thought if allow reverse scans used , index will used even when we specify oredr by desc.
Please correct me if i'm wrong.
Quote:
|
I took long time for completion. can you please tell me reason..if you have idea why it took long time(more than 2hours)?
|
I have run below command
db2 runstats on table SNM.SECURITY_AUDITS and indexes all
it has 19K rows
Quote:
|
You care to join with us which version of DB2 you are using on which platform? Also, what's the exact query plan (if you are using DB2 LUW, then you can get a textual version with the "db2expln" tool)?
|
DB2 - 8.2 running on Sun solaris 5.8
Query plan is
-------------
bash-2.03$ db2expln -d ONMDB -t -q "select * from SNM.SECURITY_AUDITS securityau0_ order by SECURITY_AUDIT_ID desc fetch first 10 rows only"
DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL Explain Tool
DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL 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", "DB2INST1"
SQL Statement:
select *
from SNM.SECURITY_AUDITS securityau0_
order by SECURITY_AUDIT_ID desc
fetch first 10 rows only
Section Code Page = 819
Estimated Cost = 1915.921143
Estimated Cardinality = 10.000000
Access Table Name = SNM.SECURITY_AUDITS ID = 4,1037
| #Columns = 12
| Relation Scan
| | Prefetch: Eligible
| Lock Intents
| | Table: Intent Share
| | Row : Next Key Share
| Sargable Predicate(s)
| | Insert Into Sorted Temp Table ID = t1
| | | #Columns = 12
| | | #Sort Key Columns = 1
| | | | Key 1: SECURITY_AUDIT_ID (Descending)
| | | Sortheap Allocation Parameters:
| | | | #Rows = 10
| | | | Row Width = 100
| | | | Sort Limited To Estimated Row Count
| | | Piped
Sorted Temp Table Completion ID = t1
Access Temp Table ID = t1
| #Columns = 12
| Relation Scan
| | Prefetch: Eligible
Return Data to Application
| #Columns = 12
End of section