473,856 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Planning multiple queries

I'm cleaning data which involves updating ~12 million rows with three
different models, progressively. First clean values using the model
with finest granularity, then the remainder with the next model,
finally what's left using the last model. The first model sets ~1/2 of
the rows, the second ~1/4, the third ~1/5, and the remaining 5% don't
get updated.

It's something like this:

UPDATE t SET value=value*m.A djustmentFactor , updateFlag='upd ated'
FROM Table t JOIN Models m ON ....
WHERE m.ModelID='firs t model' AND t.updateFlag IS NULL

Start with 'first model' then 'second model' etc.

I'm wondering what happens if I submit all three queries together, or
as three separate submissions, waiting for the one before to complete.
If I do them all as one group, the query planner might plan for the
second and third updates based on the initial distribution of values.
However, the first update removes half of the rows from consideration,
so it seems to me a new plan should be prepared for the second query,
based on the distribution at that time. If I highlight the queries in
Query Analyzer and execute, are all three plans created at the
beginning? Does putting GO between them (which I do) make any
difference?

This is SQL Server 2000.

Thanks,
Jim

Dec 2 '05 #1
2 1454
(ji**********@c ountrywide.com) writes:
I'm cleaning data which involves updating ~12 million rows with three
different models, progressively. First clean values using the model
with finest granularity, then the remainder with the next model,
finally what's left using the last model. The first model sets ~1/2 of
the rows, the second ~1/4, the third ~1/5, and the remaining 5% don't
get updated.

It's something like this:

UPDATE t SET value=value*m.A djustmentFactor , updateFlag='upd ated'
FROM Table t JOIN Models m ON ....
WHERE m.ModelID='firs t model' AND t.updateFlag IS NULL

Start with 'first model' then 'second model' etc.

I'm wondering what happens if I submit all three queries together, or
as three separate submissions, waiting for the one before to complete.
If I do them all as one group, the query planner might plan for the
second and third updates based on the initial distribution of values.
However, the first update removes half of the rows from consideration,
so it seems to me a new plan should be prepared for the second query,
based on the distribution at that time. If I highlight the queries in
Query Analyzer and execute, are all three plans created at the
beginning? Does putting GO between them (which I do) make any
difference?


If you submit them all in one batch, SQL Server generates a query plan
for all three queries at that point. However, if the first update
causes suffciently many rows to be updated, this may trigger auto-
statistcs to set in, which can lead to the entire query batch to be
recompiled. So in this case, using separate batches is a little more
effective, as you avoid the recompilations. But I suspect that's a
negliglible part of the operation.

If no statistics get updated as result of the query, it will not matter
how you submit them.

The recompilation threshold is when 20% of the rows has changed, so
judging from your description, there is a fair chance that you will
get statistics updated. And, of course, if there were no statistics
when SQL Server started, it will create statistics automatically.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.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
Dec 2 '05 #2
Thank you, Erland.

Jim

Dec 2 '05 #3

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

Similar topics

4
16761
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from customers; I can execute each statement individually but get the 'you have an error in
6
1939
by: Steven D.Arnold | last post by:
I have a query which does not use column indexes that it should use. I have discovered some interesting behaviors of Postgres which may indicate a bug in the database's query planning. Take a look at the query below. There is a btree index on both m.account_id and a.account_id. Query (1) does not use the index on the messages table, instead opting for a full table scan, thus killing performance. The messages table can contain...
2
1777
by: Atreju | last post by:
I apologize in advance for the x-post, but I am really not sure where this would best be addressed. I am designing a database in MSAccess for which I want to make the front-end in VB. I have planned out the basic structure of the tables and fields. However, my experience with Access is limited to doing all the work within Access, so I have a couple of issues I'm confused about.
2
4780
by: Koen | last post by:
Hi all, Is there any example code available somewhere that graphical visualizes a simple network planning (PERT chart)? I have two tables: tblAction: ActionID (PK) Description
1
3462
by: Jeremy | last post by:
I have built a form that calls queries. I have the first 2 set up as select queries, and the third set up as a make table query. When multiple users are on this application at the same time, they get errors or the data is overwritten while they are sitting there. If I do all select queries, 1. the records pop up if I use a "RUN" command button, or if I have my "Report" command button set to the last query then each time they hit one of...
0
8786
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11 Append Queries) when the Database is first opened, and then again anytime I invoke the Macro (somehow) after the database is already open. The latter function is useful, because the queries must be rerun every time data is added, deleted, or...
4
3760
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure and username, password etc will be exactly the same for each server, the only thing that will change is the server name. Idealy I would like to get the server names from a seperate dataset so there could be any number of servers, allthough in...
8
3193
by: beretta819 | last post by:
Ok, so I apologize in advance for the wordiness of what follows... (I am not looking for someone to make this for me, but to point me in the right direction for the steps I need to take.) I was nominated at work to design a "system" that would allow us to track the performance of our employees. So I thought Access. Should be simple enough because I have made simple DB's with it before. I was wrong. This has turned into a bigger deal than I...
14
6696
by: Supermansteel | last post by:
My team at work uses Cognos to run multiple queries to pull in data. Then they take that data and import into Access and then usually run an Append Query to run a RND function to pull out a few samples for them to review the accounts. I was making a suggestion to my team that maybe if we only ran one Cognos query and pulled in all of the columns that everyone needs to pull samples for each of there tests that this would be better on the time...
0
9904
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10692
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10772
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10378
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7928
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7086
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.