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.94.2) (envelope-from ) id 1tdEIz-005kPX-CG for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jan 2025 20:04:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tdEIx-008eNy-QA for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Jan 2025 20:04:55 +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.94.2) (envelope-from ) id 1tdEIx-008eNq-BT for pgsql-hackers@lists.postgresql.org; Wed, 29 Jan 2025 20:04:55 +0000 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tdEIv-002AWd-0I for pgsql-hackers@lists.postgresql.org; Wed, 29 Jan 2025 20:04:54 +0000 Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-3a9c9f2a569so767725ab.0 for ; Wed, 29 Jan 2025 12:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738181093; x=1738785893; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XSwBVbqPaWgCBLCWznCcJxnJ6VYR4IK6Km7hxs3x3jc=; b=XKXaWgu77CeDoEgBVySu5FVotpwm6uHkNJe6OqfBFdVkUzzWSk+mAouF7z2+Fxgscw FwKrUUmGV9C0O3PWGfcn/vfHE8DYTZ80oiCvhHXdTdi8w3/RM8gvPfLdZMDaa3xKrF+E 825N/5NIscN6SLi3RESpiUzDH1Lr+sJbnbly0sZFDfrTbL0HwxCR1Rwk5oO3y52Kp4Q7 xiGNzDX+TWueoIL7U7ZWc+E6+iceYxtl5Bh0AsSXCUeZzF6J+pvTOHdQzOlGQxFzYQVA 7EaNw+0Z2PY1ePQC+EkCdTIoiiKKx3dSHPDPmkAaixIs4rDWEEl4DSBUNYyZYucguuUs EKrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738181093; x=1738785893; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XSwBVbqPaWgCBLCWznCcJxnJ6VYR4IK6Km7hxs3x3jc=; b=qflztqiPvZ/wUgMt3TA8oopwKlyCEvxR7wgGHXkhJbBxBIOEXXABb4sQZL4B00n4uQ SmfA0702KAMcy6xXFRdLkGcAVIA6aexhiy1Y5b4TBtrMvkHI6+wX29USM2Q78Nodt37r MmPNg+TPPfkRzVBdWLPY6d8vT546efW0l1EsTAtHw+62vuoo/BwkMpHVNZkbRlnYLZgg Zj/yLMG4oNVwaaz1XaV5av/MEQG/aCgsEIkYcKbUxnoSa5/LtqG820qUcLemFfhm5jfP qJC1niGuo7MCoqfTkm+hTPLxFw5hgHOqhdbmAKM4iKeoENbioQ+o2yIlcyGLexx0WuEc 19Vw== X-Forwarded-Encrypted: i=1; AJvYcCUBbXNLXL2z3jP56d5VxpE4rkuAg1cH49cW7jS4sNW+y5AaxE9rMzjjj0U4eEZDcgJuYwZ3TcEwIoHBqgD2@lists.postgresql.org X-Gm-Message-State: AOJu0Yz1OlpaKR0fUsKax6gcJmen3JusQwMwo0hI7Xn4JgZsfJwIn0tV nka42pUzenSMRfsThzK8gqlFKXfs0O5lfxT9wUQ83gcE01eICRNJ0cEbqMOe2VOR8WzjMB/KwcE x3QedZ5LDwf681CVoUr5YpTiS0Ok= X-Gm-Gg: ASbGncttykXBgfbt2PwIo+82PLocJ9/9BTRtG2GQA74ZuLXPL1t27GLp7LVAMYp0UmR UxzHnd6+JrD/Eml5a237Y8OX2knWyVRtyUiJMsrgxsBtuMMLvUCKoGP9h4LFC4rWI5bOrkKK7 X-Google-Smtp-Source: AGHT+IHxj98iDX5JRrdKbeShcDQkzSo0kcFLS6GFdjtAN+XMeDBsa8Qnw0LA1y4JHweUz04u+f14K/SR3OUcSXU4dH8= X-Received: by 2002:a05:6e02:1ca1:b0:3ce:87e3:c26c with SMTP id e9e14a558f8ab-3cffe3d1960mr36934785ab.5.1738181092761; Wed, 29 Jan 2025 12:04:52 -0800 (PST) MIME-Version: 1.0 References: <4630636f-7720-4ce4-ab1c-253b390e5174@vondra.me> In-Reply-To: From: Corey Huinker Date: Wed, 29 Jan 2025 15:04:40 -0500 X-Gm-Features: AWEUYZnmatCTCooUgk5RPJ26pgg6fHcVwiVQXiVV4wKF4Hwa2netUHZdGoY6BMQ Message-ID: Subject: Re: Extended Statistics set/restore/clear functions. To: jian he Cc: Tomas Vondra , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000096e71f062cddd2cb" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000096e71f062cddd2cb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 29, 2025 at 2:50=E2=80=AFAM jian he wrote: > hi. > > select '{"1, 0B100101":"NaN"}'::pg_ndistinct; > pg_ndistinct > ------------------------ > {"1, 37": -2147483648} > (1 row) > I think my initial reaction is to just refuse those special values, but I'll look into the parsing code to see what can be done. this is not what we expected? > For the VALUE part of pg_ndistinct, float8 has 3 special values: inf, > -inf, NaN. > > For the key part of pg_ndistinct, see example. > select '{"1, 16\t":"1"}'::pg_ndistinct; > here \t is not tab character, ascii 9. it's two characters: backslash > and character "t". > so here it should error out? > (apply this to \n, \r, \b) > I don't have a good answer as to what should happen here. Special cases like this make Tomas' suggestion to change the in/out format more attractive. > > > pg_ndistinct_in(PG_FUNCTION_ARGS) > ending part should be: > > freeJsonLexContext(lex); > if (result =3D=3D JSON_SUCCESS) > { > ...... > } > else > { > ereturn(parse_state.escontext, (Datum) 0, > errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), > errmsg("malformed pg_ndistinct: \"%s\"", str), > errdetail("Must be valid JSON.")); > PG_RETURN_NULL(); > } > result should be either JSON_SUCCESS or anything else. > > > > all these functions: > ndistinct_object_start, ndistinct_array_start, > ndistinct_object_field_start, ndistinct_array_element_start > have > ndistinctParseState *parse =3D state; > > do we need to change it to > ndistinctParseState *parse =3D (ndistinctParseState *)state; > ? > The compiler isn't complaining so far, but I see no harm in it. --00000000000096e71f062cddd2cb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Jan 29, 2025 at 2:50=E2=80=AFAM j= ian he <jian.universality= @gmail.com> wrote:
hi.

select '{"1, 0B100101":"NaN"}'::pg_ndistinct; =C2=A0 =C2=A0 =C2=A0 pg_ndistinct
------------------------
=C2=A0{"1, 37": -2147483648}
(1 row)

I think my initial reaction is = to just refuse those special values, but I'll look into the parsing cod= e to see what can be done.



this is not what we expected?
For the VALUE part of pg_ndistinct, float8 has 3 special values: inf, -inf,= NaN.

For the key part of pg_ndistinct, see example.
select '{"1, 16\t":"1"}'::pg_ndistinct;
here \t is not tab character, ascii 9. it's two characters: backslash and character "t".
so here it should error out?
(apply this to \n, \r, \b)

I don't = have a good answer as to what should happen here. Special cases like this m= ake Tomas' suggestion to change the in/out format more attractive.


=C2=A0


pg_ndistinct_in(PG_FUNCTION_ARGS)
ending part should be:

=C2=A0 =C2=A0 freeJsonLexContext(lex);
=C2=A0 =C2=A0 if (result =3D=3D JSON_SUCCESS)
=C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ......
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 else
=C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 =C2=A0ereturn(parse_state.escontext, (Datum) 0,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 errco= de(ERRCODE_INVALID_TEXT_REPRESENTATION),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 errms= g("malformed pg_ndistinct: \"%s\"", str),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 errde= tail("Must be valid JSON."));
=C2=A0 =C2=A0 =C2=A0 =C2=A0PG_RETURN_NULL();
=C2=A0 =C2=A0 }
result should be either JSON_SUCCESS or anything else.



all these functions:
ndistinct_object_start, ndistinct_array_start,
ndistinct_object_field_start, ndistinct_array_element_start
have
ndistinctParseState *parse =3D state;

do we need to change it to
ndistinctParseState *parse =3D (ndistinctParseState *)state;
?

The compiler isn't complaining=C2= =A0so far, but I see no harm in it.

--00000000000096e71f062cddd2cb--