3
3
<sect2 id="jsquery-introduction">
4
4
<title>Introduction</title>
5
5
<para>
6
- JsQuery - is a language to query jsonb data type, introduced in
6
+ JsQuery is a language to query jsonb data type, introduced in
7
7
PostgreSQL release 9.4.
8
8
</para>
9
9
<para>
10
- It's primary goal is to provide an additional functionality to
10
+ Its primary goal is to provide an additional functionality to
11
11
jsonb (currently missing in PostgreSQL), such as a simple and
12
12
effective way to search in nested objects and arrays, more
13
- comparison operators with indexes support. We hope, that jsquery
13
+ comparison operators with indexes support. We hope that jsquery
14
14
will be eventually a part of PostgreSQL.
15
15
</para>
16
16
<para>
@@ -72,7 +72,7 @@ CREATE EXTENSION jsquery;
72
72
<para>
73
73
Simple expression is specified as
74
74
<literal>path binary_operator value</literal> or
75
- <literal>path unary_operator</literal>. See following examples.
75
+ <literal>path unary_operator</literal>. See the following examples.
76
76
</para>
77
77
<itemizedlist spacing="compact">
78
78
<listitem>
@@ -135,9 +135,9 @@ CREATE EXTENSION jsquery;
135
135
</itemizedlist>
136
136
<para>
137
137
Path selects set of JSON values to be checked using given
138
- operators. In the simplest case path is just an key name. In
139
- general path is key names and placeholders combined by dot signs.
140
- Path can use following placeholders:
138
+ operators. In the simplest case, path is just a key name. In
139
+ general, path is key names and placeholders combined by dot signs.
140
+ Path can use the following placeholders:
141
141
</para>
142
142
<itemizedlist spacing="compact">
143
143
<listitem>
@@ -176,7 +176,7 @@ CREATE EXTENSION jsquery;
176
176
<para>
177
177
Key names could be given either with or without double quotes. Key
178
178
names without double quotes shouldn't contain spaces, start with
179
- number or concur with jsquery keyword.
179
+ number, or concur with jsquery keyword.
180
180
</para>
181
181
<para>
182
182
The supported binary operators are:
@@ -256,25 +256,26 @@ CREATE EXTENSION jsquery;
256
256
<itemizedlist spacing="compact">
257
257
<listitem>
258
258
<para>
259
- <literal>#(a = 1 AND b = 2)</literal> - exists element of
260
- array which a key is 1 and b key is 2
259
+ <literal>#(a = 1 AND b = 2)</literal> - an array contains
260
+ an element where the <literal>a</literal> key is 2
261
+ and the <literal>b</literal> key is 2
261
262
</para>
262
263
</listitem>
263
264
<listitem>
264
265
<para>
265
- <literal>%($ >= 10 AND $ <= 20)</literal> - exists
266
- object key which values is between 10 and 20
266
+ <literal>%($ >= 10 AND $ <= 20)</literal> - an
267
+ object contains a key with a value between 10 and 20
267
268
</para>
268
269
</listitem>
269
270
</itemizedlist>
270
271
<para>
271
- Path also could contain following special placeholders with
272
+ Path also could contain the following special placeholders with
272
273
"every" semantics:
273
274
</para>
274
275
<itemizedlist spacing="compact">
275
276
<listitem>
276
277
<para>
277
- <literal>#:</literal> - every indexes of array;
278
+ <literal>#:</literal> - every index of array;
278
279
</para>
279
280
</listitem>
280
281
<listitem>
@@ -290,14 +291,14 @@ CREATE EXTENSION jsquery;
290
291
</listitem>
291
292
</itemizedlist>
292
293
<para>
293
- Consider following example.
294
+ Consider the following example.
294
295
</para>
295
296
<programlisting>
296
297
%.#:($ >= 0 AND $ <= 1)
297
298
</programlisting>
298
299
<para>
299
- This example could be read as following : there is at least one key
300
- which value is array of numerics between 0 and 1.
300
+ This example could be read as follows : there is at least one key
301
+ for which the value is an array of numerics between 0 and 1.
301
302
</para>
302
303
<para>
303
304
We can rewrite this example in the following form with extra
@@ -309,7 +310,7 @@ CREATE EXTENSION jsquery;
309
310
<para>
310
311
The first placeholder <literal>%</literal> checks that expression
311
312
in braces is true for at least one value in object. The second
312
- placeholder <literal>#:</literal> checks value to be array and all
313
+ placeholder <literal>#:</literal> checks that the value is an array and all
313
314
its elements satisfy expressions in braces.
314
315
</para>
315
316
<para>
@@ -321,7 +322,7 @@ CREATE EXTENSION jsquery;
321
322
</programlisting>
322
323
<para>
323
324
In this example we transform assertion that every element of array
324
- satisfy some condition to assertion that there is no one element
325
+ satisfies some condition to assertion that there is no one element
325
326
which doesn't satisfy the same condition.
326
327
</para>
327
328
<para>
@@ -350,7 +351,7 @@ CREATE EXTENSION jsquery;
350
351
<listitem>
351
352
<para>
352
353
<literal>documents.#:.% = *</literal> - "documents"
353
- is array of objects containing at least one key.
354
+ is an array of objects containing at least one key.
354
355
</para>
355
356
</listitem>
356
357
<listitem>
@@ -362,41 +363,41 @@ CREATE EXTENSION jsquery;
362
363
<listitem>
363
364
<para>
364
365
<literal>#.% = true</literal> - at least one array element is
365
- objects which contains at least one "true" value.
366
+ an object that contains at least one "true" value.
366
367
</para>
367
368
</listitem>
368
369
</itemizedlist>
369
370
<para>
370
371
Usage of path operators and braces need some explanation. When
371
- same path operators are used multiple times they may refer
372
- different values while you can refer same value multiple time by
373
- using braces and <literal>$</literal> operator. See following
372
+ same path operators are used multiple times they may refer to
373
+ different values while you can refer to the same value multiple times by
374
+ using braces and <literal>$</literal> operator. See the following
374
375
examples.
375
376
</para>
376
377
<itemizedlist spacing="compact">
377
378
<listitem>
378
379
<para>
379
- <literal># < 10 AND # > 20</literal> - exists element
380
- less than 10 and exists another element greater than 20.
380
+ <literal># < 10 AND # > 20</literal> - there is an element
381
+ less than 10 and another element greater than 20.
381
382
</para>
382
383
</listitem>
383
384
<listitem>
384
385
<para>
385
- <literal>#($ < 10 AND $ > 20)</literal> - exists element
386
- which both less than 10 and greater than 20 (impossible).
386
+ <literal>#($ < 10 AND $ > 20)</literal> - there is an element
387
+ that is both less than 10 and greater than 20 (impossible).
387
388
</para>
388
389
</listitem>
389
390
<listitem>
390
391
<para>
391
- <literal>#($ >= 10 AND $ <= 20)</literal> - exists
392
+ <literal>#($ >= 10 AND $ <= 20)</literal> - there is an
392
393
element between 10 and 20.
393
394
</para>
394
395
</listitem>
395
396
<listitem>
396
397
<para>
397
- <literal># >= 10 AND # <= 20</literal> - exists element
398
- great or equal to 10 and exists another element less or equal
399
- to 20. Query can be satisfied by array with no elements
398
+ <literal># >= 10 AND # <= 20</literal> - there is an element
399
+ great than or equal to 10 and another element less than or equal
400
+ to 20. The query can be satisfied by an array with no elements
400
401
between 10 and 20, for instance [0,30].
401
402
</para>
402
403
</listitem>
@@ -409,7 +410,7 @@ CREATE EXTENSION jsquery;
409
410
Type checking operators and "every" placeholders are
410
411
useful for document schema validation. JsQuery matching operator
411
412
<literal>@@</literal> is immutable and can be used in CHECK
412
- constraint. See following example.
413
+ constraint. See the following example.
413
414
</para>
414
415
<programlisting>
415
416
CREATE TABLE js (
@@ -453,14 +454,14 @@ CREATE TABLE js (
453
454
</itemizedlist>
454
455
<para>
455
456
In each of two GIN opclasses jsonb documents are decomposed into
456
- entries. Each entry is associated with particular value and it's
457
+ entries. Each entry is associated with a particular value and its
457
458
path. Difference between opclasses is in the entry representation,
458
- comparison and usage for search optimization.
459
+ comparison, and usage for search optimization.
459
460
</para>
460
461
<para>
461
462
For example, jsonb document
462
463
<literal>{"a": [{"b": "xyz", "c": true}, 10], "d": {"e": [7, false]}}</literal>
463
- would be decomposed into following entries:
464
+ would be decomposed into the following entries:
464
465
</para>
465
466
<itemizedlist spacing="compact">
466
467
<listitem>
@@ -490,9 +491,9 @@ CREATE TABLE js (
490
491
</listitem>
491
492
</itemizedlist>
492
493
<para>
493
- Since JsQuery doesn't support search in particular array index, we
494
+ Since JsQuery doesn't support search in a particular array index, we
494
495
consider all array elements to be equivalent. Thus, each array
495
- element is marked with same <literal>#</literal> sign in the path.
496
+ element is marked with the same <literal>#</literal> sign in the path.
496
497
</para>
497
498
<para>
498
499
Major problem in the entries representation is its size. In the
@@ -505,7 +506,7 @@ CREATE TABLE js (
505
506
<title>jsonb_path_value_ops</title>
506
507
<para>
507
508
jsonb_path_value_ops represents entry as pair of path hash and
508
- value. Following pseudocode illustrates it.
509
+ value. The following pseudocode illustrates it.
509
510
</para>
510
511
<programlisting>
511
512
(hash(path_item_1.path_item_2. ... .path_item_n); value)
@@ -534,7 +535,7 @@ CREATE TABLE js (
534
535
features of this opclass. Since value is the higher part of
535
536
entry we can perform only exact value search efficiently. Range
536
537
value search is possible as well but we would have to filter all
537
- the the different paths where matching values occur. Bloom
538
+ the different paths where matching values occur. Bloom
538
539
filter over path items allows index usage for conditions
539
540
containing <literal>%</literal> and <literal>*</literal> in
540
541
their paths.
@@ -547,7 +548,7 @@ CREATE TABLE js (
547
548
valuable for developer or administrator to see the result of
548
549
such optimization. Unfortunately, opclasses aren't allowed to do
549
550
any custom output to the EXPLAIN. That's why JsQuery provides
550
- following functions which allows to see how particular opclass
551
+ the following functions which allows to see how particular opclass
551
552
optimizes given query.
552
553
</para>
553
554
<itemizedlist spacing="compact">
@@ -566,7 +567,7 @@ CREATE TABLE js (
566
567
</itemizedlist>
567
568
<para>
568
569
Result of these functions is a textual representation of query
569
- tree which leafs are GIN search entries. Following examples show
570
+ tree which leaves are GIN search entries. The following examples show
570
571
different results of query optimization by different opclasses.
571
572
</para>
572
573
<programlisting>
@@ -585,11 +586,11 @@ CREATE TABLE js (
585
586
y = 2 , entry 2 +
586
587
</programlisting>
587
588
<para>
588
- Unfortunately, jsonb have no statistics yet. That's why JsQuery
589
+ Unfortunately, jsonb has no statistics yet. That's why JsQuery
589
590
optimizer has to do imperative decision while selecting
590
591
conditions to be evaluated using index. This decision is made by
591
592
assumption that some condition types are less selective than
592
- others. Optimizer divides conditions into following selectivity
593
+ others. Optimizer divides conditions into the following selectivity
593
594
class (listed by descending of selectivity).
594
595
</para>
595
596
<orderedlist numeration="arabic" spacing="compact">
@@ -638,7 +639,7 @@ CREATE TABLE js (
638
639
inaccurate. That's why JsQuery supports hints. Comments
639
640
<literal>/*-- index */</literal> and
640
641
<literal>/*-- noindex */</literal> placed in the conditions
641
- forces optimizer to use and not use index correspondingly.
642
+ forces optimizer to use and not to use index correspondingly.
642
643
</para>
643
644
<programlisting>
644
645
SELECT gin_debug_query_path_value('x = 1 AND y /*-- index */ > 0');
@@ -658,14 +659,14 @@ CREATE TABLE js (
658
659
<sect2 id="jsquery-contribution">
659
660
<title>Contribution</title>
660
661
<para>
661
- Please, notice, that JsQuery is still under development and while
662
- it's stable and tested, it may contains some bugs. Don't hesitate
662
+ Please, notice, that JsQuery is still under development and before
663
+ it's stable and tested, it may contain some bugs. Don't hesitate
663
664
to raise
664
665
<ulink url="https://github.com/akorotkov/jsquery/issues">issues at
665
666
github</ulink> with your bug reports.
666
667
</para>
667
668
<para>
668
- If you're lacking of some functionality in JsQuery and feeling
669
+ If you're lacking some functionality in JsQuery and feeling
669
670
power to implement it then you're welcome to make pull requests.
670
671
</para>
671
672
</sect2>
0 commit comments