Skip to content

Commit

Permalink
Fix bug in assignment of next jsquery item offset.
Browse files Browse the repository at this point in the history
Output buffer could be reallocated after next item is filled.  So, we need
to make sure that we calculate pointer inside the buffer after item is filled.
  • Loading branch information
Alexander Korotkov committed Oct 26, 2017
1 parent 2ead3ad commit f560d99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions expected/jsquery.out
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,12 @@ select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is
t
(1 row)

SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64)'::jsquery;
jsquery
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
"test".# IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64)
(1 row)

select '[]' @@ '(@# > 0 and #: = 16)'::jsquery;
?column?
----------
Expand Down
5 changes: 4 additions & 1 deletion jsquery_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ flattenJsQueryParseItem(StringInfo buf, JsQueryParseItem *item, bool onlyCurrent
}

if (item->next)
*(int32*)(buf->data + next) = flattenJsQueryParseItem(buf, item->next, onlyCurrentInPath);
{
chld = flattenJsQueryParseItem(buf, item->next, onlyCurrentInPath);
*(int32*)(buf->data + next) = chld;
}

return pos;
}
Expand Down
1 change: 1 addition & 0 deletions sql/jsquery.sql
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '%:.aa is numeric'::jsquery;
select '{"a":{"aa":1}, "b":{"aa":true, "bb":2}}' @@ '%:.aa is numeric'::jsquery;
select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}, "aa":16}' @@ '*: (not $ is object or $.aa is numeric)'::jsquery;
select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is numeric or % is object)'::jsquery;
SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64)'::jsquery;

select '[]' @@ '(@# > 0 and #: = 16)'::jsquery;
select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery;
Expand Down

0 comments on commit f560d99

Please sign in to comment.