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 1ghFxh-0008Ig-4N for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jan 2019 15:40:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghFxf-0002fh-GT for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jan 2019 15:40:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghFxf-0002fa-5V for pgsql-hackers@lists.postgresql.org; Wed, 09 Jan 2019 15:40:07 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghFxb-0003Fl-K6 for pgsql-hackers@postgresql.org; Wed, 09 Jan 2019 15:40:05 +0000 Received: by mail-wm1-x331.google.com with SMTP id b11so8122426wmj.1 for ; Wed, 09 Jan 2019 07:40:03 -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=xYmoZp2+VXmZEOe7PIYZjLKFhk5bsttWbErBSrgXr4k=; b=LoHnIqb2JTsUNsH743wAFH3D6QYaBBvAkV4QhuBo4SpsW/zxCQK6ayA9ljwS0DVhX9 bqoGyGI1TFLHGWpaDF8nEY+rKKACG8bwJi53HrvLlBWOp+kM7kHlpSVViRkSDEMVCHge UPCnp6PNRZY9Ianr9ukOiT50snXrGupuT1oZjVaGR2wqRTFLuGBosBPedph7TpdN6lsc OZVItnTtG8QZmgrqUt8QRpDX7SowpcMWaVPZ14mtncnhclNyMxwIWFfwbXCwK6VJh+Hh /AFvmAC6/yfQ11G0l3QosS9IdLkjufHqW8usgf04lP+GhEawD5i/u7nw7cbT2u2l/EoL iT8A== 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=xYmoZp2+VXmZEOe7PIYZjLKFhk5bsttWbErBSrgXr4k=; b=Mc1jn7Mqwa0g9iDMpmTkACmenE8riS8TWQudF60FdCSGIzrrJqokXLdSY9uk/S5RtI TULhNkKMZ5qKBJY1l3ChG2K/2303AQ1PvpB2EQ4kz4To7U8s4CoryOzK9eU2iniLB6uv R3/HfaoDWgN9Nle95cYbEQNGfx9tYPejC+JM3whJNzZ+6gikdMTg4geub4sCI3FE8J3b JD/n1b3q78vdjJQxuf9RvLwoZQaA/2E72QWTg8lGky2FtP5aWGud0ZCEjDLRkBD0kyIq bKVkRaYFq5IuiAE0a6SBsX+MYaAR0m56zF6kqByrgVqBwTAoU+ytlcAQtVuNI3xEKNYq ZC4w== X-Gm-Message-State: AJcUukfzMcdK4X2eKXmT8RjQKUdTGzxF2al5d3JGiht1EbS/6iF7JEcI LplqHpLq+MOqW6FHjXxcg89hnIKeINUqkIGAE20C94rUYi4ZE4UdnWEgP90V97z2NCwQuDV8rYK wrZAKM9ItjSw4mQNMCCAOD/FSdNqnQEfbI7+webSRpRCWgY6bkN/6UINAejSKz4S7PSM9pLa8XE TTRdD9Mn3Ka2GLfg== X-Google-Smtp-Source: ALg8bN5BfFPtStxaeuc3VSwqRvPdmtx1S4olPoqXDX9rgP1j5avhCA6Zd6Jv4WBxchTk2RObY86BhQ== X-Received: by 2002:a1c:1d81:: with SMTP id d123mr5998569wmd.112.1547048401587; Wed, 09 Jan 2019 07:40:01 -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 3sm14096442wmw.46.2019.01.09.07.40.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 07:40:00 -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> From: Tomas Vondra Message-ID: <11223173-bd90-4fa8-8cf1-49928b615405@2ndquadrant.com> Date: Wed, 9 Jan 2019 16:39:57 +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/8/19 3:18 PM, Dean Rasheed wrote: > On Mon, 7 Jan 2019 at 00:45, Tomas Vondra wrote: >> >> FWIW the main unsolved issue (at least on the MCV part) is how it >> decides which items to keep in the list. >> >> As explained in [1], in the multivariate case we can't simply look at >> the group frequency and compare it to the average frequency (of the >> non-MCV items), which is what analyze_mcv_list() does in the >> single-column case. In the multivariate case we also case about observed >> vs. base frequency, i.e. we want the MCV list to include groups that are >> present singificantly more/less than product of per-column stats. >> >> I've repeatedly tried to come up with a criteria that would address >> that, but it seems rather difficult because we can't abandon the other >> criteria either. So the MCV list should include groups that match both >> >> (a) items that are statistically more common than the non-MCV part (i.e. >> the rule from per-column analyze_mcv_list) >> >> (b) items that are statistically more/less common than estimated from >> per-column stats (i.e. the new rule) > > Thinking about this some more, I think that it probably isn't > appropriate to use analyze_mcv_list() directly because that's making > specific assumptions about how items not in the list will be estimated > that aren't actually true for groups of values in multivariate stats. > If a group of values isn't in the MCV list, it gets estimated based on > the product of the selectivities from the per-column stats (modulo the > additional logic preventing the selectivity not exceeding the total > non-MCV selectivity). > > 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. >> Enforcing rule (a) seems reasonable because it ensures the MCV list >> includes all items more frequent than the last one. Without it, it's >> difficult to decide know whether the absent item is very common (but >> close to base frequency) or very uncommon (so less frequent than the >> last MCV item). > > I'm not sure there's much we can do about that. Keeping the item will > result in keeping a frequency that we know is close to the base > frequency, and not keeping the item will result in per-column stats > being used that we expect to also give an estimate close to the base > frequency. So either way, the result is about the same, and it's > probably better to discard it, leaving more room for other items about > which we may have more information. > > That said, there is a separate benefit to keeping items in the list > even if their frequency is close to the base frequency -- the more > items kept, the larger their total selectivity will be, giving a > better cap on the non-MCV selectivities. So if, after keeping all > items satisfying rule (b), there are free slots available, perhaps > they should be used for the most common remaining values satisfying > rule (a). > Hmm, so essentially we'd use (b) first to bootstrap the MCV list, and then we could do what analyze_mcv_list() does. That could work, I guess. The question is how to define "significantly different from base freq" though. Any ideas? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services