View previous topic :: View next topic |
Author |
Message |
rsantosh Beginner
Joined: 20 Dec 2014 Posts: 38 Topics: 9
|
Posted: Thu May 28, 2020 5:20 am Post subject: SPUFI vs Stored PROC Access path |
|
|
Hi,
I am running same query through batch SPUFI and SP but they use different access path when I EXPLAIN. The only difference is SPUFI has host variable values while SP has host variables.
e.g. EMP table has say 2 indexes X1 X2
in SPUFI
Code: | SELECT ID
FROM EMP
WHERE ID = 100
AND NAME = 'SANTOSH'
|
SPUFI selects index X1
In SP
Code: |
SELECT ID
FROM EMP
WHERE ID = :HOST-ID
AND NAME = :HOST-NAME |
SP selects index X2
Why is DB2 choosing different access path?
Regards,
Santosh |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Thu May 28, 2020 12:01 pm Post subject: |
|
|
rsantosh,
You haven't shown the entire output from the EXPLAIN. One of the reason is that SPUFI case is using One-fetch index access which requires retrieving only one row. That is because you specifically provided the info that would result in 1 row.
When you are using host variables, it might be using index-only access.
I would start the analysis using this link.
Interpreting data access by using EXPLAIN and then Questions for investigating data access _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
rsantosh Beginner
Joined: 20 Dec 2014 Posts: 38 Topics: 9
|
Posted: Sat May 30, 2020 8:41 am Post subject: |
|
|
Hi Kolusu,
Thank you. I will go through the link.
To provide further detail. Unique Index X1 is on column ID while Duplicate Index X2 on NAME and ID(please ignore how can different name have same ID, what I provided is just to replicate the actual query which has many columns in index).
Apologies if this is not very useful.Unfortunately I can not share the EXPLAIN as it contains the customer query. What I provided was the identical query.
What makes SPUFI go for X1 and not for X2 like SP.
Code: |
SPUFI SP
Index X1 Index X2
INDEXED ACCESS Indexed Access
1 OF 1 COL MATCHED 1 OF 2 COL MATCHED
Sequential prefetch will be employed during this index only access
|
|
|
Back to top |
|
|
haatvedt Beginner
Joined: 14 Nov 2003 Posts: 66 Topics: 0 Location: St Cloud, Minnesota USA
|
Posted: Sat Jun 20, 2020 1:22 pm Post subject: |
|
|
Santosh,
the access path for SPUFI is accessing the current DB2 stats to determine the access path
the access path for the SP is using the DB2 stats at the time the BIND was done on the SP
most likely the DB2 stats have changed between the time the SP BIND was done and when the SPUFI was run. _________________ Chuck Haatvedt
email --> clastnameatcharterdotnet
(replace lastname, at, dot with appropriate
characters) |
|
Back to top |
|
|
|
|