Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0scX-0001Cv-Gf for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Mar 2018 17:42:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0scU-0006KI-9E for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Mar 2018 17:42:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0scU-0006K8-29 for pgsql-hackers@lists.postgresql.org; Tue, 27 Mar 2018 17:42:50 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f0scQ-0002WG-9r for pgsql-hackers@postgresql.org; Tue, 27 Mar 2018 17:42:49 +0000 Received: by mail-wr0-x243.google.com with SMTP id d1so11215424wrj.13 for ; Tue, 27 Mar 2018 10:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=U4Keaf44uWW0eRGT4JW3MbTwEPnzOg0guSxaAQkGZdM=; b=TsibKViUknBQlbvF3oYgAwl+tcwmDIVLAagnG5pgccz9CCGQ4KCInYUYex+uu9hz2J MPXXxcSSuPJX9ygl6JjUyuyWzQGt/svWU/7hUgGAvb29gePlr65QFkqy83QTSG9ONhib bPSMIGULTIr23oBYAMjlzTF+mUPrwC54I+wEDwLFcHp835BjdT+oWVb3JZVmxfeTtH6J XqY6ShBvtJ6h7WkOcVuvsYF97rTq/itFClh/r0lGkTAIYKkA05SoyNNyz1siVAwfCaNo iGk3P+MGCI61S84uLxk6aNxJU/dU4XQ7i93KdHuNZrLy8gvrJSrC8LXy6vnNvqOz910l bNxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=U4Keaf44uWW0eRGT4JW3MbTwEPnzOg0guSxaAQkGZdM=; b=N2qXDm5DX/wx4pkQKxi12DD8JhmW0geTWSvoIOLN9lGCdVxNwHeR+zBRm1u8Ryaqic omV9sjiwOCb+JM56AKTicskAJIOI2piHsiFNDaQ83p0nlMT+mA8/1ZaJTvwKr/nwFflH MCxu9JomzewoDQt8uyLEKhQmKXzuggTcD1V+IQows7Ay7zEmknydbWkkAtqJAfPV+XHi Oh/R56SSTP4s8bIedlP7BPR8iJ3WB1BiGyqX5rSELsJXlXUHABmeCzit44ZjTfUNIEq9 X4JbG4eJl8rmwTYbxhRf4y1wCizFq+XseQlJak5KTPaaPbKoEI7Bpt/ig86lljab5663 2PNw== X-Gm-Message-State: AElRT7FzcsqRQ4ums0ioscfZHsBjsS2Qne3tafK8dyCkoFEqjMqJSQY4 LOoYsfn7WsicXpeWledZH3kmWN31+8+4TBUUxTE5nnd+jwoTQKsPdpL6VLkNW6ciKlhFL5C0HiB n0eYfOLsHqS4/mAPOGBdhAdXtc+H1V42GgDeJQp02MCsb8mQms2E9N19ifrbsnqm7vQIzdCy2rf ap0JE5bNsW X-Google-Smtp-Source: AIpwx48Es8vB3kadnM2DqkT2/xyBkU9rMqnsbZ2Hn2WAvONwq93A1Za039w55hy2x4hUHK1oifKOrA== X-Received: by 10.223.219.198 with SMTP id e6mr276439wrj.212.1522172563199; Tue, 27 Mar 2018 10:42:43 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id m129sm2003440wma.16.2018.03.27.10.42.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 10:42:42 -0700 (PDT) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Dean Rasheed Cc: Alvaro Herrera , Andres Freund , Thomas Munro , Mark Dilger , Adrien Nayrat , Pg Hackers References: <20180310171906.gd6vyz6hnou2n3h7@alvherre.pgsql> <850c3b6b-2641-496c-4efc-500c720f7260@2ndquadrant.com> <66ba9c45-3b07-e5b6-fd11-15e75f6ee8e1@2ndquadrant.com> <49348328-1a02-7e45-e50f-e1d4d0243c5c@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Tue, 27 Mar 2018 19:42:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/27/2018 04:58 PM, Dean Rasheed wrote: > On 27 March 2018 at 01:36, Tomas Vondra 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