Re: group by clause filling up temp space



On 30 Aug 2005 12:11:33 -0700, "ewong" <ewong@xxxxxxxx> wrote:

>I have this query which filled up 12GB of temp space. tableA has 500K
>records where tableB has 5M records. sid are indexed. The 2 tables
>combine only 200 mega bytes and yet this query needs more than 12GB of
>temp space to perform. I am thinking it's the multiple group by that
>is causing trouble? Is there any workaround on this? Thanks.
>
>SELECT a.id, a.type1, a.type2, count(b.sid)
>FROM tableA a, tableB b
>WHERE a.sid = b.sid
>and b.status = 'Y'
>GROUP BY a.id, a.type1, a.type2;
>
>The database is 9.2 EE. The involved tables are analyzed.

Firstly: how did you conclude that this query takes up so much temp
space?

Secondly: suppose two extreme scenarios:
1) sid's are unique in both tables. The hash-join would result in 500k
records at the most.
2) both tables have only one equal value for sid. The hash-join would
be equal to an cartesian product, which would produce 500k * 5M = 2.5
TB records.

So if your value distribution leans to the second scenario, your hash
join, together with the group by sort, would easily get 12 GB filled,
before the group by itself would make this smaller.

Jaap.
.



Relevant Pages

  • Re: Problem with Dual subselect
    ... So I've constructed a UNION QUERY as follows. ... FROM TABLEA AS A ... B.STATUS_DATE FROM [TABLEB] As B ... A Lookup property on the foreign-key field ...
    (microsoft.public.access.queries)
  • Re: use a result as a FIELD in the design grid
    ... I have a key TableA that maps each station's flow (and ... Station: FlowField: TankLevel: PumpRun: ... OK, now from the previous query, I know that the FlowField ... So in a new query grid where TableA is linked to TableB ...
    (microsoft.public.access.queries)
  • Re: Finding matching records
    ... >> An inner join in a query will return only records where the join ... Suppose you have two tables, TableA and TableB, with these fields: ... A_ShouldMatch has a match in the B_ShouldMatch field in TableB. ... create a new query in Design View and add both TableA and TableB to the ...
    (microsoft.public.access.modulesdaovba)
  • Re: Advanced query issue
    ... and then write a query linking just by your new ... FROM tablea As a RIGHT JOIN tableb as b ... That assumes tableb has all the possible occurrence of the two ... I also used UNION ALL, ...
    (microsoft.public.access.queries)
  • Re: LDAP query...
    ... Joe Kaplan-MS MVP Directory Services Programming ... What led you to want to search via sid? ... The query processor on ... Your query isn't going to work that way, at least not with the ADUC ...
    (microsoft.public.windows.server.active_directory)