X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C4DD4D1B1D0 for ; Tue, 15 Jun 2004 10:23:26 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55701-02 for ; Tue, 15 Jun 2004 13:23:21 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id E5933D1B19F for ; Tue, 15 Jun 2004 10:23:17 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i5FDNKMj000297; Tue, 15 Jun 2004 09:23:20 -0400 (EDT) To: Frank van Vugt Cc: pgsql-performance@postgresql.org Subject: Re: why is a constraint not 'pushed down' into a subselect when this subselect is using a 'group by' ?? In-reply-to: <200406150849.29470.ftm.van.vugt@foxi.nl> References: <200406150849.29470.ftm.van.vugt@foxi.nl> Comments: In-reply-to Frank van Vugt message dated "Tue, 15 Jun 2004 08:49:29 +0200" Date: Tue, 15 Jun 2004 09:23:19 -0400 Message-ID: <296.1087305799@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/155 X-Sequence-Number: 7213 Frank van Vugt writes: > If I ditch the group by, then this contraint does get pushed into the > subselect : You're misinterpreting it. Without the group by, the plan is a candidate for nestloop-with-inner-index-scan; with the group by, there's another step in the way. Pushing down into subselects does get done, for instance in CVS tip I can change the last part of your query to "foo.article_id < 50" and get Hash Join (cost=25.18..53.53 rows=335 width=8) Hash Cond: ("outer".id = "inner".article_id) -> Seq Scan on article (cost=0.00..20.00 rows=1000 width=4) -> Hash (cost=25.01..25.01 rows=67 width=8) -> Subquery Scan foo (cost=24.17..25.01 rows=67 width=8) -> HashAggregate (cost=24.17..24.34 rows=67 width=8) -> Seq Scan on package (cost=0.00..22.50 rows=334 width=8) Filter: (article_id < 50) Obviously this is on toy tables, but the point is that the constraint does get pushed down through the GROUP BY when appropriate. regards, tom lane