Skip to content

Commit

Permalink
Fix indexing of raw scalar values
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Glukhov committed May 17, 2017
1 parent 7a30b56 commit b70cf0f
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 2 deletions.
17 changes: 17 additions & 0 deletions data/test_jsquery.data
Original file line number Diff line number Diff line change
Expand Up @@ -1015,3 +1015,20 @@
{"t": "a"}
{"t": true}
{"t": false}
[1, 2, 3]
["a", "b", "c"]
1
2
3
4
5
null
null
null
false
false
true
"aaa"
"bbb"
"ccc"
"ddd"
128 changes: 127 additions & 1 deletion expected/jsquery.out
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,36 @@ select count(*) from test_jsquery where v @@ 't is object';
2
(1 row)

select count(*) from test_jsquery where v @@ '$ is boolean';
count
-------
3
(1 row)

select count(*) from test_jsquery where v @@ '$ is string';
count
-------
4
(1 row)

select count(*) from test_jsquery where v @@ '$ is numeric';
count
-------
5
(1 row)

select count(*) from test_jsquery where v @@ '$ is array';
count
-------
2
(1 row)

select count(*) from test_jsquery where v @@ '$ is object';
count
-------
1017
(1 row)

select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
count
-------
Expand All @@ -2252,7 +2282,19 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
count
-------
23
40
(1 row)

select count(*) from test_jsquery where v @@ '$ > 2';
count
-------
3
(1 row)

select count(*) from test_jsquery where v @@ '$ = false';
count
-------
2
(1 row)

select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
Expand Down Expand Up @@ -2443,6 +2485,36 @@ select count(*) from test_jsquery where v @@ 't is object';
2
(1 row)

select count(*) from test_jsquery where v @@ '$ is boolean';
count
-------
3
(1 row)

select count(*) from test_jsquery where v @@ '$ is string';
count
-------
4
(1 row)

select count(*) from test_jsquery where v @@ '$ is numeric';
count
-------
5
(1 row)

select count(*) from test_jsquery where v @@ '$ is array';
count
-------
2
(1 row)

select count(*) from test_jsquery where v @@ '$ is object';
count
-------
1017
(1 row)

select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
count
-------
Expand All @@ -2461,6 +2533,18 @@ select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $
7
(1 row)

select count(*) from test_jsquery where v @@ '$ > 2';
count
-------
3
(1 row)

select count(*) from test_jsquery where v @@ '$ = false';
count
-------
2
(1 row)

explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
QUERY PLAN
---------------------------------------------------------------
Expand Down Expand Up @@ -2694,6 +2778,36 @@ select count(*) from test_jsquery where v @@ 't is object';
2
(1 row)

select count(*) from test_jsquery where v @@ '$ is boolean';
count
-------
3
(1 row)

select count(*) from test_jsquery where v @@ '$ is string';
count
-------
4
(1 row)

select count(*) from test_jsquery where v @@ '$ is numeric';
count
-------
5
(1 row)

select count(*) from test_jsquery where v @@ '$ is array';
count
-------
2
(1 row)

select count(*) from test_jsquery where v @@ '$ is object';
count
-------
1017
(1 row)

select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
count
-------
Expand All @@ -2712,6 +2826,18 @@ select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $
7
(1 row)

select count(*) from test_jsquery where v @@ '$ > 2';
count
-------
3
(1 row)

select count(*) from test_jsquery where v @@ '$ = false';
count
-------
2
(1 row)

explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
QUERY PLAN
---------------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion jsonb_gin_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom
switch (r)
{
case WJB_BEGIN_ARRAY:
entries[i++] = PointerGetDatum(make_gin_key(&v, get_path_bloom(stack)));
if (!v.val.array.rawScalar)
entries[i++] = PointerGetDatum(make_gin_key(&v, get_path_bloom(stack)));
break;
case WJB_BEGIN_OBJECT:
entries[i++] = PointerGetDatum(make_gin_key(&v, get_path_bloom(stack)));
Expand Down Expand Up @@ -1111,6 +1112,8 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries)
switch (r)
{
case WJB_BEGIN_ARRAY:
if (v.val.array.rawScalar)
break;
entries[i++] = PointerGetDatum(make_gin_key(&v, stack->hash));
tmp = stack;
stack = (PathHashStack *) palloc(sizeof(PathHashStack));
Expand All @@ -1137,6 +1140,9 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries)
entries[i++] = PointerGetDatum(make_gin_key(&v, stack->hash));
break;
case WJB_END_ARRAY:
if (!stack->parent)
break; /* raw scalar array */
/* fall through */
case WJB_END_OBJECT:
/* Pop the stack */
tmp = stack->parent;
Expand Down
21 changes: 21 additions & 0 deletions sql/jsquery.sql
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,16 @@ select count(*) from test_jsquery where v @@ 't is string';
select count(*) from test_jsquery where v @@ 't is numeric';
select count(*) from test_jsquery where v @@ 't is array';
select count(*) from test_jsquery where v @@ 't is object';
select count(*) from test_jsquery where v @@ '$ is boolean';
select count(*) from test_jsquery where v @@ '$ is string';
select count(*) from test_jsquery where v @@ '$ is numeric';
select count(*) from test_jsquery where v @@ '$ is array';
select count(*) from test_jsquery where v @@ '$ is object';
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
select count(*) from test_jsquery where v @@ '$ > 2';
select count(*) from test_jsquery where v @@ '$ = false';

select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
select v from test_jsquery where v @@ 'array && [2,3]' order by v;
Expand Down Expand Up @@ -462,9 +469,16 @@ select count(*) from test_jsquery where v @@ 't is string';
select count(*) from test_jsquery where v @@ 't is numeric';
select count(*) from test_jsquery where v @@ 't is array';
select count(*) from test_jsquery where v @@ 't is object';
select count(*) from test_jsquery where v @@ '$ is boolean';
select count(*) from test_jsquery where v @@ '$ is string';
select count(*) from test_jsquery where v @@ '$ is numeric';
select count(*) from test_jsquery where v @@ '$ is array';
select count(*) from test_jsquery where v @@ '$ is object';
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
select count(*) from test_jsquery where v @@ '$ > 2';
select count(*) from test_jsquery where v @@ '$ = false';

explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v;
Expand Down Expand Up @@ -508,9 +522,16 @@ select count(*) from test_jsquery where v @@ 't is string';
select count(*) from test_jsquery where v @@ 't is numeric';
select count(*) from test_jsquery where v @@ 't is array';
select count(*) from test_jsquery where v @@ 't is object';
select count(*) from test_jsquery where v @@ '$ is boolean';
select count(*) from test_jsquery where v @@ '$ is string';
select count(*) from test_jsquery where v @@ '$ is numeric';
select count(*) from test_jsquery where v @@ '$ is array';
select count(*) from test_jsquery where v @@ '$ is object';
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
select count(*) from test_jsquery where v @@ '$ > 2';
select count(*) from test_jsquery where v @@ '$ = false';

explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
explain (costs off) select v from test_jsquery where v @@ 'array && [2,3]' order by v;
Expand Down

0 comments on commit b70cf0f

Please sign in to comment.