I came across a situation that I've been unable to explain and was
hoping somebody had an answer:
I had written an update query which was taking about 8 seconds to run
and considered it too slow. I copied the SQL statement from the query
and tried executing it from code which then ran in 1 second. To make
sure that I didn't miss anything, I copied the SQL statement back into
a query and tried running it again. It now also only took 1 second
and looked exactly the same as before. I later realized that if I
take the original query, change it to SQL view and run it, then change
it back to design view and save it, it acomplishes the same thing.
The query looks exactly the same as before, but appears to have been
optimized somehow by running as a SQL statement first (either from
code or simply from the SQL view of the query).
Just to clear this from the discussion, I understand that a query can
run faster the second time around (I believe do to optimization), so I
made sure that when I compared them, I always ran them twice to
eliminate this from being the answer. Even after running the query
several times in its original state, it took 8 seconds. After simply
changing the view to SQL, running it, and changing it back, it always
takes 1 second thereafter.
If anybody has an answer to this, I would appreciate it.
Ryan 6 4472
When you save a query and run it, JET performs and saves an execution plan.
The execution plan is not recalculated unless the query is altered.
If the data has changed radically since the query was created, the saved
execution plan may be completely inappropriate. For example, if you create
the query with a few dozen records and later execute it with many thousands
of records, the saved plan may be completely wrong. If you then change the
SQL statement (or generate one dynamically in code), Access recalculates the
execution plan and so the query runs in a way that is much more appropriate
to the new data.
The issues regarding execution plan are quite different from the caching of
the data which speeds up the retrieval of the information from the disk on
subsequent reads.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
"Ryan" <rp@rdoffice.net> wrote in message
news:cf*************************@posting.google.co m... I came across a situation that I've been unable to explain and was hoping somebody had an answer:
I had written an update query which was taking about 8 seconds to run and considered it too slow. I copied the SQL statement from the query and tried executing it from code which then ran in 1 second. To make sure that I didn't miss anything, I copied the SQL statement back into a query and tried running it again. It now also only took 1 second and looked exactly the same as before. I later realized that if I take the original query, change it to SQL view and run it, then change it back to design view and save it, it acomplishes the same thing. The query looks exactly the same as before, but appears to have been optimized somehow by running as a SQL statement first (either from code or simply from the SQL view of the query).
Just to clear this from the discussion, I understand that a query can run faster the second time around (I believe do to optimization), so I made sure that when I compared them, I always ran them twice to eliminate this from being the answer. Even after running the query several times in its original state, it took 8 seconds. After simply changing the view to SQL, running it, and changing it back, it always takes 1 second thereafter.
If anybody has an answer to this, I would appreciate it.
Ryan
"Allen Browne" <ab***************@bigpond.net.au> wrote in message news:<7P********************@news-server.bigpond.net.au>... When you save a query and run it, JET performs and saves an execution plan. The execution plan is not recalculated unless the query is altered.
If the data has changed radically since the query was created, the saved execution plan may be completely inappropriate. For example, if you create the query with a few dozen records and later execute it with many thousands of records, the saved plan may be completely wrong. If you then change the SQL statement (or generate one dynamically in code), Access recalculates the execution plan and so the query runs in a way that is much more appropriate to the new data.
The issues regarding execution plan are quite different from the caching of the data which speeds up the retrieval of the information from the disk on subsequent reads.
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html
"Ryan" <rp@rdoffice.net> wrote in message news:cf*************************@posting.google.co m... I came across a situation that I've been unable to explain and was hoping somebody had an answer:
I had written an update query which was taking about 8 seconds to run and considered it too slow. I copied the SQL statement from the query and tried executing it from code which then ran in 1 second. To make sure that I didn't miss anything, I copied the SQL statement back into a query and tried running it again. It now also only took 1 second and looked exactly the same as before. I later realized that if I take the original query, change it to SQL view and run it, then change it back to design view and save it, it acomplishes the same thing. The query looks exactly the same as before, but appears to have been optimized somehow by running as a SQL statement first (either from code or simply from the SQL view of the query).
Just to clear this from the discussion, I understand that a query can run faster the second time around (I believe do to optimization), so I made sure that when I compared them, I always ran them twice to eliminate this from being the answer. Even after running the query several times in its original state, it took 8 seconds. After simply changing the view to SQL, running it, and changing it back, it always takes 1 second thereafter.
If anybody has an answer to this, I would appreciate it.
Ryan
Thank you for the response, Allen. That was very helpful. Is there
another way of recalculating the execution plans on a query or all
queries other than the way I described?
Ryan
I think you will find that compacting the database causes it to recalculate
the query plan. That would be the simplest approach for a database in
operation.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
"Ryan" <rp@rdoffice.net> wrote in message
news:cf**************************@posting.google.c om... "Allen Browne" <ab***************@bigpond.net.au> wrote in message
news:<7P********************@news-server.bigpond.net.au>... When you save a query and run it, JET performs and saves an execution
plan. The execution plan is not recalculated unless the query is altered.
If the data has changed radically since the query was created, the saved execution plan may be completely inappropriate. For example, if you
create the query with a few dozen records and later execute it with many
thousands of records, the saved plan may be completely wrong. If you then change
the SQL statement (or generate one dynamically in code), Access recalculates
the execution plan and so the query runs in a way that is much more
appropriate to the new data.
The issues regarding execution plan are quite different from the caching
of the data which speeds up the retrieval of the information from the disk
on subsequent reads.
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html
"Ryan" <rp@rdoffice.net> wrote in message news:cf*************************@posting.google.co m... I came across a situation that I've been unable to explain and was hoping somebody had an answer:
I had written an update query which was taking about 8 seconds to run and considered it too slow. I copied the SQL statement from the query and tried executing it from code which then ran in 1 second. To make sure that I didn't miss anything, I copied the SQL statement back into a query and tried running it again. It now also only took 1 second and looked exactly the same as before. I later realized that if I take the original query, change it to SQL view and run it, then change it back to design view and save it, it acomplishes the same thing. The query looks exactly the same as before, but appears to have been optimized somehow by running as a SQL statement first (either from code or simply from the SQL view of the query).
Just to clear this from the discussion, I understand that a query can run faster the second time around (I believe do to optimization), so I made sure that when I compared them, I always ran them twice to eliminate this from being the answer. Even after running the query several times in its original state, it took 8 seconds. After simply changing the view to SQL, running it, and changing it back, it always takes 1 second thereafter.
If anybody has an answer to this, I would appreciate it.
Ryan
Thank you for the response, Allen. That was very helpful. Is there another way of recalculating the execution plans on a query or all queries other than the way I described?
Ryan
> Hmm... interesting. So, how do you force Access to reoptimize your queries Loop through them in VB and do some minor thing then undo it to force the compiler to see the query as changed? (Okay, I'll go back to smoking crack now...)
My question exactly. By the way, I work for a drug testing company
(i.e. smoking crack) (<:
Allen, I tried compacting the database and even repairing it. Neither
one seemed to effect anything. I even tried making a small change to
the query, saving it, and running it again and still no change. The
only time it makes a major difference (from over 30 seconds to less
than 5) is when I change the query view to SQL, run it, then change it
back to design view and run it again. When the query is in SQL view,
it is still slow and sometimes I even need to break it because it
takes so long. However, as soon as I switch back to design view, it
is lightning fast compared to what it was. Also, if I copy the SQL
statement out of the query and run it in code, it is very fast.
I understand what you are saying about the "execution plan" and it
makes sense, because the tables did indeed grow to thousands of
records since it was written. I would just like to know how I could
re-calculate all of the execution plans. Although, I've noticed that
this set of events only seems to help on my update queries, not
others.
Ryan
Interesting, Ryan. I've never had reason to test MS's claim that compacting
causes the query plan to be recalc'd.
You could try reassigning the SQL property of the QueryDef - even assigning
it to itself:
For Each qdf in db.QueryDefs
qdf.SQL = qdf.SQL
Next
Over time this approach may cause the database to bloat.
Interestingly, I think there is a training CrLf at the end of the SQL
statement built through the query design grid.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
"Ryan" <rp@rdoffice.net> wrote in message
news:cf**************************@posting.google.c om... Hmm... interesting. So, how do you force Access to reoptimize your queries Loop through them in VB and do some minor thing then undo it to force the compiler to see the query as changed? (Okay, I'll go back to smoking crack now...)
My question exactly. By the way, I work for a drug testing company (i.e. smoking crack) (<:
Allen, I tried compacting the database and even repairing it. Neither one seemed to effect anything. I even tried making a small change to the query, saving it, and running it again and still no change. The only time it makes a major difference (from over 30 seconds to less than 5) is when I change the query view to SQL, run it, then change it back to design view and run it again. When the query is in SQL view, it is still slow and sometimes I even need to break it because it takes so long. However, as soon as I switch back to design view, it is lightning fast compared to what it was. Also, if I copy the SQL statement out of the query and run it in code, it is very fast.
I understand what you are saying about the "execution plan" and it makes sense, because the tables did indeed grow to thousands of records since it was written. I would just like to know how I could re-calculate all of the execution plans. Although, I've noticed that this set of events only seems to help on my update queries, not others.
Ryan
"Allen Browne" <ab***************@bigpond.net.au> wrote in message news:<sO********************@news-server.bigpond.net.au>... Interesting, Ryan. I've never had reason to test MS's claim that compacting causes the query plan to be recalc'd.
You could try reassigning the SQL property of the QueryDef - even assigning it to itself:
For Each qdf in db.QueryDefs qdf.SQL = qdf.SQL Next
Over time this approach may cause the database to bloat. Interestingly, I think there is a training CrLf at the end of the SQL statement built through the query design grid.
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html
Hey Allen,
I tried the above and it did work. Thank you very much. After I
optimized the query, I tried making change to it to see if it remains
fast and it did. I suppose I'll just have to re-set the SQL statement
with the above method every so often to keep things optimized in the
event of major data increases.
Thanks again for the assistance.
Ryan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: A Future Computer Scientist |
last post by:
A question: Is it really important to think about optimizing the native code
or optimizing it for P Code? Or does the code you write make a difference?
|
by: Soefara |
last post by:
Dear Sirs,
I am experiencing strange results when trying to optimize a LEFT JOIN
on 3 tables using MySQL.
Given 3 tables A, B, C such as the following:
create table A (
uniqueId int not...
|
by: Stefano |
last post by:
Hi everibody,
it's the first time i post on this newsgroup. I'm Stefano from Milano,
italy.
I'm a beginners with Sql2000. My problem is this.
I run a View using enterprise manager and after less...
|
by: Uros |
last post by:
Hello!
I have some trouble getting good results from my query.
here is structure
stat_views
id | integer
id_zone | integer
created | timestamp
|
by: Henk Ernst Blok |
last post by:
Hi Posgres users/developers,
Can anyone explain why PosgreSQL (version 7.4.5 on Linux) does a full
table scan to compute a count(*) on a base table after a vacuum analyze
has been done with no...
|
by: xpcer |
last post by:
hi, friends, i have an problem, like this,
i have tables, when i want to use "select" statement that include "join" sintaxt, my query will execute about 1 hour, so long.
can u tell me how to...
|
by: rashmigaikwad |
last post by:
Hi All,
I need help in optimizing the query mentioned below:
SELECT
SUM(CASE WHEN PROD_TYP='HBRMC' AND INC_MULTIPLE < 2.50 AND LTV <= 0.75 OR LTV IS NULL THEN ADV_IN_QTR ELSE 0 END) ...
|
by: Paul Furman |
last post by:
I don't know, maybe this isn't strange but someone else set up the
shopping card coding I'm working with, the way it works is to get the
time() in seconds like 1172693735 and that's the shopper_ID...
|
by: John Rivers |
last post by:
Hello
has anybody else noticed
I have queries that SQL 2000 optimizes correctly and they run very
fast
Yet SQL 2005 keeps using a dumb query plan and queries run very slow
The problem...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |