pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: Introducing floating point cast into filter drastically changes row estimate
Date: Wed, 24 Oct 2012 15:26:39 -0400
Message-ID: <6962.1351106799@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHyXU0zLUJ1jPUW5rJ8c269m=sGFCQd1AuSGudDNFSJ5DFk0QA@mail.gmail.com>
References: <CAHyXU0zLUJ1jPUW5rJ8c269m=sGFCQd1AuSGudDNFSJ5DFk0QA@mail.gmail.com>

Merlin Moncure <mmoncure@gmail.com> 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




view thread (8+ messages)  latest in thread

Message-ID: <6962.1351106799@sss.pgh.pa.us>
Permalink:  ../6962.1351106799@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6962.1351106799@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, mmoncure@gmail.com
  Subject: Re: Introducing floating point cast into filter drastically changes row estimate
  In-Reply-To: <6962.1351106799@sss.pgh.pa.us>
  References: <CAHyXU0zLUJ1jPUW5rJ8c269m=sGFCQd1AuSGudDNFSJ5DFk0QA@mail.gmail.com> <6962.1351106799@sss.pgh.pa.us>

* 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