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 1wImqw-008TrU-2J for pgsql-bugs@arkaria.postgresql.org; Fri, 01 May 2026 12:20:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wImqu-00B7u9-1R for pgsql-bugs@arkaria.postgresql.org; Fri, 01 May 2026 12:20:16 +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.96) (envelope-from ) id 1wImqu-00B7u0-0B for pgsql-bugs@lists.postgresql.org; Fri, 01 May 2026 12:20:16 +0000 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wImqr-00000004GON-2fzM for pgsql-bugs@lists.postgresql.org; Fri, 01 May 2026 12:20:15 +0000 Received: from mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:94a9:0:640:a3fa:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id A47F980799; Fri, 01 May 2026 15:20:11 +0300 (MSK) Received: from smtpclient.apple (unknown [2a02:6bf:8080:43f::1:e]) by mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net (smtpcorp) with ESMTPSA id AKbWbS0L60U0-MtmTYWKC; Fri, 01 May 2026 15:20:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1777638011; bh=YyX2DOhndqpS9D/mwYYNn6qd03mrQQYr3PHHn6W2dQE=; h=To:Message-Id:Date:References:Cc:In-Reply-To:From:Subject; b=jgCgeDjXwxHpKLEuzlWTDEce+xffig55uD48/5SVBkX4oU/vW5Go0379qB7fdu6Au ngz18UPnPCoolUQm3BW9IRShNsFDygWOVehg5/q1EzaJt0lFxJWlli9YJyyD9OM8yq uzf7V6WH54eei2tlYbUK+w/E5oSNHtUZYayiBRxc= Authentication-Results: mail-nwsmtp-smtp-corp-main-68.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: BUG #19362: Extremely log processing of jsonb_path_exists_opr From: Andrey Borodin X-Priority: 3 (Normal) In-Reply-To: <1766516577.178080141@f533.i.mail.ru> Date: Fri, 1 May 2026 17:20:00 +0500 Cc: pgsql-bugs@lists.postgresql.org, dhyan@nataraj.su Content-Transfer-Encoding: quoted-printable Message-Id: References: <1766516577.178080141@f533.i.mail.ru> To: Andrey Rachitskiy X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 24 Dec 2025, at 00:02, Andrey Rachitskiy = wrote: >=20 > Strict mode exhibits similar behavior to LAX mode, consuming = significant CPU resources. >=20 Hi! Examples that you show represent an opportunity for a performance = optimization, but hardly constitute a bug. But I think to showcase this opportunity it would be good to demonstrate = more realistic query. I cannot imagine end user wanting a query like SELECT data @? '$.**.**.**.**.*' FROM test_json; or select = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[= [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[= [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[= [[[[[[[[[[[[[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]]]]]]]]]]]]]]]]]]]]= ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'::jsonb @? '++$.**.**.**.**.*'::jsonpath; Please, construct a more realistic example of what user might want, but = not get in reasonable time. FWIW, I've asked LLM and it thinks that optimization is worth doing: The query pattern $.**[*] ? (@ =3D=3D "x") or $.**.* ? (@ =3D=3D "x") = is something a=20 developer might write when searching for values at any depth in JSON = data that=20 contains arrays (task lists, comment threads, nested categories). The = intent=20 is clear: "find this value anywhere in the structure, including inside = arrays." The performance degradation from O(N) to O(N=C2=B2) occurs at moderate = nesting=20 depths that can appear in real data =E2=80=94 50-level comment threads, = 30-level=20 org charts, etc. More importantly, if the application passes user-provided jsonpath = expressions=20 to @?, the $.**.**.**.**.* pattern becomes a DoS vector requiring no = special=20 privileges =E2=80=94 only the ability to submit a query. A meaningful optimization would be to collapse consecutive .** operators=20= (.** {a,b} .** {c,d} =E2=86=92 .** {a+c, b+d}) at parse or execution = time, which=20 would make $.**.**.**.**.* behave identically to $.**.* in O(N=C2=B2) = time=20 rather than O(N=E2=81=B5). But I think it's a matter for pgsql-hackers, not pgsql-bugs. Best regards, Andrey Borodin.=