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 1h32Nn-0000Up-LS for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Mar 2019 17:37:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h32Nk-0005AG-DW for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Mar 2019 17:37:04 +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 1h32Nk-0005A9-23 for pgsql-hackers@lists.postgresql.org; Sun, 10 Mar 2019 17:37:04 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h32Nh-0002r7-51 for pgsql-hackers@postgresql.org; Sun, 10 Mar 2019 17:37:03 +0000 Received: by mail-wr1-x434.google.com with SMTP id i16so2567669wrs.13 for ; Sun, 10 Mar 2019 10:37:00 -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=pwX73tpnEK8HDDRMwDt7rK2A/jNT+QDjOWZDHhGaS9w=; b=ZDQlNV4VLOUPOVQwAcRgmORgIQC59AjbA6gavpY5FL6dnub7Ac1OSOengGOw0J1yPL /LcaYxc4tipiTrIAM8Gfgd0cB+wdAa01AFJ2M1ELTZWHquSUyl2eRls9/girYbdRLjs4 hMmiof5MMT/d2SiCYW+yTWlpHMXH9hiiwrUItT/Dufh5YvlG92cayC0Wfi2h3EOkt5mM y1Ia0mJLeHvm00bA/244ABEqKgcgrCD+iOvLekXOX6t66I5K6TcfYRVjBfgt1c1w1jBg nmdeW5oo9NvBdcftwOTptkmvNx7a4DaUdhjDDGTDCempNqLAlbCr/tUNYvGte33H2nwg CTpA== 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=pwX73tpnEK8HDDRMwDt7rK2A/jNT+QDjOWZDHhGaS9w=; b=jLOMm0jtp5sq8lAHJPiZkK3ACOv5gRrKZVDSgd4KSyxTndsUdnseOZjvYsfb6M5lZw SlCXHnz4TOGDEqJQq2Q6oMe0/EXnxhUbMvuMmzuTveL7CaRZm5ec64xesqehOJAVPNC4 qBpfnlv7+NG5cAqPLws+gAWiU57Nf1s+rUhGFI3VD/BWXbNFDCa++k6KuuQ4cHBFoRjP bjI7wx5d7VJl0jubd1FJ8/r4ByQ6DLIEIIB4Vtq9kD7oqKyv9kWRvigySsp4BpPkhznl QoB8YX5TzczDd460LsP+K22BcwchlCl8kHLwyKCWxATk/MdX/VgmVYOuxIKifGiidBwB LVFw== X-Gm-Message-State: APjAAAW21SqzrJM0ynyW8kpUd1oPSAR/czDfh/sPKX9nXi4A01j0lBWe Liq9XOApFzHNsYYwClivJl/zqZbroPympyW5gxffiU5wM0BgomdU1HPS1/8kUkhPSGq6/uoO5F/ H4TgczWJNpWeYPiy5+EPpBCZz/q6aQQKRQkP2HtBiueGfhqONO40C/iXqttgkjYvrVYkTEOhVdN kltWR9/7FyVQioLg== X-Google-Smtp-Source: APXvYqxX246G3Y0vQj9fZ+U5PXDOMqiH6TBZsDbWNMzeM9iY3DrIb/sqcXQpb/S8ohcV96hBPFl7kQ== X-Received: by 2002:adf:f4d0:: with SMTP id h16mr18374025wrp.103.1552239418340; Sun, 10 Mar 2019 10:36:58 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-253-144.net.upcbroadband.cz. [86.49.253.144]) by smtp.gmail.com with ESMTPSA id h13sm5557077wrt.89.2019.03.10.10.36.57 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Sun, 10 Mar 2019 10:36:57 -0700 (PDT) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Dean Rasheed Cc: David Rowley , Alvaro Herrera , Michael Paquier , Andres Freund , Thomas Munro , Bruce Momjian , Mark Dilger , Pg Hackers References: <20190206012140.GA3626@alvherre.pgsql> <53386926-08a6-76f7-6a8f-f36e4ffb1b9d@2ndquadrant.com> <60a3741a-dcd5-4a30-90a2-c427b94524fc@2ndquadrant.com> From: Tomas Vondra Message-ID: <5c865c03-9963-c62a-ef0c-c42f3c0e855f@2ndquadrant.com> Date: Sun, 10 Mar 2019 18:36:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.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 Hi Dean, Thanks for the review. I'll post a patch fixing most of the stuff soon, but a few comments/questions regarding some of the issues: On 3/9/19 7:33 PM, Dean Rasheed wrote: > 5). It's not obvious what some of the new test cases in the > "stats_ext" tests are intended to show. For example, the first test > creates a table with 5000 rows and a couple of indexes, does a couple > of queries, builds some MCV stats, and then repeats the queries, but > the results seem to be the same with and without the stats. > Hmmm. I thought those tests are testing that we get the right plan, but maybe I broke that somehow during the rebases. Will check. > I wonder if it's possible to write smaller, more targeted tests. > Currently "stats_ext" is by far the slowest test in its group, and I'm > not sure that some of those tests add much. It ought to be possible to > write a function that calls EXPLAIN and returns a query's row > estimate, and then you could write tests to confirm the effect of the > new stats by verifying the row estimates change as expected. Sure, if we can write more targeted tests, that would be good. But it's not quite clear to me how wrapping EXPLAIN in a function makes those tests any faster? On 3/10/19 2:09 PM, Dean Rasheed wrote: > 12). bms_member_index() should surely be in bitmapset.c. It could be > more efficient by just traversing the bitmap words and making use of > bmw_popcount(). Also, its second argument should be of type 'int' for > consistency with other bms_* functions. Yes, moving to bitmapset.c definitely makes sense. I don't see how it could use bms_popcount() though. On 3/10/19 2:09 PM, Dean Rasheed wrote: > 14). The attnums Bitmapset passed to > statext_is_compatible_clause_internal() is an input/output argument > that it updates. That should probably be documented. When it calls > itself recursively for AND/OR/NOT clauses, it could just pass the > original Bitmapset through to be updated (rather than creating a new > one and merging it), as it does for other types of clause. > I don't think it's really possible, because the AND/OR/NOT clause is considered compatible only when all the pieces are compatible. So we can't tweak the original bitmapset directly in case the incompatible clause is not the very first one. > On the other hand, the outer function statext_is_compatible_clause() > does need to return a new bitmap, which may or may not be used by its > caller, so it would be cleaner to make that a strictly "out" parameter > and initialise it to NULL in that function, rather than in its caller. On 3/10/19 2:09 PM, Dean Rasheed wrote: > 15). As I said yesterday, I don't think that there is a clean > separator of concerns between the functions clauselist_selectivity(), > statext_clauselist_selectivity(), > dependencies_clauselist_selectivity() and > mcv_clauselist_selectivity(), I think things could be re-arranged as > follows: > > statext_clauselist_selectivity() - as the name suggests - should take > care of *all* extended stats estimation, not just MCVs and histograms. > So make it a fairly small function, calling > mcv_clauselist_selectivity() and > dependencies_clauselist_selectivity(), and histograms when that gets > added. > > Most of the current code in statext_clauselist_selectivity() is really > MCV-specific, so move that to mcv_clauselist_selectivity(). Amongst > other things, that would move the call to choose_best_statistics() to > mcv_clauselist_selectivity() (just as > dependencies_clauselist_selectivity() calls choose_best_statistics() > to get the best dependencies statistics). Then, when histograms are > added later, you won't have the problem pointed out before where it > can't apply both MCV and histogram stats if they're on different > STATISTICS objects. I agree clauselist_selectivity() shouldn't care about various types of extended statistics (MCV vs. functional dependencies). But I'm not sure the approach you suggested (moving stuff to mcv_clauselist_selectivity) would work particularly well because most of it is not specific to MCV lists. It'll also need to care about histograms, for example. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services