Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vLDwi-008q35-0K for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Nov 2025 05:08:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vLDwg-0042dG-2M for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Nov 2025 05:08:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vLDwg-0042d8-1S for pgsql-hackers@lists.postgresql.org; Tue, 18 Nov 2025 05:08:02 +0000 Received: from mail-vs1-xe32.google.com ([2607:f8b0:4864:20::e32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vLDwe-0006jm-0p for pgsql-hackers@lists.postgresql.org; Tue, 18 Nov 2025 05:08:01 +0000 Received: by mail-vs1-xe32.google.com with SMTP id ada2fe7eead31-5de23ddba5eso3305025137.3 for ; Mon, 17 Nov 2025 21:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763442480; x=1764047280; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HmtLGehOQUy8KW5uxD5ucnBBd2iGOsus7DEQDs6/M1Q=; b=kvFXjdgNHqmokyMly0CjPPKy1g0QrObDkb/tTl7d6Nl0/jdwg1kaz8k58WVGZkDvmN N1/oFdPiBz7T1Fo4V/VLbWNSfEZok+SZfgCeSzJsnweJScd5rd4QAb52WYOfzNAV0AzH BA1l3ZB1+mIdunqpA5Q/bavX+1cu/tfI/7Cv26lnC8rvspUxVFfQI0Ju1W68MDqyWotQ Gs49WG29kJeMc5vnp/MLC1zAGG37OIvGrerFyq1yEJc5BnyINs9rEqLpcL4UMPD82SvU bMihcg3M51SKiYtvTvVkmwrdo8BIIkmxjKWSRU9kHLaoDVFc8DdBWbQu8iGroAOnkbBs W/YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763442480; x=1764047280; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=HmtLGehOQUy8KW5uxD5ucnBBd2iGOsus7DEQDs6/M1Q=; b=U9AvxztZQle7v/sTUMbuY172V5QWZ2x0kFigjxvBJGznGNcd973RL0wxqSqXxON1Xx G++flZnrm8cAWiRPxkJEfmTjYtkSbPlm7mC4DIQi948zd7X0epucl0uiafl+vWFNu1hY gEC3Y9Scp9C+SarzDoGZTD9W3nqnkSXCkgU/21qS/WAtvJ0Ioj3CJbGb/O8QHjSa92b4 giFjwgzLartjlSFW7dH+1qMJyMDRu8Os/cQNS+42OTuaakdF3M2mCOyCPyHJ2UGFAus6 MA6mOtKr9vGD2Cv/atP5+6RJ38Mg2/EnYTkJ27CzIKVAt7XqGoD9EffcJmsLe/vd8OFj EZDw== X-Forwarded-Encrypted: i=1; AJvYcCXVZgPAnApgb03AFY37WeD4nQZa8NrewKgfE1yxifaiwwGA7jMsRt2V/z/COr6GwmjRIOj8CowAHS91BJWL@lists.postgresql.org X-Gm-Message-State: AOJu0Yw4nCJIB+tmMybqHYyir7T50WVqBf17bjfn1pUn6mMcGkNla5D6 duxCgMMmhyoSb7v2/U/6pIUXCVd1E63tNoqADVXQMj1TWKICANDCAw96M21vca1nw+ZAakjTQvx lOburH4mbNIcxDwwH9toUMG6JzpGTwXE= X-Gm-Gg: ASbGncteYfGaRNWtkZfSGlOreZTG5K5Kid3xTUshcSEhak89wL/R4qpXjYDN8finqVF bXx114npadQkv3UI+b79ElHcHZ0SZUOQWZFHWbws/cWXBZIHHVMeS/Gcr4Yn1qJp5DfXL2mGRsi 8UjY4keA9EC1a+nbTAzEbJCPWo+5fddm0db1bplZqFZNjykp0IflPegC9jK13XbuhBwk+gucRU2 PZg5CL5DzQfNg9qA+mmcSonLFo2boU7W265uMDFO164gfkzuK4cvUVYiMnFkmeps7XRhLXSn67Z 7hZIiQxuv162rkBCj1lEO64xM5p4h+x0U1E1LHVuRcfiOgWOC4nWcRxVrrlePg/YK/LojYM7clm sjVcJTZdD8FfQDxjP0kB4174vI1pOhe5oX1KOTTLsVtcfLzttzbh2wKK1zDdwvpa1cmnDV8qlGw == X-Google-Smtp-Source: AGHT+IESRV4QbU9DGd7WaN7fmMEcbQ50oV3KYOTcHdcdAf5xzn7U+LHHlmnQHAlbZ85ygtjSpE2Y4IdVN0TYkWs6J0k= X-Received: by 2002:a05:6102:d89:b0:5de:736:71d9 with SMTP id ada2fe7eead31-5dfc5b9440emr5537583137.28.1763442480025; Mon, 17 Nov 2025 21:08:00 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: jian he Date: Tue, 18 Nov 2025 13:07:23 +0800 X-Gm-Features: AWmQ_bn1I2zRgETofLi7g4CT6QovoMlFGReAD28n5Zg6-KioIEGaDaHvzfOVi5k Message-ID: Subject: Re: Extended Statistics set/restore/clear functions. To: Michael Paquier Cc: Corey Huinker , Tomas Vondra , pgsql-hackers@lists.postgresql.org, tgl@sss.pgh.pa.us Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Nov 17, 2025 at 2:56=E2=80=AFPM Michael Paquier wrote: > > On Fri, Nov 14, 2025 at 03:25:27PM +0900, Michael Paquier wrote: > > Thanks for the new versions, I'll also look at all these across the > > next couple of days. Probably not at 0005~ for now. > > 0001 and 0002 from series v13 have been applied to change the output > functions. > > And I have looked at 0003 in details for now. Attached is a revised > version for it, with many adjustments. Some notes: > - Many portions of the coverage were missing. I have measured the > coverage at 91% with the updated version attached. This includes > coverage for some error reporting, something that we rely a lot on for > this code. > - The error reports are made simpler, with the token values getting > hidden. While testing with some fancy values, I have actually noticed > that the error handlings for the parsing of the int16 and int32 values > were incorrect, the error reports used what the safe functions > generated, not the reports from the data type. > - Passing down arbitrary bytes sequences was leading to these bytes > reported in the error outputs because we cared about the token values. > I have added a few tests based on that for the code paths involved. > hi. in src/backend/statistics/mvdistinct.c, we have: Assert(AttributeNumberIsValid(item->attributes[j])); should we disallow 0 in key attributes? SELECT '[{"attributes" : [0,1], "ndistinct" : 4}]'::pg_ndistinct; I didn't find a way to trigger this Assert yet. + errsave(parse->escontext, + errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("malformed pg_ndistinct: \"%s\"", parse->str), + errdetail("Invalid \"%s\" value.", PG_NDISTINCT_KEY_ATTRIBUTES)); + errsave(parse->escontext, + errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("malformed pg_ndistinct: \"%s\"", parse->str), + errdetail("Invalid \"%s\" value.", + PG_NDISTINCT_KEY_NDISTINCT)); the errdetail is way too generic? similar to ``select 'a'::int;`` we can DETAIL: Invalid input syntax for type integer: "a" HINT: "ndistinct" value expected to be a type of integer. what do you think? we already have "fname" in ndistinct_object_field_start, we can also print out the "fname", like: errsave(parse->escontext, errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("malformed pg_ndistinct: \"%s\"", parse->str), errdetail("Unexpected key \"%s\"", fname), errhint("Only allowed keys are \"%s\" and \"%s\".", PG_NDISTINCT_KEY_ATTRIBUTES, PG_NDISTINCT_KEY_NDISTINCT)); SELECT '[{"attributes" : [2,3], "ndistinct" : 4, "ndistinct" : 14}]'::pg_ndistinct; pg_ndistinct ------------------------------------------- [{"attributes": [2, 3], "ndistinct": 14}] SELECT '[{"attributes" : [2,3], "ndistinct" : 4, "attributes" : []}]'::pg_ndistinct; pg_ndistinct ------------------------------------------ [{"attributes": [2, 3], "ndistinct": 4}] Is the above output what we expected? + /* + * We need at least two attribute numbers for a ndistinct item, anything + * less is malformed. + */ + natts =3D parse->attnum_list->length; here, we can use list_length. + if (parse->attnum_list !=3D NIL) + if (parse->distinct_items !=3D NIL) here, we can also use list_length. -- jian https://www.enterprisedb.com/