Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1feh5j-0005h7-3K for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Jul 2018 13:29:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1feh5g-0007H5-7r for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Jul 2018 13:29:32 +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 1feh5g-0007Gy-0p for pgsql-hackers@lists.postgresql.org; Sun, 15 Jul 2018 13:29:32 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1feh5X-0001oE-UU for pgsql-hackers@postgresql.org; Sun, 15 Jul 2018 13:29:31 +0000 Received: by mail-wm0-x243.google.com with SMTP id h20-v6so13163273wmb.4 for ; Sun, 15 Jul 2018 06:29:23 -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=BaUgswxay7DKgDcy4CVjhVCwghAv16UEfdlfwxFWw/0=; b=NLwBNPacOn5uqY1XzgNkJ4XlcFyIlgwSvmveLCARJkTq705PohDnq/2MRO+zTAaEpN rTLogddEdB1zB/hef0ExxXy1ob7tXSveOSH8w54qdhGjO+y3qp78qoxkUywMSI2DKibr rGy4lTjKCzsQ9e+zjMzdXbDPtP67I+vGU/JnQOJ+vHhz94yD0uqh1ljiC4XlUPRZFsLL nHQqjAAc1ShBWpofeB6hPR7eahWStP9nSXx8WE1w2o8wqQU5gkii2x7CoPox49GYAyEr XyCyn8zHZlQZxC72S6hsp8xsQ1eg5QG+5lnN47H5dP8FmvueyQijIc72+q8osEBA6f51 cl0w== 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=BaUgswxay7DKgDcy4CVjhVCwghAv16UEfdlfwxFWw/0=; b=bezVSzpXMICfA4yWrLwaYQVMYB4HahgSChbs5gSTw+DPGKGGPOZKhO7Qf0kCBJ0iph kK0aNjG6TLAunwpvy1W73m1Arllj/J7t1vd37UeczZB0SOU1lAgkbPQUhMJVoKqX3FLh stxuKPoyQij6UwvRwCBke3KMWFie0i/nUdBRTTyfi5B3GIzA4+jq0X/Q3fTQ3OGoiBCn EdG0DOIE0qgrIGODDvcSjLVzoYDPnXbzlD4ft9pkVjMPSFDjfGn8WywTNYKuHzLtUvV+ 4wSpK3XP/ewkpUf2nXyQrLqCcbrCtYZXh1IOkeWHHalboZ+PpwpV60CA3Ubzbn2sVGzH 8VUQ== X-Gm-Message-State: AOUpUlHmtzkt+dI10Zx1SxLe7OkL8HZA+XRtgpaxBGI1UHpcBQOV5kvu IymPGoSycJ0afbXYSWGkA1npU2ukmonJ7bFdkcBNEljZY2Nf/UPb8+X2aeYq3uM6fTvWgNrV3WA tusTRVZ6tAMw1yWKZUsktFeedXCv9VErZL0JMR01H+9lE1/NfbLJfIXlNQPmlK3hECpLcZskFVU WmXMUKtIbh X-Google-Smtp-Source: AAOMgpflH7owBWTPGnF5Q7rhUeRd+QM4faL+7ytXWSD35+xnGWDyi1Pt6U4lhxcsn4wfHYrgcDkKCA== X-Received: by 2002:a1c:864c:: with SMTP id i73-v6mr8145626wmd.40.1531661362238; Sun, 15 Jul 2018 06:29:22 -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 k14-v6sm25257859wrg.38.2018.07.15.06.29.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Jul 2018 06:29:21 -0700 (PDT) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Dean Rasheed Cc: Bruce Momjian , Alvaro Herrera , Andres Freund , Thomas Munro , Mark Dilger , Adrien Nayrat , Pg Hackers References: <49348328-1a02-7e45-e50f-e1d4d0243c5c@2ndquadrant.com> <1aaa338a-fa70-1b92-988e-498eb996ce57@2ndquadrant.com> <681c6a78-2aef-769e-bd0f-290ac650e71d@2ndquadrant.com> <7d12b5d1-ac77-67e3-c67e-7fcbd3753e9c@2ndquadrant.com> <20180407141201.GA10394@momjian.us> <4416a567-4452-c5fd-7117-5cc7827b5fad@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Sun, 15 Jul 2018 15:29:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 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 07/15/2018 11:36 AM, Dean Rasheed wrote: > ... > > What I'm considering is an algorithm where we simultaneously compute 3 things: > > simple_sel - The result we would get without multivariate stats (*) > mcv_sel - The multivariate MCV result > hist_sel - The multivariate histogram result > > (*) except that at each stage where we add a new clause to the > simple_sel value, we improve upon that estimate by factoring in a > lower bound from the multivariate stats so far, so that even if the > multivariate stats fail to generate anything at the end, we've managed > to account for some of the non-independence of the columns. > > If the MCV matches represented all the matches, then at the end we > would have simple_sel = mcv_sel, and hist_sel = 0, and we'd be done. > It's quite unclear to me how this algorithm could reliably end up with hist_sel=0 (in cases where we already don't end up with that). I mean, if a bucket matches the conditions, then the only way to eliminate is by deducing that MCV already contains all the matches - and that's rather difficult for complex clauses ... > Otherwise, we'd have simple_sel >= mcv_sel, and a possibly non-zero > hist_sel, but if we had managed to factor in both mcv_sel and hist_sel > to simple_sel at each stage as we went along, then simple_sel is the > best overall estimate we can return. > Hmm. I may not be understanding the algorithm yet, but I find it hard to believe applying the stats incrementally is going to produce reliably better estimates that looking at all clauses at once. I understand deducing upper/lower boundaries is useful, but I wonder if we could do that somehow with the current algorithm. > Perhaps this is not so very different from what you're currently > doing, except that with this approach we might also end up with > mcv_sel = 0 and hist_sel = 0, but still have an improved simple_sel > estimate that had accounted for some the multivariate stats available > along the way. > I don't know, really. I'll have to try hacking on this a bit I guess. But there's one obvious question - in what order should we add the clauses? Does it matter at all, or what is the optimal order? We don't need to worry about it now, because we simply consider all clauses at once, but I guess the proposed algorithm is more sensitive to this. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services