![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I found a speed improvement in a sub select. Using "SELECT TOP 1" instead of "SELECT", a union query completed in seconds, instead of minutes. tblzDate is a temp table that holds 1 record of dates input from the user. The union query compiles cost information from multiple tables for a report. Each query in the union uses the dates to limit the records selected. Before the change the report would take more then 30 minutes to open, now it takes less then a minute. Following is an example of one on the queries. SELECT DISTINCTROW Sum([Issued]*[Price]) AS Cost FROM tblIssued WHERE (((tblIssued.DateIssued) Between (SELECT TOP 1 tblzDate.Date1 FROM tblzDate And (SELECT TOP 1 tblzDate.Date2 FROM tblzDate )); |
#3
| |||
| |||
|
|
ron paii wrote: I found a speed improvement in a sub select. Using "SELECT TOP 1" instead of "SELECT", a union query completed in seconds, instead of minutes. tblzDate is a temp table that holds 1 record of dates input from the user. The union query compiles cost information from multiple tables for a report. Each query in the union uses the dates to limit the records selected. Before the change the report would take more then 30 minutes to open, now it takes less then a minute. Following is an example of one on the queries. SELECT DISTINCTROW Sum([Issued]*[Price]) AS Cost FROM tblIssued WHERE (((tblIssued.DateIssued) Between (SELECT TOP 1 tblzDate.Date1 FROM tblzDate And (SELECT TOP 1 tblzDate.Date2 FROM tblzDate ));What is the purpose of that DISTINCTROW keyword in this query? This query, because it's only returning a single column that aggregates all the data, is going to return a single result - get rid of the useless DISTINCTROW. |
|
Instead of the subselects, simply join to tblzDate: SELECT Sum([Issued]*[Price]) AS Cost FROM tblIssued As i, tblzDate As d WHERE i.DateIssued BETWEEN Date1 AND Date2 Or SELECT Sum([Issued]*[Price]) AS Cost FROM tblIssued As i JOIN tblzDate As d ON i.DateIssued BETWEEN Date1 AND Date2 I will test that, don't know why I used a sub query instead. |
#4
| |||
| |||
|
| "Bob Barrows" <reb01501 (AT) NOyahooSPAM (DOT) com> wrote in message news:j5fpqt$9c3$1 (AT) dont-email (DOT) me... ron paii wrote: I found a speed improvement in a sub select. Using "SELECT TOP 1" instead of "SELECT", a union query completed in seconds, instead of minutes. tblzDate is a temp table that holds 1 record of dates input from the user. The union query compiles cost information from multiple tables for a report. Each query in the union uses the dates to limit the records selected. Before the change the report would take more then 30 minutes to open, now it takes less then a minute. Following is an example of one on the queries. SELECT DISTINCTROW Sum([Issued]*[Price]) AS Cost FROM tblIssued WHERE (((tblIssued.DateIssued) Between (SELECT TOP 1 tblzDate.Date1 FROM tblzDate And (SELECT TOP 1 tblzDate.Date2 FROM tblzDate ));What is the purpose of that DISTINCTROW keyword in this query? This query, because it's only returning a single column that aggregates all the data, is going to return a single result - get rid of the useless DISTINCTROW. The DISTINCTROW is an artifact of the original query that returned more then 1 row. I strip out the other columns to make it easer to show in the post. But even so it may not need the DISTINCTROW. Instead of the subselects, simply join to tblzDate: SELECT Sum([Issued]*[Price]) AS Cost FROM tblIssued As i, tblzDate As d WHERE i.DateIssued BETWEEN Date1 AND Date2 Or SELECT Sum([Issued]*[Price]) AS Cost FROM tblIssued As i JOIN tblzDate As d ON i.DateIssued BETWEEN Date1 AND Date2 I will test that, don't know why I used a sub query instead. |
#5
| |||
| |||
|
|
I found a speed improvement in a sub select. Using "SELECT TOP 1" insteadof "SELECT", a union query completed in seconds, instead of minutes. tblzDate is a temp table that holds 1 record of dates input from the user.. The union query compiles cost information from multiple tables for a report. Each query in the union uses the dates to limit the records selected. Before the change the report would take more then 30 minutes to open, now it takes less then a minute. Following is an example of one on the queries. SELECT DISTINCTROW Sum([Issued]*[Price]) AS Cost FROM tblIssued WHERE (((tblIssued.DateIssued) Between (SELECT TOP 1 tblzDate.Date1 FROM tblzDate And (SELECT TOP 1 tblzDate.Date2 FROM tblzDate )); |

#6
| |||
| |||
|
|
After some testing there wasn't much a difference in performance between the sub query and the join. Getting rid of the DISTINCTROW was more noticeable. |
#7
| |||
| |||
|
| "ron paii" <none (AT) nospam (DOT) com> wrote in message news:j5g174$100$1 (AT) dont-email (DOT) me... "Bob Barrows" <reb01501 (AT) NOyahooSPAM (DOT) com> wrote in message news:j5fpqt$9c3$1 (AT) dont-email (DOT) me... ron paii wrote: I found a speed improvement in a sub select. Using "SELECT TOP 1" instead of "SELECT", a union query completed in seconds, instead of minutes. tblzDate is a temp table that holds 1 record of dates input from the user. The union query compiles cost information from multiple tables for a report. Each query in the union uses the dates to limit the records selected. Before the change the report would take more then 30 minutes to open, now it takes less then a minute. Following is an example of one on the queries. SELECT DISTINCTROW Sum([Issued]*[Price]) AS Cost FROM tblIssued WHERE (((tblIssued.DateIssued) Between (SELECT TOP 1 tblzDate.Date1 FROM tblzDate And (SELECT TOP 1 tblzDate.Date2 FROM tblzDate ));What is the purpose of that DISTINCTROW keyword in this query? This query, because it's only returning a single column that aggregates all the data, is going to return a single result - get rid of the useless DISTINCTROW. The DISTINCTROW is an artifact of the original query that returned more then 1 row. I strip out the other columns to make it easer to show in the post. But even so it may not need the DISTINCTROW. Instead of the subselects, simply join to tblzDate: SELECT Sum([Issued]*[Price]) AS Cost FROM tblIssued As i, tblzDate As d WHERE i.DateIssued BETWEEN Date1 AND Date2 Or SELECT Sum([Issued]*[Price]) AS Cost FROM tblIssued As i JOIN tblzDate As d ON i.DateIssued BETWEEN Date1 AND Date2 I will test that, don't know why I used a sub query instead. After some testing there wasn't much a difference in performance between the sub query and the join. Getting rid of the DISTINCTROW was more noticeable. |
#8
| |||
| |||
|
|
The DISTINCTROW is an artifact of the original query that returned more then 1 row. |
#9
| |||
| |||
|
|
ron paii wrote: After some testing there wasn't much a difference in performance between the sub query and the join. Getting rid of the DISTINCTROW was more noticeable. I'm a little puzzled as to why these dates are being stored in a table. I assume the user uses a form to enter the dates ... You could unbind the textboxes from the table and directly reference the values in the textboxes from your query. It would save a bit of i/o ... They are user input of range of dates. I stored them in a table for |
#10
| |||
| |||
|
|
On Sep 22, 10:23 am, "ron paii" <n... (AT) nospam (DOT) com> wrote: I found a speed improvement in a sub select. Using "SELECT TOP 1" instead of "SELECT", a union query completed in seconds, instead of minutes. tblzDate is a temp table that holds 1 record of dates input from the user. The union query compiles cost information from multiple tables for a report. Each query in the union uses the dates to limit the records selected. Before the change the report would take more then 30 minutes to open, now it takes less then a minute. Following is an example of one on the queries. SELECT DISTINCTROW Sum([Issued]*[Price]) AS Cost FROM tblIssued WHERE (((tblIssued.DateIssued) Between (SELECT TOP 1 tblzDate.Date1 FROM tblzDate And (SELECT TOP 1 tblzDate.Date2 FROM tblzDate ));I've not been a fan of subselects in the past due to the extreme degradataion of speed in queries. it appears not much has changed. What would happen of you had two queries; TopDate1 and TopDate2? TopDate1's SQL was SELECT TOP 1 tblzDate.Date1 FROM tblzDate ![]() And then join table/query Cost to TopDate1 and TopDate2? I'll assume Date1 and Date2 are indexed. |
|
Glad you got it down from 30 minutes. That'd be excuciating. Strange thing is this query ran much faster before the BE was converted from |
![]() |
| Thread Tools | |
| Display Modes | |
| |