@@ -413,17 +413,19 @@ SELECT doc->'site_name' FROM websites
413
413
</para>
414
414
<para>
415
415
The default GIN operator class for <type>jsonb</type> supports queries with
416
- top-level key-exists operators <literal>?</literal>, <literal>?&</literal>
417
- and <literal>?|</literal> operators and path/value-exists operator
418
- <literal>@></literal>.
416
+ the key-exists operators <literal>?</literal>, <literal>?|</literal>
417
+ and <literal>?&</literal>, the containment operator
418
+ <literal>@></literal>, and the <type>jsonpath</type> match
419
+ operators <literal>@?</literal> and <literal>@@</literal>.
419
420
(For details of the semantics that these operators
420
421
implement, see <xref linkend="functions-jsonb-op-table"/>.)
421
422
An example of creating an index with this operator class is:
422
423
<programlisting>
423
424
CREATE INDEX idxgin ON api USING GIN (jdoc);
424
425
</programlisting>
425
426
The non-default GIN operator class <literal>jsonb_path_ops</literal>
426
- supports indexing the <literal>@></literal> operator only.
427
+ does not support the key-exists operators, but it does support
428
+ <literal>@></literal>, <literal>@?</literal> and <literal>@@</literal>.
427
429
An example of creating an index with this operator class is:
428
430
<programlisting>
429
431
CREATE INDEX idxginp ON api USING GIN (jdoc jsonb_path_ops);
@@ -480,22 +482,7 @@ CREATE INDEX idxgintags ON api USING GIN ((jdoc -> 'tags'));
480
482
(More information on expression indexes can be found in <xref
481
483
linkend="indexes-expressional"/>.)
482
484
</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
+
499
486
<para>
500
487
Another approach to querying is to exploit containment, for example:
501
488
<programlisting>
@@ -512,10 +499,33 @@ SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @> '{"tags": ["qu
512
499
index.
513
500
</para>
514
501
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
+
515
525
<para>
516
526
Although the <literal>jsonb_path_ops</literal> operator class supports
517
- only queries with the <literal>@></literal>, <literal>@@ </literal>
518
- and <literal>@? </literal> operators, it has notable
527
+ only queries with the <literal>@></literal>, <literal>@? </literal>
528
+ and <literal>@@ </literal> operators, it has notable
519
529
performance advantages over the default operator
520
530
class <literal>jsonb_ops</literal>. A <literal>jsonb_path_ops</literal>
521
531
index is usually much smaller than a <literal>jsonb_ops</literal>