473,791 Members | 3,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Too long calculation - subquery issue?

Hi.

I have an issue with my Access project.

I have rather big tables of data (about 11 000 rows).
These tables are historical product quotations, so they are very simple :
- MyDate (PrimaryKey)
- Quote

I do some calculations on these data:
- I calculate the 10-days Average, using a subquery.
- I calculate the 10-days StDev, using a subquery.
- I use the query1 to gather all the infos ( MyDate / Quote / 10-days
average/ 10-days StDev)
- I use a form to open a chart which plots the query1.

However, when I open the chart, it takes more than 10 minutes to show the
results !
As I have quite a good Notebook (Sony 1.7Mhz, 1.25Go RAM...), I think there
is an issue in my query optimisation.

What do you think?

My queries are based on this code:
qry1_Average10:

SELECT a.Mydate, a.quote, Avg(b.quote) AS Average10
FROM Mytable AS a, Mytable AS b
WHERE(b.[MyDate]>[a].[MyDate]-10 And b.[MyDate]<=[a].[MyDate])
GROUP BY a.[MyDate],
ORDER BY a.[MyDate];
qry1_StdDev10:

SELECT a.Mydate, a.quote, StDev(b.quote) AS StdDev10
FROM Mytable AS a, Mytable AS b
WHERE(b.[MyDate]>=[a].[MyDate]-14 And b.[MyDate]<[a].[MyDate])
GROUP BY a.[MyDate],
ORDER BY a.[MyDate];

And I just ask for the fields MyDate and Quote from "Mytable" and StDev10 and
Average10 from the subqueries.

How could I make it work much faster?

Regards,

Laurent

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200609/1

Sep 27 '06 #1
3 3518
Yes. If the query takes more than a few seconds to run that suggests a
problem somewhere - a bottleneck. Note: when I say a query should take
only a few seconds, if you have say a giant union query that is composed
of a dozen queries and that takes 3 minutes to run, I am refereing to
each individual query of the dozen.

In your case, I would isolate each individual query (if there is more
than one) and run it straight from the query builder. See how long it
takes to run in the Query tool. If it (or each query) only takes a few
seconds to run individually, then the problem is not with the query but
how you access them. If each query takes a long time by itself, then
you need to isolate that query and just post a question on that query
alone for starters.

I would work on one query at a time. A lot of times you could gain some
performance by using temporary tables to store transient data. The idea
here is that you are whittling down the size of the data rather than
querying against all of your data. The Access Jet engine doesn't do as
well with a bunch of subqueries as say the Sql Server Engine (which is
1000 times bigger than Jet).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 27 '06 #2
Thanks for your answer, Rich.
My issue is that the first subquery (which calculates the average) is rather
slow, the second query (which calculate the stdev) is also rather slow (more
than 1 minute each).

And the query which takes the Average from the first subquery, the stdev from
the second subquery, and the date and close from the table is very, very slow.
.. (up to 10 minutes)
So you must be right when you say that there is an issue in my queries.
However, I cannot find how to calculate a "mobile average" or a "mobile
standard dev" without this kind of "loop" (I use the my table two times, and
I name it "a" and "b" to be able to do my calculations, as shown in my codes).
What do you think?
Regards,

Laurent


Rich P wrote:
>Yes. If the query takes more than a few seconds to run that suggests a
problem somewhere - a bottleneck. Note: when I say a query should take
only a few seconds, if you have say a giant union query that is composed
of a dozen queries and that takes 3 minutes to run, I am refereing to
each individual query of the dozen.

In your case, I would isolate each individual query (if there is more
than one) and run it straight from the query builder. See how long it
takes to run in the Query tool. If it (or each query) only takes a few
seconds to run individually, then the problem is not with the query but
how you access them. If each query takes a long time by itself, then
you need to isolate that query and just post a question on that query
alone for starters.

I would work on one query at a time. A lot of times you could gain some
performance by using temporary tables to store transient data. The idea
here is that you are whittling down the size of the data rather than
querying against all of your data. The Access Jet engine doesn't do as
well with a bunch of subqueries as say the Sql Server Engine (which is
1000 times bigger than Jet).

Rich
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200609/1

Sep 28 '06 #3
Hi Laurent,

If you are calling your query in a loop several times then is it the
loop which is taking a long time? How long does it take to run the
query from the Query tool? If it takes a long time from the query tool
then what I would do is to first pull the subset of data that you are
actually querying. For example, if you are querying rows that are
between certain date ranges, I would first pull the rows that are within
those date ranges and store those rows in a temporary table (an actual
table that you can create on the fly with "Select * Into tblTempForAvg
from ..." and then query that temp table for the average and do the
same for the Sdev and so on.

If it is not possible to pull a subset of your data then you will have
to face a fact of life (which a lot of people in this NG seem to have a
problem with) that Access is designed ideally for single user desktop
usage not Enterprise multiuser usage (ideally - that is). If you have
to query against a ton of data with several subqueries, you will have to
use something with a bigger engine than Access Jet - like sql server.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 28 '06 #4

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

Similar topics

6
72674
by: DC | last post by:
Is there a way to use a column alias in an another calculation within the same query? Since I am using some long and complex logic to compute total1 and total2, I don't want to repeat the same logic to compute the ratio of those two columns. I know that I can do a nested query, but that seems too lengthy as well since I actually have many, many columns. select total1 = sum(case(long complex logic)), total2 = sum(case(another long...
6
1604
by: Caveman | last post by:
-- I have a situation where doing -- first example -- 1. Get series of values througha query into a string (@val)like '1,2,3,4': declare @val varchar(4000) select @Val = @val + cast(myval as varchar) + ',' -- myval is an integer variable from xyz
7
9229
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into a table (c) re-queries another table using a subquery which references the inserted table (correlated or not)
4
2809
by: Trevor Best | last post by:
I have a report that's fairly simple, page headers and footers, detail has a subreport in (can vary in length). The customer wanted a signature block for them, their client and 3rd party. This was no problem, couple of boxes and labels in the report footer. Now customer wants this signature block on the foot of page 1 (stoopid IMO as that implies people read page 1 where at the end implies they read past page 1 at least). Anyway to...
2
5433
by: Miguel Morales | last post by:
Hello: Currently, I am trying to solve a problem that requires the calculation of Airy functions for big arguments. Because Airy functions diverge rapidly for positive values, the results of the calculation quickly produces overflow (or underflow depending on which Airy function is used) for values of the argument greater than about 100 when using double. Because of this, I need to find a routine that calculates Airy function producing...
6
5300
by: jimfortune | last post by:
In: http://groups.google.com/group/comp.databases.ms-access/msg/60d7faa790c65db1 james.ea...@gmail.com said: :Ok, I've answered the first half of my own question. From a MSDN :article, I can now use the following to reference the last primary :key's values: :
77
5251
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop. Is this because .NET is inherently slower or does the C# compiler merely produce code that is not as well optimized as the C++ compiler?
3
1616
by: ApexData | last post by:
Hello My MainForm manages Employee records. I have created another form that manages employee promotions. On the MainForm a button launches the PromotionForm and lists the promotions for the employee shown on the MainForm. The buttons clickevent looks like this: DoCmd.OpenForm stDocName, , , "EMPID = " & Me.txtEMPID The results are FILTERED. The Form is Continuous. Fields are: (EmpID) (Rank) (PromoDate) and UnboundTxtBox:
3
1716
by: Bogdan | last post by:
Hi, I've been struggling subqueries/joins and table adapters for some time and can't find a clear answer. I have a stored procedure that returns columns from 2 tables. Two columns from the second table are returned by subquery. All this is done in a stored procedure. I also have a stored procedure that takes most of the params from the select
0
9517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10156
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
9030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
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
5435
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...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
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.