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 1qRQRO-001fZK-Kb for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Aug 2023 05:00:02 +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 1qRQRM-009y5Q-N0 for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Aug 2023 05:00:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qRQRM-009y5H-Di for pgsql-hackers@lists.postgresql.org; Thu, 03 Aug 2023 05:00:00 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qRQRJ-000Gee-Sm for pgsql-hackers@postgresql.org; Thu, 03 Aug 2023 05:00:00 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-584243f84eeso5048807b3.0 for ; Wed, 02 Aug 2023 21:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691038796; x=1691643596; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Tvx4t3izmBDZWvIzIBb2Iwg7aqhHiaUJDUxl+8Lte5k=; b=PPfoobeaH8HUOfvC0r5BBzdFfEmHlJx31AhqZKiHX6HwAxcMnwiVkP7duI5TvkgrQv x/tHeFo2kSrDfP6cHvk7vj7+RQT054TBu/h2rRm8hMbjsWoBUbj1K0zLJi4cMVmoBviY Bjs2FZvi+a6ExjPMF3jCtEfVGI4z59zbcl4N5ltGCt8LMwcaUAzn642VJt+/1UTXA6Oo Nf9Dmo1xfK5MZz7pkzvQmIJizj31raGH8LtANXu35wBDsh4nmEBz1yzq0iq6pUQJqELp i7KzbrVaEy3SHISkhReGOD/mNjhBw7DhbrwQ55m2sW4Y2Esnv7l7aFWYaG43Dx+lMWwM CUWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691038796; x=1691643596; 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=Tvx4t3izmBDZWvIzIBb2Iwg7aqhHiaUJDUxl+8Lte5k=; b=PeP28OH4SSDLSV1L9i+NjHbz86jCNpajlAMTsjLytxL+zDqFsXIIfIt1d8dD4GkYud p+/FC7r0OGWDZW5ud9y00USliuy45oigJknrLMgfmDl5WM2bqmR8YB3a7zXOvnXN6L9K b+jW7FVKhd5NpJnAQM6n5E1EcdX5KRSX2M3Mdm7uEMTjZTckBoCNDnqmDwy9EKaGK0ST i5sEvI6A1xXTAK+c/QIyEMXARrTLniaShYIb1x/6mNRPnUVjCFdI0oIfgRYbjvQPx1pO AXPYQkItwlxyo0uHYczw4+WpQ7VcnIvK0SqhxrONEoPcbhiqJsG3f4P/6JM/zcUAFbHe uCAQ== X-Gm-Message-State: ABy/qLbFDa+eCturYiZ1k8u3tyUDY3QgJo4Xq6m+0F2f2npUwLfWNui9 +aN0sHopZF9BxVtzDWcydo2EpvNkj3PYZQk6ZDc= X-Google-Smtp-Source: APBJJlHpYUcAw52cRnRITyC3cGYcM/3fX+N8qSFsoh26vqP7fq1P/tKq/Hd4gmZ/Hs4toUVNeiWWsdhtJHHDAgj/9i8= X-Received: by 2002:a81:4fcb:0:b0:573:44b3:bf7f with SMTP id d194-20020a814fcb000000b0057344b3bf7fmr21638322ywb.41.1691038796381; Wed, 02 Aug 2023 21:59:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pavel Stehule Date: Thu, 3 Aug 2023 06:59:19 +0200 Message-ID: Subject: Re: Extract numeric filed in JSONB more effectively To: Andy Fan Cc: jian he , pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000c2838a0601fda635" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c2838a0601fda635 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi =C4=8Dt 3. 8. 2023 v 2:51 odes=C3=ADlatel Andy Fan napsal: > Hi Jian: > > >> return PointerGetDatum(v->val.numeric); >> should be something like >> PG_RETURN_NUMERIC(v->val.numeric); >> ? >> > > Thanks for this reminder, a new patch is attached. and commitfest > entry is added as well[1]. For recording purposes, I compared the > new operator with all the existing operators. > > select 1 from tb where (a->'a')::numeric =3D 2; 30.56ms > select 1 from tb where (a->>'a')::numeric =3D 2; 29.43ms > select 1 from tb where (a@->'a') =3D 2; 14.80ms > > [1] https://commitfest.postgresql.org/44/4476/ > > I don't like this solution because it is bloating operators and it is not extra readable. For completeness you should implement cast for date, int, boolean too. Next, the same problem is with XML or hstore type (probably with any types that are containers). It is strange so only casting is 2x slower. I don't like the idea so using a special operator is 2x faster than common syntax for casting. It is a signal, so there is a space for optimization. Black magic with special operators is not user friendly for relatively common problems. 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) Regards Pavel --=20 > Best Regards > Andy Fan > --000000000000c2838a0601fda635 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

=C4=8Dt 3. 8. 2023 v=C2=A02:51 odes=C3=ADlate= l Andy Fan <zhihui.fan1213@g= mail.com> napsal:
Hi Jian:
<= div>=C2=A0
return PointerGetDatum(v->val.numeric);
should be something like
PG_RETURN_NUMERIC(v->val.numeric);
?

Thanks for this reminder, a new p= atch is attached.=C2=A0 and commitfest
entry is added as well[1].= For recording purposes,=C2=A0 I compared the
new operator with a= ll the existing operators.

select 1 from tb where (a-&g= t;'a')::numeric =3D 2;=C2=A0 =C2=A030.56ms
select 1 from tb wher= e (a->>'a')::numeric =3D 2; 29.43ms
select 1 from tb where= (a@->'a') =3D 2;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 14.80ms=C2=A0



I= don't like this solution because it is bloating=C2=A0 operators and it= is not extra readable. For completeness you should implement cast for date= , int, boolean too. Next, the same problem is with XML or hstore type (prob= ably with any types that are containers).

It = is strange so only casting is 2x slower. I don't like the idea so using= a special operator is 2x faster than common syntax for casting. It is a si= gnal, so there is a space for optimization. Black magic with special operat= ors is not user friendly for relatively common problems.

=
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)

Regards

Pavel


=
--
Best Regards
Andy Fan
--000000000000c2838a0601fda635--