Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VbtSV-000205-74 for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Oct 2013 14:42:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VbtSU-00017k-NE for pgsql-bugs@arkaria.postgresql.org; Thu, 31 Oct 2013 14:42:50 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VblZI-0000or-1J for pgsql-bugs@postgresql.org; Thu, 31 Oct 2013 06:17:20 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VblZF-00035h-BN for pgsql-bugs@postgresql.org; Thu, 31 Oct 2013 06:17:19 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VblZE-00052U-ML for pgsql-bugs@postgresql.org; Thu, 31 Oct 2013 06:17:17 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1VblZ9-00044Z-5J for pgsql-bugs@postgresql.org; Thu, 31 Oct 2013 06:17:11 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8571: Planner miss-estimates ' is not true' as not matching any rows To: pgsql-bugs@postgresql.org From: tgarnett@panjiva.com Message-Id: Date: Thu, 31 Oct 2013 06:17:11 +0000 X-Pg-Spam-Score: -0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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 ' IS NOT true/false', it does not seem to do so for equivalent expressions such as ' is null or not ' 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