473,387 Members | 1,365 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,387 software developers and data experts.

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 2520
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
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
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
by: Eugenio | last post by:
Excuse me in advance fo my little English. I've got this stored procedure **************************************************************************** ********** declare @Azienda as...
8
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
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
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
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
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
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
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
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:
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.