Skip to content

Commit 27e5214

Browse files
author
Nikita Glukhov
committed
Fix indexing of empty arrays and objects
1 parent 3e820d9 commit 27e5214

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

data/test_jsquery.data

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,8 @@
10151015
{"t": "a"}
10161016
{"t": true}
10171017
{"t": false}
1018+
{}
1019+
[]
10181020
[1, 2, 3]
10191021
["a", "b", "c"]
10201022
1

expected/jsquery.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,13 +2631,13 @@ select count(*) from test_jsquery where v @@ '$ is numeric';
26312631
select count(*) from test_jsquery where v @@ '$ is array';
26322632
count
26332633
-------
2634-
2
2634+
3
26352635
(1 row)
26362636

26372637
select count(*) from test_jsquery where v @@ '$ is object';
26382638
count
26392639
-------
2640-
1017
2640+
1018
26412641
(1 row)
26422642

26432643
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
@@ -2655,7 +2655,7 @@ select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
26552655
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
26562656
count
26572657
-------
2658-
40
2658+
42
26592659
(1 row)
26602660

26612661
select count(*) from test_jsquery where v @@ '$ > 2';
@@ -2679,7 +2679,7 @@ select count(*) from test_jsquery where v @@ 't';
26792679
select count(*) from test_jsquery where v @@ '$';
26802680
count
26812681
-------
2682-
1034
2682+
1036
26832683
(1 row)
26842684

26852685
select count(*) from test_jsquery where v @@ 'similar_product_ids.#';
@@ -2909,13 +2909,13 @@ select count(*) from test_jsquery where v @@ '$ is numeric';
29092909
select count(*) from test_jsquery where v @@ '$ is array';
29102910
count
29112911
-------
2912-
2
2912+
3
29132913
(1 row)
29142914

29152915
select count(*) from test_jsquery where v @@ '$ is object';
29162916
count
29172917
-------
2918-
1017
2918+
1018
29192919
(1 row)
29202920

29212921
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
@@ -2957,7 +2957,7 @@ select count(*) from test_jsquery where v @@ 't';
29572957
select count(*) from test_jsquery where v @@ '$';
29582958
count
29592959
-------
2960-
1034
2960+
1036
29612961
(1 row)
29622962

29632963
select count(*) from test_jsquery where v @@ 'similar_product_ids.#';
@@ -3232,13 +3232,13 @@ select count(*) from test_jsquery where v @@ '$ is numeric';
32323232
select count(*) from test_jsquery where v @@ '$ is array';
32333233
count
32343234
-------
3235-
2
3235+
3
32363236
(1 row)
32373237

32383238
select count(*) from test_jsquery where v @@ '$ is object';
32393239
count
32403240
-------
3241-
1017
3241+
1018
32423242
(1 row)
32433243

32443244
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
@@ -3280,7 +3280,7 @@ select count(*) from test_jsquery where v @@ 't';
32803280
select count(*) from test_jsquery where v @@ '$';
32813281
count
32823282
-------
3283-
1034
3283+
1036
32843284
(1 row)
32853285

32863286
select count(*) from test_jsquery where v @@ 'similar_product_ids.#';

jsonb_gin_ops.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,7 @@ gin_extract_jsonb_value_path_internal(Jsonb *jb, int32 *nentries, uint32 **bloom
656656
uint32 hash;
657657

658658
if (total == 0)
659-
{
660-
*nentries = 0;
661-
return NULL;
662-
}
659+
total = 2; /* single entry for empty object/array */
663660

664661
entries = (Datum *) palloc(sizeof(Datum) * total);
665662
if (bloom)
@@ -1093,10 +1090,7 @@ gin_extract_jsonb_path_value_internal(Jsonb *jb, int32 *nentries)
10931090
Datum *entries = NULL;
10941091

10951092
if (total == 0)
1096-
{
1097-
*nentries = 0;
1098-
return NULL;
1099-
}
1093+
total = 2; /* single entry for empty object/array */
11001094

11011095
entries = (Datum *) palloc(sizeof(Datum) * total);
11021096

0 commit comments

Comments
 (0)