On Tue, 31 Aug 2004 13:12:48 -0400, Rhino wrote:
"Ian" <ia***************@yahoo.com> wrote in message
news:1k******************************@40tude.net.. . On Tue, 31 Aug 2004 08:31:58 -0400, Rhino wrote:
"Ian" <ia***************@yahoo.com> wrote in message
news:cr***************************@40tude.net...
Hi,
can someone tell me why this join perform sort(saw it in access plan). Is there a book that explains db2 query tuning, especially this kind of
stuff.
SELECT
C.*,
O.*
FROM
crm.CUSTOMER C, crm.ORGANISATION O
WHERE
C.ID = O.ID
A join can require a sort of one or both tables depending on what indexes are available.
I have indexes on both ID's. Is there a way to avoid this sort?
I've already downloaded DB2 manuals for v7.2, but haven't found this sort
of info.
I assume you mean DB2 V7.2 for Windows/Linux/Unix. I have the same manuals
and found a discussion that might answer your question via the search engine
in the IBM DB2/Information application. I searched on "join concepts" and
Rhino, AK thank you both. I run dynexpln and found that query is using
merge join. I also reorganized both tables but sort is stil here.
I will read those chapters you suggested and try to solve this.
This is output from dynexpln:
------------------------------------------------------
Estimated Cost = 128906
Estimated Cardinality = 159397
Access Table Name = CRM.ORGANISATION ID = 2,97
| #Columns = 7
| Relation Scan
| | Prefetch: Eligible
| Lock Intents
| | Table: Intent Share
| | Row : Next Key Share
| Insert Into Sorted Temp Table ID = t1
| | #Columns = 7
| | #Sort Key Columns = 1
| | | Key 1: ID (Ascending)
| | Sortheap Allocation Parameters:
| | | #Rows = 159397
| | | Row Width = 68
| | Piped
Sorted Temp Table Completion ID = t1
Access Temp Table ID = t1
| #Columns = 7
| Relation Scan
| | Prefetch: Eligible
Merge Join
| Early Out: Single Match Per Outer Row
| Access Table Name = CRM.CUSTOMER ID = 2,74
| | #Columns = 17
| | Index Scan: Name = CRM.SQL040720111132250 ID = 1
| | | Index Columns:
| | | | 1: ID (Ascending)
| | | #Key Columns = 0
| | | | Start Key: Beginning of Index
| | | | Stop Key: End of Index
| | | Data Prefetch: Eligible 0
| | | Index Prefetch: None
| | Lock Intents
| | | Table: Intent Share
| | | Row : Next Key Share
Return Data to Application
| #Columns = 24
---------------------------------------------------------
Thanks, Ian