On Wed, 23 Oct 2002, Tomasz Myrta wrote: > Hi > I want to perform query looking like this: > > select > user_id, > a/sum_a as percent_a, > b/sum_b as percent_b > from > users join > (select > group_id, > sum(a) as sum_a, > sum(b) as sum_b > from users group by group_id) X using (group_id) > where group_id=3; > > This query works, but very slow. Subquery with aggregate is performed > for all table rows instead of group_id=3.
Does using X.group_id=3 in the where clause work better? On 7.3 with no statistics for the table, that appears to move the filter into the subquery plan rather than the outer users scan. ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]