Re: Row count estimation bug in BETWEEN?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Щекин Ярослав <ladayaroslav(at)yandex(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Row count estimation bug in BETWEEN?
Date: 2015-06-13 16:35:20
Message-ID: 17475.1434213320@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

=?koi8-r?B?/cXLyc4g8dLP08zB1w==?= <ladayaroslav(at)yandex(dot)ru> writes:
> I've noticed strange row count estimations in BETWEEN predicate:

> EXPLAIN
> SELECT *
> FROM t1
> WHERE f1 = 42;
> -->> Bitmap Heap Scan on t1 (cost=203.07..28792.94 rows=10662 width=24) <skipped>

> EXPLAIN
> SELECT *
> FROM t1
> WHERE f1 BETWEEN 42 AND 42;
> -->> Index Scan using table1_field1_idx on t1 (cost=0.44..8.46 rows=1 width=24) <skipped>

> Why row count estimations for two logically equivalent queries are so
> different?

PG doesn't try to estimate inequalities exactly, because it usually
doesn't make enough of a difference to matter. Currently we don't
even bother to distinguish say ">" from ">=" for estimation purposes,
though certainly we would need to in order to deal with zero-width ranges
with any great amount of precision.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yaroslav 2015-06-13 20:51:50 Re: Row count estimation bug in BETWEEN?
Previous Message José María Terry Jiménez 2015-06-13 10:32:13 Re: FW: PostgreSQL and iptables