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

What am I missing?

Been too long since I wrote queries but this one bugs me. Two fairly
large tables (DB2 7.2 and a remote DB2 server), one needs to update
fairly often based upon some properties stored in the first (in the
remote DB). I cobbled this together and it works, but as the local
table grows performance goes to pot in a hurry

UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME = (SELECT DISTINCT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

I've forgotten what the problem with the above update is exactly (been
5 years or so since I did much SQL) and would apprecitate someone
pointing out just what is causing the slowdown.

When I was doing a lot of this I had a web site that had excellent
tutorial coverage of this kind of question but I've lost the URL - any
suggestions on a good 'SQL for Dummies' site?

--
Will Honea
Nov 12 '05 #1
5 1551
Hi Will.

Will Honea wrote:
UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME = (SELECT DISTINCT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

I've forgotten what the problem with the above update is exactly (been
5 years or so since I did much SQL) and would apprecitate someone
pointing out just what is causing the slowdown.


I guess, the above statement is slow because it contains a correlated
subquery (I dont't know if that's the exact english name, sorry if not).
For each row in TABLE2, the subquery is executed and returns either zero
or one row, depending on whether TABLE1 contains the name or not. Iff a
row is returned, the "current" row of TABLE2 is updated.
The statement will be faster if you remove the correlation, for example
like this:

update table2
set valid_info='Y'
where name in ( select name from table1 )

hth,
Benjamin
--
Please compose your messages as plaintext:
http://www.netby.dk/Oest/Europa-Alle/vermeer/plain.html
And do not send MS Office attachments:
http://www.goldmark.org/netrants/no-word/attach.html
Nov 12 '05 #2
Will Honea wrote:
Been too long since I wrote queries but this one bugs me. Two fairly
large tables (DB2 7.2 and a remote DB2 server), one needs to update
fairly often based upon some properties stored in the first (in the
remote DB). I cobbled this together and it works, but as the local
table grows performance goes to pot in a hurry

UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME = (SELECT DISTINCT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

I've forgotten what the problem with the above update is exactly (been
5 years or so since I did much SQL) and would apprecitate someone
pointing out just what is causing the slowdown.

When I was doing a lot of this I had a web site that had excellent
tutorial coverage of this kind of question but I've lost the URL - any
suggestions on a good 'SQL for Dummies' site?

I would use:
UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME IN (SELECT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

or EXISTS(SELECT 1
FROM TABLE1
WHERE TABLE1.NAME WHERE TABLE1.NAME = TABLE2.NAME)
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
On Fri, 4 Feb 2005 12:41:45 UTC Serge Rielau <sr*****@ca.ibm.com>
wrote:
Will Honea wrote:
Been too long since I wrote queries but this one bugs me. Two fairly
large tables (DB2 7.2 and a remote DB2 server), one needs to update
fairly often based upon some properties stored in the first (in the
remote DB). I cobbled this together and it works, but as the local
table grows performance goes to pot in a hurry

UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME = (SELECT DISTINCT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

I've forgotten what the problem with the above update is exactly (been
5 years or so since I did much SQL) and would apprecitate someone
pointing out just what is causing the slowdown.

When I was doing a lot of this I had a web site that had excellent
tutorial coverage of this kind of question but I've lost the URL - any
suggestions on a good 'SQL for Dummies' site?

I would use:
UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME IN (SELECT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

or EXISTS(SELECT 1
FROM TABLE1
WHERE TABLE1.NAME WHERE TABLE1.NAME = TABLE2.NAME)


OK, I see where this goes and the fog is lifting - I was doing a full
select on table1 for every row of table2. I used the access plan tool
(things have sure improved since I fought with 5.2 and 6.1 4-5 years
back!) and the size of the mess became obvious. Thanks for pointing
what is a subtle difference with enormous consequences.

--
Will Honea
Nov 12 '05 #4
I think a common table expression is executed only once and reused.
You may try it to see if it helps.
WITH ... AS ... (... distinct...) Select ...
PM

"Will Honea" <wh****@yahoo.com> a écrit dans le message de
news:Jx***************************@anon.none.net.. .
Been too long since I wrote queries but this one bugs me. Two fairly
large tables (DB2 7.2 and a remote DB2 server), one needs to update
fairly often based upon some properties stored in the first (in the
remote DB). I cobbled this together and it works, but as the local
table grows performance goes to pot in a hurry

UPDATE TABLE2 SET VALID_INFO ='Y'
WHERE TABLE2.NAME = (SELECT DISTINCT TABLE1.NAME
FROM TABLE1
WHERE TABLE1.NAME
= TABLE2.NAME)

I've forgotten what the problem with the above update is exactly (been
5 years or so since I did much SQL) and would apprecitate someone
pointing out just what is causing the slowdown.

When I was doing a lot of this I had a web site that had excellent
tutorial coverage of this kind of question but I've lost the URL - any
suggestions on a good 'SQL for Dummies' site?

--
Will Honea

Nov 12 '05 #5
to my best knowledge, not always

Nov 12 '05 #6

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

Similar topics

28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
5
by: SimpSity | last post by:
I am a complete noob, what book would be the best for complete begginers, u know the ones that could teach a a retarted neborn monkey to program C++ thats the kind of thing im looking for alotr of...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
1
by: Sarah | last post by:
Hello. I am using Microsoft.Office.Interop.Excel in a C# .NET project. I want to open an Excel application with a specific file name. I am currently opening it with this code: ...
1
by: bradleyc | last post by:
Definately need my eyes checked... Error:asstester.cpp(300,1):Declaration missing ; Error:asstester.cpp(300,1):Compound statement missing } void doModify() { clrscr(); char inputv,...
0
by: kris | last post by:
hi can any one help me out, i have written a code for Word Indexing using Dll's i think this is an incomplete code for WORD INDEX. I had encountered this error "Error! No index entries found"...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
5
by: le0 | last post by:
Hello guys, Im really having a hard time doing this, I have a record set with the ItemNo field with the data type as Text. In the record that I have, I want to find the missing number in the...
20
by: mc | last post by:
I may be opening a can of worms and don't want to start a religious war, but... What features of Java do Java programmers miss when working in C#? Other than, of course, great portability. C#...
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: 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
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.