473,796 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Optimize Queries and Recordsets

ADezii
8,834 Recognized Expert Expert
  1. Create Indexes on all Columns used in 'ad hoc' Query Joins, restrictions, and sorts (Jet already creates Indexes for Enforced Relationships).
  2. Use Primary Keys instead of Unique Indexes wherever possible.
  3. Use Unique Indexes instead of Non-Unique Indexes whenever possible.
  4. Include as few Columns as possible in the result set.
  5. Refrain from using Expressions, such as IIf(), in Queries.
  6. Use Count(*) instead of Count([column]).
  7. Use the Between Operator in restriction clauses rather than open-ended >, >=, <, <= restrictions (Between 35 And 50 rather than >=35).
  8. Normalize your Tables.
  9. Avoid using Outer Joins if possible since a complete scan of the outer Table is required.
  10. For nontrivial Queries, use saved Queries instead of SQL since they are already optimized.
  11. If you create a Recordset based on an SQL string using ADO, specify the adOpenDynamic Cursor Type value. Because Jet doesn't support this Cursor, it will handle this specifically, thus providing the best performance for SQL strings.
  12. When you create an ADO Recordset retrieving Jet data, do not specify adUseClient for the Recordset's Cursor Location.
  13. Manually recompile Queries when the size of Tables, or the presence or type of Indexes, has changed.
  14. When possible, use Action Queries instead of looping through Recordsets in VBA to Update or Delete batches of data.
  15. When you need to use a DAO Snapshot Recordset, or a Static Recordset using ADO, use a Forward Scrolling Snapshot, or a Forward Only Recordset using ADO.
  16. When you only wish to add new Rows to a Recordset, open the Recordset using the dbAppendOnly option.
  17. When creating Queries using Client/Server sources, consider using Pass-Through Queries.
  18. When running very large Action Queries, set the Use Transaction property of the Query to False.
  19. If you are going to add many single Rows using DAO or ADO code, try and open the Recordset using dbOpenTable or its ADO equivalent, adCmdTableDirec t.
  20. It is usually faster to Update data in a Non-Indexed Column. You may want to drop the Indexes, perform the Updates, and then re-add them.
  21. Don't over-Index, but Index Fields that will be used for sorting, searching, or joining.
  22. Do not Index Columns that contain highly duplicated information.
Apr 7 '07 #1
2 17948
Denburt
1,356 Recognized Expert Top Contributor
Very interesting article, I do have a question or two for clarification and I would also like to add a thing or two (Hope you don't mind).

5. Refrain from using Expressions, such as IIf(), in Queries.

I do understand that using Functions and conditional statements do not process well in an underlying query or even sub queries however if it is in the direct query that is used as a recordset or recordsource would there be much of a time difference or other effect verses using it in the form or report itself?

6. Use Count(*) instead of Count([column]).

Interesting point I thought should be expanded on. :

Originally Posted by
• Count(*) counts all rows returned.
• Count([Column Name]) counts all rows where [Column Name] is not NULL.
10. For nontrivial Queries, use saved Queries instead of SQL since they are already optimized.

By this I am sure that you are referring to using Saved Queries versus SQL strings in combo Boxes, Form and Report Recordsources etc.

13. Manually recompile Queries when the size of Tables, or the presence or type of Indexes, has changed.

Just wow (missed this one somewhere along the way) I will be adding a subroutine to do this right away. If all goes well i may post it in the articles section shortly.

Information about query performance in an Access database
For 2000 - 2002 - 2003 A short snippet of the article:

After you compact your database, run each query to compile the query so that each query will now have the updated table statistics.
The article also stated that there are many reason to recompile the queries such as adding a number of records etc. a very interesting read.


Found this in a MS Access 97 article for Optimization.
A short snippet of the article:
Compile your saved queries before delivering your application. Do this by opening them in datasheet view and immediately closing them. Doing so will save the query plan with the query. This plan tells Jet how to process the query in the most efficient way. If you can, avoid using SQL strings in module code that are constructed and run on the fly. When these are run, they have to be compiled. Also be aware that, over time, the plan saved with the query may become obsolete as the data in the MDB file changes. You may want to recompile queries after compacting your database.
Apr 9 '07 #2
ADezii
8,834 Recognized Expert Expert
Very interesting article, I do have a question or two for clarification and I would also like to add a thing or two (Hope you don't mind).

5. Refrain from using Expressions, such as IIf(), in Queries.

I do understand that using Functions and conditional statements do not process well in an underlying query or even sub queries however if it is in the direct query that is used as a recordset or recordsource would there be much of a time difference or other effect verses using it in the form or report itself?

6. Use Count(*) instead of Count([column]).

Interesting point I thought should be expanded on. :



10. For nontrivial Queries, use saved Queries instead of SQL since they are already optimized.

By this I am sure that you are referring to using Saved Queries versus SQL strings in combo Boxes, Form and Report Recordsources etc.

13. Manually recompile Queries when the size of Tables, or the presence or type of Indexes, has changed.

Just wow (missed this one somewhere along the way) I will be adding a subroutine to do this right away. If all goes well i may post it in the articles section shortly.

Information about query performance in an Access database
For 2000 - 2002 - 2003 A short snippet of the article:


The article also stated that there are many reason to recompile the queries such as adding a number of records etc. a very interesting read.


Found this in a MS Access 97 article for Optimization.
A short snippet of the article:
Don't mind the questions at all:

05. Using Expressions in Queries may be detrimental to the speed of your Queries. Because Jet cannot use an Index in any way with a Calculated Column, you may be causing sequential scans of your data by including an Expression in a Query. Even if a Row is excluded from output because of a restriction you placed in the Query, all Expressions for that Row are still evaluated. If you have a Table containing 1,000 Rows and you've only requested 1 Row back, if your Query includes an Expression and you're filtering based on that Expression, Jet must calculate the Expression for all 1,000 Rows.

06. Jet has built in optimizations that make Count(*) much faster than column-based counts.

10. Access creates hidden QueryDefs for SQL statements it finds in RecordSource and RowSource properties of Forms and Reports, but it won't create QueryDefs for SQL statements that are embedded in VBA code. Here is where the problem lies.

13. Manually recompile Queries when the size of Tables, or the presence or type of Indexes, has changed. The reasoning behind this should be fairly obvious.

I hope all your questions have been answered, if not let me know and I'll do my best to attempt a better response.
Apr 9 '07 #3

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

Similar topics

7
11384
by: Gary | last post by:
I'm using ASP (VB Script) to generate some reports from a SQL Server database. These queries often take a significant amount of time to complete, and many of these reports consist of multiple queries. One of the biggest problems end users have with this is that if the report generation is cancelled (e.g. hitting the stop button on the browser) SQL Server continues to process the request, which usually renders the server unresponsive...
6
6786
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
9
4359
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
2
2023
by: vulcaned | last post by:
I'm thinking I might want to move the back-end to one of my Access97 applications to SQLServer instead of continuing to use Access jet but before I start/do that I have several questions I'm hoping can be answered as I have not yet used SQLServer for a back-end. 1. Just moving my tables from a jet back-end to a SQLServer back-end and not changing anything else will not improve performance, True???? 2. If I create pass-thru queries can...
7
21640
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
20
2654
by: Darryl Kerkeslager | last post by:
I use the following code to retrieve to recordsets into two local tables, from an mdb file over a WAN. Works fine, but I'm trying to tweak the speed, and I have some questions: 1. I tried both an ADOX-created stored procedure and a regular Access parameter query. After several tests, I came to the conclusion that there was no statistcal difference between the two. Does this make sense, or could I do something different to speed it up...
14
2471
by: google | last post by:
I am creating a new database for use within our company, that I'd like to make reasonably secure (short of a true server based solution). The back-end of a non-server based database seems to be the biggest security hole, due to the ease of opening, linking, and/or importing raw data directly from the back-end database. I've read information that indicates that locking down the back-end tables to the owner, then using RWOP queries in the...
13
3127
by: Frank Swarbrick | last post by:
IBM has a product for the VSE operating system called the VSAM Redirector. It allows you to use VSAM to access RDBMS tables/views as if they were actual VSAM files. We're doing a comparison right now between Oracle, which we've been running in production for many years, and DB2, which we are just starting with. One of the tests I am trying is to see how efficient the VSAM Redirector works with DB2 versus Oracle. Below are two types of...
2
7049
by: zwasdl | last post by:
Some of my queries take 1 hour to run, can I run other queries in access while waiting on the first query? If so, how can I do it? Thanks a lot, Wei
0
9684
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
10236
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
10182
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
10017
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
9055
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
5445
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
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
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
2928
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.