Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8nkr-00032w-5r for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2019 15:12:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h8nkp-0003aK-Cp for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2019 15:12:43 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8nkp-0003aD-5a for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2019 15:12:43 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8nkm-0001d5-HK for pgsql-hackers@postgresql.org; Tue, 26 Mar 2019 15:12:42 +0000 Received: by mail-wr1-x442.google.com with SMTP id o1so14766220wrs.13 for ; Tue, 26 Mar 2019 08:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=tGljVm7gcCJJVW1/7I5PsMHIN2w/s7geFbOjSGhKZy4=; b=XoZU0YNT+ou4W2n/8W2lK31987oj9Jdh+JpO0URdDTTDBu68N9yYZVAmrIXAmws45J 7XZTJMfy3r8r3AV7uZ0TGpmJEhyAlH0+MJGuYfCinstp2lyc7gRPGh19tBQBfq3LY5o3 7l/UPvIutbEyXbNmkYRW/q0B+a2PE6fOSi/jEF9I/UhGbh1yqFthIBz8S/9c3ao53pId KZ+6TVcWr2BoOSbBXNJajVuMpDn9keunySG4kZpzDF/50/mdzfj1MrJTomkR3kcP9Nfj wtFTovDDyjh85Ew6UK1+76dpR8b9B7RWIneAlPzv8lXaE1xWF9+wtl+HRTBfslowUSC3 xUfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tGljVm7gcCJJVW1/7I5PsMHIN2w/s7geFbOjSGhKZy4=; b=cH3JHb2ZGueK5IlK+NxUMxBr2V6s0eiFRJl9xro3EK2GVm17xnzMwCleQeFMoBgoR3 B0SQNZAqctBsEHs8pwP1UFYHlD0Q7KQliyN0tB5oSs3+P4n2YoQhhT/A6oiCPcnO78N5 zkFgGlvFv6NJNaf9dz9JKayaT9gcSPKWOB7ZU3s52mmYyA22gAP98fCV+qpkBNI0djIP qnuVLntXvpF7zv8KHX6VmiAPItU/jjkrLs7PMjXPBZM0evgAXmVIvUfZkWjpiNXMwkB1 ZXeRtMHggD3VermOH3keS/1TAWFoVrgBOWRn8pzgVNgdUTNW0JuA8ZU6Dt+7kzlMWgSR F2rA== X-Gm-Message-State: APjAAAV/G5NAdYdyjSpuFZvPUNf6H5Sg9e/1AIcx+EPUzDmxteG1lMLu WMcp4qtSHjvTdJIxAJJ99JB7PQ== X-Google-Smtp-Source: APXvYqz7JC2HYoQsGEDN5p6SQ4mvh4XsFdnCcwi9CJ3quRlmRgahJN+JUiTKuHE6LmmK2Ed2z0uGhA== X-Received: by 2002:a5d:4f89:: with SMTP id d9mr19001910wru.195.1553613159450; Tue, 26 Mar 2019 08:12:39 -0700 (PDT) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id j184sm28847453wma.47.2019.03.26.08.12.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 08:12:38 -0700 (PDT) Date: Tue, 26 Mar 2019 16:12:35 +0100 From: Tomas Vondra To: Dean Rasheed Cc: David Rowley , Kyotaro HORIGUCHI , Alvaro Herrera , Michael Paquier , Andres Freund , Thomas Munro , Bruce Momjian , Mark Dilger , PostgreSQL Hackers Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists Message-ID: <20190326151235.GA3088@development> References: <37ce47c5-e0cf-c6d3-6923-6b8cfd1cc6b1@2ndquadrant.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Mar 26, 2019 at 11:59:56AM +0000, Dean Rasheed wrote: >On Mon, 25 Mar 2019 at 23:36, Tomas Vondra wrote: >> >> Attached is an updated patch, fixing all the issues pointed out so far. >> Unless there are some objections, I plan to commit the 0001 part by the >> end of this CF. Part 0002 is a matter for PG13, as previously agreed. >> > >Yes, I think that's reasonable. It looks to be in pretty good shape. I >have reviewed most of the actual code, but note that I haven't >reviewed the docs changes and I didn't spend much time reading code >comments. It might benefit from a quick once-over comment tidy up. > >I just looked through the latest set of changes and I have a couple of >additional review comments: > >In the comment about WIDTH_THRESHOLD, s/pg_statistic/pg_statistic_ext/. > >In statext_mcv_build(), I'm not convinced by the logic around keeping >the whole MCV list if it fits. Suppose there were a small number of >very common values, and then a bunch of uniformly distributed less >common values. The sample might consist of all the common values, plus >one or two instances of some of the uncommon ones, leading to a list >that would fit, but it would not be appropriate to keep the uncommon >values on the basis of having seen them only one or two times. The >fact that the list of items seen fits doesn't by itself mean that >they're all common enough to justify being kept. In the per-column >stats case, there are a bunch of other checks that have to pass, which >are intended to test not just that the list fits, but that it believes >that those are all the items in the table. For MV stats, you don't >have that, and so I think it would be best to just remove that test >(the "if (ngroups > nitems)" test) and *always* call >get_mincount_for_mcv_list() to determine how many MCV items to keep. >Otherwise there is a risk of keeping too many MCV items, with the ones >at the tail end of the list producing poor estimates. > I need to think about it a bit, but I think you're right we may not need to keep those items. The reason why I decided to keep them is that they may represent cases where the (actual frequency << base frequency). But now that I think about it, that can probably be handled as ((1 - total_sel) / ndistinct) So yeah, I think I'll just change the code to always us the mincount. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services