BUG #14010: Multi-valued Index-only scans do not properly handle nulls in search - Mailing list pgsql-bugs

From gtakahashi@palantir.com
Subject BUG #14010: Multi-valued Index-only scans do not properly handle nulls in search
Date
Msg-id 20160309165136.8903.83559@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #14010: Multi-valued Index-only scans do not properly handle nulls in search
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      14010
Logged by:          Glen Takahashi
Email address:      gtakahashi@palantir.com
PostgreSQL version: 9.3.6
Operating system:   Red Hat Enterprise Linux Server release 6.7
Description:

Example table:

 a |   b
---+--------
 a | b
 a | [NULL]
 a | [NULL]
 (repeated 100's of times)
 b | a

select a,b from test_table where (a,b) > ('a','a') order by a,b;
returns:
 a | b
---+---
 a | b
 b | a
(2 rows)

create index on test_table (a,b);
The same query now returns:
 a | b
---+---
 a | b
(1 row)

However, the query without using `order by` returns the right values!
select a,b from test where (a,b) > ('a','a');
a | b
---+---
 a | b
 b | a
(2 rows)

If there are sufficiently small enough number of nulls in between (I got
differing numbers from 100-200 depending on the table), the query will
instead use a Quicksort for what I can only assume is optimization to avoid
reading random pages, and will actually return the right value. I was able
to get this to reproduce 100% of the time when using > 256 nulls in between
('a','b') and ('b','a');

pgsql-bugs by date:

Previous
From: alexander@spiteri.org
Date:
Subject: BUG #14009: pg_restore not restoring privilegs when one login/group role is missing
Next
From: Tom Lane
Date:
Subject: Re: BUG #14008: corr, covar_pop function returns different values on the same dataset