Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id EEF0D632A74 for ; Fri, 27 Mar 2009 15:43:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 49054-02 for ; Fri, 27 Mar 2009 15:43:21 -0300 (ADT) 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 AEE7B632885 for ; Fri, 27 Mar 2009 15:43:23 -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 n2RIhD35002299; Fri, 27 Mar 2009 14:43:14 -0400 (EDT) To: Matthew Wakeling cc: =?KOI8-U?B?96bUwcymyiD0yc3eydvJzg==?= , pgsql-performance@postgresql.org Subject: Re: Very specialised query In-reply-to: References: <331e40660903270936u5db00807sb1169df66443ade3@mail.gmail.com> Comments: In-reply-to Matthew Wakeling message dated "Fri, 27 Mar 2009 17:34:26 -0000" Date: Fri, 27 Mar 2009 14:43:13 -0400 Message-ID: <2298.1238179393@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.012 tagged_above=0 required=5 tests=AWL=0.012 X-Spam-Level: X-Archive-Number: 200903/397 X-Sequence-Number: 33319 Matthew Wakeling writes: > Notice the two different index conditions: > (l1.end > l2.start) AND (l1.start < l2.start) - "between" > (l1.end > l2.start) AND (l1.start >= l2.start) - open-ended > Both have a cost of (cost=0.00..123.10 rows=4809 width=12) > Postgres estimates these two index scans to be equivalent in cost, where > they are actually vastly different in real cost. Shouldn't Postgres favour > a "between" index scan over an open-ended one? Currently the planner only notices that for a range check that involves comparisons of the same variable expression to two constants (or pseudoconstants anyway). In principle it might be reasonable to have a heuristic that reduces the estimated selectivity in the example above, but it looks to me like it'd make clauselist_selectivity() a lot slower and more complicated. When you see (l1.end > l2.start), how do you know which variable to try to match up against others? And if you try to match both, what do you do when you get matches for both? regards, tom lane