Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite6ab2bc

Browse files
committed
Rework processing query for index.
1 parentea4dcb8 commite6ab2bc

File tree

6 files changed

+618
-154
lines changed

6 files changed

+618
-154
lines changed

‎expected/jsquery.out

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,225 @@ select 'a = /* noindex */ 5'::jsquery;
10781078
"a" = 5
10791079
(1 row)
10801080

1081+
--extract entries for index scan
1082+
SELECT gin_debug_query_path_value('!!!x(y(!(a=1) & !(b=2)) | !!(c=3)) & z = 5');
1083+
gin_debug_query_path_value
1084+
----------------------------
1085+
AND +
1086+
z = 5 , entry 0 +
1087+
OR +
1088+
x.y.a = 1 , entry 1 +
1089+
x.y.b = 2 , entry 2 +
1090+
1091+
(1 row)
1092+
1093+
SELECT gin_debug_query_path_value('!#(x=1) & !*(y=1) & !%(z=1) ');
1094+
gin_debug_query_path_value
1095+
----------------------------
1096+
NULL +
1097+
1098+
(1 row)
1099+
1100+
SELECT gin_debug_query_path_value('#(!x=1) & *(!y=1) & %(!z=1) ');
1101+
gin_debug_query_path_value
1102+
----------------------------
1103+
NULL +
1104+
1105+
(1 row)
1106+
1107+
SELECT gin_debug_query_path_value('!#(!x=1) & !*(!y=1) & !%(!z=1) ');
1108+
gin_debug_query_path_value
1109+
----------------------------
1110+
NULL +
1111+
1112+
(1 row)
1113+
1114+
SELECT gin_debug_query_path_value('#(x = "a" & y > 0 & y < 1 & z > 0)');
1115+
gin_debug_query_path_value
1116+
----------------------------
1117+
#.x = "a" , entry 0 +
1118+
1119+
(1 row)
1120+
1121+
SELECT gin_debug_query_path_value('#(x = "a" & y /*-- index */ >= 0 & y < 1 & z > 0)');
1122+
gin_debug_query_path_value
1123+
-----------------------------
1124+
AND +
1125+
#.x = "a" , entry 0 +
1126+
#.y >= 0 , < 1 , entry 1 +
1127+
1128+
(1 row)
1129+
1130+
SELECT gin_debug_query_path_value('#(x /*-- noindex */ = "a" & y > 0 & y <= 1 & z /*-- index */ > 0)');
1131+
gin_debug_query_path_value
1132+
-----------------------------
1133+
AND +
1134+
#.y > 0 , <= 1 , entry 0 +
1135+
#.z > 0 , entry 1 +
1136+
1137+
(1 row)
1138+
1139+
SELECT gin_debug_query_path_value('x = 1 & (y /*-- index */ > 0 & y < 1 | z > 0)');
1140+
gin_debug_query_path_value
1141+
----------------------------
1142+
AND +
1143+
x = 1 , entry 0 +
1144+
OR +
1145+
y > 0 , < 1 , entry 1 +
1146+
z > 0 , entry 2 +
1147+
1148+
(1 row)
1149+
1150+
SELECT gin_debug_query_path_value('%.x = 1');
1151+
gin_debug_query_path_value
1152+
----------------------------
1153+
NULL +
1154+
1155+
(1 row)
1156+
1157+
SELECT gin_debug_query_path_value('*.x = "b"');
1158+
gin_debug_query_path_value
1159+
----------------------------
1160+
NULL +
1161+
1162+
(1 row)
1163+
1164+
SELECT gin_debug_query_path_value('x && [1,2,3]');
1165+
gin_debug_query_path_value
1166+
----------------------------
1167+
OR +
1168+
x.# = 1 , entry 0 +
1169+
x.# = 2 , entry 1 +
1170+
x.# = 3 , entry 2 +
1171+
1172+
(1 row)
1173+
1174+
SELECT gin_debug_query_path_value('x @> [1,2,3]');
1175+
gin_debug_query_path_value
1176+
----------------------------
1177+
AND +
1178+
x.# = 1 , entry 0 +
1179+
x.# = 2 , entry 1 +
1180+
x.# = 3 , entry 2 +
1181+
1182+
(1 row)
1183+
1184+
SELECT gin_debug_query_path_value('x <@ [1,2,3]');
1185+
gin_debug_query_path_value
1186+
----------------------------
1187+
NULL +
1188+
1189+
(1 row)
1190+
1191+
SELECT gin_debug_query_value_path('!!!x(y(!(a=1) & !(b=2)) | !!(c=3)) & z = 5');
1192+
gin_debug_query_value_path
1193+
----------------------------
1194+
AND +
1195+
z = 5 , entry 0 +
1196+
OR +
1197+
x.y.a = 1 , entry 1 +
1198+
x.y.b = 2 , entry 2 +
1199+
1200+
(1 row)
1201+
1202+
SELECT gin_debug_query_value_path('!#(x=1) & !*(y=1) & !%(z=1) ');
1203+
gin_debug_query_value_path
1204+
----------------------------
1205+
NULL +
1206+
1207+
(1 row)
1208+
1209+
SELECT gin_debug_query_value_path('#(!x=1) & *(!y=1) & %(!z=1) ');
1210+
gin_debug_query_value_path
1211+
----------------------------
1212+
NULL +
1213+
1214+
(1 row)
1215+
1216+
SELECT gin_debug_query_value_path('!#(!x=1) & !*(!y=1) & !%(!z=1) ');
1217+
gin_debug_query_value_path
1218+
----------------------------
1219+
NULL +
1220+
1221+
(1 row)
1222+
1223+
SELECT gin_debug_query_value_path('#(x = "a" & y > 0 & y < 1 & z > 0)');
1224+
gin_debug_query_value_path
1225+
----------------------------
1226+
#.x = "a" , entry 0 +
1227+
1228+
(1 row)
1229+
1230+
SELECT gin_debug_query_value_path('#(x = "a" & y /*-- index */ >= 0 & y < 1 & z > 0)');
1231+
gin_debug_query_value_path
1232+
-----------------------------
1233+
AND +
1234+
#.x = "a" , entry 0 +
1235+
#.y >= 0 , < 1 , entry 1 +
1236+
1237+
(1 row)
1238+
1239+
SELECT gin_debug_query_value_path('#(x /*-- noindex */ = "a" & y > 0 & y <= 1 & z /*-- index */ > 0)');
1240+
gin_debug_query_value_path
1241+
-----------------------------
1242+
AND +
1243+
#.y > 0 , <= 1 , entry 0 +
1244+
#.z > 0 , entry 1 +
1245+
1246+
(1 row)
1247+
1248+
SELECT gin_debug_query_value_path('x = 1 & (y /*-- index */ > 0 & y < 1 | z > 0)');
1249+
gin_debug_query_value_path
1250+
----------------------------
1251+
AND +
1252+
x = 1 , entry 0 +
1253+
OR +
1254+
y > 0 , < 1 , entry 1 +
1255+
z > 0 , entry 2 +
1256+
1257+
(1 row)
1258+
1259+
SELECT gin_debug_query_value_path('%.x = 1');
1260+
gin_debug_query_value_path
1261+
----------------------------
1262+
%.x = 1 , entry 0 +
1263+
1264+
(1 row)
1265+
1266+
SELECT gin_debug_query_value_path('*.x = "b"');
1267+
gin_debug_query_value_path
1268+
----------------------------
1269+
*.x = "b" , entry 0 +
1270+
1271+
(1 row)
1272+
1273+
SELECT gin_debug_query_value_path('x && [1,2,3]');
1274+
gin_debug_query_value_path
1275+
----------------------------
1276+
OR +
1277+
x.# = 1 , entry 0 +
1278+
x.# = 2 , entry 1 +
1279+
x.# = 3 , entry 2 +
1280+
1281+
(1 row)
1282+
1283+
SELECT gin_debug_query_value_path('x @> [1,2,3]');
1284+
gin_debug_query_value_path
1285+
----------------------------
1286+
AND +
1287+
x.# = 1 , entry 0 +
1288+
x.# = 2 , entry 1 +
1289+
x.# = 3 , entry 2 +
1290+
1291+
(1 row)
1292+
1293+
SELECT gin_debug_query_value_path('x <@ [1,2,3]');
1294+
gin_debug_query_value_path
1295+
----------------------------
1296+
NULL +
1297+
1298+
(1 row)
1299+
10811300
---table and index
10821301
select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0;
10831302
count

‎jsonb_gin_ops.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,31 @@ PG_FUNCTION_INFO_V1(gin_extract_jsonb_value_path);
8484
PG_FUNCTION_INFO_V1(gin_extract_jsonb_query_value_path);
8585
PG_FUNCTION_INFO_V1(gin_consistent_jsonb_value_path);
8686
PG_FUNCTION_INFO_V1(gin_triconsistent_jsonb_value_path);
87+
PG_FUNCTION_INFO_V1(gin_debug_query_value_path);
8788

8889
Datumgin_compare_jsonb_value_path(PG_FUNCTION_ARGS);
8990
Datumgin_compare_partial_jsonb_value_path(PG_FUNCTION_ARGS);
9091
Datumgin_extract_jsonb_value_path(PG_FUNCTION_ARGS);
9192
Datumgin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS);
9293
Datumgin_consistent_jsonb_value_path(PG_FUNCTION_ARGS);
9394
Datumgin_triconsistent_jsonb_value_path(PG_FUNCTION_ARGS);
95+
Datumgin_debug_query_value_path(PG_FUNCTION_ARGS);
9496

9597
PG_FUNCTION_INFO_V1(gin_compare_jsonb_path_value);
9698
PG_FUNCTION_INFO_V1(gin_compare_partial_jsonb_path_value);
9799
PG_FUNCTION_INFO_V1(gin_extract_jsonb_path_value);
98100
PG_FUNCTION_INFO_V1(gin_extract_jsonb_query_path_value);
99101
PG_FUNCTION_INFO_V1(gin_consistent_jsonb_path_value);
100102
PG_FUNCTION_INFO_V1(gin_triconsistent_jsonb_path_value);
103+
PG_FUNCTION_INFO_V1(gin_debug_query_path_value);
101104

102105
Datumgin_compare_jsonb_path_value(PG_FUNCTION_ARGS);
103106
Datumgin_compare_partial_jsonb_path_value(PG_FUNCTION_ARGS);
104107
Datumgin_extract_jsonb_path_value(PG_FUNCTION_ARGS);
105108
Datumgin_extract_jsonb_query_path_value(PG_FUNCTION_ARGS);
106109
Datumgin_consistent_jsonb_path_value(PG_FUNCTION_ARGS);
107110
Datumgin_triconsistent_jsonb_path_value(PG_FUNCTION_ARGS);
111+
Datumgin_debug_query_path_value(PG_FUNCTION_ARGS);
108112

109113
staticint
110114
add_entry(Entries*e,Datumkey,Pointerextra,boolpmatch)
@@ -348,6 +352,12 @@ make_gin_query_key_minus_inf(uint32 hash)
348352
returnkey;
349353
}
350354

355+
staticbool
356+
check_bloom_entry_handler(ExtractedNode*node,Pointerextra)
357+
{
358+
return true;
359+
}
360+
351361
staticint
352362
make_bloom_entry_handler(ExtractedNode*node,Pointerextra)
353363
{
@@ -630,6 +640,19 @@ gin_extract_jsonb_value_path(PG_FUNCTION_ARGS)
630640
PG_RETURN_POINTER(gin_extract_jsonb_bloom_value_internal(jb,nentries,NULL));
631641
}
632642

643+
Datum
644+
gin_debug_query_value_path(PG_FUNCTION_ARGS)
645+
{
646+
JsQuery*jq;
647+
Entriese= {0};
648+
char*s;
649+
650+
jq=PG_GETARG_JSQUERY(0);
651+
s=debugJsQuery(jq,make_bloom_entry_handler,
652+
check_bloom_entry_handler, (Pointer)&e);
653+
PG_RETURN_TEXT_P(cstring_to_text(s));
654+
}
655+
633656
Datum
634657
gin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS)
635658
{
@@ -669,7 +692,8 @@ gin_extract_jsonb_query_value_path(PG_FUNCTION_ARGS)
669692

670693
caseJsQueryMatchStrategyNumber:
671694
jq=PG_GETARG_JSQUERY(0);
672-
root=extractJsQuery(jq,make_bloom_entry_handler, (Pointer)&e);
695+
root=extractJsQuery(jq,make_bloom_entry_handler,
696+
check_bloom_entry_handler, (Pointer)&e);
673697
if (root)
674698
{
675699
*nentries=e.count;
@@ -840,6 +864,16 @@ get_query_path_hash(PathItem *pathItem, uint32 *hash)
840864
}
841865
}
842866

867+
staticbool
868+
check_hash_entry_handler(ExtractedNode*node,Pointerextra)
869+
{
870+
uint32hash;
871+
hash=0;
872+
if (!get_query_path_hash(node->path,&hash))
873+
return false;
874+
return true;
875+
}
876+
843877
staticint
844878
make_hash_entry_handler(ExtractedNode*node,Pointerextra)
845879
{
@@ -1067,6 +1101,19 @@ gin_extract_jsonb_path_value(PG_FUNCTION_ARGS)
10671101
PG_RETURN_POINTER(gin_extract_jsonb_hash_value_internal(jb,nentries));
10681102
}
10691103

1104+
Datum
1105+
gin_debug_query_path_value(PG_FUNCTION_ARGS)
1106+
{
1107+
JsQuery*jq;
1108+
Entriese= {0};
1109+
char*s;
1110+
1111+
jq=PG_GETARG_JSQUERY(0);
1112+
s=debugJsQuery(jq,make_hash_entry_handler,
1113+
check_hash_entry_handler, (Pointer)&e);
1114+
PG_RETURN_TEXT_P(cstring_to_text(s));
1115+
}
1116+
10701117
Datum
10711118
gin_extract_jsonb_query_path_value(PG_FUNCTION_ARGS)
10721119
{
@@ -1091,7 +1138,8 @@ gin_extract_jsonb_query_path_value(PG_FUNCTION_ARGS)
10911138

10921139
caseJsQueryMatchStrategyNumber:
10931140
jq=PG_GETARG_JSQUERY(0);
1094-
root=extractJsQuery(jq,make_hash_entry_handler, (Pointer)&e);
1141+
root=extractJsQuery(jq,make_hash_entry_handler,
1142+
check_hash_entry_handler, (Pointer)&e);
10951143
if (root)
10961144
{
10971145
*nentries=e.count;

‎jsquery--1.0.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,13 @@ CREATE OPERATOR CLASS jsonb_path_value_ops
281281
FUNCTION5 gin_compare_partial_jsonb_path_value(bytea,bytea,smallint, internal),
282282
FUNCTION6 gin_triconsistent_jsonb_path_value(internal,smallint, anyarray,integer, internal, internal, internal),
283283
STORAGEbytea;
284+
285+
CREATE OR REPLACEFUNCTIONgin_debug_query_value_path(jsquery)
286+
RETURNStext
287+
AS'MODULE_PATHNAME'
288+
LANGUAGE C STRICT IMMUTABLE;
289+
290+
CREATE OR REPLACEFUNCTIONgin_debug_query_path_value(jsquery)
291+
RETURNStext
292+
AS'MODULE_PATHNAME'
293+
LANGUAGE C STRICT IMMUTABLE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp