473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query performance

I am currently using the following query to select rows for a report. It
takes forever, even though there are < 100 rows in the result set; The
problem is that animals, epd and ent_herdid are all large tables, but
the selected rows of animal_sets are always much fewer. I, not being an
SQL guru by any means tried the second select statement in order to
reduce the size of the join operations early. DB2 must know about my
lack of expertise, I swear I heard chuckling along with my error message
(but that might have the currently playing cut on my sound system)
reproduced even further below.

Any suggestions on how I can improve the performance would be greatly
appreciated.

BTW bhid is the primary key or an index of animals, epd and ent_herdid.

"SELECT tattoo, herd_id tag,namex,prefix,regnum,t2.*
FROM ($schema.animals t1 LEFT OUTER JOIN
$schema.epd t2 on t1.bhid=t2.bhid)
JOIN $schema.ent_herdid t3 on t1.bhid=t3.bhid
WHERE t1.bhid IN
(SELECT bhid FROM $schema.animal_sets
WHERE set_name='$setname' AND userid='$setuser')";

SELECT tattoo, herd_id tag,namex,prefix,regnum,t2.*
FROM (is3.animals t1 WHERE t1.bhid IN
(SELECT bhid FROM is3.animal_sets
WHERE set_name='AN' AND userid='jhough')
LEFT OUTER JOIN
is3.epd t2 on t1.bhid=t2.bhid)
JOIN is3.ent_herdid t3 on t1.bhid=t3.bhid;
[IBM][CLI Driver][DB2/LINUX] SQL0104N An unexpected token "WHERE" was
found following "FROM (is3.animals t1". Expected tokens may include:
"JOIN". SQLSTATE=42601

Nov 12 '05 #1
2 2526
You need a SELECT ... FROM <tablename> WHERE <predicate>
Just (<tablename> WHERE <predicate>) alone is a not a legal SQL query.
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
Robert Stearns wrote:
I am currently using the following query to select rows for a report. It
takes forever, even though there are < 100 rows in the result set; The
problem is that animals, epd and ent_herdid are all large tables, but
the selected rows of animal_sets are always much fewer. I, not being an
SQL guru by any means tried the second select statement in order to
reduce the size of the join operations early. DB2 must know about my
lack of expertise, I swear I heard chuckling along with my error message
(but that might have the currently playing cut on my sound system)
reproduced even further below.

Any suggestions on how I can improve the performance would be greatly
appreciated.

BTW bhid is the primary key or an index of animals, epd and ent_herdid.

"SELECT tattoo, herd_id tag,namex,prefix,regnum,t2.*
FROM ($schema.animals t1 LEFT OUTER JOIN
$schema.epd t2 on t1.bhid=t2.bhid)
JOIN $schema.ent_herdid t3 on t1.bhid=t3.bhid
WHERE t1.bhid IN
(SELECT bhid FROM $schema.animal_sets
WHERE set_name='$setname' AND userid='$setuser')";


I have no hard data to support this, but very ofter I get much better
response times by using a correlated subquery (as opposed to an
uncorrelated one as in your case). You could try this:

SELECT tattoo, herd_id tag, namex, prefix, regnum, t2.*
FROM ($schema.animals t1 LEFT OUTER JOIN
$schema.epd t2 on t1.bhid=t2.bhid) JOIN
$schema.ent_herdid t3 on t1.bhid=t3.bhid
WHERE EXISTS ( SELECT 1
FROM $schema.animal_sets AS a
WHERE a.set_name = '$setname' AND
a.userid = '$setuser' AND
a.bhid = t1.bhid )";

Also, do you have an index on the columns "set_name" and/or "userid" of the
table "animal_sets"?

p.s: The usual performance-related steps should also be applied like looking
at the query plan and physical database design.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #3

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

Similar topics

3
3021
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...
3
5204
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
11
5375
by: Eugenio | last post by:
Excuse me in advance fo my little English. I've got this stored procedure **************************************************************************** ********** declare @Azienda as...
8
3224
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
15
5625
by: Rolan | last post by:
There must be a way to enhance the performance of a query, or find a plausible workaround, but I seem to be hitting a wall. I have tried a few tweaks, however, there has been no improvement. ...
14
3470
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
1
2613
by: rdemyan via AccessMonster.com | last post by:
My application has a table that contains information on buildings. The building data comes from another database and is imported from a spreadsheet into my application. Originally, I thought...
2
2407
by: Brian Tabios | last post by:
Hello Everyone, I have a very complex performance issue with our production database. Here's the scenario. We have a production webserver server and a development web server. Both are running...
0
3282
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex...
1
4190
by: Jimbo | last post by:
I have a query..if you look at the bottom of the where clause you'll see an "NOT IN" statement that is really hanging up the query..i'm trying to replace with a "NOT EXISTS" but it isnt appearing...
0
7199
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
7074
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
7322
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
5572
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
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.