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 1ghcWU-00087D-2r for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jan 2019 15:45:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghcWS-0003V3-DU for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Jan 2019 15:45: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_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghcWS-0003Uv-1t for pgsql-hackers@lists.postgresql.org; Thu, 10 Jan 2019 15:45:32 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghcWP-0004LD-Af for pgsql-hackers@postgresql.org; Thu, 10 Jan 2019 15:45:31 +0000 Received: by mail-wm1-x32b.google.com with SMTP id r24so13632165wmh.0 for ; Thu, 10 Jan 2019 07:45:29 -0800 (PST) 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=5CWOCsL1/v4R4WcXTtti1orz5vBTaOXKnB20r9ptjOU=; b=BrWvcYbOGZykNAowG0CpGHKJk71xi/TCgJqZxHdienTjRwWv0tyc37jjNFaWD/JQ0K E0CyGupS8TLMrOqvyx8RUlhEDIC9e8GYGkFcQuhL96RFn94EKGPjJY85g6mzi376UWKI O7q3+46KltzhrMXOdm/yyuYJ9LT1FS6mVxoveIuBtfwax7mIhKK0+9jiatzgiQl2T9en X0+Vx8zkvS6c9nWPkBfSU0sebAPjvvw0I7fayagIPBtU/3Yyr53osU17fXZA5F2G96SV nTLeaayWHgcuUQHePEn8keJcZNIikRUMcpYPPZ9f7MUzaMKtzTpEdWdYKcIDKVOn42uf VFKA== 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=5CWOCsL1/v4R4WcXTtti1orz5vBTaOXKnB20r9ptjOU=; b=ADV+9o2arTd33Zb7gYQG4AdkOEAsTxTNYA6w3cbxpBYvio60kdLh/fYAZMdPMF5L6t uKxvfW0pcTxOlaW+Pz1DSyfwfpp9EmykEHorb+dfvRJibfO5Hmr7/jKBoNZS65BZxLGW s57cVMWAVxfBNAMq7M3Z2rnn4xA1BqSL69wnBg/X3bdPfMoPk+72Y35hEQWYmQO83MwR Qple3Pe2rMFTgsDJrr3jlzqDmOsWMKbYqXeyVXXjVKt3GJy4TDEry9xwQr3IHTc2FA7/ mdW9wAYV/kKcvbEyACLj4GWF2bOBWpjrtGA/oUl7kfzhNsZvsK12sOE+z/3eMWYFKQZn 84/g== X-Gm-Message-State: AJcUukedhaC9r3TrdY7R5pP/VhDGMiJ4edZKzr4Ym9Xsz90QGRekamkI RAAEC8lYZM2LMWVBWV6o6IlBbjHhXp+LDNvmrOsQphlRccIvtisH7jHpc6JKJ8WgR1TnPznf3VA UGDwFRWRGJoWNxxoZGLoIks/EgY/gwU5LXwretyrNwiF8ifzrJVcArzQv/oJ/03jX9iWs/1xW0T j0YCvlb8qGv6x3nw== X-Google-Smtp-Source: ALg8bN5UUDOfHjKTPG2qHgigcBzIP6Wje0usGc3XL2gl/tQXSAsBsK4F8wbDGT6nKO8XbCXDb/uP6Q== X-Received: by 2002:a1c:b687:: with SMTP id g129mr10174245wmf.59.1547135127594; Thu, 10 Jan 2019 07:45:27 -0800 (PST) Received: from [10.137.2.21] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id s5sm12462809wmh.37.2019.01.10.07.45.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 07:45:26 -0800 (PST) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Dean Rasheed Cc: Thomas Munro , Bruce Momjian , Alvaro Herrera , Andres Freund , Mark Dilger , Adrien Nayrat , Pg Hackers References: <49348328-1a02-7e45-e50f-e1d4d0243c5c@2ndquadrant.com> <80bc98b2-1c43-1fe8-b316-d447bb68cff2@2ndquadrant.com> <341ca23f-144d-130d-1b45-ddddf581797e@2ndquadrant.com> <8ac8bd94-478d-215d-e6bd-339f1f20a74c@2ndquadrant.com> <11b0d685-152d-8320-5f49-a7c6ac3ee90a@2ndquadrant.com> <3b8577ba-6a29-d1f0-b155-d3a50c1a8399@2ndquadrant.com> <11223173-bd90-4fa8-8cf1-49928b615405@2ndquadrant.com> From: Tomas Vondra Message-ID: Date: Thu, 10 Jan 2019 16:45:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 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 1/10/19 4:20 PM, Dean Rasheed wrote: > On Wed, 9 Jan 2019 at 15:40, Tomas Vondra wrote: >> On 1/8/19 3:18 PM, Dean Rasheed wrote: >>> So actually, the estimate for a group of values will be either the MCV >>> item's frequency (if the MCV item is kept), or (roughly) the MCV >>> item's base_frequency (if the MCV item is not kept). That suggests >>> that we should simply keep items that are significantly more or less >>> common than the item's base frequency -- i.e., keep rule (b) and ditch >>> rule (a). >>> >> >> Hmmm, but won't that interfere with how we with how we extrapolate the >> MCV estimate to the non-MCV part? Currently the patch does what you >> proposed, i.e. >> >> other_sel = simple_sel - mcv_basesel; >> >> I'm worried that if we only include the items that are significantly >> more or less common than the base frequency, it may skew the other_sel >> estimate. >> > > I don't see how that would skew other_sel. Items close to the base > frequency would also tend to be close to simple_sel, making other_sel > approximately zero, so excluding them should have little effect. Oh, I see. You're right those items should contribute very little to other_sel, I should have realized that. > However... > > Re-reading the thread where we enhanced the per-column MCV stats last > year [1], it was actually the case that an algorithm based on just > looking at the relative standard error worked pretty well for a very > wide range of data distributions. > > The final algorithm chosen in analyze_mcv_list() was only a marginal > improvement on that, and was directly based upon the fact that, in the > univariate statistics case, all the values not included in the MCV > list are assigned the same selectivity. However, that's not the case > for multivariate stats, because each group not included in the > multivariate MCV list gets assigned a different selectivity based on > its per-column stats. > > So perhaps what we should do for multivariate stats is simply use the > relative standard error approach (i.e., reuse the patch in [2] with a > 20% RSE cutoff). That had a lot of testing at the time, against a wide > range of data distributions, and proved to be very good, not to > mention being very simple. > > That approach would encompass both groups more and less common than > the base frequency, because it relies entirely on the group appearing > enough times in the sample to infer that any errors on the resulting > estimates will be reasonably well controlled. It wouldn't actually > look at the base frequency at all in deciding which items to keep. > > Moreover, if the group appears sufficiently often in the sample to > justify being kept, each of the individual column values must also > appear at least that often as well, which means that the errors on the > base frequency estimate are also well controlled. That was one of my > concerns about other algorithms such as "keep items significantly more > or less common than the base frequency" -- in the less common case, > there's no lower bound on the number of occurrences seen, and so no > guarantee that the errors are kept under control. > Yep, that looks like a great approach. Simple and tested. I'll try tweaking the patch accordingly over the weekend. Thanks! -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services