mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
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
This commit is contained in:
@ -480,6 +480,22 @@ CREATE INDEX idxgintags ON api USING GIN ((jdoc -> 'tags'));
|
||||
(More information on expression indexes can be found in <xref
|
||||
linkend="indexes-expressional"/>.)
|
||||
</para>
|
||||
<para>
|
||||
Also, GIN index supports <literal>@@</literal> and <literal>@?</literal>
|
||||
operators, which perform <literal>jsonpath</literal> matching.
|
||||
<programlisting>
|
||||
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] == "qui"';
|
||||
</programlisting>
|
||||
<programlisting>
|
||||
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] ? (@ == "qui")';
|
||||
</programlisting>
|
||||
GIN index extracts statements of following form out of
|
||||
<literal>jsonpath</literal>: <literal>accessors_chain = const</literal>.
|
||||
Accessors chain may consist of <literal>.key</literal>,
|
||||
<literal>[*]</literal> and <literal>[index]</literal> accessors.
|
||||
<literal>jsonb_ops</literal> additionally supports <literal>.*</literal>
|
||||
and <literal>.**</literal> statements.
|
||||
</para>
|
||||
<para>
|
||||
Another approach to querying is to exploit containment, for example:
|
||||
<programlisting>
|
||||
@ -498,7 +514,8 @@ SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @> '{"tags": ["qu
|
||||
|
||||
<para>
|
||||
Although the <literal>jsonb_path_ops</literal> operator class supports
|
||||
only queries with the <literal>@></literal> operator, it has notable
|
||||
only queries with the <literal>@></literal>, <literal>@@</literal>
|
||||
and <literal>@?</literal> operators, it has notable
|
||||
performance advantages over the default operator
|
||||
class <literal>jsonb_ops</literal>. A <literal>jsonb_path_ops</literal>
|
||||
index is usually much smaller than a <literal>jsonb_ops</literal>
|
||||
|
Reference in New Issue
Block a user