@@ -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 justan key name. In general path is key names and
93- placeholders combined by dot signs. Path can use following placeholders:
90+ Path selectsa set of JSON values to be checked using given operators. In
91+ the simplest case path is justa key name. In general path is key names and
92+ placeholders combined by dot signs. Path can usethe following placeholders:
9493
95- * ` # ` – any index of array;
96- * ` #N ` – N-th index of array;
97- * ` % ` – any key of object;
94+ * ` # ` – any index ofan array;
95+ * ` #N ` – N-th index ofan array;
96+ * ` % ` – any key ofan 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 onlybe used as the last component of
99+ a path;
100+ * ` $ ` – the whole JSON document as single value,may only be the whole path.
102101
103102Expression is true when operator is true against at least one value selected
104103by path.
105104
106105Key names could be given either with or without double quotes. Key names
107- without double quotesshouldn't contain spaces, start with number orconcur
108- with jsquery keyword.
106+ without double quotesmay not contain spaces, start witha number ormatch
107+ a jsquery keyword.
109108
110109The 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- Expressionscould be complex. Complex expression is a set of expressions
123+ Expressionscan be complex. Complex expression is a set of expressions
125124combined 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 usingthe given subexpression.
134133Check 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 alsocould contain following special placeholders with "every" semantics:
138+ Pathcan also contain the following special placeholders with "every" semantics:
140139
141- * ` #: ` – everyindexes of array;
142- * ` %: ` – every key of object;
140+ * ` #: ` – everyindex of an array;
141+ * ` %: ` – every key ofan object;
143142* ` *: ` – every sequence of array indexes and object keys.
144143
145144Consider following example.
146145
147146%.#:($ >= 0 AND $ <= 1)
148147
149- This example could be read as following: there is at least one keywhich value
150- is array of numerics between 0 and 1.
148+ This example could be read as following: there is at least one keywhose value
149+ isan 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 valueto be array and
158- all its elements satisfy expressions in braces.
155+ The first placeholder` % ` checks thatthe expression in braces is true for at least
156+ one value inthe object. The second placeholder` #: ` checksif the valueis 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 withoutthe ` #: ` 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 thereis noone element whichdoesn 't satisfy the
166- same condition.
163+ In this example we transformthe assertion that every element of array satisfy some
164+ condition toan assertion that thereare noelements whichdon '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 isan object containing
174173 only numeric values between 0 and 1.
175- * ` documents.#:.% = * ` – "documents" is array of objects containing at least
174+ * ` documents.#:.% = * ` – "documents" isan 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 isobjects which contains at least
177+ * ` #.% = true ` – at least one array element isan 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 10and 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 elementgreat or equal to 10 andexists
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 20exists (impossible).
188+ * ` #($ >= 10 AND $ <= 20) ` –an element between 10 and 20 exists .
189+ * ` # >= 10 AND # <= 20 ` –an elementgreater or equal to 10exists, andanother
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 whenyou search inside objects andbranchy structures.
193+ Same rules apply whensearching inside objects andbranch structures.
196194
197195Type checking operators and "every" placeholders are useful for document
198196schema 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 examplethe check constraint validates that inthe "data" jsonb column
210+ the value ofthe "name" key isa string,the value ofthe "similar_ids" key is an array of numerics,
211+ and the value ofthe "points" key is an array of objects which contain numeric values in
214212"x" and "y" keys.
215213
216214See our
@@ -227,11 +225,11 @@ provide different kinds of query optimization.
227225* jsonb\_ value\_ path\_ ops
228226
229227In each of two GIN opclasses jsonb documents are decomposed into entries. Each
230- entry is associated with particular value andit's path.Difference between
228+ entry is associated witha particular value andits path.The difference between
231229opclasses is in the entry representation, comparison and usage for search
232230optimization.
233231
234- For example, jsonb document
232+ For example,the jsonb document
235233` {"a": [{"b": "xyz", "c": true}, 10], "d": {"e": [7, false]}} `
236234would 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 supportsearch in particular array index, we consider
242+ Since JsQuery doesn't supportsearching in a particular array index, we consider
245243all array elements to be equivalent. Thus, each array element is marked with
246- same` # ` sign inthe path.
244+ the same` # ` sign inits path.
247245
248246Major 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- keyssize of naive entries representation becomesunreasonable. Both opclasses
251- address this issue but ina slightly differentway .
247+ the key "a" is presented three times. In large branchy documents with long
248+ keyssizes of naive entries, the representation becomesunreasonably large.
249+ Both opclasses address this issue, but in slightly differentways .
252250
253251###jsonb\_ path\_ value\_ ops
254252
255253jsonb\_ 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 comparisonof 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 forsearch . 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 ofthe entry, we need to know the full path to
261+ a value in order to usethe it forsearching . However, once the path is specified
264262we 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- ofpath.
266+ jsonb\_ value\_ path\_ ops represents entry as pair ofthe value and a bloom filter
267+ ofpaths:
270268
271269(value; bloom(path_item_1) | bloom(path_item_2) | ... | bloom(path_item_n))
272270
273271In comparison of entries value is the higher part of entry and bloom filter of
274272path is its lower part. This determines the features of this opclass. Since
275- value is the higher part of entry we canperform 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 indexusage for conditions containing` % ` and` * ` in
273+ the value is the higher part ofan entry, we can only perform exact value search
274+ effectively. A searchover 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 allowsthe indexto be used for conditions containing` % ` and` * ` in
279277their 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
284282developer or administrator to see the result of such optimization.
285- Unfortunately, opclasses aren't allowed todo any custom outputto the
286- EXPLAIN. That's why JsQuery providesfollowing functionswhich allows to see
287- how particular opclass optimizes given query.
283+ Unfortunately, opclasses aren't allowed toput any custom outputin an
284+ EXPLAIN. That's why JsQuery providesthese functionsto 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 ofthe 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
310308Unfortunately, jsonb have no statistics yet. That's why JsQuery optimizer has
311309to do imperative decision while selecting conditions to be evaluated using
312- index. This decision is made byassumtion that some condition types are less
313- selective than others.Optimizer divides conditions into following selectivity
314- class (listedby descending of selectivity).
310+ index. This decision is made byassuming that some condition types are less
311+ selective than others.The optimizer divides conditions into following selectivity
312+ classes (listedin descendingorder of selectivity):
315313
3163141 . Equality (x = c)
3173152 . Range (c1 < x < c2)
3183163 . Inequality (x > c)
3193174 . Is (x is type)
3203185 . 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.
323321For 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 whythe 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 conditionsforces optimizer to useand not use index
334- correspondingly.
329+ Withthe 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 conditionsforce the optimizer to useor not use an index
332+ correspondingly:
335333
336334SELECT gin_debug_query_path_value('x = 1 AND y /*-- index */ > 0');
337335 gin_debug_query_path_value
@@ -348,11 +346,11 @@ correspondingly.
348346Contribution
349347------------
350348
351- Please, notice, that JsQuery is still under development and while it's
352- stable and tested, it maycontains some bugs. Don't hesitate toraise
349+ Please note that JsQuery is still under development. While it's
350+ stable and tested, it maycontain some bugs. Don't hesitate tocreate
353351[ issues at github] ( https://github.com/postgrespro/jsquery/issues ) with your
354352bug reports.
355353
356- If you're lacking of some functionality in JsQuery andfeeling power to
357- implement it then you're welcome to make pull requests.
354+ Ifthere's some functionality you'd like to see added to JsQuery andyou feel
355+ like you can implement it, then you're welcome to make pull requests.
358356