473,698 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some SQL is *Much* Faster Than Other

Greetings,

I have this database I converted from Access 97 to Access 2000. Front
end on the PC, back end on the server. It works fine, except for one
thing: one of the reports is extremely slow (20-25 minutes to process
less than a thousand records), and even crashes Access sometimes. Yet
another very similar report runs almost instantly.

Both reports take a couple of parameters from a user form and have SQL
statements for data source. The slow one is:

SELECT tblProperty.Man agerID, tblProperty.Pro pertyID, tblProperty.MSA ,
tblProperty.CUS IP, tblRollForward. DateEntered,
tblRollForward. EndingCost, tblRollForward. EndingMkt FROM tblProperty
INNER JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID;

The fast one is:

SELECT DISTINCTROW tblPropFund.Man agerCode, * FROM (tblPropFund INNER
JOIN tblProperty ON tblPropFund.Fun dNumber = tblProperty.MSA ) INNER
JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID, tblRollForward. DateEntered;

Moving the back end to the same PC has no effect. Is there such a
major difference in these SQL statements that the former one is highly
inefficient? Or is there something else going on?

Many thanks,

Yisroel
Nov 13 '05 #1
4 1614
"Yisroel Markov" <ey*******@inam e.com> wrote in message
news:2f******** *************** ***@posting.goo gle.com...
Greetings,

I have this database I converted from Access 97 to Access 2000. Front
end on the PC, back end on the server. It works fine, except for one
thing: one of the reports is extremely slow (20-25 minutes to process
less than a thousand records), and even . . ..
One beneficial change you can make to both is to eliminate the ORDER BY --
the order of the RecordSource is completely ignored. Report sorting is ONLY
via the Sorting and Grouping properties of the Report.
Both reports take a couple of parameters
from a user form and have SQL
statements for data source.
I see no WHERE clause in either of these. If you are using the
WHERECONDITION of a DoCmd.OpenRepor t, be aware that works like a Filter and
may retrieve all the records before choosing the desired ones. I'd suggest
you create a replacement SQL statement including the WHERE clause, and use
it, in the OPEN event of the Report, to replace the RecordSource. Also, make
certain that the Fields used as Joins and Criteria are indexed Fields...
that way the whole index will be brought for selection, but only the
selected records. If any of these is not indexed, all the records will be
brought across the LAN.

This is important, because Access and the Jet database engine are executing
on the user's workstation and the shared folder is used just as it would be
if the data were on a local hard drive. The extraction and manipulation are
all done on the user's machine... Jet is a file-server database, not a
server-database that executes on the server.
SELECT tblProperty.Man agerID, tblProperty.Pro pertyID, tblProperty.MSA ,
tblProperty.CUS IP, tblRollForward. DateEntered,
tblRollForward. EndingCost, tblRollForward. EndingMkt FROM tblProperty
INNER JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID;

The fast one is:

SELECT DISTINCTROW tblPropFund.Man agerCode, * FROM (tblPropFund INNER
JOIN tblProperty ON tblPropFund.Fun dNumber = tblProperty.MSA ) INNER
JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID, tblRollForward. DateEntered;

Moving the back end to the same PC has no effect. Is there such a
major difference in these SQL statements that the former one is highly
inefficient? Or is there something else going on?

Many thanks,

Yisroel

Nov 13 '05 #2
"Larry Linson" <bo*****@localh ost.not> wrote in message news:<5i******* ******@nwrddc03 .gnilink.net>.. .

First, thanks for taking the time to answer.
"Yisroel Markov" <ey*******@inam e.com> wrote in message
news:2f******** *************** ***@posting.goo gle.com...
Greetings,

I have this database I converted from Access 97 to Access 2000. Front
end on the PC, back end on the server. It works fine, except for one
thing: one of the reports is extremely slow (20-25 minutes to process
less than a thousand records), and even . . ..
One beneficial change you can make to both is to eliminate the ORDER BY --
the order of the RecordSource is completely ignored. Report sorting is ONLY
via the Sorting and Grouping properties of the Report.


If there's a speed gain from this, it's negligible.
> Both reports take a couple of parameters
> from a user form and have SQL
> statements for data source.


I see no WHERE clause in either of these. If you are using the
WHERECONDITION of a DoCmd.OpenRepor t, be aware that works like a Filter and
may retrieve all the records before choosing the desired ones.


Yes, that's how this thing is built. The user selects the month and
year of the report, and the code behind the form builds a string used
as a filter condition in DoCmd.OpenRepor t.
I'd suggest
you create a replacement SQL statement including the WHERE clause, and use
it, in the OPEN event of the Report, to replace the RecordSource.
I suspect the reason it's not already this way is the filter. Here's
the string the code builds:

(DateEntered = #5/31/2004#) AND tblProperty.Pro pertyID NOT IN (SELECT
tblRollForward. PropertyID FROM tblRollForward WHERE
tblRollForward. DateEntered = #6/30/2004#)

I copied the original SQL into a query and put the query in the
report's Record Source. When I added WHERE and tried putting the
filter string after WHERE, I got a syntax error. I tried experimenting
with brackets, to no avail (which of course doesn't mean anything).
Can a query, or SQL, take this kind of nested WHERE? And if it does,
will it speed things up? The whole database is about 12,000 records.
Also, make
certain that the Fields used as Joins and Criteria are indexed Fields...
that way the whole index will be brought for selection, but only the
selected records. If any of these is not indexed, all the records will be
brought across the LAN.
Check - they are indexed.
This is important, because Access and the Jet database engine are executing
on the user's workstation and the shared folder is used just as it would be
if the data were on a local hard drive. The extraction and manipulation are
all done on the user's machine... Jet is a file-server database, not a
server-database that executes on the server.


Thanks again!
SELECT tblProperty.Man agerID, tblProperty.Pro pertyID, tblProperty.MSA ,
tblProperty.CUS IP, tblRollForward. DateEntered,
tblRollForward. EndingCost, tblRollForward. EndingMkt FROM tblProperty
INNER JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID;

The fast one is:

SELECT DISTINCTROW tblPropFund.Man agerCode, * FROM (tblPropFund INNER
JOIN tblProperty ON tblPropFund.Fun dNumber = tblProperty.MSA ) INNER
JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID, tblRollForward. DateEntered;

Moving the back end to the same PC has no effect. Is there such a
major difference in these SQL statements that the former one is highly
inefficient? Or is there something else going on?

Many thanks,

Yisroel

Nov 13 '05 #3
Update - I examined the report further, and it turns out that of the 8
controls it has for displaying data, each has as Control Source a
custom function, which pulls data with yet another SQL statement from
yet a third table.

I ran the report, interrupting code execution every 10 seconds to look
where in the code the execution was, and it looks like it's precisely
these functions that cause the slowdown. Nor is it surprising - it
looks like for each of the 180 properties in the database, 8 SQL
queries have to run. Each of these does have the proper WHERE,
selecting Sum() of transactions from another 10,000 record table based
on a date range and a matching property ID, but that doesn't seem to
help speed.

So I guess the question has changed: is there a better way to build
this report? What if I first SELECT all the sums from this transaction
table and then feed them to the report? What's the best way to do
that?

Thanks,

Yisroel
Nov 13 '05 #4
Instead of using the subquery, try using an outer join on tblRollForward
with a criteria of Null on the id of the tblRollForward record (that should
give the same result as the NOT IN subquery, but without running a separate
query of all the records for a given day of tblRollForward for each of your
main report records).

That should also be sufficiently simple that you can use the Query Builder
rather than writing your own SQL from scratch. It is also likely to be
sufficiently simpler that it will be easier to build the SQL statement with
criteria. I see no reason why you cannot do what you were trying...
sometimes concatenating strings and text can be frustrating -- it is easy to
overlook something and end up with a reference that doesn't work rather than
the value you intended to extract from a control, for example... but if you
keep at it, and display the results before running the query (Debug.Print or
MsgBox), you should be able to get it right. In my case, I might have to
tack on "eventually " to the preceding. :-)

Yes, you can have subqueries in Queries and SQL, and the Queries and SQL
with subqueries are legal for RecordSource.

It may be that you simply have too much data retrieval going on for it to be
very fast. Perhaps you can rethink what you need to accomplish, and come up
with an approach that doesn't require several queries run for each record.
If you can clarify in a precise and concise statement of what you have and
what you are trying to accomplish (rather than how you are going about
trying to do it), perhaps someone here can make useful suggestions.

Larry Linson
Microsoft Access MVP

"Yisroel Markov" <ey*******@inam e.com> wrote in message
news:2f******** *************** ***@posting.goo gle.com...
"Larry Linson" <bo*****@localh ost.not> wrote in message news:<5i******* ******@nwrddc03 .gnilink.net>.. .
First, thanks for taking the time to answer.
"Yisroel Markov" <ey*******@inam e.com> wrote in message
news:2f******** *************** ***@posting.goo gle.com...
Greetings,

I have this database I converted from Access 97 to Access 2000. Front
end on the PC, back end on the server. It works fine, except for one
thing: one of the reports is extremely slow (20-25 minutes to process
less than a thousand records), and even . . ..


One beneficial change you can make to both is to eliminate the ORDER BY --
the order of the RecordSource is completely ignored. Report sorting is ONLY via the Sorting and Grouping properties of the Report.


If there's a speed gain from this, it's negligible.
> Both reports take a couple of parameters
> from a user form and have SQL
> statements for data source.


I see no WHERE clause in either of these. If you are using the
WHERECONDITION of a DoCmd.OpenRepor t, be aware that works like a Filter and
may retrieve all the records before choosing the desired ones.


Yes, that's how this thing is built. The user selects the month and
year of the report, and the code behind the form builds a string used
as a filter condition in DoCmd.OpenRepor t.
I'd suggest
you create a replacement SQL statement including the WHERE clause, and use it, in the OPEN event of the Report, to replace the RecordSource.


I suspect the reason it's not already this way is the filter. Here's
the string the code builds:

(DateEntered = #5/31/2004#) AND tblProperty.Pro pertyID NOT IN (SELECT
tblRollForward. PropertyID FROM tblRollForward WHERE
tblRollForward. DateEntered = #6/30/2004#)

I copied the original SQL into a query and put the query in the
report's Record Source. When I added WHERE and tried putting the
filter string after WHERE, I got a syntax error. I tried experimenting
with brackets, to no avail (which of course doesn't mean anything).
Can a query, or SQL, take this kind of nested WHERE? And if it does,
will it speed things up? The whole database is about 12,000 records.
Also, make
certain that the Fields used as Joins and Criteria are indexed Fields...
that way the whole index will be brought for selection, but only the
selected records. If any of these is not indexed, all the records will be brought across the LAN.


Check - they are indexed.
This is important, because Access and the Jet database engine are executing on the user's workstation and the shared folder is used just as it would be if the data were on a local hard drive. The extraction and manipulation are all done on the user's machine... Jet is a file-server database, not a
server-database that executes on the server.


Thanks again!
SELECT tblProperty.Man agerID, tblProperty.Pro pertyID, tblProperty.MSA ,
tblProperty.CUS IP, tblRollForward. DateEntered,
tblRollForward. EndingCost, tblRollForward. EndingMkt FROM tblProperty
INNER JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID;

The fast one is:

SELECT DISTINCTROW tblPropFund.Man agerCode, * FROM (tblPropFund INNER
JOIN tblProperty ON tblPropFund.Fun dNumber = tblProperty.MSA ) INNER
JOIN tblRollForward ON tblProperty.Pro pertyID =
tblRollForward. PropertyID ORDER BY tblProperty.Man agerID,
tblProperty.Pro pertyID, tblRollForward. DateEntered;

Moving the back end to the same PC has no effect. Is there such a
major difference in these SQL statements that the former one is highly
inefficient? Or is there something else going on?

Many thanks,

Yisroel

Nov 13 '05 #5

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

Similar topics

36
2012
by: Antoon Pardon | last post by:
I'm rather new at this, so I don't know how I should introduce this, nor whether these ideas are worth much but here goes. What I would like to change is access to variables on an intermediate scope. Given the following example def fun_1() a = some_value
16
2135
by: Michele Simionato | last post by:
I have read with interest the recent thread about closures. The funny thing is that the authors are arguing one against the other but I actually agree with all of them and I have a proposal that may be of some interest. To refresh your memory, I report here some quotation from that thread. Jacek Generowicz: > I sumbit to you that read-only closures are rare in Python because > they are a recent addition to the language.
19
1675
by: bearophile | last post by:
This is my first post here, I hope this is the right place to talk about such things. I have few comments and notes on the Python language. I've just started to learn it; this is negative because I'm ignorant still, but it's also positive because I can still see details that later probably I'll start to ignore. Some of the functions of IPython seem good and simple, and I think some of them can be integrated into the main Python line. ...
22
2317
by: bearophile | last post by:
Ville Vainio: >It's highly typical for the newbies to suggest improvements to the >language. They will usually learn that they are wrong, but the >discussion that ensues can be fruitfull anyway :-). Few more notes on the language. I don't know if I can really suggest improvements to the language... but I hope to learn something :-) I think some things are better in Delphi/Pascal (like the := for assignments instead of = and = for...
193
9565
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
26
4829
by: Olaf Baeyens | last post by:
I am trying to port some C++ structures to C# but I have troubles with this one. Note: this is a file record, so I must keep this format. #pragma pack( push, 1 ) typedef struct { char title; DWORD dwCount; } STLHEADER, *LPSTLHEADER;
11
1599
by: Sensei | last post by:
Hi again! I have still curiosity about the reason of some C constructs/keywords... The first is about static functions. What was the reason of restricting a function to be visible just in a specific source file? Wasn't it sufficient not to be given a prototype (for visibility)? What about register and volatile variables? Was at that time a compiler not smart enough to optimize with in-register variables? And why would
11
2901
by: Stef Mientki | last post by:
hi All, instead of questions, my first success story: I converted my first MatLab algorithm into Python (using SciPy), and it not only works perfectly, but also runs much faster: MatLab: 14 msec
20
4268
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
5
1432
by: Joel | last post by:
(1) Can anyone please tell me the exact meaning of primitive types in the MSIL context. (2) Also what is the meaning of the world inline? (3) What is the meaning of the statement: "You should bear in mind, however, that decimal is not implemented under the hood as a primitive type, so using decimal will have a performance impact on your calculations." ?
0
8610
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
9170
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...
0
9031
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
8902
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
8873
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...
0
7740
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...
1
6528
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
4372
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
3052
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

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.