Skip to content

Commit abed46a

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 b46e8a8 commit abed46a

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

doc/src/sgml/json.sgml

+32-22
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,19 @@ SELECT doc->'site_name' FROM websites
415415
</para>
416416
<para>
417417
The default GIN operator class for <type>jsonb</type> supports queries with
418-
top-level key-exists operators <literal>?</literal>, <literal>?&amp;</literal>
419-
and <literal>?|</literal> operators and path/value-exists operator
420-
<literal>@&gt;</literal>.
418+
the key-exists operators <literal>?</literal>, <literal>?|</literal>
419+
and <literal>?&amp;</literal>, the containment operator
420+
<literal>@&gt;</literal>, and the <type>jsonpath</type> match
421+
operators <literal>@?</literal> and <literal>@@</literal>.
421422
(For details of the semantics that these operators
422423
implement, see <xref linkend="functions-jsonb-op-table"/>.)
423424
An example of creating an index with this operator class is:
424425
<programlisting>
425426
CREATE INDEX idxgin ON api USING GIN (jdoc);
426427
</programlisting>
427428
The non-default GIN operator class <literal>jsonb_path_ops</literal>
428-
supports indexing the <literal>@&gt;</literal> operator only.
429+
does not support the key-exists operators, but it does support
430+
<literal>@&gt;</literal>, <literal>@?</literal> and <literal>@@</literal>.
429431
An example of creating an index with this operator class is:
430432
<programlisting>
431433
CREATE INDEX idxginp ON api USING GIN (jdoc jsonb_path_ops);
@@ -482,22 +484,7 @@ CREATE INDEX idxgintags ON api USING GIN ((jdoc -&gt; 'tags'));
482484
(More information on expression indexes can be found in <xref
483485
linkend="indexes-expressional"/>.)
484486
</para>
485-
<para>
486-
Also, GIN index supports <literal>@@</literal> and <literal>@?</literal>
487-
operators, which perform <literal>jsonpath</literal> matching.
488-
<programlisting>
489-
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @@ '$.tags[*] == "qui"';
490-
</programlisting>
491-
<programlisting>
492-
SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @? '$.tags[*] ? (@ == "qui")';
493-
</programlisting>
494-
GIN index extracts statements of following form out of
495-
<literal>jsonpath</literal>: <replaceable>accessors_chain</replaceable> = <replaceable>const</replaceable>.
496-
Accessors chain may consist of <literal>.key</literal>,
497-
<literal>[*]</literal>, and <literal>[<replaceable>index</replaceable>]</literal> accessors.
498-
<literal>jsonb_ops</literal> additionally supports <literal>.*</literal>
499-
and <literal>.**</literal> accessors.
500-
</para>
487+
501488
<para>
502489
Another approach to querying is to exploit containment, for example:
503490
<programlisting>
@@ -514,10 +501,33 @@ SELECT jdoc-&gt;'guid', jdoc-&gt;'name' FROM api WHERE jdoc @&gt; '{"tags": ["qu
514501
index.
515502
</para>
516503

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

0 commit comments

Comments
 (0)