Skip to content

Commit 51b0198

Browse files
committed
Doc: copy-edit "jsonb Indexing" section.
The patch introducing jsonpath dropped a para about that between two related examples, and didn't bother updating the introductory sentences that it falsified. The grammar was pretty shaky as well.
1 parent 9b100ee commit 51b0198

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

doc/src/sgml/json.sgml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,19 @@ SELECT doc->'site_name' FROM websites
413413
</para>
414414
<para>
415415
The default GIN operator class for <type>jsonb</type> supports queries with
416-
top-level key-exists operators <literal>?</literal>, <literal>?&amp;</literal>
417-
and <literal>?|</literal> operators and path/value-exists operator
418-
<literal>@&gt;</literal>.
416+
the key-exists operators <literal>?</literal>, <literal>?|</literal>
417+
and <literal>?&amp;</literal>, the containment operator
418+
<literal>@&gt;</literal>, and the <type>jsonpath</type> match
419+
operators <literal>@?</literal> and <literal>@@</literal>.
419420
(For details of the semantics that these operators
420421
implement, see <xref linkend="functions-jsonb-op-table"/>.)
421422
An example of creating an index with this operator class is:
422423
<programlisting>
423424
CREATE INDEX idxgin ON api USING GIN (jdoc);
424425
</programlisting>
425426
The non-default GIN operator class <literal>jsonb_path_ops</literal>
426-
supports indexing the <literal>@&gt;</literal> operator only.
427+
does not support the key-exists operators, but it does support
428+
<literal>@&gt;</literal>, <literal>@?</literal> and <literal>@@</literal>.
427429
An example of creating an index with this operator class is:
428430
<programlisting>
429431
CREATE INDEX idxginp ON api USING GIN (jdoc jsonb_path_ops);
@@ -480,22 +482,7 @@ CREATE INDEX idxgintags ON api USING GIN ((jdoc -&gt; 'tags'));
480482
(More information on expression indexes can be found in <xref
481483
linkend="indexes-expressional"/>.)
482484
</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>: <replaceable>accessors_chain</replaceable> = <replaceable>const</replaceable>.
494-
Accessors chain may consist of <literal>.key</literal>,
495-
<literal>[*]</literal>, and <literal>[<replaceable>index</replaceable>]</literal> accessors.
496-
<literal>jsonb_ops</literal> additionally supports <literal>.*</literal>
497-
and <literal>.**</literal> accessors.
498-
</para>
485+
499486
<para>
500487
Another approach to querying is to exploit containment, for example:
501488
<programlisting>
@@ -512,10 +499,33 @@ SELECT jdoc-&gt;'guid', jdoc-&gt;'name' FROM api WHERE jdoc @&gt; '{"tags": ["qu
512499
index.
513500
</para>
514501

502+
<para>
503+
GIN indexes also support the <literal>@?</literal>
504+
and <literal>@@</literal> operators, which
505+
perform <type>jsonpath</type> matching. Examples are
506+
<programlisting>
507+
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @? '$.tags[*] ? (@ == "qui")';
508+
</programlisting>
509+
<programlisting>
510+
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] == "qui"';
511+
</programlisting>
512+
For these operators, a GIN index extracts clauses of the form
513+
<literal><replaceable>accessors_chain</replaceable>
514+
= <replaceable>constant</replaceable></literal> out of
515+
the <type>jsonpath</type> pattern, and does the index search based on
516+
the keys and values mentioned in these clauses. The accessors chain
517+
may include <literal>.<replaceable>key</replaceable></literal>,
518+
<literal>[*]</literal>,
519+
and <literal>[<replaceable>index</replaceable>]</literal> accessors.
520+
The <literal>jsonb_ops</literal> operator class also
521+
supports <literal>.*</literal> and <literal>.**</literal> accessors,
522+
but the <literal>jsonb_path_ops</literal> operator class does not.
523+
</para>
524+
515525
<para>
516526
Although the <literal>jsonb_path_ops</literal> operator class supports
517-
only queries with the <literal>@&gt;</literal>, <literal>@@</literal>
518-
and <literal>@?</literal> operators, it has notable
527+
only queries with the <literal>@&gt;</literal>, <literal>@?</literal>
528+
and <literal>@@</literal> operators, it has notable
519529
performance advantages over the default operator
520530
class <literal>jsonb_ops</literal>. A <literal>jsonb_path_ops</literal>
521531
index is usually much smaller than a <literal>jsonb_ops</literal>

0 commit comments

Comments
 (0)