Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TR6bG-0003X0-7v for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 19:26:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TR6bA-0004li-PC for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 19:26:45 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q9OJQd38006963; Wed, 24 Oct 2012 15:26:39 -0400 (EDT) From: Tom Lane To: Merlin Moncure cc: pgsql-bugs Subject: Re: Introducing floating point cast into filter drastically changes row estimate In-reply-to: References: Comments: In-reply-to Merlin Moncure message dated "Wed, 24 Oct 2012 10:06:51 -0500" Date: Wed, 24 Oct 2012 15:26:39 -0400 Message-ID: <6962.1351106799@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201210/218 X-Sequence-Number: 34518 Merlin Moncure writes: > The following query runs fine: it estimates the returned rows pretty wel: > postgres=# explain analyze select * from foo where i > 100 and i < 10000; > ...but if you introduce a floating point cast, it drastically changes > the returned rows (why?): > postgres=# explain analyze select * from foo where i::float8 > 100 > and i::float8 < 10000; The planner has stats about "i", but none about "i::float8", so you're getting a default estimate in the second case. It does, however, realize that you're applying a range restriction condition to "i::float8", and the default selectivity estimate for that is intentionally pretty small. regards, tom lane