Re: What GROUP BY is not...
- From: "Michel Walsh" <vanderghast@VirusAreFunnierThanSpam>
- Date: Fri, 8 Jun 2007 09:52:35 -0400
I really don't know about what Jet does in the step "group" of its query
plan. MS SQL Server is more detailed and uses the index (if it exists, and
if the number of records is high enough) of the field to be DISTINCT/GROUP
BY.
If you implant that strategy yourself, in this case, and if the index
exists, since the reading of the records (note the query is covered by the
index) is done already sorted, so you can dump the result list onto a stack
rather than on a sorted list. Indeed, to find if a record is already in the
"selected/grouped" list, you only have to compare it with the top value on
the stack. If the index does not exist, you have to relay on stats (if they
are available): does the result will have much less rows than the initial
data, or not. If the number of row is much smaller in the result, may be
preferable to use a sorted list (faster to sort, a little bit longer to
search) than to sort the whole initial set first, then use a stack (longer
to sort the whole initial set, faster to 'search' for existence). Again, if
the index exists, the query being covered by the index, you don't need to
touch the data at all, just the index, so, you have less IO (since index
would be, generally, more compact, than the 'table', it will resides on less
'pages', so less requirements to hit the hard disk). You see, that is what
SQL is: it knows different way of doing the described set, and decide which
strategy it will take. If you want to do the same, clearly, you should
weight the similar alternatives, and 'hard code' multiple solutions, not
just one (in general).
Vanderghast, Access MVP
"Warrio" <warrio@xxxxxxxxxxx> wrote in message
news:4666fcfb$0$23409$5402220f@xxxxxxxxxxxxxxxxxx
one question then :
Does the jet engine sort the selected data before grouping them? If I had
to write the function my self, I would create two queries one for a small
amount of data and the other for considerable amount of data.
Because sorting the data would be useful to avoid make a useless loop on
the list of data to display to check if it's displayed already or not,
because it's the same as the previous record of the sorted data...
.
- References:
- GROUP BY vs DISTINCT
- From: Warrio
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: GROUP BY vs DISTINCT
- From: John Spencer
- Re: GROUP BY vs DISTINCT
- From: Warrio
- Re: GROUP BY vs DISTINCT
- From: Baz
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: GROUP BY vs DISTINCT
- From: David W. Fenton
- Re: GROUP BY vs DISTINCT
- From: Baz
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: GROUP BY vs DISTINCT
- From: David W. Fenton
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: GROUP BY vs DISTINCT
- From: David W. Fenton
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: GROUP BY vs DISTINCT
- From: Rick Brandt
- Re: GROUP BY vs DISTINCT
- From: Michel Walsh
- Re: What GROUP BY is not...
- From: Michel Walsh
- Re: What GROUP BY is not...
- From: Rick Brandt
- Re: What GROUP BY is not...
- From: Michel Walsh
- Re: What GROUP BY is not...
- From: Warrio
- GROUP BY vs DISTINCT
- Prev by Date: Re: Getting a custom function to work in a criteria
- Next by Date: RE: Can I specify Either/Or?
- Previous by thread: Re: What GROUP BY is not...
- Next by thread: Re: What GROUP BY is not...
- Index(es):
Relevant Pages
|