Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

+4
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

+18-1
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)