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 1hfCKB-0001hV-Iv for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Jun 2019 23:55:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfCKA-0006yu-5K for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Jun 2019 23:55:06 +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 1hfCK9-0006vp-Qx for pgsql-hackers@lists.postgresql.org; Sun, 23 Jun 2019 23:55:05 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfCK6-0003YS-CK for pgsql-hackers@lists.postgresql.org; Sun, 23 Jun 2019 23:55:05 +0000 Received: by mail-wr1-x429.google.com with SMTP id f15so2022712wrp.2 for ; Sun, 23 Jun 2019 16:55:01 -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=HN114l0Hjok8Y3Wb2k7AcR+krgzqePXn/e3lJRHGT+0=; b=K3owkuXWepIvWwGyrSMjzeO3AmYSnhrKOvPuf4dD2FwR1CVj4O8ImEsucslbMBmBSL 1sV7RbBM/jTw7Gvj4hOOye02H8PJF2fCjx93qSSez+rGgp/BMMxCT/iIP085/7mXMm6g OGTYIs6wO0cfSI+RC/Sr8n9v7VQvBK/2Tjg2uhPKEN+FA0Z4wRg1xFzoMN1l4zpV10D+ mQwkcmyUFjlr8qslIHcdzQoNDhSeihxHHoWDhVjQh/1dzScrJnodPCve0wGEkyzkspWg DFk7Uk/zsf3j5SynaCp+F2Z1ZOr7PrBTpwtnrMLuytD0CCxT+Y3Kvw2x4Xg0pnIzcEyz k8nA== 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=HN114l0Hjok8Y3Wb2k7AcR+krgzqePXn/e3lJRHGT+0=; b=p5mfcZroL7XyQ8o9Gqm5fYoRhaLm7fXWjEjA0WnDZ0kjaranaVn7FQJM4hCvYdCcPM WWxpGa1kyeUb70y/1XJsPAsi+CNTV1R97N8N7kum7ztYzwPxgo4rtkzD7LIWOgYTmur1 9gShNz4ct8uGteP/bFzCcFIGRrMY9FGXQqcJapJuyKiX7fqrP0cx3TZhzZLImwB+7jp5 GoWHp8mj/ObtL/pCJM9/ippWg9+PanujAaPdAR8hFvH0Jmf2Qsz0jMK5DnlPiG9JEw+m C8xOUE6M+39wW0R3oeabo7bSHV4aeqm4Umui+dNxh0q6CT8bwVQae1lOtfpEcul3JZ5y i1aA== X-Gm-Message-State: APjAAAVCaW1f4GMwPhbKacrv/thwTOaIFoEqJB1KAea5E95Moq+OAsIk qdkxcTqKPhNN8FvPejyOBsOyag== X-Google-Smtp-Source: APXvYqw94gLDWE9gCOrm2fwfCUjkxJH7r5ok0YhqVo/HiYFJuIu0PbIXScgvSSt+q9wdAsVL2/G9/g== X-Received: by 2002:adf:de90:: with SMTP id w16mr73836329wrl.217.1561334099283; Sun, 23 Jun 2019 16:54:59 -0700 (PDT) Received: from localhost (ip-86-49-253-160.net.upcbroadband.cz. [86.49.253.160]) by smtp.gmail.com with ESMTPSA id d201sm7485691wmd.19.2019.06.23.16.54.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 16:54:56 -0700 (PDT) Date: Mon, 24 Jun 2019 01:54:55 +0200 From: Tomas Vondra To: Dean Rasheed Cc: PostgreSQL Hackers Subject: Re: Choosing values for multivariate MCV lists Message-ID: <20190623235455.td5yjk5rsmovwjin@development> References: <20190618205920.qtlzcu73whfpfqne@development> <20190620223548.p22wj7uejbrhkglf@development> <20190622141052.5csokbp3sx577mub@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190622141052.5csokbp3sx577mub@development> User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Jun 22, 2019 at 04:10:52PM +0200, Tomas Vondra wrote: >On Fri, Jun 21, 2019 at 08:50:33AM +0100, Dean Rasheed wrote: >>On Thu, 20 Jun 2019 at 23:35, Tomas Vondra wrote: >>> >>>On Thu, Jun 20, 2019 at 06:55:41AM +0100, Dean Rasheed wrote: >>> >>>>I'm not sure it's easy to justify ordering by Abs(freq-base_freq)/freq >>>>though, because that would seem likely to put too much weight on the >>>>least commonly occurring values. >>> >>>But would that be an issue, or a good thing? I mean, as long as the item >>>is above mincount, we take the counts as reliable. As I explained, my >>>motivation for proposing that was that both >>> >>> ... (cost=... rows=1 ...) (actual=... rows=1000001 ...) >>> >>>and >>> >>> ... (cost=... rows=1000000 ...) (actual=... rows=2000000 ...) >>> >>>have exactly the same Abs(freq - base_freq), but I think we both agree >>>that the first misestimate is much more dangerous, because it's off by six >>>orders of magnitude. >>> >> >>Hmm, that's a good example. That definitely suggests that we should be >>trying to minimise the relative error, but also perhaps that what we >>should be looking at is actually just the ratio freq / base_freq, >>rather than their difference. >> > >Attached are patches that implement this (well, the first one optimizes >how the base frequency is computed, which helps for high statistic target >values). The 0002 part picks the items based on > > Max(freq/base_freq, base_freq/freq) > >It did help with the addresses data set quite a bit, but I'm sure it needs >more testing. I've also tried using > > freq * abs(freq - base_freq) > >but the estimates were not as good. > >One annoying thing I noticed is that the base_frequency tends to end up >being 0, most likely due to getting too small. It's a bit strange, though, >because with statistic target set to 10k the smallest frequency for a >single column is 1/3e6, so for 2 columns it'd be ~1/9e12 (which I think is >something the float8 can represent). > FWIW while doing more tests on this, I've realized a rather annoying behavior while increasing the statistics target. With the current algorithm picking values merely based on frequency, the MCV list is expanded in a stable way. Increasing the statistics target means the MCV list may grow, but the larger MCV list will contain the smaller MCV one (ignoring changes due to a differences in the sample). After switching to the two-phase algorithm (first picking candidates based on mincount, then picking the items based on error) that's no longer true. I've repeatedly seen cases when increasing the target lowered mincount, adding candidates with larger frequency errors, removing some of the items from the "smaller" MCV list. In practice this means that increasing the statistics target may easily make the estimates much worse (for some of the values). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services