Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D8D2BB5DC3F for ; Mon, 31 Oct 2011 11:37:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 05683-09 for ; Mon, 31 Oct 2011 14:37:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id A19E2B5DC3E for ; Mon, 31 Oct 2011 11:37:39 -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 p9VEbctU026439; Mon, 31 Oct 2011 10:37:39 -0400 (EDT) To: Robert Haas cc: Maksym Boguk , pgsql-bugs@postgresql.org Subject: Re: BUG #6278: Index scans on '>' condition on field with many NULLS In-reply-to: References: <201110310339.p9V3dtIb015254@wwwmaster.postgresql.org> Comments: In-reply-to Robert Haas message dated "Mon, 31 Oct 2011 09:48:26 -0400" Date: Mon, 31 Oct 2011 10:37:38 -0400 Message-ID: <26438.1320071858@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.101 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201110/317 X-Sequence-Number: 31587 Robert Haas writes: > On Sun, Oct 30, 2011 at 11:39 PM, Maksym Boguk wrote: >> Seems index scan cannot stop after finding first NULL during scan on '>' >> condition, and doing scan through all 90% nulls in table. > I can reproduce this. I'm not sure whether it's a bug either, but it > sure seems less than ideal. I suppose the problem is that we are > generating an index scan that starts at 0.9999 and runs through the > end of the index, rather than stopping when it hits the first NULL. I poked at this a bit last night. The reason it's happening is that the ">" key is only marked SK_BT_REQBKWD, not SK_BT_REQFWD, so _bt_checkkeys doesn't think it can stop when it hits the NULLs. Right at the moment it seems like we could mark that key with both flags, which leads to the conclusion that two flags are unnecessary and we could get by with only one direction-independent flag. Which, if memory serves, is how it used to be ... until I split the flag into two to fix some bug or other. But the regression tests still pass if you make _bt_mark_scankey_required mark any required key with both flags (which is the zeroth-order version of recombining them). So either my analysis was wrong at the time, or some later change has eliminated the need for two flags, or the regression tests aren't covering the problematic case. Will investigate further once I've absorbed some caffeine. regards, tom lane