Skip to content

Commit 0a02e2a

Browse files
committed
GIN support for @@ and @? jsonpath operators
This commit makes existing GIN operator classes jsonb_ops and json_path_ops support "jsonb @@ jsonpath" and "jsonb @? jsonpath" operators. Basic idea is to extract statements of following form out of jsonpath. key1.key2. ... .keyN = const The rest of jsonpath is rechecked from heap. Catversion is bumped. Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com Author: Nikita Glukhov, Alexander Korotkov Reviewed-by: Jonathan Katz, Pavel Stehule
1 parent 7241911 commit 0a02e2a

File tree

11 files changed

+1456
-78
lines changed

11 files changed

+1456
-78
lines changed

doc/src/sgml/gin.sgml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@
102102
<literal>?&amp;</literal>
103103
<literal>?|</literal>
104104
<literal>@&gt;</literal>
105+
<literal>@?</literal>
106+
<literal>@@</literal>
105107
</entry>
106108
</row>
107109
<row>
108110
<entry><literal>jsonb_path_ops</literal></entry>
109111
<entry><type>jsonb</type></entry>
110112
<entry>
111113
<literal>@&gt;</literal>
114+
<literal>@?</literal>
115+
<literal>@@</literal>
112116
</entry>
113117
</row>
114118
<row>

doc/src/sgml/json.sgml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,22 @@ CREATE INDEX idxgintags ON api USING GIN ((jdoc -&gt; 'tags'));
480480
(More information on expression indexes can be found in <xref
481481
linkend="indexes-expressional"/>.)
482482
</para>
483+
<para>
484+
Also, GIN index supports <literal>@@</literal> and <literal>@?</literal>
485+
operators, which perform <literal>jsonpath</literal> matching.
486+
<programlisting>
487+
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] == "qui"';
488+
</programlisting>
489+
<programlisting>
490+
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] ? (@ == "qui")';
491+
</programlisting>
492+
GIN index extracts statements of following form out of
493+
<literal>jsonpath</literal>: <literal>accessors_chain = const</literal>.
494+
Accessors chain may consist of <literal>.key</literal>,
495+
<literal>[*]</literal> and <literal>[index]</literal> accessors.
496+
<literal>jsonb_ops</literal> additionally supports <literal>.*</literal>
497+
and <literal>.**</literal> statements.
498+
</para>
483499
<para>
484500
Another approach to querying is to exploit containment, for example:
485501
<programlisting>
@@ -498,7 +514,8 @@ SELECT jdoc-&gt;'guid', jdoc-&gt;'name' FROM api WHERE jdoc @&gt; '{"tags": ["qu
498514

499515
<para>
500516
Although the <literal>jsonb_path_ops</literal> operator class supports
501-
only queries with the <literal>@&gt;</literal> operator, it has notable
517+
only queries with the <literal>@&gt;</literal>, <literal>@@</literal>
518+
and <literal>@?</literal> operators, it has notable
502519
performance advantages over the default operator
503520
class <literal>jsonb_ops</literal>. A <literal>jsonb_path_ops</literal>
504521
index is usually much smaller than a <literal>jsonb_ops</literal>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy