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 1ht6T4-0004jg-8z for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Aug 2019 08:29:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ht6T3-00040V-5M for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Aug 2019 08:29:45 +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 1ht6T2-00040K-Sq for pgsql-hackers@lists.postgresql.org; Thu, 01 Aug 2019 08:29:44 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ht6Sy-0006H2-7P for pgsql-hackers@lists.postgresql.org; Thu, 01 Aug 2019 08:29:44 +0000 Received: by mail-pf1-x443.google.com with SMTP id y15so33629813pfn.5 for ; Thu, 01 Aug 2019 01:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=SVnAtNJxopU4ZVYhPFlCd8eHagZZO+z1bsYvrvaPyW4=; b=p7o9/0YS6nF8dcsk+6VSOh3HWcLU5XailQTb+EbIh7H6b4HGV4MbboH+X6cY5aOYnp UXX6qGqyKFhkC/SalssGJ+NQ2r75Ho/w6FfZW7fwuBSAi7pRNeTZHTSr3uspXVKpApEP H3UjBTm/IU9+SL+W3xJgqdovBbjWMwJVANqxvLWPdUsLz7Z52XgtCuhPxpwek1vqHF7Y FKtFptk4hIkGH66YXQZqXFpoTzrW++MLxettcT7QiLbAldj041hfBxKKKjTyULEV++97 cFEh1PWJPjHMOWkGssoa9yQES909v85dBWB+SM8PPzxApc4cJbR6BACNtvGHrgF39DSh lQYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=SVnAtNJxopU4ZVYhPFlCd8eHagZZO+z1bsYvrvaPyW4=; b=MGJTB/xuGoLqv9ChWDhlgC0srD/bq5+mZGM2qyZKiZGy5bPe51Lsl/tVBUJvh5z2fA kEbFgrBLXArJ4KViKwYceBnKtjqi27KL/IKcNTpeTsVhgbUyb0PPAm6rPF9uqUxKuWxp ta7s6NcOMyZfZDlGRc8Zuj7/DRaQU/aDRZHWsOqpRHvDcQ00nsb80TJAe6EotwgyQoDr pc1A4bIqXc2tD56xV2um/GBDcYH+/2jN/p1ytqRWvYTUbE1Ees75nvtRXjagB/GVe4w+ qwj5k7I3z3J2y/Duf3Ego8xShuWLMAO2jen7GgMAjYpg9OrHnKGLX/+cMsUw/KTEbQik C8tw== X-Gm-Message-State: APjAAAUJdLzquU5Fkyv6X3DQljwuY/7FcD6Xv2p0wVmvbOSnfhGMCKV9 WswARBR+TAeQr08rdH7dyBw= X-Google-Smtp-Source: APXvYqxAmsqpEng+B0+hxWuOZhKDnZfPIVq79D+jER3Mo1HQO0psQyjf5xftqHadZzqB0USHACiw3Q== X-Received: by 2002:a63:9e43:: with SMTP id r3mr93926402pgo.148.1564648177906; Thu, 01 Aug 2019 01:29:37 -0700 (PDT) Received: from localhost (w204177.dynamic.ppp.asahi-net.or.jp. [121.1.204.177]) by smtp.gmail.com with ESMTPSA id d2sm3771747pjs.21.2019.08.01.01.29.35 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 01 Aug 2019 01:29:37 -0700 (PDT) Date: Thu, 01 Aug 2019 17:29:20 +0900 (Tokyo Standard Time) Message-Id: <20190801.172920.37913541.horikyota.ntt@gmail.com> To: k.jamison@jp.fujitsu.com Cc: tomas.vondra@2ndquadrant.com, dean.a.rasheed@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: Multivariate MCV list vs. statistics target From: Kyotaro Horiguchi In-Reply-To: References: <20190726220552.kafvalbd2o3l7xw6@development> User-Agent: Mew version 6.5 on Emacs 22.2 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.01-dev (TSUBO-SUMIRE) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello. At Thu, 1 Aug 2019 00:15:48 +0000, "Jamison, Kirk" wrote in > The patch does not apply anymore. > In addition to the whitespace detected, > kindly rebase the patch as there were changes from recent commits > in the following files: > src/backend/commands/analyze.c > src/bin/pg_dump/pg_dump.c > src/bin/pg_dump/t/002_pg_dump.pl > src/test/regress/expected/stats_ext.out > src/test/regress/sql/stats_ext.sql The patch finally failed only for stats_ext.out, where 14ef15a222 is hitting. (for b2a3d706b8) I looked through this patch and have some comments. +++ b/src/backend/commands/statscmds.c +#include "access/heapam.h" .. +#include "utils/fmgroids.h" These don't seem needed. + Assert(stmt->missing_ok); Perhaps we shouldn't Assert on this condition. Isn't it better we just "elog(ERROR" here? + DeconstructQualifiedName(stmt->defnames, &schemaname, &statname); Maybe we don't need detailed analysis that the function emits on error. Couldn't we use NameListToString() instead? That reduces the number of ereport()s and considerably simplify the code around. + oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(stxoid)); + + /* Must be owner of the existing statistics object */ + if (!pg_statistics_object_ownercheck(stxoid, GetUserId())) This repeats the SearchSysCache twice in a quite short duration. I suppose it'd be better that ACL (and validity) checks done directly using oldtup. + /* replace the stxstattarget column */ + repl_repl[Anum_pg_statistic_ext_stxstattarget - 1] = true; + repl_val[Anum_pg_statistic_ext_stxstattarget - 1] = Int32GetDatum(newtarget) We usually do this kind of work using SearchSysCacheCopyN(), which simplifies the code around, too. +++ b/src/backend/statistics/mcv.c > * Maximum number of MCV items to store, based on the attribute with the > * largest stats target (and the number of groups we have available). > */ - nitems = stats[0]->attr->attstattarget; - for (i = 1; i < numattrs; i++) - { - if (stats[i]->attr->attstattarget > nitems) - nitems = stats[i]->attr->attstattarget; - } + nitems = stattarget; Maybe you forgot to modify the comment. check_xact_readonly() returns false for this command. As the result it emits a somewhat pointless error message. =# alter statistics s1 set statistics 0; ERROR: cannot assign TransactionIds during recovery +++ b/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.h > i_stxname = PQfnumber(res, "stxname"); > i_stxnamespace = PQfnumber(res, "stxnamespace"); > i_rolname = PQfnumber(res, "rolname"); + i_stattarget = PQfnumber(res, "stxstattarget"); I'm not sure whether it is the convention here, but variable name is different from column name only for the added line. +++ b/src/bin/psql/tab-complete.c - COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA"); + COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA", "SET STATISTICS"); ALTER STATISTICS s2 SET STATISTICS is suggested with ext-stats names, but it's the place for target value. +++ b/src/include/nodes/nodes.h T_CallStmt, + T_AlterStatsStmt, I think it should be immediately below T_CreateStatsStmt. +++ b/src/include/nodes/parsenodes.h + bool missing_ok; /* skip error if statistics object is missing */ Should be very trivial, but many bool members especially missing_ok have a comment having "?" at the end. regards. -- Kyotaro Horiguchi NTT Open Source Software Center