X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E99849DCB53 for ; Sun, 19 Feb 2006 13:31:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21240-04 for ; Sun, 19 Feb 2006 13:31:19 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id B5F0F9DCB69 for ; Sun, 19 Feb 2006 13:31:18 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1JHVHTS011674; Sun, 19 Feb 2006 12:31:18 -0500 (EST) To: Fredrik Olsson cc: pgsql-performance@postgresql.org Subject: Re: Force another plan. In-reply-to: <43F866E2.20001@treyst.se> References: <43F74592.7010701@treyst.se> <20490.1140287811@sss.pgh.pa.us> <43F866E2.20001@treyst.se> Comments: In-reply-to Fredrik Olsson message dated "Sun, 19 Feb 2006 13:38:58 +0100" Date: Sun, 19 Feb 2006 12:31:17 -0500 Message-ID: <11673.1140370277@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.11 required=5 tests=[AWL=0.110] X-Spam-Score: 0.11 X-Spam-Level: X-Archive-Number: 200602/312 X-Sequence-Number: 17298 Fredrik Olsson writes: > -> Seq Scan on t_entities (cost=0.00..1.49 rows=7 width=4) > (actual time=404.539..409.302 rows=2 loops=1) > Filter: ((haveaccess(createdby, responsible, "class", > false) OR CASE WHEN (partof = 'contacts'::name) THEN > ischildof(ancestorof(me()), "ID") ELSE false END) AND (subplan)) > SubPlan > -> Function Scan on alleventoccurances > (cost=0.00..12.50 rows=1000 width=8) (actual time=27.871..27.871 rows=0 > loops=14) This seems to be your problem right here: evaluating that subplan for each row of t_entities is pretty expensive, and yet the planner's estimating a total cost of only 1.49 to run the scan. What PG version is this? AFAICT we've accounted for subplan costs in scan quals for a long time, certainly since 7.4. Can you put together a self-contained test case for this? regards, tom lane