pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Mark Dilger <hornschnorter@gmail.com>
Cc: Adrien Nayrat <adrien.nayrat@dalibo.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists
Date: Tue, 27 Mar 2018 19:42:39 +0200
Message-ID: <fb20a5d8-032c-0678-10c8-522b695af7dd@2ndquadrant.com> (raw)
In-Reply-To: <CAEZATCVKFCLi4NcXBU9ETvOO4WouVr8nfaUkeW6QUg_87YXBUg@mail.gmail.com>
References: <20180310171906.gd6vyz6hnou2n3h7@alvherre.pgsql>
	<850c3b6b-2641-496c-4efc-500c720f7260@2ndquadrant.com>
	<ec49a434-b814-2cfa-f602-02a0cc9e518c@2ndquadrant.com>
	<CAEZATCW9AXzf+1T44B0=rBd8a0AD+pWO_PpkhApqLBE9JS1Cyg@mail.gmail.com>
	<66ba9c45-3b07-e5b6-fd11-15e75f6ee8e1@2ndquadrant.com>
	<CAEZATCUC8h6Osegq2Lw75Hc1NG=72JgNiiTQSSp9CpDCkQgakw@mail.gmail.com>
	<49348328-1a02-7e45-e50f-e1d4d0243c5c@2ndquadrant.com>
	<CAEZATCVKFCLi4NcXBU9ETvOO4WouVr8nfaUkeW6QUg_87YXBUg@mail.gmail.com>



On 03/27/2018 04:58 PM, Dean Rasheed wrote:
> On 27 March 2018 at 01:36, Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote:
>> BTW I think there's a bug in handling the fullmatch flag - it should not
>> be passed to AND/OR subclauses the way it is, because then
>>
>>     WHERE a=1 OR (a=2 AND b=2)
>>
>> will probably set it to 'true' because of (a=2 AND b=2). Which will
>> short-circuit the statext_clauselist_selectivity, forcing it to ignore
>> the non-MCV part.
>>
> 
> I'm not sure that's true. Won't the outer call to
> mcv_update_match_bitmap() overwrite the value of fullmatch returned by
> the nested call, and set fullmatch to false because it has only seen 1
> attribute equality match? I think that's the correct result, but I
> think that's just luck.
> 
> The dubious part is the way fullmatch is calculated for OR clauses --
> I think for an OR clause we want to know the attributes matched in
> *every* subclause, rather than in *any* subclause, as we do for AND.
> So I think the only way an OR clause at the top-level should return a
> full match is if every sub-clause was a full match, for example:
> 
>   WHERE (a=1 AND b=2) OR (a=2 AND b=1)
> 

Yes, that seems like the right behavior.

> But then consider this:
> 
>   WHERE a=1 AND (b=1 OR b=2)
> 
> That should also potentially be a full match, but that can only work
> if mcv_update_match_bitmap() returned the set of matching attributes
> (eqmatches), rather than fullmatch, so that it can be merged
> appropriately in the caller. So for an OR clause, it needs to return
> eqmatches containing the list of attributes for which every sub-clause
> matched with equality against the MCV list, and in an outer AND clause
> that can be added to the outer eqmatches list, which is the list of
> attributes for which any sub-clause matched with equality.
> 

I think it's useful to see it transformed from:

    WHERE a=1 AND (b=1 OR b=2)

to

    WHERE (a=1 AND b=1) OR (a=1 AND b=2)

which is the case already handled above. And yes, tracking columns with
an equality seems reasonable.

regards

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




view thread (167+ messages)  latest in thread

Message-ID: <fb20a5d8-032c-0678-10c8-522b695af7dd@2ndquadrant.com>
Permalink:  ../fb20a5d8-032c-0678-10c8-522b695af7dd@2ndquadrant.com/
Also on:    postgresql.org/message-id/fb20a5d8-032c-0678-10c8-522b695af7dd@2ndquadrant.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, dean.a.rasheed@gmail.com, alvherre@2ndquadrant.com, andres@anarazel.de, thomas.munro@enterprisedb.com, hornschnorter@gmail.com, adrien.nayrat@dalibo.com
  Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists
  In-Reply-To: <fb20a5d8-032c-0678-10c8-522b695af7dd@2ndquadrant.com>

* 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