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 1qhFPx-001pGq-IA for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Sep 2023 20:27: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 1qhFPv-00339v-W5 for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Sep 2023 20:27: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 1qhFPv-00339M-E6 for pgsql-hackers@lists.postgresql.org; Fri, 15 Sep 2023 20:27:55 +0000 Received: from pb-smtp1.pobox.com ([64.147.108.70]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qhFPr-004mER-3q for pgsql-hackers@lists.postgresql.org; Fri, 15 Sep 2023 20:27:53 +0000 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 15C7A1A0D13; Fri, 15 Sep 2023 16:27:49 -0400 (EDT) (envelope-from david@justatheory.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h= content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; s=sasl; bh=4xL7+m87wxr1KGA1hzjlFJMmmh S8whpRPtfhbp9FsVk=; b=u7tyiqmxvoAq2Y+EKgCTtubRV4A2Slv4fU5TIMvEcL fuPybwPKnQt/YSUUb/MZ37qkGDn7EGeImGVpQR2DTwHLXC9ayeCy45F5uTnT/yI+ wuEpRcGsy2mkFLDza7PPHaCVqjxdNPnbGWMHV4rZHDchH/Ka3KqR0G6e6+NNgNCx A= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 0EA8D1A0D12; Fri, 15 Sep 2023 16:27:49 -0400 (EDT) (envelope-from david@justatheory.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=justatheory.com; h=content-type:mime-version:subject:from:in-reply-to:date:cc:message-id:references:to; s=2016-12.pbsmtp; bh=4xL7+m87wxr1KGA1hzjlFJMmmhS8whpRPtfhbp9FsVk=; b=Hf7lVCk9w+a+Y5bz6Do9oHmF0XoCvYKq8nHDi3nh8uChTI8XrOn5SZIooPC6onV2QZtbrmKrQnS9EGUpcXqClMluZKpsY5/+UguvTbsg2i7WQVKfjqnVhDVdB4MwZbqaN2b27HoppTBgSCwV0WqUrOODST7b/ms8BdSSTXkp84Q= Received: from smtpclient.apple (unknown [158.222.197.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 842831A0D11; Fri, 15 Sep 2023 16:27:48 -0400 (EDT) (envelope-from david@justatheory.com) Content-Type: multipart/signed; boundary="Apple-Mail=_0F412960-2E89-48F6-8D2A-FB825E4B1ECB"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: JSON Path and GIN Questions From: "David E. Wheeler" X-Priority: 3 In-Reply-To: <133696180.303713.1694566807910@office.mailbox.org> Date: Fri, 15 Sep 2023 16:27:37 -0400 Cc: pgsql-hackers@lists.postgresql.org Message-Id: <729CC2EA-9194-459C-B2A6-BC660F62E6A9@justatheory.com> References: <15DD78A5-B5C4-4332-ACFE-55723259C07F@justatheory.com> <133696180.303713.1694566807910@office.mailbox.org> To: Erik Wienhold X-Mailer: Apple Mail (2.3731.700.6) X-Pobox-Relay-ID: 56166282-5406-11EE-AB53-78DCEB2EC81B-76319746!pb-smtp1.pobox.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_0F412960-2E89-48F6-8D2A-FB825E4B1ECB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On Sep 12, 2023, at 21:00, Erik Wienhold wrote: > That's also my understanding. We had a discussion about the docs on = @@, @?, and > jsonb_path_query on -general a while back [1]. Maybe it's useful = also. Okay, I=E2=80=99ll take a pass at expanding the docs on this. I think a = little mini-tutorial on these two operators would be useful. Meanwhile, I=E2=80=99d like to re-up this question about the index = qualification of non-equality JSON Path operators. On Sep 12, 2023, at 20:16, David E. Wheeler = wrote: > Issue 3: Index Use for Comparison > --------------------------------- >=20 > =46rom the docs = (https://www.postgresql.org/docs/current/datatype-json.html#JSON-INDEXING)= , I had assumed any JSON Path query would be able to use the GIN index. = However while the use of the =3D=3D JSON Path operator is able to take = advantage of the GIN index, apparently the >=3D operator cannot: >=20 > david=3D# explain analyze select id from movies where movie @? '$ = ?($.year >=3D 2023)'; > QUERY PLAN = = --------------------------------------------------------------------------= ------------------------------- > Seq Scan on movies (cost=3D0.00..3741.41 rows=3D366 width=3D4) = (actual time=3D34.815..36.259 rows=3D192 loops=3D1) > Filter: (movie @? '$?($."year" >=3D 2023)'::jsonpath) > Rows Removed by Filter: 36081 > Planning Time: 1.864 ms > Execution Time: 36.338 ms > (5 rows) >=20 > Is this expected? Originally I tried with json_path_ops, which I can = understand not working, since it stores hashes of paths, which would = allow only exact matches. But a plain old GIN index doesn=E2=80=99t = appear to work, either. Should it? Is there perhaps some other op class = that would allow it to work? Or would I have to create a separate BTREE = index on `movie -> 'year'`? Thanks, David --Apple-Mail=_0F412960-2E89-48F6-8D2A-FB825E4B1ECB Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEd+KfmbOQis6ZycGGkt9idPjIgfEFAmUEvjkACgkQkt9idPjI gfFWNw/+OYDVMubUJVGiSqD2fKAowo+/MWN2g/4CiC3JvGKkQ5SIiggjt6LLH92H 3Q72Aa1oLg2U/P2ME73V/Axq2/xYLd+eQJ7QWoaIzga939Sz5DgyPuZg9ld4AFbl dwQvk6Q4C+2MW7ZNkATA1pU51OHOaL7sWZMXqcmJz2xJBGVaN93jIPQ1aBa9y6iJ b7MoGjATw3Pev5juVLZqV7yK1GbMzPIOdqoLzEK53e/Cg0EEO0wr7jippumgZP9e r8gbfRHrLqqpNUOT1amkcRk85ny/l+u7DAuy97Lh09HsMyuv0c7Fw1IEMurzRtSz wd6PA8O55pXwKyNn0hfycQAvFomOk4tJJxiAXF/WxbgvoGEjsbu4mApPjFNfFrnp ZPfyCq523gpUPNaOPqFEMdAAZNBI1lbp6Trs7nzdnKduTiqKquN6RNB0omiI1mFJ etaTt6y1Trkp0RXCYWd76bmMFSSIyz5ajgK0YszMHMcILY6/xoBzCbl25GSQfYLH k+arQY6BQCpMFLdNkJeAUfHPbnX2o0AXRqdUf2bl718/gSmnHma0OZgikXDjfVrj XAj/VWsc0x0NuedDtpVNaE7H1CaShPUMHxYQRw5jn1oEmjKgs2uaBmuxQqem9YdT MetBic2tgezRsvkedr6uAwZfkTbzETWtDOxWbwrZEYSY6c9/Prc= =r7Sf -----END PGP SIGNATURE----- --Apple-Mail=_0F412960-2E89-48F6-8D2A-FB825E4B1ECB--