pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Mark Dilger <hornschnorter@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Using multiple extended statistics for estimates
Date: Thu, 14 Nov 2019 22:51:25 +0100
Message-ID: <20191114215125.awaa77vsihszguqk@development> (raw)
In-Reply-To: <63781298-77de-bfff-f390-b4bfcdfb720b@gmail.com>
References: <20191106195849.odhhc66xd23hw6hf@development>
	<97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com>
	<0da76f1f-5f9c-3ce3-3ac6-042d2a18430a@gmail.com>
	<20191110173428.w5klequcmb6gawaa@development>
	<20191113152823.jdpertc73gfo2mk7@development>
	<2e183f8d-1304-6024-90de-1017a861a235@gmail.com>
	<20191114155541.zliellgi2if4bb5f@development>
	<e41167d8-53cd-0f18-9301-85fd9a70d8d8@gmail.com>
	<20191114200420.c3x2jf7ywzs23uzo@development>
	<63781298-77de-bfff-f390-b4bfcdfb720b@gmail.com>

On Thu, Nov 14, 2019 at 01:17:02PM -0800, Mark Dilger wrote:
>
>
>On 11/14/19 12:04 PM, Tomas Vondra wrote:
>>Aha, I think I understand now - thanks for the explanation. You're right
>>the comment is trying to explain why just taking the last clause for a
>>given attnum is fine. I'll try to make the comment clearer.
>>
>>For the case with equal Const values that should be mostly obvious, i.e.
>>"a=1 AND a=1 AND a=1" has the same selectivity as "a=1".
>>
>>The case with different Const values is harder, unfortunately. It might
>>seem obvious that "a=1 AND a=2" means there are no matching rows, but
>>that heavily relies on the semantics of the equality operator. And we
>>can't simply compare the Const values either, I'm afraid, because there
>>are cases with cross-type operators like
>>
>>  a = 1::int AND a = 1.0::numeric
>>
>>where the Consts are of different type, yet both conditions can be true.
>>
>>So it would be pretty tricky to do this, and the current code does not
>>even try to do that.
>>
>>Instead, it just assumes that it's mostly fine to overestimate, because
>>then at runtime we'll simply end up with 0 rows here.
>
>I'm unsure whether that could be a performance problem at runtime.
>
>I could imagine the planner short-circuiting additional planning when
>it finds a plan with zero rows, and so we'd save planner time if we
>avoid overestimating.  I don't recall if the planner does anything like
>that, or if there are plans to implement such logic, but it might be
>good not to rule it out.  Tom's suggestion elsewhere in this thread to
>use code in predtest.c sounds good to me.
>

No, AFAIK the planner does not do anything like that - it might probaly
do that if it could prove there are no such rows, but that's hardly the
case for estimates based on approximate information (i.e. statistics).

If could do that based on the predicate analysis in predtest.c mentioned
by Tom, although I don't think it does anything beyond tweaking the row
estimate to ~1 row.

>I don't know if you want to expand the scope of this particular patch to
>include that, though.
>

Certainly not. It's an interesting but surprisingly complicated problem,
and this patch simply aims to add different improvement.

regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services 





view thread (26+ messages)  latest in thread

Message-ID: <20191114215125.awaa77vsihszguqk@development>
Permalink:  ../20191114215125.awaa77vsihszguqk@development/
Also on:    postgresql.org/message-id/20191114215125.awaa77vsihszguqk@development

 · 

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-hackers@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, hornschnorter@gmail.com
  Subject: Re: Using multiple extended statistics for estimates
  In-Reply-To: <20191114215125.awaa77vsihszguqk@development>
  References: <20191106195849.odhhc66xd23hw6hf@development> <97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com> <0da76f1f-5f9c-3ce3-3ac6-042d2a18430a@gmail.com> <20191110173428.w5klequcmb6gawaa@development> <20191113152823.jdpertc73gfo2mk7@development> <2e183f8d-1304-6024-90de-1017a861a235@gmail.com> <20191114155541.zliellgi2if4bb5f@development> <e41167d8-53cd-0f18-9301-85fd9a70d8d8@gmail.com> <20191114200420.c3x2jf7ywzs23uzo@development> <63781298-77de-bfff-f390-b4bfcdfb720b@gmail.com> <20191114215125.awaa77vsihszguqk@development>

* 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