Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id C8A829ED581 for ; Wed, 7 Dec 2011 09:42:18 -0400 (AST) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RYHlI-0004gV-CY for pgsql-bugs@postgresql.org; Wed, 07 Dec 2011 13:42:18 +0000 Received: from [204.145.120.229] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RYHl5-0007xz-Ip for pgsql-bugs@postgresql.org; Wed, 07 Dec 2011 13:42:03 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1RYHl5-0002hz-8N for pgsql-bugs@postgresql.org; Wed, 07 Dec 2011 13:42:03 +0000 Date: Wed, 07 Dec 2011 13:42:03 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6330: Incorrect select results when using mutually exclusive conditions for nullable column with index To: pgsql-bugs@postgresql.org From: nikolay.gorshkov@gmail.com X-Pg-Spam-Score: -2.2 (--) X-Archive-Number: 201112/54 X-Sequence-Number: 31865 The following bug has been logged on the website: Bug reference: 6330 Logged by: Nikolay Gorshkov Email address: nikolay.gorshkov@gmail.com PostgreSQL version: 9.0.4 Operating system: Ubuntu 10.04.2 LTS Description: = How to reproduce: # create table test (uid varchar(255) primary key, dt date); # insert into test values ('1', now()), ('2', now()), ('3', null); # create index test_dt on test(dt); # analyze test; # select * from test where dt is null and dt >=3D '2011-01-01 +01:00:00'; I expect zero results from the selection since the conditions are mutually exclusive. However, one row with NULL value in "dt" column is returned: uid | dt -----+---- 3 | (1 row) If the index "test_dt" is dropped: # drop index test_dt; The same query return zero rows, as expected: # select * from test where dt is null and dt >=3D '2011-01-01 +01:00:00'; uid | dt -----+---- (0 rows) PostgreSQL version information: # select version(); Result: PostgreSQL 9.0.4 on i486-pc-linux-gnu, compiled by GCC gcc-4.4.real (Ubuntu 4.4.3-4ubuntu5) 4.4.3, 32-bit Linux information: # uname -a Result: Linux hostname 2.6.32-21-generic-pae #32-Ubuntu SMP Fri Apr 16 09:39:35 UTC 2010 i686 GNU/Linux