Skip to content

Commit 1ef3ad2

Browse files
author
Alexander Korotkov
committedFeb 20, 2017
Fix jqiIndexArray handling in GIN.
1 parent bd4989b commit 1ef3ad2

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed
 

‎jsonb_gin_ops.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ get_query_path_hash(PathItem *pathItem, uint32 *hash)
947947
*hash = (*hash << 1) | (*hash >> 31);
948948
*hash ^= hash_any((unsigned char *)pathItem->s, pathItem->len);
949949
}
950-
else if (pathItem->type == iAnyArray)
950+
else if (pathItem->type == iAnyArray || pathItem->type == iIndexArray)
951951
{
952952
*hash = (*hash << 1) | (*hash >> 31);
953953
*hash ^= JB_FARRAY;

‎jsquery.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,16 @@ typedef enum
170170
iAny = jqiAny,
171171
iAnyArray = jqiAnyArray,
172172
iKey = jqiKey,
173-
iAnyKey = jqiAnyKey
173+
iAnyKey = jqiAnyKey,
174+
iIndexArray = jqiIndexArray
174175
} PathItemType;
175176

176177
typedef struct PathItem PathItem;
177178
struct PathItem
178179
{
179180
PathItemType type;
180181
int len;
182+
int arrayIndex;
181183
char *s;
182184
PathItem *parent;
183185
};

‎jsquery_extract.c

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
106106
jsqGetNext(jsq, &elem);
107107
return recursiveExtract(&elem, not, true, pathItem);
108108
case jqiIndexArray:
109+
pathItem = (PathItem *)palloc(sizeof(PathItem));
110+
pathItem->type = iIndexArray;
111+
pathItem->arrayIndex = jsq->arrayIndex;
112+
pathItem->parent = path;
113+
jsqGetNext(jsq, &elem);
114+
return recursiveExtract(&elem, not, true, pathItem);
109115
case jqiAnyArray:
110116
case jqiAllArray:
111117
if ((not && jsq->type == jqiAnyArray) || (!not && jsq->type == jqiAllArray))
@@ -864,6 +870,9 @@ debugPath(StringInfo buf, PathItem *path)
864870
case jqiAnyArray:
865871
appendStringInfoChar(buf, '#');
866872
break;
873+
case jqiIndexArray:
874+
appendStringInfo(buf, "#%d", path->arrayIndex);
875+
break;
867876
case jqiKey:
868877
appendBinaryStringInfo(buf, path->s, path->len);
869878
break;

0 commit comments

Comments
 (0)