473,386 Members | 1,804 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,386 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 3529
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.