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

Performance of SQL

In the query below (in php format, but the intent should be clear), the
result set from the sub select is always 1% or less of each of the two
tables which are joined in the main query. Is the query planner smart
enough to know (discover?) this or should rewrite the query as the join
of two sub selects (for which I could use some syntax help)? I ask
because some variant of this query is used by all of my reporting and
multiple row display screens, so its performance will impact the whole
application (also, it feels slow, but since I am the sole user, I could
be seeing buffer or other effects of the application sleeping for "long"
times and having to be woken up). If it makes a difference, I'm running
DB2 v 8.1.5 on a Linux system, with the application being
apache/php/Smarty. Any thought/assistance would be greatly appreciated.

$sql = "SELECT herd_id tag,namex,prefix,regnum,sex,birth_date,
sire_bhid,dam_bhid,location locationid,
'Exp Ranches (100%)' owners
FROM $schema.animals t1
JOIN $schema.ent_herdid
ON t1.bhid=t2.bhid
WHERE t1.bhid IN
(SELECT bhid FROM $schema.animal_sets
WHERE set_name='" . $_SESSION["setid"] . "')";
/

Nov 12 '05 #1
3 1474
Do a rewrite of the query - making a little result before doing the join.
I can't do the exact wrting, because I can't see which column comes from
which table.
But something like :

Select xxx, yyy
from
(select z
from animals t1
join animal_sets t2
on t1.bhid = t2.bhid
) as s1
join ent_herdid t3
on s1.bhid = t3.bhid
"Robert Stearns" <rs**********@charter.net> wrote in message
news:10*************@corp.supernews.com...
In the query below (in php format, but the intent should be clear), the
result set from the sub select is always 1% or less of each of the two
tables which are joined in the main query. Is the query planner smart
enough to know (discover?) this or should rewrite the query as the join
of two sub selects (for which I could use some syntax help)? I ask
because some variant of this query is used by all of my reporting and
multiple row display screens, so its performance will impact the whole
application (also, it feels slow, but since I am the sole user, I could
be seeing buffer or other effects of the application sleeping for "long"
times and having to be woken up). If it makes a difference, I'm running
DB2 v 8.1.5 on a Linux system, with the application being
apache/php/Smarty. Any thought/assistance would be greatly appreciated.

$sql = "SELECT herd_id tag,namex,prefix,regnum,sex,birth_date,
sire_bhid,dam_bhid,location locationid,
'Exp Ranches (100%)' owners
FROM $schema.animals t1
JOIN $schema.ent_herdid
ON t1.bhid=t2.bhid
WHERE t1.bhid IN
(SELECT bhid FROM $schema.animal_sets
WHERE set_name='" . $_SESSION["setid"] . "')"; /

Nov 12 '05 #2
I forgot your where clause ...

Select xxx, yyy
from
(select z
from animals t1
join animal_sets t2
on t1.bhid = t2.bhid
and t2.set_name='" . $_SESSION["setid"]
) as s1
join ent_herdid t3
on s1.bhid = t3.bhid

"Robert Stearns" <rs**********@charter.net> wrote in message
news:10*************@corp.supernews.com...
In the query below (in php format, but the intent should be clear), the
result set from the sub select is always 1% or less of each of the two
tables which are joined in the main query. Is the query planner smart
enough to know (discover?) this or should rewrite the query as the join
of two sub selects (for which I could use some syntax help)? I ask
because some variant of this query is used by all of my reporting and
multiple row display screens, so its performance will impact the whole
application (also, it feels slow, but since I am the sole user, I could
be seeing buffer or other effects of the application sleeping for "long"
times and having to be woken up). If it makes a difference, I'm running
DB2 v 8.1.5 on a Linux system, with the application being
apache/php/Smarty. Any thought/assistance would be greatly appreciated.

$sql = "SELECT herd_id tag,namex,prefix,regnum,sex,birth_date,
sire_bhid,dam_bhid,location locationid,
'Exp Ranches (100%)' owners
FROM $schema.animals t1
JOIN $schema.ent_herdid
ON t1.bhid=t2.bhid
WHERE t1.bhid IN
(SELECT bhid FROM $schema.animal_sets
WHERE set_name='" . $_SESSION["setid"] . "')"; /

Nov 12 '05 #3
You need to use the EXPLAIN facility to find out.

"Robert Stearns" <rs**********@charter.net> wrote in message
news:10*************@corp.supernews.com...
In the query below (in php format, but the intent should be clear), the
result set from the sub select is always 1% or less of each of the two
tables which are joined in the main query. Is the query planner smart
enough to know (discover?) this or should rewrite the query as the join
of two sub selects (for which I could use some syntax help)? I ask
because some variant of this query is used by all of my reporting and
multiple row display screens, so its performance will impact the whole
application (also, it feels slow, but since I am the sole user, I could
be seeing buffer or other effects of the application sleeping for "long"
times and having to be woken up). If it makes a difference, I'm running
DB2 v 8.1.5 on a Linux system, with the application being
apache/php/Smarty. Any thought/assistance would be greatly appreciated.

$sql = "SELECT herd_id tag,namex,prefix,regnum,sex,birth_date,
sire_bhid,dam_bhid,location locationid,
'Exp Ranches (100%)' owners
FROM $schema.animals t1
JOIN $schema.ent_herdid
ON t1.bhid=t2.bhid
WHERE t1.bhid IN
(SELECT bhid FROM $schema.animal_sets
WHERE set_name='" . $_SESSION["setid"] . "')"; /

Nov 12 '05 #4

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

Similar topics

25
by: Brian Patterson | last post by:
I have noticed in the book of words that hasattr works by calling getattr and raising an exception if no such attribute exists. If I need the value in any case, am I better off using getattr...
12
by: Fred | last post by:
Has anyone a link or any information comparing c and c++ as far as execution speed is concerned? Signal Processing algorithms would be welcome... Thanks Fred
12
by: serge | last post by:
I have an SP that is big, huge, 700-800 lines. I am not an expert but I need to figure out every possible way that I can improve the performance speed of this SP. In the next couple of weeks I...
6
by: teedilo | last post by:
We have an application with a SQL Server 2000 back end that is fairly database intensive -- lots of fairly frequent queries, inserts, updates -- the gamut. The application does not make use of...
5
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
7
by: Michael D. Ober | last post by:
When calling Enqueue, the internal array may need to be reallocated. My question is by how much? In the old MFC array classes, you could tell MFC how many additional elements to add to the array...
1
by: jvn | last post by:
I am experiencing a particular problem with performance counters. I have created a set of classes, that uses System.Diagnostics.PerformanceCounter to increment custom performance counters (using...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.