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

JOIN columns question???

Here's an oversimplified version of a query that I'm writing and wanted
to know if there are any performance differences between the two versions.
select *
from table_a a , table_b b
where a.col_1 = b.col_1
and a.col_1 = 1000
versus
select *
from table_a a , table_b b
where a.col_1 = 1000
and b.col_1 = 1000

All the tests show that they run at the same speed. But I have a very
large query that joins 5 tables together and I'm trying to get as much
out of it as possible. Currently it runs at 2 seconds which I really
don't like and would like to get it at under 1 second. So I'm looking
for every little bit.

I've already removed the DISTINCT, which in my test case doesn't do
anything, but still took up one second.
Jan 29 '07 #1
2 1685
MC
Well, why dont you check execution plan for both queries? If thats the same,
the performance should be the same. Also, if you need more help, generate
some real sample here. Select * and no table schema/data doesnt help.
MC

"Don Vaillancourt" <do**@webimpact.comwrote in message
news:hY******************@nnrp.ca.mci.com!nnrp1.uu net.ca...
Here's an oversimplified version of a query that I'm writing and wanted to
know if there are any performance differences between the two versions.
select *
from table_a a , table_b b
where a.col_1 = b.col_1
and a.col_1 = 1000
versus
select *
from table_a a , table_b b
where a.col_1 = 1000
and b.col_1 = 1000

All the tests show that they run at the same speed. But I have a very
large query that joins 5 tables together and I'm trying to get as much out
of it as possible. Currently it runs at 2 seconds which I really don't
like and would like to get it at under 1 second. So I'm looking for every
little bit.

I've already removed the DISTINCT, which in my test case doesn't do
anything, but still took up one second.

Jan 29 '07 #2
Don Vaillancourt (do**@webimpact.com) writes:
Here's an oversimplified version of a query that I'm writing and wanted
to know if there are any performance differences between the two versions.
select *
from table_a a , table_b b
where a.col_1 = b.col_1
and a.col_1 = 1000
versus
select *
from table_a a , table_b b
where a.col_1 = 1000
and b.col_1 = 1000

All the tests show that they run at the same speed. But I have a very
large query that joins 5 tables together and I'm trying to get as much
out of it as possible. Currently it runs at 2 seconds which I really
don't like and would like to get it at under 1 second. So I'm looking
for every little bit.
The latter query looks problematic to me. I recall that I once resolved
a performance issue which was due to that the programmer had joined to
tables only over a variable. This was in SQL 6.5, and the optimizer gets
better for every version, so this may not be an issue anymore.

But when tweaking queries, just poking around with the syntax at random
is time-consuming. A better strategy is to examine the query plans, and
also see if indexing can be improved.

Also keep in mind that if one certain way of writing the query seems to work
better, it may be different next week when statistics have changed.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 29 '07 #3

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

Similar topics

2
by: Preston Landers | last post by:
Hello all. I am trying to write a query that "just" switches some data around so it is shown in a slightly different format. I am already able to do what I want in Oracle 8i, but I am having...
8
by: xixi | last post by:
when i create a join view like this create view JV104FZ.APJTINM1 (APAM32, APNO20, APQY05, PONO01, PONO05, PONO19, POCD01, POCD13, systimestamp, loginname, id ) as select JV104FZ.APPTINM.APAM32,...
3
by: Peter | last post by:
Hi, I have two datatables and I want to efficiently query the intersection of the two using the studentID. In my example code below, I want to print out Mary and Jane and their exam grades and I...
7
by: Chris | last post by:
I'm using ASP.NET and SQL Server and this might be an obviuos question for most, but if I have a table that contains several fields that I need to relate to just one field in another table, how do...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
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
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
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
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
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,...

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.