From: Maksym Boguk <maxim.boguk@gmail.com>
To: pgsql-bugs@postgresql.org
Subject: BUG #6278: Index scans on '>' condition on field with many NULLS
Date: Mon, 31 Oct 2011 03:39:55 GMT
Message-ID: <201110310339.p9V3dtIb015254@wwwmaster.postgresql.org> (raw)
The following bug has been logged online:
Bug reference: 6278
Logged by: Maksym Boguk
Email address: maxim.boguk@gmail.com
PostgreSQL version: 9.0
Operating system: Linux
Description: Index scans on '>' condition on field with many NULLS
Details:
I not sure it is missing feature or actual bug.
However very selective index scan on '>' condition can work pretty
inefficient on column with many nulls.
(in the same time '<' work well).
Seems index scan on '>' condition going through all nulls in index.
Test case (tested on 8.4 and 9.0 with same effect):
postgres=# CREATE table test as select (case when random()>0.1 then NULL
else random() end) as value from generate_series(1,10000000);
SELECT 10000000
postgres=# CREATE INDEX test_value_key on test(value);
CREATE INDEX
postgres=# SELECT count(*) from test;
count
----------
10000000
(1 row)
postgres=# VACUUM ANALYZE test;
VACUUM
postgres=# EXPLAIN ANALYZE select * from test where value>0.9999;
QUERY PLAN
----------------------------------------------------------------------------
-----------------------------------------------
Index Scan using test_value_key on test (cost=0.00..13.78 rows=105
width=8) (actual time=0.010..155.318 rows=91 loops=1)
Index Cond: (value > 0.9999::double precision)
Total runtime: 155.346 ms
(3 rows)
Oops... 160ms to return 90 rows from memory.
In the same time 100 rows from other index side:
postgres=# EXPLAIN ANALYZE select * from test where value<0.0001;
QUERY PLAN
----------------------------------------------------------------------------
----------------------------------------------
Index Scan using test_value_key on test (cost=0.00..15.69 rows=120
width=8) (actual time=0.006..0.158 rows=103 loops=1)
Index Cond: (value < 0.0001::double precision)
Total runtime: 0.175 ms
(3 rows)
That is good result (1000 faster then other way around).
For sure that can be fixed via create index with NOT NULL predicated. But
may be that problem worth small investigation.
Seems index scan cannot stop after finding first NULL during scan on '>'
condition, and doing scan through all 90% nulls in table.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: maxim.boguk@gmail.com
Subject: Re: BUG #6278: Index scans on '>' condition on field with many NULLS
In-Reply-To: <201110310339.p9V3dtIb015254@wwwmaster.postgresql.org>
References: <201110310339.p9V3dtIb015254@wwwmaster.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox