Re: Introducing floating point cast into filter drastically changes row estimate

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Introducing floating point cast into filter drastically changes row estimate
Date: 2012-10-24 19:26:39
Message-ID: 6962.1351106799@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Merlin Moncure <mmoncure(at)gmail(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Merlin Moncure 2012-10-24 19:47:48 Re: Introducing floating point cast into filter drastically changes row estimate
Previous Message Greg Hazel 2012-10-24 15:46:08 Re: BUG #7620: array_to_json doesn't support heterogeneous arrays