isladogs
MVP / VIP
- Local time
- Today, 14:28
- Joined
- Jan 14, 2017
- Messages
- 18,538
Allen Browne has an excellent web page devoted to various methods of improving query performance: http://allenbrowne.com/QueryPerfIssue.html
I thought it would be helpful to others to illustrate his suggestions by performing a series of speed tests showing the effect of each suggested change.
To reduce file size, the queries are based on cut down versions of 3 tables from the DEMO version of my School Data Analyser application. All data is for fictitious students in a fictitious school.
The aim of the query is to get the count of each type of pastoral incident recorded for each student in the year 2018. The query is also filtered to those students whose date of birth was in the year 2005.
There are 11 versions of the query with varying amounts of optimisation starting with a (deliberately) badly designed query and ending with the most optimised.
All queries return the same records (total = 882) but the times should get progressively faster each time (except for the final stacked queries test).
Each test is run several times to reduce natural variations caused by other processes that may be running in the background. The total time recorded is for the set number of loops. By default, the number of loops = 3
The fields used in each table to filter and sort the data are indexed to speed up searches:
The indexed fields are Surname, Forename, DateOfBirth, DateOfIncident
The average times recorded after running each set of tests 10 times was as follows:
As you can see, the times taken improved significantly from over 23 s originally down to about 0.46 s – almost 50 times faster
If anyone can see ways in which the query can be further optimised, please do let me know!
I have attached the example database used in these tests together with the JET ShowPlan (query execution plans) for each query.
A PDF summarising the effect of each change is also attached
Alternatively, you can view an extended version of the PDF on my website: http://www.mendipdatasystems.co.uk/speed-comparison-tests-8/4594556613
EDIT:
There is an updated version of the OptimiseQueries.zip file in post #5.
This fixes an issue with the code to collect workstation info as well as the form resizing issue described by CJ_London in post #2
I thought it would be helpful to others to illustrate his suggestions by performing a series of speed tests showing the effect of each suggested change.
To reduce file size, the queries are based on cut down versions of 3 tables from the DEMO version of my School Data Analyser application. All data is for fictitious students in a fictitious school.
The aim of the query is to get the count of each type of pastoral incident recorded for each student in the year 2018. The query is also filtered to those students whose date of birth was in the year 2005.
There are 11 versions of the query with varying amounts of optimisation starting with a (deliberately) badly designed query and ending with the most optimised.
All queries return the same records (total = 882) but the times should get progressively faster each time (except for the final stacked queries test).
Each test is run several times to reduce natural variations caused by other processes that may be running in the background. The total time recorded is for the set number of loops. By default, the number of loops = 3
The fields used in each table to filter and sort the data are indexed to speed up searches:
The indexed fields are Surname, Forename, DateOfBirth, DateOfIncident
The average times recorded after running each set of tests 10 times was as follows:
As you can see, the times taken improved significantly from over 23 s originally down to about 0.46 s – almost 50 times faster
If anyone can see ways in which the query can be further optimised, please do let me know!
I have attached the example database used in these tests together with the JET ShowPlan (query execution plans) for each query.
A PDF summarising the effect of each change is also attached
Alternatively, you can view an extended version of the PDF on my website: http://www.mendipdatasystems.co.uk/speed-comparison-tests-8/4594556613
EDIT:
There is an updated version of the OptimiseQueries.zip file in post #5.
This fixes an issue with the code to collect workstation info as well as the form resizing issue described by CJ_London in post #2
Attachments
Last edited: