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 1qRYil-002B4E-J2 for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Aug 2023 13:50:31 +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 1qRYij-00DlCV-Ob for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Aug 2023 13:50:30 +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 1qRYij-00DlCN-FT for pgsql-hackers@lists.postgresql.org; Thu, 03 Aug 2023 13:50:29 +0000 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qRYih-000K7J-9V for pgsql-hackers@postgresql.org; Thu, 03 Aug 2023 13:50:28 +0000 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6bc9811558cso877321a34.0 for ; Thu, 03 Aug 2023 06:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691070626; x=1691675426; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eNDHHBLtr0eDCvFLwNkP4/UHZO6QpyO7KtQkA6Sh2tQ=; b=iYrGH3fwIPIPrBtYXS8grHNzkrMZTrRKWtRJT8g3RodMXncPz+e+NwH2Tum2v8ZCny q5/YcUgjYqM2hPGVBDtlQ3mxK5BmuffAQiDnDE+I1fz65/w1MSlWZGcxliQFuWYeIpVD m/89r7SgGFgi0ZiGt8ShOVZogvMq2+RJ2ZRnRw9QRqnLZg1eToyZgRWitYCu2qm1OHMq AxrdDTQWVcYfG9w1ZaIm9SPQWBzMJWJkHoKQDAY7vZJMIk0mBCBl4QcYPJSPZvzVcG3u h/4tl/GhhHtNnMdlMKBeWYY0B5sBLi/Bj4JLcFQh6dDLsGmlYbe0hPSUzf10n6EzJUvG ET+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691070626; x=1691675426; 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=eNDHHBLtr0eDCvFLwNkP4/UHZO6QpyO7KtQkA6Sh2tQ=; b=juU9n0bTS2f4W0kxyJQAn3MHXaJoIHb5seG07tn9nhq5XyqQB+d0Xa4cxwcqp6hqT1 Bh4dtgUiQXc2RbTtnhr8sDOXytngo5eltZk3N8zCjZznWJ2xTc20n0wH0LLp6HcWPqnN OFo0S3W0lt2/riXgPVro1n47+I1CTwT4ZpTnO1fPuvulJBFKzr9QMK0ffCUScZK6qYYa hmKBghgWA0ttUpSe7Lz5x1Ce5vCAX9amw+pH21dcR2JQ+X6INRtWKm7p9yX3bKksuMfk eo8mScGTQ1uZQfDWehg8aMSidew9Dz1ToiWTk2e+3JCSQucsfvS13tuDW5Lc9JsKaq+3 Rd1A== X-Gm-Message-State: ABy/qLarCj0LbJRuXnG1b4qZrgvwnOMCPPb5lMmreJxKGJXXW67uAmQ6 PTQYDEC5mLjgf0Cn3wMYIWW3gEaQO9Y4ZArf0qA= X-Google-Smtp-Source: APBJJlH23gm3YCZVHd94xKFknqyjtCAo1nSNgRbiTkx0GLbD4JeW/enAZJDr8TprBxjRtZlOIGaTvfsIUgcqnDXp0Gc= X-Received: by 2002:a05:6870:41d0:b0:1a6:a547:ffe1 with SMTP id z16-20020a05687041d000b001a6a547ffe1mr20690980oac.21.1691070626730; Thu, 03 Aug 2023 06:50:26 -0700 (PDT) MIME-Version: 1.0 References: <3198e7c138fc0b5f80512785a87b7bb2@anastigmatix.net> In-Reply-To: <3198e7c138fc0b5f80512785a87b7bb2@anastigmatix.net> From: Andy Fan Date: Thu, 3 Aug 2023 21:50:15 +0800 Message-ID: Subject: Re: Extract numeric filed in JSONB more effectively To: Chapman Flack Cc: Pavel Stehule , jian he , pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000ff1b710602050fb4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ff1b710602050fb4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi: On Thu, Aug 3, 2023 at 8:34=E2=80=AFPM Chapman Flack wrote: > On 2023-08-03 03:53, Andy Fan wrote: > > I didn't realize timetime types are binary compatible with SQL, > > so maybe we can have some similar optimization as well. > > (It is a pity that timestamp(tz) are not binary, or else we may > > just need one operator). > > Not to veer from the thread, but something about that paragraph > has been hard for me to parse/follow. > I don't think this is a key conflict so far. but I'd explain this in more detail. If timestamp -> timestamptz or timestamptz -> timestamp is binary compatible, we can only have 1 operator to return a timestamp. then when we cast it to timestamptz, it will be a no-op during runtime. however cast between timestamp and timestamptz is not binary compatible. whose castmethod is 'f'; > > >> Maybe we can introduce some *internal operator* "extract to type", and > >> in > >> rewrite stage we can the pattern (x->'field')::type transform to OP(x, > >> 'field', typid) > > > > Not sure what the OP should be? If it is a function, what is the > > return value? It looks to me like it is hard to do in c language? > > Now I am wondering about the 'planner support function' available > in CREATE FUNCTION since PG 12. I've never played with that yet. > Would that make it possible to have some, rather generic, extract > from JSON operator that can look at the surrounding expression > and replace itself sometimes with something efficient? > I didn't realize this before, 'planner support function' looks amazing and SupportRequestSimplify looks promising, I will check it more. --=20 Best Regards Andy Fan --000000000000ff1b710602050fb4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi:=C2=A0

On Thu, Aug 3, 2023 at 8:34=E2=80=AFPM Chapm= an Flack <cha= p@anastigmatix.net> wrote:
On 2023-08-03 03:53, Andy Fan wrote:
> I didn't realize timetime types are binary compatible with SQL, > so maybe we can have some similar optimization as well.
> (It is a pity that timestamp(tz) are not binary, or else we may
> just need one operator).

Not to veer from the thread, but something about that paragraph
has been hard for me to parse/follow.

I= don't think this is a key conflict so far. but I'd explain this in= more
detail. If timestamp -> timestamptz or timestamptz ->= timestamp is
binary compatible,=C2=A0 we can only have 1 operato= r to return a timestamp.
then when we cast it to timestamptz, it = will be a no-op during runtime.
however cast between timestamp an= d timestamptz is not binary
compatible. whose=C2=A0castmethod=C2= =A0is 'f';=C2=A0

=C2=A0

>> Maybe we can introduce some *internal operator* "extract to t= ype", and
>> in
>> rewrite stage we can the pattern (x->'field')::type tra= nsform to OP(x,
>> 'field', typid)
>
> Not sure what the OP should be?=C2=A0 If it is a function, what is the=
> return value?=C2=A0 It looks to me like it is hard to do in c language= ?

Now I am wondering about the 'planner support function' available in CREATE FUNCTION since PG 12. I've never played with that yet.
Would that make it possible to have some, rather generic, extract
from JSON operator that can look at the surrounding expression
and replace itself sometimes with something=C2=A0 efficient?

I didn't realize this before,=C2=A0 'planner = support function' looks
amazing and SupportRequestSimplify lo= oks promising, I will check it=C2=A0
more.=C2=A0
=
--
Best Regards
Andy Fan
--000000000000ff1b710602050fb4--