Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D0A0BB5DBDF for ; Tue, 28 Jun 2011 18:45:52 -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 92313-10 for ; Tue, 28 Jun 2011 21:45:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f174.google.com (mail-gx0-f174.google.com [209.85.161.174]) by mail.postgresql.org (Postfix) with ESMTP id 3850BB5D803 for ; Tue, 28 Jun 2011 18:45:46 -0300 (ADT) Received: by gxk21 with SMTP id 21so253059gxk.19 for ; Tue, 28 Jun 2011 14:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=il6lOI52bv5KLbRTaV00ke94GitKu62QSrT2/Hs+5io=; b=SAhOqg1tZCbvD26TiAURr5Iu09cbSNF2s1S/EF3t3H6L55BtgEamqM94RNas6Jkn4m 8ZWaUHnXzJF5qERml1/F4Ic0t+EymHVWkjenmTNx5/0atHUUruOsyqi2ugOtPtaHS8jr zzxRY/h+OxTawHuIVVK7XAfHyvBth3X2DM9KQ= MIME-Version: 1.0 Received: by 10.101.60.5 with SMTP id n5mr60753ank.8.1309297545991; Tue, 28 Jun 2011 14:45:45 -0700 (PDT) Received: by 10.100.227.4 with HTTP; Tue, 28 Jun 2011 14:45:45 -0700 (PDT) In-Reply-To: References: <201106281441.p5SEfU5x051446@wwwmaster.postgresql.org> Date: Tue, 28 Jun 2011 22:45:45 +0100 Message-ID: Subject: Re: BUG #6079: Wrong select result From: Dean Rasheed To: Pavel Stehule Cc: Renat , pgsql-bugs@postgresql.org Content-Type: multipart/mixed; boundary=001636ed6b352254e604a6cc9779 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.276 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, URIBL_SBL=1.623 X-Spam-Level: X-Archive-Number: 201106/212 X-Sequence-Number: 30591 --001636ed6b352254e604a6cc9779 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable > 2011/6/28 Renat : >> >> create table foo ( >> id bigint not null, >> date_to timestamp without time zone, >> CONSTRAINT foo_pkey PRIMARY KEY (id) >> ); >> >> CREATE INDEX foo_date_to_index >> =A0ON foo >> =A0USING btree >> =A0(date_to) >> >> insert into foo (id, date_to) values (1, now()); >> insert into foo (id, date_to) values (2, NULL); >> >> select * from foo where date_to is null and date_to > '2011-01-01' >> >> Expected: 0 rows >> >> But: it return 1 row with id=3D2 >> I get the same error on HEAD too. An even simpler test case is this: create table foo(a int); create index foo_a_idx on foo(a); insert into foo values (10),(NULL); select 1 from foo where a is null and a > 10000; ?column? ---------- 1 (1 row) The problem seems to be in _bt_preprocess_keys(), which discards the "a > 10000" predicate in favour of the "a is null" predicate on the grounds that "null > 10000" in a nulls-last index. It looks like a previous revision had the right check, based on the logic that x IS NULL is incompatible with any other predicate. Regards, Dean --001636ed6b352254e604a6cc9779 Content-Type: application/octet-stream; name="nbtutils.patch" Content-Disposition: attachment; filename="nbtutils.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_gphdrnyu0 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2FjY2Vzcy9uYnRyZWUvbmJ0dXRpbHMuYyBiL3NyYy9i YWNrZW5kL2FjY2Vzcy9uYnRyZWUvbmJ0dXRpbHMuYwpuZXcgZmlsZSBtb2RlIDEwMDY0NAppbmRl eCAyZTg5NmEyLi4wOWI4YzhlCioqKiBhL3NyYy9iYWNrZW5kL2FjY2Vzcy9uYnRyZWUvbmJ0dXRp bHMuYwotLS0gYi9zcmMvYmFja2VuZC9hY2Nlc3MvbmJ0cmVlL25idHV0aWxzLmMKKioqKioqKioq KioqKioqIF9idF9wcmVwcm9jZXNzX2tleXMoSW5kZXhTY2FuRGVzYyBzY2FuKQoqKiogMzM5LDM0 NCAqKioqCi0tLSAzMzksMzUxIC0tLS0KICAJCQkJCWlmICghY2hrIHx8IGogPT0gKEJURXF1YWxT dHJhdGVneU51bWJlciAtIDEpKQogIAkJCQkJCWNvbnRpbnVlOwogIAorIAkJCQkJLyogSVMgTlVM TCB0b2dldGhlciB3aXRoIGFueSBvdGhlciBwcmVkaWNhdGUgbXVzdCBmYWlsICovCisgCQkJCQlp ZiAoZXEtPnNrX2ZsYWdzICYgU0tfU0VBUkNITlVMTCkKKyAJCQkJCXsKKyAJCQkJCQlzby0+cXVh bF9vayA9IGZhbHNlOworIAkJCQkJCXJldHVybjsKKyAJCQkJCX0KKyAKICAJCQkJCWlmIChfYnRf Y29tcGFyZV9zY2Fua2V5X2FyZ3Moc2NhbiwgY2hrLCBlcSwgY2hrLAogIAkJCQkJCQkJCQkJCSAm dGVzdF9yZXN1bHQpKQogIAkJCQkJewo= --001636ed6b352254e604a6cc9779--