Skip to content

Commit 8bc077d

Browse files
Jim NasbyEkaterina Sokolova
Jim Nasby
authored and
Ekaterina Sokolova
committed
Grammatical fixes.
1 parent e3c5701 commit 8bc077d

File tree

1 file changed

+86
-88
lines changed

1 file changed

+86
-88
lines changed

README.md

+86-88
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,27 @@ Simple expression is specified as `path binary_operator value` or
8484
than 5;
8585
* `similar_product_ids.# = "0684824396"` – array "similar\_product\_ids"
8686
contains string "0684824396".
87-
* `*.color = "red"` – there is object somewhere which key "color" has value
88-
"red".
87+
* `*.color = "red"` – there is object somewhere which key "color" has value "red".
8988
* `foo = *` – key "foo" exists in object.
9089

91-
Path selects set of JSON values to be checked using given operators. In
92-
the simplest case path is just an key name. In general path is key names and
93-
placeholders combined by dot signs. Path can use following placeholders:
90+
Path selects a set of JSON values to be checked using given operators. In
91+
the simplest case path is just a key name. In general path is key names and
92+
placeholders combined by dot signs. Path can use the following placeholders:
9493

95-
* `#` – any index of array;
96-
* `#N` – N-th index of array;
97-
* `%` – any key of object;
94+
* `#` – any index of an array;
95+
* `#N` – N-th index of an array;
96+
* `%` – any key of an object;
9897
* `*` – any sequence of array indexes and object keys;
99-
* `@#` – length of array or object, could be only used as last component of
100-
path;
101-
* `$` – the whole JSON document as single value, could be only the whole path.
98+
* `@#` – length of array or object, may only be used as the last component of
99+
a path;
100+
* `$` – the whole JSON document as single value, may only be the whole path.
102101

103102
Expression is true when operator is true against at least one value selected
104103
by path.
105104

106105
Key names could be given either with or without double quotes. Key names
107-
without double quotes shouldn't contain spaces, start with number or concur
108-
with jsquery keyword.
106+
without double quotes may not contain spaces, start with a number or match
107+
a jsquery keyword.
109108

110109
The supported binary operators are:
111110

@@ -121,78 +120,77 @@ The supported unary operators are:
121120
* Check for type operators: `IS ARRAY`, `IS NUMERIC`, `IS OBJECT`, `IS STRING`
122121
and `IS BOOLEAN`.
123122

124-
Expressions could be complex. Complex expression is a set of expressions
123+
Expressions can be complex. Complex expression is a set of expressions
125124
combined by logical operators (`AND`, `OR`, `NOT`) and grouped using braces.
126125

127-
Examples of complex expressions are given below.
126+
Examples of complex expressions:
128127

129128
* `a = 1 AND (b = 2 OR c = 3) AND NOT d = 1`
130129
* `x.% = true OR x.# = true`
131130

132-
Prefix expressions are expressions given in the form path (subexpression).
133-
In this case path selects JSON values to be checked using given subexpression.
131+
Prefix expressions are expressions given in the form `path (subexpression)`.
132+
In this case path selects JSON values to be checked using the given subexpression.
134133
Check results are aggregated in the same way as in simple expressions.
135134

136135
* `#(a = 1 AND b = 2)` – exists element of array which a key is 1 and b key is 2
137136
* `%($ >= 10 AND $ <= 20)` – exists object key which values is between 10 and 20
138137

139-
Path also could contain following special placeholders with "every" semantics:
138+
Path can also contain the following special placeholders with "every" semantics:
140139

141-
* `#:` – every indexes of array;
142-
* `%:` – every key of object;
140+
* `#:` – every index of an array;
141+
* `%:` – every key of an object;
143142
* `*:` – every sequence of array indexes and object keys.
144143

145144
Consider following example.
146145

147146
%.#:($ >= 0 AND $ <= 1)
148147

149-
This example could be read as following: there is at least one key which value
150-
is array of numerics between 0 and 1.
148+
This example could be read as following: there is at least one key whose value
149+
is an array of numerics between 0 and 1.
151150

152-
We can rewrite this example in the following form with extra braces.
151+
We can rewrite this example in the following form with extra braces:
153152

154153
%(#:($ >= 0 AND $ <= 1))
155154

156-
The first placeholder `%` checks that expression in braces is true for at least
157-
one value in object. The second placeholder `#:` checks value to be array and
158-
all its elements satisfy expressions in braces.
155+
The first placeholder `%` checks that the expression in braces is true for at least
156+
one value in the object. The second placeholder `#:` checks if the value is an array
157+
and that all its elements satisfy the expressions in braces.
159158

160-
We can rewrite this example without `#:` placeholder as follows.
159+
We can rewrite this example without the `#:` placeholder as follows:
161160

162161
%(NOT #(NOT ($ >= 0 AND $ <= 1)) AND $ IS ARRAY)
163162

164-
In this example we transform assertion that every element of array satisfy some
165-
condition to assertion that there is no one element which doesn't satisfy the
166-
same condition.
163+
In this example we transform the assertion that every element of array satisfy some
164+
condition to an assertion that there are no elements which don't satisfy the same
165+
condition.
167166

168-
Some examples of using paths are given below.
167+
Some examples of using paths:
169168

170169
* `numbers.#: IS NUMERIC` – every element of "numbers" array is numeric.
171170
* `*:($ IS OBJECT OR $ IS BOOLEAN)` – JSON is a structure of nested objects
172171
with booleans as leaf values.
173-
* `#:.%:($ >= 0 AND $ <= 1)` – each element of array is object containing
172+
* `#:.%:($ >= 0 AND $ <= 1)` – each element of array is an object containing
174173
only numeric values between 0 and 1.
175-
* `documents.#:.% = *` – "documents" is array of objects containing at least
174+
* `documents.#:.% = *` – "documents" is an array of objects containing at least
176175
one key.
177176
* `%.#: ($ IS STRING)` – JSON object contains at least one array of strings.
178-
* `#.% = true` – at least one array element is objects which contains at least
177+
* `#.% = true` – at least one array element is an object which contains at least
179178
one "true" value.
180179

181-
Usage of path operators and braces need some explanation. When same path
182-
operators are used multiple times they may refer different values while you can
183-
refer same value multiple time by using braces and `$` operator. See following
184-
examples.
180+
The use of path operators and braces need some further explanation. When the same path
181+
operators are used multiple times, they may refer to different values. If you want them
182+
to always refer to the same value, you must use braces and the `$` operator. For example:
185183

186-
* `# < 10 AND # > 20`exists element less than 10 and exists another element
187-
greater than 20.
188-
* `#($ < 10 AND $ > 20)`exists element which both less than 10 and greater
189-
than 20 (impossible).
190-
* `#($ >= 10 AND $ <= 20)`exists element between 10 and 20.
191-
* `# >= 10 AND # <= 20`exists element great or equal to 10 and exists
192-
another element less or equal to 20. Query can be satisfied by array with
193-
no elements between 10 and 20, for instance [0,30].
184+
* `# < 10 AND # > 20`an element less than 10 exists, and another element
185+
greater than 20 exists.
186+
* `#($ < 10 AND $ > 20)`an element which is both less than 10 and greater
187+
than 20 exists (impossible).
188+
* `#($ >= 10 AND $ <= 20)`an element between 10 and 20 exists.
189+
* `# >= 10 AND # <= 20`an element greater or equal to 10 exists, and another
190+
element less or equal to 20 exists. Please note that this query also can be
191+
satisfied by an array with no elements between 10 and 20, for instance [0,30].
194192

195-
Same rules apply when you search inside objects and branchy structures.
193+
Same rules apply when searching inside objects and branch structures.
196194

197195
Type checking operators and "every" placeholders are useful for document
198196
schema validation. JsQuery matchig operator `@@` is immutable and can be used
@@ -208,9 +206,9 @@ CREATE TABLE js (
208206
points.#:(x IS NUMERIC AND y IS NUMERIC)'::jsquery));
209207
```
210208

211-
In this example check constraint validates that in "data" jsonb column:
212-
value of "name" key is string, value of "similar_ids" key is array of numerics,
213-
value of "points" key is array of objects which contain numeric values in
209+
In this example the check constraint validates that in the "data" jsonb column
210+
the value of the "name" key is a string, the value of the "similar_ids" key is an array of numerics,
211+
and the value of the "points" key is an array of objects which contain numeric values in
214212
"x" and "y" keys.
215213

216214
See our
@@ -227,11 +225,11 @@ provide different kinds of query optimization.
227225
* jsonb\_value\_path\_ops
228226

229227
In each of two GIN opclasses jsonb documents are decomposed into entries. Each
230-
entry is associated with particular value and it's path. Difference between
228+
entry is associated with a particular value and its path. The difference between
231229
opclasses is in the entry representation, comparison and usage for search
232230
optimization.
233231

234-
For example, jsonb document
232+
For example, the jsonb document
235233
`{"a": [{"b": "xyz", "c": true}, 10], "d": {"e": [7, false]}}`
236234
would be decomposed into following entries:
237235

@@ -241,57 +239,57 @@ would be decomposed into following entries:
241239
* "d"."e".#.7
242240
* "d"."e".#.false
243241

244-
Since JsQuery doesn't support search in particular array index, we consider
242+
Since JsQuery doesn't support searching in a particular array index, we consider
245243
all array elements to be equivalent. Thus, each array element is marked with
246-
same `#` sign in the path.
244+
the same `#` sign in its path.
247245

248246
Major problem in the entries representation is its size. In the given example
249-
key "a" is presented three times. In the large branchy documents with long
250-
keys size of naive entries representation becomes unreasonable. Both opclasses
251-
address this issue but in a slightly different way.
247+
the key "a" is presented three times. In large branchy documents with long
248+
keys sizes of naive entries, the representation becomes unreasonably large.
249+
Both opclasses address this issue, but in slightly different ways.
252250

253251
### jsonb\_path\_value\_ops
254252

255253
jsonb\_path\_value\_ops represents entry as pair of path hash and value.
256-
Following pseudocode illustrates it.
254+
Following pseudocode illustrates it:
257255

258256
(hash(path_item_1.path_item_2. ... .path_item_n); value)
259257

260-
In comparison of entries path hash is the higher part of entry and value is
261-
its lower part. This determines the features of this opclass. Since path
262-
is hashed and it is higher part of entry we need to know the full path to
263-
the value in order to use it for search. However, once path is specified
258+
When comparison entries, the path hash is the higher part of entry and the value is
259+
the lower part. This determines the features of this opclass. Since the path
260+
is hashed and it's the higher part of the entry, we need to know the full path to
261+
a value in order to use the it for searching. However, once the path is specified
264262
we can use both exact and range searches very efficiently.
265263

266264
### jsonb\_value\_path\_ops
267265

268-
jsonb\_value\_path\_ops represents entry as pair of value and bloom filter
269-
of path.
266+
jsonb\_value\_path\_ops represents entry as pair of the value and a bloom filter
267+
of paths:
270268

271269
(value; bloom(path_item_1) | bloom(path_item_2) | ... | bloom(path_item_n))
272270

273271
In comparison of entries value is the higher part of entry and bloom filter of
274272
path is its lower part. This determines the features of this opclass. Since
275-
value is the higher part of entry we can perform only exact value search
276-
efficiently. Range value search is possible as well but we would have to
277-
filter all the the different paths where matching values occur. Bloom filter
278-
over path items allows index usage for conditions containing `%` and `*` in
273+
the value is the higher part of an entry, we can only perform exact value search
274+
effectively. A search over a range of values is possible as well, but we have to
275+
filter all the the different paths where matching values occur. The Bloom filter
276+
over path items allows the index to be used for conditions containing `%` and `*` in
279277
their paths.
280278

281279
### Query optimization
282280

283-
JsQuery opclasses perform complex query optimization. Thus it's valuable for
281+
JsQuery opclasses perform complex query optimization. It's valuable for a
284282
developer or administrator to see the result of such optimization.
285-
Unfortunately, opclasses aren't allowed to do any custom output to the
286-
EXPLAIN. That's why JsQuery provides following functions which allows to see
287-
how particular opclass optimizes given query.
283+
Unfortunately, opclasses aren't allowed to put any custom output in an
284+
EXPLAIN. That's why JsQuery provides these functions to let you see
285+
how particular opclass optimizes given query:
288286

289287
* gin\_debug\_query\_path\_value(jsquery) – for jsonb\_path\_value\_ops
290288
* gin\_debug\_query\_value\_path(jsquery) – for jsonb\_value\_path\_ops
291289

292-
Result of these functions is a textual representation of query tree which
293-
leafs are GIN search entries. Following examples show different results of
294-
query optimization by different opclasses.
290+
The result of these functions is a textual representation of the query tree
291+
where leaves are GIN search entries. Following examples show different results of
292+
query optimization by different opclasses:
295293

296294
# SELECT gin_debug_query_path_value('x = 1 AND (*.y = 1 OR y = 2)');
297295
gin_debug_query_path_value
@@ -309,29 +307,29 @@ query optimization by different opclasses.
309307

310308
Unfortunately, jsonb have no statistics yet. That's why JsQuery optimizer has
311309
to do imperative decision while selecting conditions to be evaluated using
312-
index. This decision is made by assumtion that some condition types are less
313-
selective than others. Optimizer divides conditions into following selectivity
314-
class (listed by descending of selectivity).
310+
index. This decision is made by assuming that some condition types are less
311+
selective than others. The optimizer divides conditions into following selectivity
312+
classes (listed in descending order of selectivity):
315313

316314
1. Equality (x = c)
317315
2. Range (c1 < x < c2)
318316
3. Inequality (x > c)
319317
4. Is (x is type)
320318
5. Any (x = \*)
321319

322-
Optimizer evades index evaluation of less selective conditions when possible.
320+
The optimizer avoids index evaluation of less selective conditions when possible.
323321
For example, in the `x = 1 AND y > 0` query `x = 1` is assumed to be more
324-
selective than `y > 0`. That's why index isn't used for evaluation of `y > 0`.
322+
selective than `y > 0`. That's why the index isn't used for evaluation of `y > 0`.
325323

326324
# SELECT gin_debug_query_path_value('x = 1 AND y > 0');
327325
gin_debug_query_path_value
328326
----------------------------
329327
x = 1 , entry 0 +
330328

331-
With lack of statistics decisions made by optimizer can be inaccurate. That's
332-
why JsQuery supports hints. Comments `/*-- index */` and `/*-- noindex */`
333-
placed in the conditions forces optimizer to use and not use index
334-
correspondingly.
329+
With the lack of statistics, decisions made by optimizer can be inaccurate. That's
330+
why JsQuery supports hints. The comments `/*-- index */` or `/*-- noindex */`
331+
placed in the conditions force the optimizer to use or not use an index
332+
correspondingly:
335333

336334
SELECT gin_debug_query_path_value('x = 1 AND y /*-- index */ > 0');
337335
gin_debug_query_path_value
@@ -348,11 +346,11 @@ correspondingly.
348346
Contribution
349347
------------
350348

351-
Please, notice, that JsQuery is still under development and while it's
352-
stable and tested, it may contains some bugs. Don't hesitate to raise
349+
Please note that JsQuery is still under development. While it's
350+
stable and tested, it may contain some bugs. Don't hesitate to create
353351
[issues at github](https://github.com/postgrespro/jsquery/issues) with your
354352
bug reports.
355353

356-
If you're lacking of some functionality in JsQuery and feeling power to
357-
implement it then you're welcome to make pull requests.
354+
If there's some functionality you'd like to see added to JsQuery and you feel
355+
like you can implement it, then you're welcome to make pull requests.
358356

0 commit comments

Comments
 (0)