Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eIjxR-0007Ug-0z for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Nov 2017 23:34:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eIjxQ-0001go-8r for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Nov 2017 23:34:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eIjxP-0001ge-Vj for pgsql-hackers@lists.postgresql.org; Sat, 25 Nov 2017 23:34:00 +0000 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eIjxI-0001Ud-HN for pgsql-hackers@postgresql.org; Sat, 25 Nov 2017 23:33:58 +0000 Received: by mail-wr0-x22e.google.com with SMTP id a63so23166817wrc.12 for ; Sat, 25 Nov 2017 15:33:51 -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=0XODKVAyqja4fMvOuYDp4kRSgwkBfwGUOFYfJ8w1/fw=; b=yOWvpnUec98KjPwX7PjXCs8jTVhnj3MBnpPCFOioBPOVUJJ5KM/ouNv1I5z9xEUTfF fDmfde3HddldS4PJiwo8Uu5HfR/lQ/sfXNBi5yNisKt5WG+zUyIkb9O5FTj4Z8ov+WKq p+b1/RF/+Qadk2nrf4GQfPthGmpOaEYVTsWdhaRhRhKnlq78GtKwgu56cEQUxwiSt0Zj 90+wAJ+9qQfaibUgFrF/Babum6VkPVYbXAvRE+jDVPHXVUd8AFu8B8qY2WV0xN3HIBdK sFhNTsdUbYiUUP4xfNFQskxCoREaz8qPifrTFa1znH2TuLTQQM6MOCvSVZY5oIxOk5jW QKdA== 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=0XODKVAyqja4fMvOuYDp4kRSgwkBfwGUOFYfJ8w1/fw=; b=cENtoXI5oJITfDscXd4wxWgMO7MKd/Tt6heeMvJUDWUBbFXj4o4umrBlxaAZSKNH27 KI1kjxgx89JvYR5qWdEwXiEfs59eyvfJHcerjJMQhBGBytICOVy0m9UvzMI0plyNZjd9 kLa5GqslCjsSq00cAovm0SOc2exEZLjsJ/dGnGBpBwUxBaijJqXfgWlNKYhOHALO9N1t TlvXiTdQ767Fr6l7lvXhnSkxGts8ftnfIqMIL8KnxIv56Cj6/r32R7XaklR5hrHARKj9 Fpe7VlV5UoT1A929mKjh23oAdOj1Lct5/SrxrpOji7Y3oBKdAsqV+d37Pf3lxj7JCGWZ L9PQ== X-Gm-Message-State: AJaThX43rSEXuIzcXZrPWadgJWs/Jy01rFw1H3M7ZFNAdOoaB7y9dTVw jER4nnr4eNVtSEGPipLdX5/1eZddQhUytny02eTHvkWaFB4TxBcUyes6K+3TxOnCZ+52TK06zvp UXSiYB+3zOfbf2J57YKbyfuU6SjDUgGa1SRyPbHZ2QhpHRii4rtqoVyglsDactsXGTw9XoGUz+4 DSQOpa3fwO X-Google-Smtp-Source: AGs4zMYm2UXh2BogYb7asyMOz3eoC8WPtY/bGekCKW1spV+2Y2QgkFk4U5BjpNIXFLnxL+J6Y+0veg== X-Received: by 10.223.132.6 with SMTP id 6mr27952630wrf.93.1511652828594; Sat, 25 Nov 2017 15:33:48 -0800 (PST) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id l33sm4575272wrl.88.2017.11.25.15.33.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Nov 2017 15:33:47 -0800 (PST) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Mark Dilger Cc: Adrien Nayrat , Pg Hackers References: <31ee8686-6d62-7f10-4129-7580ec74a710@dalibo.com> <340ffd44-2d67-d39d-e54f-5a97a842cd3a@2ndquadrant.com> <67EAB5B3-F9FB-4753-8102-4D77DCFFFCD4@gmail.com> From: Tomas Vondra Message-ID: <63aa9ad9-cebd-a842-ea50-7f99b94443cd@2ndquadrant.com> Date: Sun, 26 Nov 2017 00:33:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 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 11/25/2017 10:01 PM, Mark Dilger wrote: > >> On Nov 18, 2017, at 12:28 PM, Tomas Vondra wrote: >> >> Hi, >> >> Attached is an updated version of the patch, adopting the psql describe >> changes introduced by 471d55859c11b. > > Hi Tomas, > > In src/backend/statistics/dependencies.c, you have introduced a comment: > > + /* > + * build an array of SortItem(s) sorted using the multi-sort support > + * > + * XXX This relies on all stats entries pointing to the same tuple > + * descriptor. Not sure if that might not be the case. > + */ > > Would you mind explaining that a bit more for me? I don't understand exactly what > you mean here, but it sounds like the sort of thing that needs to be clarified/fixed > before it can be committed. Am I misunderstanding this? > The call right after that comment is items = build_sorted_items(numrows, rows, stats[0]->tupDesc, mss, k, attnums_dep); That method processes an array of tuples, and the structure is defined by "tuple descriptor" (essentially a list of attribute info - data type, length, ...). We get that from stats[0] and assume all the entries point to the same tuple descriptor. That's generally safe assumption, I think, because all the stats entries relate to columns from the same table. > > In src/backend/statistics/mcv.c, you have comments: > > + * FIXME: Single-dimensional MCV is sorted by frequency (descending). We > + * should do that too, because when walking through the list we want to > + * check the most frequent items first. > + * > + * TODO: We're using Datum (8B), even for data types (e.g. int4 or float4). > + * Maybe we could save some space here, but the bytea compression should > + * handle it just fine. > + * > + * TODO: This probably should not use the ndistinct directly (as computed from > + * the table, but rather estimate the number of distinct values in the > + * table), no? > > Do you intend these to be fixed/implemented prior to committing this patch? > Actually, the first FIXME is obsolete, as build_distinct_groups returns the groups sorted by frequency. I'll remove that. I think the rest is more a subject for discussion, so I'd need to hear some feedback. > > Further down in function statext_mcv_build, you have two loops, the first allocating > memory and the second initializing the memory. There is no clear reason why this > must be done in two loops. I tried combining the two loops into one, and it worked > just fine, but did not look any cleaner to me. Feel free to disregard this paragraph > if you like it better the way you currently have it organized. > I did it this way because of readability. I don't think this is a major efficiency issue, as the maximum number of items is fairly limited, and it happens only once at the end of the MCV list build (and the sorts and comparisons are likely much more CPU expensive). > > Further down in statext_mcv_deserialize, you have some elogs which might need to be > ereports. It is unclear to me whether you consider these deserialize error cases to be > "can't happen" type errors. If so, you might add that fact to the comments rather than > changing the elogs to ereports. > I might be missing something, but why would ereport be more appropriate than elog? Ultimately, there's not much difference between elog(ERROR) and ereport(ERROR) - both will cause a failure. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services