Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C22F9632CB9 for ; Mon, 12 Jul 2010 11:45:24 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 17346-01 for ; Mon, 12 Jul 2010 14:45:15 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 72ABE632944 for ; Mon, 12 Jul 2010 11:45:17 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o6CEjElV015040; Mon, 12 Jul 2010 10:45:14 -0400 (EDT) To: =?KOI8-U?B?96bUwcymyiD0yc3eydvJzg==?= cc: pgsql-performance@postgresql.org Subject: Re: Exists, limit and alternate plans In-reply-to: References: Comments: In-reply-to =?KOI8-U?B?96bUwcymyiD0yc3eydvJzg==?= message dated "Mon, 12 Jul 2010 16:29:07 +0300" Date: Mon, 12 Jul 2010 10:45:14 -0400 Message-ID: <15039.1278945914@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/197 X-Sequence-Number: 39586 =?KOI8-U?B?96bUwcymyiD0yc3eydvJzg==?= writes: > So, my Qs: > 1) Do we really have alternative plans for SubPlan that are selected at > runtime? Wow. Yup, see the AlternativeSubPlan stuff. > 2) Why "Seq scan" plan is selected by default? Is it because of outer limit > not being applied when calculating costs for subplans at runtime? It's currently driven off the estimated rowcount for the parent plan node --- 6831169 in your example. The subplan cannot see that the parent plan node will be terminated short of full execution, so it thinks that hashing the whole investor table will be a win. Obviously it'd be nice to improve that for cases like upper LIMITs. > 3) Why does limit inside exists helps? I think it defeats the applicability of the hash-the-whole-subtable approach. regards, tom lane