pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tgarnett@panjiva.com
To: pgsql-bugs@postgresql.org
Subject: BUG #8571: Planner miss-estimates '<null_column> is not true' as not matching any rows
Date: Thu, 31 Oct 2013 06:17:11 +0000
Message-ID: <E1VblZ9-00044Z-5J@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      8571
Logged by:          Timothy Garnett
Email address:      tgarnett@panjiva.com
PostgreSQL version: 9.2.4
Operating system:   Ubuntu Linux x86_64 12.04.3 LTS
Description:        

The planner seems to be badly miss-estimating the selectivity of '<always
null col> IS NOT true/false', it does not seem to do so for equivalent
expressions such as '<col> is null or not <col>' or expressions where the
selectivity is difficult to determine.


Simplified scenario:


create temporary table test_tbl as (select generate_series as id,
null::boolean as val from generate_series(1,1000));
analyze verbose test_tbl;


select count(*) from test_tbl where val is not true;
=> 1000


explain select * from test_tbl where val is null; -- correctly estimates
1000 rows
=> Seq Scan on test_tbl  (cost=0.00..15.00 rows=1000 width=5)
   Filter: (val IS NULL)


-- problem case --
explain select * from test_tbl where val is not true; -- estimates only 1
row!
=>  Seq Scan on test_tbl  (cost=0.00..15.00 rows=1 width=5)
   Filter: (val IS NOT TRUE)


explain select * from test_tbl where NOT coalesce(val, false); -- estimates
500 rows (actual 1,000) but will still generally result in a reasonable
plan
=>  Seq Scan on test_tbl  (cost=0.00..15.00 rows=500 width=5)
   Filter: (NOT COALESCE(val, false))


explain select * from test_tbl where val is null or not val; -- correctly
estimates 1000 rows
=> Seq Scan on test_tbl  (cost=0.00..15.00 rows=1000 width=5)
   Filter: ((val IS NULL) OR (NOT val))




Estimating only one row for the selectivity of a where clause with
additional joins involved when many rows match can result in some very bad
plans which is what we ran into.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <E1VblZ9-00044Z-5J@wrigleys.postgresql.org>
Permalink:  ../E1VblZ9-00044Z-5J@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1VblZ9-00044Z-5J@wrigleys.postgresql.org

 · 

reply

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: tgarnett@panjiva.com
  Subject: Re: BUG #8571: Planner miss-estimates '<null_column> is not true' as not matching any rows
  In-Reply-To: <E1VblZ9-00044Z-5J@wrigleys.postgresql.org>
  References: <E1VblZ9-00044Z-5J@wrigleys.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