473,396 Members | 2,013 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.

Fairly simple query taking a long time to process

10
Hi all,

I have a table with 300,000 records in it and I want to run an update that has a few clauses in the WHERE command and just changes one boolean value on a subset of records. What I am curious about is the query, (if it works at all) takes ages to complete. I suppose 300,000 records is alot to process and I will sometimes want to change this boolean value on up to 20,000 of those, but I have had times of over an hour and it is still thinking. I usually break it and try again. I can break the query up into its component parts and they each run fine, but I think it is the combination of the "...Key NOT IN (..." part that causes the slowdown. The query is :

UPDATE Exclusion1 SET Exclusion1.Dumped = True
WHERE (Exclusion1.Job_Code = "xxxxxx" AND Exclusion1.Dumped = False)
AND Exclusion1.Key NOT IN (SELECT Key FROM Exclusion1 WHERE Exclusion1.Dumped =True);

NB: "Key" in this case is not the primary key just a number.

Is there a logic issue with my query? Should I be using EXISTS or something?
When I am using the query there is a subset within the table identified by a job code. Some of these records have the same key number as others. These records always have one that is marked as True and one as false. What I want to do is find all the records of the job code in question that are currently marked as false for the "Dumped" boolean and then set the flag to true for the ones that don't have multiple occurrences of the "Key" value.

Any ideas?
Thanks
Shal
Nov 30 '07 #1
3 7239
By using a sub query ("NOT IN"), I would say that you do NOT had a simple query.

I thinks the speed issue comes form the fact the the sub query get re-run for every single row.

Is "Key" indexed? If not, try adding an index on the field.
Nov 30 '07 #2
Shal
10
Yeah the "Key" field has the indexed setting set to "Yes (Duplicates OK)"

So I guess I didn't understand the nature of the NOT IN command.

Sounds like I would need to export the required records to a temp table and run it on that then insert them back again after the query finishes.

Is there a more efficient way to do it than that?

Shal
Nov 30 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
As key is not a primary key this may not be very efficient either. Worth a try though. However, be sure to back up a copy of your table first.

Expand|Select|Wrap|Line Numbers
  1. UPDATE Exclusion1 LEFT JOIN Exclusion1 As E2
  2. ON Exclusion1.Key = E2.Key
  3. SET Exclusion1.Dumped = True
  4. WHERE (Exclusion1.Job_Code = "xxxxxx" 
  5. AND Exclusion1.Dumped = False) 
  6. AND E2.Dumped =False);
  7.  
Dec 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bacci | last post by:
I have two tables. The first is "Locations" which has 52,000 zip codes w/cooresponding latitudes and longitudes. The second "Suppliers" has 2,000 company names and addresses. The user enters a...
11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
0
by: Dave | last post by:
Hi all, I have a problem with a query. (well, I actually have a few problems...) Here is my query. select FOCUS.SiteName, FOCUS.URL, OTWAdCars.* , REGION.SiteName as RegionSite, REGION.URL...
4
by: DBNovice | last post by:
I have a database that keeps records on the issue and failure of an item. Currently, the database is poorly desisned; therefore I'm performing queries to break the data into normalized tables and...
16
by: audleman | last post by:
I'm attempting to build a query that involves a table called "All Students". The query is simply sqlString = "SELECT * FROM All Students" but I get "Syntax error in FROM clause" when I try...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
2
by: Brian Kitt | last post by:
I have a process where I do some minimal reformating on a TAB delimited document to prepare for DTS load. This process has been running fine, but I recently made a change. I have a Full Text...
3
by: rfuscjr via AccessMonster.com | last post by:
This is truly bizzare. I have a query that runs for hours in one Access db. When I import it into another Access db, it runs in minutes. I compacted and repaired the original, relinked tables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...

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.