473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

problem with different access plan (slow & fast) for the same SQL-Statement

Hello,

I'working with IBM DB2 V8.1 and CLI/ODBC. I've got a problem with the
following
statement:

************************************************** ******************************
SELECT S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB, S_OWNER, S_SATZ
FROM SY0001_00005
WHERE S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB =
?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT > ?
OR S_ART = ? AND S_SPRACHE > ?
OR S_ART > ?

ORDER BY S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB FETCH FIRST 1 ROWS
ONLY
************************************************** ******************************

There are two indexes for the table concerned table:

first index "SQL0505250858084" with
S_ART,S_SPRACHE,S_MANDANT,S_NR,S_SUB:
- this is the primary index of the table)
- this index is identical to the ORDER-BY-Clause

second index "SY0001_00005_KEY" with
S_ART,S_MANDANT,S_NR,S_SUB,S_SPRACHE
- created with "CREATE UNIQUE INDEX"

Sometimes the statement runs fast and sometimes it runs very slow
(factor 20-30)
and the EXPLAIN-informations (with db2exfmt) shows different access
plans for
fast and slow version.
If I analyse the execution-tree of EXPLAIN, i can see, that the fast
version only uses the first key, which is identical to the
ORDER-BY-Clause.

But the slow version uses the second key and makes a IXSCAN with
SORT-Operations
for each konjunction/AND-condition of the statement. This seems to be
very slow.

Has anybody an idea? I don't know, which factor affects these choice
of access plans. If anybody is interested, I can send the
execution-trees (generated by db2exfmt) by mail. But the trees are to
big for these edit-box.

Here are two extractions with the different part of the access-plans

*********************************
FAST-PLAN

Access Plan:
-----------
Total Cost: 5174,84
Query Degree: 1

Nov 12 '05 #1
22 3265
Marc Mones wrote:
Hello,

I'working with IBM DB2 V8.1 and CLI/ODBC. I've got a problem with the
following
statement:

************************************************** ******************************
SELECT S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB, S_OWNER, S_SATZ
FROM SY0001_00005
WHERE S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB =
?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT > ?
OR S_ART = ? AND S_SPRACHE > ?
OR S_ART > ?

ORDER BY S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB FETCH FIRST 1 ROWS
ONLY

Can you change the query?
SELECT S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB, S_OWNER, S_SATZ
FROM SY0001_00005
WHERE S_ART >= ? AND
(S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB = ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT > ?
OR S_ART = ? AND S_SPRACHE > ?
OR S_ART > ?)

ORDER BY S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB FETCH FIRST 1 ROWS
ONLY

Bernard is going to love this post....

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Ian
Marc Mones wrote:
Hello,

I'working with IBM DB2 V8.1 and CLI/ODBC. I've got a problem with the
following
statement:

************************************************** ******************************
SELECT S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB, S_OWNER, S_SATZ
FROM SY0001_00005
WHERE S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB =
?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT > ?
OR S_ART = ? AND S_SPRACHE > ?
OR S_ART > ?

ORDER BY S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB FETCH FIRST 1 ROWS
ONLY
************************************************** ******************************


Not sure, but it feels like your predicate isn't doing what you expect.
(Read about operator precedence)
Is this what you mean?

WHERE
(S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB = ?)
OR
(S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB = ?)
OR
(S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR > ?)
OR
(S_ART = ? AND S_SPRACHE = ? AND S_MANDANT > ?)
OR
(S_ART = ? AND S_SPRACHE > ?)
OR
(S_ART > ?)

Nov 12 '05 #3
> Can you change the query?
SELECT S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB, S_OWNER, S_SATZ
FROM SY0001_00005
WHERE S_ART >= ? AND
(S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB = ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR = ? AND
S_SUB > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT = ? AND S_NR > ?
OR S_ART = ? AND S_SPRACHE = ? AND S_MANDANT > ?
OR S_ART = ? AND S_SPRACHE > ?
OR S_ART > ?)

ORDER BY S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB FETCH FIRST 1 ROWS
ONLY

Bernard is going to love this post....

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab


I will try to change it. In our case we work with a
ISAM/Btrieve-Database, too. We need this statement to emulate an
Btrieve-Operation "GET-GREATER OR EQUAL" on an concatenated Byte-Index
consisting of the fields S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB. We
need this
for applications, which are builded on the ISAM-Interface. These
applications
send us "GET_GREATER_EQUAL"-Requests for Key-Values. We have to
transform these
request to SQL or rather relational database.
I hope, that this explanation is comprehensible.

Thank you!

Marc

Nov 12 '05 #4
I will try to change it. In our case we work with a
ISAM/Btrieve-Database, too. We need this statement to emulate an
Btrieve-Operation "GET-GREATER OR EQUAL" on an concatenated Byte-Index
consisting of the fields S_ART, S_SPRACHE, S_MANDANT, S_NR, S_SUB. We
need this
for applications, which are builded on the ISAM-Interface. These
applications
send us "GET_GREATER_EQUAL"-Requests for Key-Values. We have to
transform these
request to SQL or rather relational database.
I hope, that this explanation is comprehensible.

Thank you!

Marc

Nov 12 '05 #5
yes

Nov 12 '05 #6
I've got still one question. Who is Bernard and why will he love this
post?

Nov 12 '05 #7
Still one question? Who ist Bernard and why will he love this post?

Nov 12 '05 #8
I've got still one question. Who is Bernard and why will he love this
post?

Nov 12 '05 #9
<mm****@web.de> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I've got still one question. Who is Bernard and why will he love this
post?

We have seen the question and you don't need to keep repeating it.
Occasionally, the people in the IBM lab in Toronto have other work to do
beside immediately answering your questions.

Bernard probably works in the IBM lab in Toronto where DB2 is developed.
Nov 12 '05 #10
Mark A wrote:
<mm****@web.de> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I've got still one question. Who is Bernard and why will he love this
post?


We have seen the question and you don't need to keep repeating it.
Occasionally, the people in the IBM lab in Toronto have other work to do
beside immediately answering your questions.

Bernard probably works in the IBM lab in Toronto where DB2 is developed.

Bernard is a consultant psoting here, who is trying to convince DB2 Dev
since many years to support row-comparsions like:
(c1, c2, c3) >= (?, ?, ?) or
(c1, c2, c3) BETWEEN (?, ?, ?) AND (?, ?, ?)

If I'm not mistaken his argument matches yours and he'll be glad to have
another customer requesting it.

Cheers
Serge

PS: Please let me know through this group or by email whether the
workaround does it. I have great difficulty judging this priority of
this feature request.
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #11
Does using the syntax I give result in consistent access times?

Nov 12 '05 #12
Hello,

The construct row-value constructors (c1,c2,c3) >= (?,?,?) is part of
SQl-92 and can help in what I call human-search (compared to the
ultimate query) when logical keys are composite.

The posting here illustrates it, the row-value clause allows to express
semantically what is needed with a direct hint I would say for the
optimizer.

After all these years I would be very glad to see it in DB2 UDB LUW.
Indeed.

But after all these years I have come to the conclusion that it would
be only a partial solution (I would already be glad with and a lot of
other developers and end-users also), it is related to scrollable
cursors and cursor positioning.

In the first SQL standard cursors where only fetch forward cursors.

Then in SQL-92 scrollable cursors where introduced but why should the
cursor be at the beginning of the set when scrollable cursors are
available? This is logic from non-scrollable cursors time, if I can
scroll backwards, it must bee possible to do it (without return-code
100) directly after open cursor.

So I see the general solution as:

declare cursor cu1 for select ... from ... where ... order
by ... (the where can contain a row-value clause, where and order by
are optional as alwas, multiple tables can be involved)

open cursur cu1 position cursor where <row-value
constructor clause>

(where clause optional, must match the order by in the
select)

fetch cu1 (next but also previous possible directly after
open, as the cursor is somewhere in the set after open).

A subset of this capability would allow to solve the posting:
select .. from SY0001_00005 where (S_ART , S_SPRACHE,
S_MANDANT, S_NR ,) >= (?,?,?,?,?) order by S_ART , S_SPRACHE,
S_MANDANT, S_NR ...
(just 1 table, optimezer sees what is wanted)

open cursor
(no cursor positioning)

fetch
(beginning of set as no cursor positioning in open)
Not all programmers write in the newsgroup, the question occured more
than once (search in comp.databases.ibm-db2 on: tuning browse
queries,DB2 is not using the index), the row-value constructor clause
is part of the SQL-92 standard, it allows to write interactive search
capabilities when logical indexes are composite, it is just part of the
users world and programmers must be able to map the reality when using
DB2 UDB.
Bernard Dhooghe

Nov 12 '05 #13
Hello Serge,

I have tested your suggested statement with the AND-Case and the () of
the
OR-Cases. But the execution time didn't change. It is still very slow.
I did not yet understand, how I can cause the faster access plan.
Sometime, DB2
chooses this access plan. So it must exist a better solution. It is
possible,
that I can send you the whole access plan of the slow (old), slow
(new, your suggestion)and fast access plan by mail?

It is possible, that some database parameters of db2 affect the choice
of access plan?

Thanks!

Marc

P.S.: MS SQL-Server runs articulately faster with your suggested
SQL-Statement.
Serge Rielau <sr*****@ca.ibm.com> wrote in message news:<3g************@individual.net>...
Mark A wrote:
<mm****@web.de> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I've got still one question. Who is Bernard and why will he love this
post?


We have seen the question and you don't need to keep repeating it.
Occasionally, the people in the IBM lab in Toronto have other work to do
beside immediately answering your questions.

Bernard probably works in the IBM lab in Toronto where DB2 is developed.

Bernard is a consultant psoting here, who is trying to convince DB2 Dev
since many years to support row-comparsions like:
(c1, c2, c3) >= (?, ?, ?) or
(c1, c2, c3) BETWEEN (?, ?, ?) AND (?, ?, ?)

If I'm not mistaken his argument matches yours and he'll be glad to have
another customer requesting it.

Cheers
Serge

PS: Please let me know through this group or by email whether the
workaround does it. I have great difficulty judging this priority of
this feature request.

Nov 12 '05 #14
Hello Serge,

I've tested your suggested access plan with the additional AND-Case.
But it is still slow and doesn't change the execution time. I can not
yet understand, what affects the choice of access plan and there must
exist a possibility to speed up the access plan. Sometimes the same
statement was very fast.

It is possible, that some database parameters affects the choice of
access plan?

It is possbile to send you the whole access plan for slow (old), slow
(new, your suggested SQL-Statement) and fast version by mail?

Thanks!

Marc

P.S.: the following point is funny: your suggested SQL-Statement
speeds up
MS SQL Server articulately. Sorry! But we need DB2 as well.
Serge Rielau <sr*****@ca.ibm.com> wrote in message news:<3g************@individual.net>...
Mark A wrote:
<mm****@web.de> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I've got still one question. Who is Bernard and why will he love this
post?


We have seen the question and you don't need to keep repeating it.
Occasionally, the people in the IBM lab in Toronto have other work to do
beside immediately answering your questions.

Bernard probably works in the IBM lab in Toronto where DB2 is developed.

Bernard is a consultant psoting here, who is trying to convince DB2 Dev
since many years to support row-comparsions like:
(c1, c2, c3) >= (?, ?, ?) or
(c1, c2, c3) BETWEEN (?, ?, ?) AND (?, ?, ?)

If I'm not mistaken his argument matches yours and he'll be glad to have
another customer requesting it.

Cheers
Serge

PS: Please let me know through this group or by email whether the
workaround does it. I have great difficulty judging this priority of
this feature request.

Nov 12 '05 #15
thank you for your these informations

Nov 12 '05 #16
Marc Mones wrote:
Hello Serge,

I've tested your suggested access plan with the additional AND-Case.
But it is still slow and doesn't change the execution time. I can not
yet understand, what affects the choice of access plan and there must
exist a possibility to speed up the access plan. Sometimes the same
statement was very fast.

It is possible, that some database parameters affects the choice of
access plan?

It is possbile to send you the whole access plan for slow (old), slow
(new, your suggested SQL-Statement) and fast version by mail?

Thanks!

Marc

P.S.: the following point is funny: your suggested SQL-Statement
speeds up
MS SQL Server articulately. Sorry! But we need DB2 as well.
Serge Rielau <sr*****@ca.ibm.com> wrote in message news:<3g************@individual.net>...
Mark A wrote:
<mm****@web.de> wrote in message
news:11*********************@g43g2000cwa.google groups.com...
I've got still one question. Who is Bernard and why will he love this
post?
We have seen the question and you don't need to keep repeating it.
Occasionally, the people in the IBM lab in Toronto have other work to do
beside immediately answering your questions.

Bernard probably works in the IBM lab in Toronto where DB2 is developed.


Bernard is a consultant psoting here, who is trying to convince DB2 Dev
since many years to support row-comparsions like:
(c1, c2, c3) >= (?, ?, ?) or
(c1, c2, c3) BETWEEN (?, ?, ?) AND (?, ?, ?)

If I'm not mistaken his argument matches yours and he'll be glad to have
another customer requesting it.

Cheers
Serge

PS: Please let me know through this group or by email whether the
workaround does it. I have great difficulty judging this priority of
this feature request.

Sure you can send it by mail, as long as you understand that my answre
is on a best efford basis. If I get pre-empted or simply forget because
I'm swamped.. that'll be life... PMR is a different (tracked) matter.
Anyway, I did soem poking with backstage and I'm told teh issue apears
to be within "index OR-ing" in teh optimizer. It was proposed to ensure
you have "column-group statistics" collected to ensure the optimizer is
aware of correlation between the index members.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #17
Hello Serge,

ok, I will send the 3 extractions from db2exfmt by mail (to
sr*****@ca.ibm.com).

I built in the "column-group statistics", but there is now effect. Is
there anything else to consider with making
statistics?
Thank you for your efforts in advance!

Marc

Nov 12 '05 #18
Another point is peculiar, too. The plans, which are slow in reality,
have got a better TOTAL-COST approximation in EXPLAIN-informations.

Marc

Nov 12 '05 #19
Repeating this mail was a little mistake in using the
GOOGLE-Group-Menu. I didn't really want this. sorry!

Marc

Nov 12 '05 #20
mm****@web.de wrote:
Another point is peculiar, too. The plans, which are slow in reality,
have got a better TOTAL-COST approximation in EXPLAIN-informations.

Marc

I got someone form the optimizer to help. Staring at the beast by trick
should have stabilized the plan.
I am someone confused why you are using a scrollabel cursor (for 1 row!)
Is this puprose or are you the victim of some client default (Rumours
have it JDBC has the nasty habit to default every cursor to scrollable)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #21
Makes it sense, to contact the official german IBM DB2 support
concerning this problem? but I think they don't have your know-how, or?

Thank you for your efforts in advance!

Marc

Nov 12 '05 #22
mm****@web.de wrote:
Makes it sense, to contact the official german IBM DB2 support
concerning this problem? but I think they don't have your know-how, or?

*lol*As always when you call any customer support anywhere. You roll
your dice, you take your chances.
We DO have "darn good" (the words of the optimizer team lead) folks in
European support.
Given that the plans have wildly different system specs you'll have to
overcome that hurdle of "you're comparing oranges with apples.. go
away!" first.
Let's run this through "L0" support for now and see where it goes.
As long as I can keep backstage interested enough to not point to the
virtual clock.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going...
5
by: Jason | last post by:
The following stored procedure is taking too long (in my opinion). The problem seems to be the SUM line. When commented out the query takes a second or two. When included the response time climbs...
5
by: Krisnamourt Correia via SQLMonster.com | last post by:
I have one query that executes many times in a week. I created one Maintenances plan that Rebuild all index in my Database that has been executed at 23:40 Saturday until stop finished at Sunday. ...
23
by: Rudolf Bargholz | last post by:
Hi, I have a ralatively simple SQL: select FK from TABLE where upper(A) like 'B%' and upper(C) like 'D%' We have DB2 UDB v7.1 FP 12 installed on Linux and on Windows 2003 On Linux using...
5
by: sql-db2-dba | last post by:
We have DB2 UDB v8.1 fixpak3 on AIX 5. Production and Development configuarations (at least for DB2) are identical albeit production is a 2-way server while development has only one processor....
15
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size (cache??)/number of records showing in Access? ...
3
by: francois | last post by:
Hi guys, I have quite big troublesome performance problem. then i did a very simpkle page with a dropdownlist, when u click on it it makes a simple sql select on the SQL server and then...
29
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
1
by: Dmitri | last post by:
Hi! I have a stored procedure that takes 22 minutes to run in one environment, that only takes 1 sec or so to run in another environment. Here is the exact situation: Database 1 on Server 1...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.