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

Commita88c1db

Browse files
committed
Index handling of "all" quantifies.
1 parent75380d7 commita88c1db

File tree

3 files changed

+123
-3
lines changed

3 files changed

+123
-3
lines changed

‎expected/jsquery.out

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,27 @@ SELECT gin_debug_query_path_value('x is object');
15811581

15821582
(1 row)
15831583

1584+
SELECT gin_debug_query_path_value('#:(x=1) AND %:(y=1) AND *:(z=1)');
1585+
gin_debug_query_path_value
1586+
----------------------------
1587+
NULL +
1588+
1589+
(1 row)
1590+
1591+
SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)');
1592+
gin_debug_query_path_value
1593+
----------------------------
1594+
NULL +
1595+
1596+
(1 row)
1597+
1598+
SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
1599+
gin_debug_query_path_value
1600+
----------------------------
1601+
#.x = 1 , entry 0 +
1602+
1603+
(1 row)
1604+
15841605
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');
15851606
gin_debug_query_value_path
15861607
----------------------------
@@ -1746,6 +1767,30 @@ SELECT gin_debug_query_value_path('x is object');
17461767

17471768
(1 row)
17481769

1770+
SELECT gin_debug_query_value_path('#:(x=1) AND %:(y=1) AND *:(z=1)');
1771+
gin_debug_query_value_path
1772+
----------------------------
1773+
NULL +
1774+
1775+
(1 row)
1776+
1777+
SELECT gin_debug_query_value_path('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)');
1778+
gin_debug_query_value_path
1779+
----------------------------
1780+
NULL +
1781+
1782+
(1 row)
1783+
1784+
SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
1785+
gin_debug_query_value_path
1786+
----------------------------
1787+
AND +
1788+
#.x = 1 , entry 0 +
1789+
%.y = 1 , entry 1 +
1790+
*.z = 1 , entry 2 +
1791+
1792+
(1 row)
1793+
17491794
---table and index
17501795
select count(*) from test_jsquery where (v->>'review_helpful_votes')::int4 > 0;
17511796
count
@@ -1935,6 +1980,24 @@ select count(*) from test_jsquery where v @@ 't is object';
19351980
2
19361981
(1 row)
19371982

1983+
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
1984+
count
1985+
-------
1986+
51
1987+
(1 row)
1988+
1989+
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
1990+
count
1991+
-------
1992+
1001
1993+
(1 row)
1994+
1995+
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
1996+
count
1997+
-------
1998+
23
1999+
(1 row)
2000+
19382001
select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
19392002
v
19402003
-------------------
@@ -2123,6 +2186,24 @@ select count(*) from test_jsquery where v @@ 't is object';
21232186
2
21242187
(1 row)
21252188

2189+
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
2190+
count
2191+
-------
2192+
51
2193+
(1 row)
2194+
2195+
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
2196+
count
2197+
-------
2198+
1001
2199+
(1 row)
2200+
2201+
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
2202+
count
2203+
-------
2204+
7
2205+
(1 row)
2206+
21262207
explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
21272208
QUERY PLAN
21282209
---------------------------------------------------------------
@@ -2356,6 +2437,24 @@ select count(*) from test_jsquery where v @@ 't is object';
23562437
2
23572438
(1 row)
23582439

2440+
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is numeric';
2441+
count
2442+
-------
2443+
51
2444+
(1 row)
2445+
2446+
select count(*) from test_jsquery where v @@ 'similar_product_ids.#: is string';
2447+
count
2448+
-------
2449+
1001
2450+
(1 row)
2451+
2452+
select count(*) from test_jsquery where v @@ 'NOT similar_product_ids.#: (NOT $ = "0440180295")';
2453+
count
2454+
-------
2455+
7
2456+
(1 row)
2457+
23592458
explain (costs off) select v from test_jsquery where v @@ 'array <@ [2,3]' order by v;
23602459
QUERY PLAN
23612460
---------------------------------------------------------------

‎jsquery_extract.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,27 @@ recursiveExtract(JsQueryItem *jsq, bool not, bool indirect, PathItem *path)
9696
jsqGetNext(jsq,&elem);
9797
returnrecursiveExtract(&elem,not,indirect,pathItem);
9898
casejqiAny:
99-
if (not)returnNULL;
99+
casejqiAll:
100+
if ((not&&jsq->type==jqiAny)|| (!not&&jsq->type==jqiAll))
101+
returnNULL;
100102
pathItem= (PathItem*)palloc(sizeof(PathItem));
101103
pathItem->type=iAny;
102104
pathItem->parent=path;
103105
jsqGetNext(jsq,&elem);
104106
returnrecursiveExtract(&elem,not, true,pathItem);
105107
casejqiAnyArray:
106-
if (not)returnNULL;
108+
casejqiAllArray:
109+
if ((not&&jsq->type==jqiAnyArray)|| (!not&&jsq->type==jqiAllArray))
110+
returnNULL;
107111
pathItem= (PathItem*)palloc(sizeof(PathItem));
108112
pathItem->type=iAnyArray;
109113
pathItem->parent=path;
110114
jsqGetNext(jsq,&elem);
111115
returnrecursiveExtract(&elem,not, true,pathItem);
112116
casejqiAnyKey:
113-
if (not)returnNULL;
117+
casejqiAllKey:
118+
if ((not&&jsq->type==jqiAnyKey)|| (!not&&jsq->type==jqiAllKey))
119+
returnNULL;
114120
pathItem= (PathItem*)palloc(sizeof(PathItem));
115121
pathItem->type=iAnyKey;
116122
pathItem->parent=path;

‎sql/jsquery.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ SELECT gin_debug_query_path_value('x is string');
308308
SELECT gin_debug_query_path_value('x is numeric');
309309
SELECT gin_debug_query_path_value('x is array');
310310
SELECT gin_debug_query_path_value('x is object');
311+
SELECT gin_debug_query_path_value('#:(x=1) AND %:(y=1) AND *:(z=1)');
312+
SELECT gin_debug_query_path_value('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)');
313+
SELECT gin_debug_query_path_value('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
311314

312315
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');
313316
SELECT gin_debug_query_value_path('NOT #(x=1) and NOT *(y=1) and NOT %(z=1)');
@@ -329,6 +332,9 @@ SELECT gin_debug_query_value_path('x is string');
329332
SELECT gin_debug_query_value_path('x is numeric');
330333
SELECT gin_debug_query_value_path('x is array');
331334
SELECT gin_debug_query_value_path('x is object');
335+
SELECT gin_debug_query_value_path('#:(x=1) AND %:(y=1) AND *:(z=1)');
336+
SELECT gin_debug_query_value_path('#:(NOT x=1) AND %:(NOT y=1) AND *:(NOT z=1)');
337+
SELECT gin_debug_query_value_path('NOT #:(NOT x=1) AND NOT %:(NOT y=1) AND NOT *:(NOT z=1)');
332338

333339
---table and index
334340

@@ -367,6 +373,9 @@ select count(*) from test_jsquery where v @@ 't is string';
367373
selectcount(*)from test_jsquerywhere v @@'t is numeric';
368374
selectcount(*)from test_jsquerywhere v @@'t is array';
369375
selectcount(*)from test_jsquerywhere v @@'t is object';
376+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#: is numeric';
377+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#: is string';
378+
selectcount(*)from test_jsquerywhere v @@'NOT similar_product_ids.#: (NOT $ = "0440180295")';
370379

371380
select vfrom test_jsquerywhere v @@'array <@ [2,3]'order by v;
372381
select vfrom test_jsquerywhere v @@'array && [2,3]'order by v;
@@ -403,6 +412,9 @@ select count(*) from test_jsquery where v @@ 't is string';
403412
selectcount(*)from test_jsquerywhere v @@'t is numeric';
404413
selectcount(*)from test_jsquerywhere v @@'t is array';
405414
selectcount(*)from test_jsquerywhere v @@'t is object';
415+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#: is numeric';
416+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#: is string';
417+
selectcount(*)from test_jsquerywhere v @@'NOT similar_product_ids.#: (NOT $ = "0440180295")';
406418

407419
explain (costs off)select vfrom test_jsquerywhere v @@'array <@ [2,3]'order by v;
408420
explain (costs off)select vfrom test_jsquerywhere v @@'array && [2,3]'order by v;
@@ -446,6 +458,9 @@ select count(*) from test_jsquery where v @@ 't is string';
446458
selectcount(*)from test_jsquerywhere v @@'t is numeric';
447459
selectcount(*)from test_jsquerywhere v @@'t is array';
448460
selectcount(*)from test_jsquerywhere v @@'t is object';
461+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#: is numeric';
462+
selectcount(*)from test_jsquerywhere v @@'similar_product_ids.#: is string';
463+
selectcount(*)from test_jsquerywhere v @@'NOT similar_product_ids.#: (NOT $ = "0440180295")';
449464

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp