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

Commit8362a5e

Browse files
author
Alexander Korotkov
committed
Handle filters in indexes
From index perspective, filter is basically the same as AND operator.
1 parent5bf859c commit8362a5e

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

‎jsquery_extract.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,25 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
5656
{
5757
casejqiAnd:
5858
casejqiOr:
59-
type= ((jsq->type==jqiAnd)==not) ?eOr :eAnd;
59+
casejqiFilter:
60+
type= ((jsq->type==jqiAnd||jsq->type==jqiFilter)==not) ?eOr :eAnd;
6061

61-
jsqGetLeftArg(jsq,&elem);
62-
leftNode=recursiveExtract(&elem,not, false,path);
63-
jsqGetRightArg(jsq,&elem);
64-
rightNode=recursiveExtract(&elem,not, false,path);
62+
if (jsq->type==jqiFilter)
63+
{
64+
jsqGetArg(jsq,&elem);
65+
leftNode=recursiveExtract(&elem,not, false,path);
66+
if (jsqGetNext(jsq,&elem))
67+
rightNode=recursiveExtract(&elem,not, false,path);
68+
else
69+
rightNode=makeAnyNode(not, false,path);
70+
}
71+
else
72+
{
73+
jsqGetLeftArg(jsq,&elem);
74+
leftNode=recursiveExtract(&elem,not, false,path);
75+
jsqGetRightArg(jsq,&elem);
76+
rightNode=recursiveExtract(&elem,not, false,path);
77+
}
6578

6679
if (!leftNode|| !rightNode)
6780
{
@@ -137,8 +150,6 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
137150
if (!jsqGetNext(jsq,&elem))
138151
returnmakeAnyNode(not,indirect,pathItem);
139152
returnrecursiveExtract(&elem,not, true,pathItem);
140-
casejqiFilter:
141-
/* ignore filter for now */
142153
casejqiCurrent:
143154
if (!jsqGetNext(jsq,&elem))
144155
returnmakeAnyNode(not,indirect,path);

‎sql/jsquery.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ SELECT gin_debug_query_path_value('#:(x=1) AND %:(y=1) AND *:(z=1)');
418418
SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)');
419419
SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
420420
SELECT gin_debug_query_path_value('$ = true');
421+
SELECT gin_debug_query_path_value('$ . ? (review_votes > 10) . review_rating < 7');
422+
SELECT gin_debug_query_path_value('similar_product_ids . ? (# = "B0002W4TL2") . $');
421423

422424
SELECT gin_debug_query_value_path('NOT NOT NOT x(y(NOT (a=1) and NOT (b=2)) OR NOT NOT (c=3)) and z = 5');
423425
SELECT gin_debug_query_value_path('NOT #(x=1) and NOT *(y=1) and NOT %(z=1)');
@@ -445,7 +447,9 @@ SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *
445447
SELECT gin_debug_query_value_path('(@# > 0 and #: = 16)');
446448
SELECT gin_debug_query_value_path('*.@# ($ = 4 or $ = 2)');
447449
SELECT gin_debug_query_value_path('tags.#.term. ? ( # = "NYC").x > 0');
448-
SELECT gin_debug_query_path_value('$ = true');
450+
SELECT gin_debug_query_value_path('$ = true');
451+
SELECT gin_debug_query_value_path('$ . ? (review_votes > 10) . review_rating < 7');
452+
SELECT gin_debug_query_value_path('similar_product_ids . ? (# = "B0002W4TL2") . $');
449453

450454
---table and index
451455

@@ -497,6 +501,8 @@ select count(*) from test_jsquery where v @@ '$ = false';
497501
selectcount(*)from test_jsquerywhere v @@'t';
498502
selectcount(*)from test_jsquerywhere v @@'$';
499503
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#';
504+
selectcount(*)from test_jsquerywhere v @@'$ . ? (review_votes > 10) . review_rating < 7';
505+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids . ? (# = "B0002W4TL2") . $';
500506

501507
select vfrom test_jsquerywhere v @@'array <@ [2,3]'order by v;
502508
select vfrom test_jsquerywhere v @@'array && [2,3]'order by v;
@@ -546,6 +552,8 @@ select count(*) from test_jsquery where v @@ '$ = false';
546552
selectcount(*)from test_jsquerywhere v @@'t';
547553
selectcount(*)from test_jsquerywhere v @@'$';
548554
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#';
555+
selectcount(*)from test_jsquerywhere v @@'$ . ? (review_votes > 10) . review_rating < 7';
556+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids . ? (# = "B0002W4TL2") . $';
549557

550558
explain (costs off)select vfrom test_jsquerywhere v @@'array <@ [2,3]'order by v;
551559
explain (costs off)select vfrom test_jsquerywhere v @@'array && [2,3]'order by v;
@@ -602,6 +610,8 @@ select count(*) from test_jsquery where v @@ '$ = false';
602610
selectcount(*)from test_jsquerywhere v @@'t';
603611
selectcount(*)from test_jsquerywhere v @@'$';
604612
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#';
613+
selectcount(*)from test_jsquerywhere v @@'$ . ? (review_votes > 10) . review_rating < 7';
614+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids . ? (# = "B0002W4TL2") . $';
605615

606616
explain (costs off)select vfrom test_jsquerywhere v @@'array <@ [2,3]'order by v;
607617
explain (costs off)select vfrom test_jsquerywhere v @@'array && [2,3]'order by v;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp