473,407 Members | 2,306 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,407 software developers and data experts.

very very slow query with parameters

Hi,
I have a problem with db2 query...
I access to my database via jdbc using com.ibm.db2.jcc.DB2Driver. I
build my string query in a java class. I have some parameters in my
query, but there are two of these which gives me some problems:
If I set the condition in the string: "...and myfield between 20001 and
20520..." all works properly. But if I want to set the values via
parameters writing "...and myField between ? and ?..."

and then I value the parameters with values "20001" and "20520" when I
execute th query it doesn't give me nothing, no errors and no results;
all remain locked...:( I waited for some minutes, but the query without
the 2 parameters finish in 10-20 seconds...

P.S. 1: myfield is integer
P.S. 2: In the same query I have other parameters, and these works
properly....

Does anybody can help me?

Thank you
Alessandro Rossi

Jan 4 '06 #1
1 3537
al******@libero.it wrote:
Hi,
I have a problem with db2 query...
I access to my database via jdbc using com.ibm.db2.jcc.DB2Driver. I
build my string query in a java class. I have some parameters in my
query, but there are two of these which gives me some problems:
If I set the condition in the string: "...and myfield between 20001 and
20520..." all works properly. But if I want to set the values via
parameters writing "...and myField between ? and ?..."

and then I value the parameters with values "20001" and "20520" when I
execute th query it doesn't give me nothing, no errors and no results;
all remain locked...:( I waited for some minutes, but the query without
the 2 parameters finish in 10-20 seconds...

P.S. 1: myfield is integer
P.S. 2: In the same query I have other parameters, and these works
properly....

The reason may be that the BETWEEN predicate has a very good
selectivity, but without the actual values DB2 doesn't know that.
So... you have two choices.
1. Use the SELECTIVITY clause on the predicate
This is an SQL statement change which will tell DB2 which
selectivity you anticipate from the predicate.
http://publib.boulder.ibm.com/infoce...n/r0000754.htm
To enable this outside of user defined predicates you need to:
db2set DB2_SELECTIVITY = ALL
http://publib.boulder.ibm.com/infoce...n/r0005664.htm
(and restart the instance.. sorry)
2. Use REOPT(ONCE) for your environment.
This directive tells DB2 that it should wait with the compilation
of any SQL until it gets the first set of values for the parameters.
So the plan is "trained" with these values.
Now, I have no clue how to set this for JDBC. Presumably you need to
rebind the CLI packages with that option.(?)

--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 4 '06 #2

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

Similar topics

11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
3
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
2
by: TD | last post by:
I created a report that contains a OLE Unbound object that is a graph. I added the code below to the Detail, Format event. When I run the report it takes approx. 50 seconds for it to open. If I...
3
by: Mario Soto | last post by:
Hi. i hava a postresql 7.4.2 in a production server. tha machine is a Pentium IV 2,6 GHZ AND 1 GB IN RAM with lINUX RH 9.0. The postresql.conf say: ...
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
4
by: pmacdiddie | last post by:
I have an append query that needs to run every time a line item is added to a subform. The append writes to a table that is the source for a pull down box. Problem is that it takes 5 seconds to...
9
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very...
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...
3
by: Richard Hollenbeck | last post by:
I hope this isn't too confusing. The following query runs pretty fast by itself, but when I want to use it in a report (pasted below the query), it takes at least fifteen seconds to run! Then I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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.