Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0Rrt-0000lO-76 for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Mar 2018 13:08:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f0Rrs-00017G-3z for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Mar 2018 13:08:56 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1f0Rrr-000176-T4 for pgsql-hackers@lists.postgresql.org; Mon, 26 Mar 2018 13:08:55 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f0Rrn-0005a0-Ph for pgsql-hackers@postgresql.org; Mon, 26 Mar 2018 13:08:55 +0000 Received: by mail-wm0-x241.google.com with SMTP id o23so5034096wmf.0 for ; Mon, 26 Mar 2018 06:08:51 -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=bBqAW8JP9FCw/8YvUxE+aV9UNAb/GB9MmIdq7l0Lq2w=; b=kMjVGhtvM69kAwGggp3UPToDczDevLweg52TdgfRteIZXCuhuUrkyn9i8K60D1xPo3 JZQNvSdRPTmo5Dkwnh7nl5OAUXdOZtiu/ONIpZGMMV9J5QH2p5UzTdCT+8DqzSmiDihA Xzp4vEQVM/KXoaMtnzTZWbfIl9Pwc4z2QGBQiFxBrRa0NV/i/3qVNMYaImrDY/PJc22p uNQGLKoJlX5vVI4psmnpWMqIADlLgUG/7uU/uueNqGzKRg7VVIftdmqC77jVmsLyrXw2 KFSNi7awqUfrQ1qn7AdyL82lyM66gVK6y8/Mi+miGlOUD6ZIKRKYL5UNnqdDnEs97iuZ r2+w== 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=bBqAW8JP9FCw/8YvUxE+aV9UNAb/GB9MmIdq7l0Lq2w=; b=Mo7W0uifVjO4GRqZQeyo8GIDykZQi1tT35tuMQzrGogINNOBMV2muBkjL0R7XHClvz Alr73bJA4kw0yXEE5SbCnN4CYDIFj/Voc7MxG0xwQq2WY+vtbN/MgE5eRIrSb+JOHo4D We84TW8vvgbg2sqrbYXLPffLPU3LkR7mBxxI4/828XZzSt3pg5eRfIn01ZlDWlBD4ZrZ typS06zO5gsWp7CbrSCJCc0eMqovuHqBb9wImzwDalY9ZgP7UVc/BeqPPxyxhpN9rrZ1 L55iRURlSkAtAhf/8AFpESPF3miqZu3gLD7pocX+DKtoMHdopmLpQk1veADuGXCopzVs Asqg== X-Gm-Message-State: AElRT7Ggm78fVdi4HNjc/8r+ScfQr4RZ8Xh0MpzSkuL++TlgpTnfM6TD NfA+bDYUYnNWTM5eWLl9S5J0obusCeV4SiaFTbC6+uarm1oSk9LWdggfMBewMbp0nOvlMol4hoc lY+aA5fsQZGhnQB3wya35bUAX1BEwkTB7bSE4DfejwqreNkIN/PsvlTsYotteCoLPj8BKHzJ+NN qqn6Ata6j3 X-Google-Smtp-Source: AG47ELvicx7ed7j5B/4dfmNHZrpQ1T0JlvUomVdV8IUj7juMOlydRk3vIN41dOIHVsOatRMwFSpw9w== X-Received: by 10.80.212.44 with SMTP id t44mr40702489edh.12.1522069728065; Mon, 26 Mar 2018 06:08:48 -0700 (PDT) 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 t19sm9423588edd.56.2018.03.26.06.08.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 06:08:46 -0700 (PDT) Subject: Re: [HACKERS] PATCH: multivariate histograms and MCV lists To: Dean Rasheed Cc: Alvaro Herrera , Andres Freund , Thomas Munro , Mark Dilger , Adrien Nayrat , Pg Hackers References: <20180310171906.gd6vyz6hnou2n3h7@alvherre.pgsql> <850c3b6b-2641-496c-4efc-500c720f7260@2ndquadrant.com> From: Tomas Vondra Message-ID: <387341b0-e4bb-e27d-8c68-afaef8189c15@2ndquadrant.com> Date: Mon, 26 Mar 2018 15:08:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.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 03/26/2018 12:31 PM, Dean Rasheed wrote: > On 18 March 2018 at 23:57, Tomas Vondra wrote: >> Attached is an updated version of the patch series, addressing issues >> pointed out by Alvaro. > > I'm just starting to look at this now, and I think I'll post > individual comments/questions as I get to them rather than trying to > review the whole thing, because it's quite a large patch. Apologies > if some of this has already been discussed. > Sure, works for me. And thanks for looking! > Looking at the changes to UpdateStatisticsForTypeChange(): > > + memset(nulls, 1, Natts_pg_statistic_ext * sizeof(bool)); > > why the "1" there -- is it just a typo? > Yeah, that should be 0. It's not causing any issues, because the "replaces" array is initialized to 0 so we're not really using the null value except for individual entries like here: if (statext_is_kind_built(oldtup, STATS_EXT_MCV)) { replaces[Anum_pg_statistic_ext_stxmcv - 1] = true; nulls[Anum_pg_statistic_ext_stxmcv - 1] = true; } but that sets the "nulls" to true anyway. > A wider concern I have is that I think this function is trying to be > too clever by only resetting selected stats. IMO it should just reset > all stats unconditionally when the column type changes, which would > be consistent with what we do for regular stats. > > Consider, for example, what would happen if a column was changed from > real to int -- all the data values will be coerced to integers, > losing precision, and any ndistinct and dependency stats would > likely be completely wrong afterwards. IMO that's a bug, and should > be back-patched independently of these new types of extended stats. > > Thoughts? > The argument a year ago was that it's more plausible that the semantics remains the same. I think the question is how the type change affects precision - had the type change in the opposite direction (int to real) there would be no problem, because both ndistinct and dependencies would produce the same statistics. In my experience people are far more likely to change data types in a way that preserves precision, so I think the current behavior is OK. The other reason is that when reducing precision, it generally enforces the dependency (you can't violate functional dependencies or break grouping by merging values). So you will have stale stats with weaker dependencies, but it's still better than not having any. But that's mostly unrelated to this patch, of course - for MCV lists and histograms we can't keep the stats anyway, because the stats actually do contain the type values (unlike stats introduced in PG10). Actually, to be more accurate - we now store OIDs of the data types in the MCV/histogram stats, so perhaps we could keep those too. But that would be way more work (if at all possible). regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services