Kouhei Sutou
null+****@clear*****
Wed Aug 23 08:47:48 JST 2017
Kouhei Sutou 2017-08-23 08:47:48 +0900 (Wed, 23 Aug 2017) New Revision: 2e6c0559465e35d85c05fc7b72ce5ef3f92af3a0 https://github.com/pgroonga/pgroonga/commit/2e6c0559465e35d85c05fc7b72ce5ef3f92af3a0 Message: Support "INTEGER_COLUMN = ANY(ARRAY[]::integer[])' GitHub: fix #53 General ANY support isn't implemented yet. Reported by tedypranolo. Thanks!!! Added files: expected/compare/integer/single/any/equal/empty/bitmapscan.out expected/compare/integer/single/any/equal/empty/indexscan.out expected/compare/integer/single/any/equal/multiple/bitmapscan.out expected/compare/integer/single/any/equal/multiple/indexscan.out sql/compare/integer/single/any/equal/empty/bitmapscan.sql sql/compare/integer/single/any/equal/empty/indexscan.sql sql/compare/integer/single/any/equal/multiple/bitmapscan.sql sql/compare/integer/single/any/equal/multiple/indexscan.sql Modified files: src/pgroonga.c Added: expected/compare/integer/single/any/equal/empty/bitmapscan.out (+34 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/integer/single/any/equal/empty/bitmapscan.out 2017-08-23 08:47:48 +0900 (1dc793c) @@ -0,0 +1,34 @@ +CREATE TABLE ids ( + id integer +); +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (3); +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + QUERY PLAN +-------------------------------------------------------- + Sort + Sort Key: id + -> Bitmap Heap Scan on ids + Recheck Cond: (id = ANY ('{}'::integer[])) + -> Bitmap Index Scan on pgroonga_index + Index Cond: (id = ANY ('{}'::integer[])) +(6 rows) + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + id +---- +(0 rows) + +DROP TABLE ids; Added: expected/compare/integer/single/any/equal/empty/indexscan.out (+30 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/integer/single/any/equal/empty/indexscan.out 2017-08-23 08:47:48 +0900 (16b2667) @@ -0,0 +1,30 @@ +CREATE TABLE ids ( + id integer +); +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (3); +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + QUERY PLAN +--------------------------------------------- + Index Only Scan using pgroonga_index on ids + Index Cond: (id = ANY ('{}'::integer[])) +(2 rows) + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + id +---- +(0 rows) + +DROP TABLE ids; Added: expected/compare/integer/single/any/equal/multiple/bitmapscan.out (+44 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/integer/single/any/equal/multiple/bitmapscan.out 2017-08-23 08:47:48 +0900 (17f1a9f) @@ -0,0 +1,44 @@ +CREATE TABLE ids ( + id integer +); +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (7); +INSERT INTO ids VALUES (6); +INSERT INTO ids VALUES (4); +INSERT INTO ids VALUES (5); +INSERT INTO ids VALUES (8); +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (10); +INSERT INTO ids VALUES (3); +INSERT INTO ids VALUES (9); +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + QUERY PLAN +------------------------------------------------------------- + Sort + Sort Key: id + -> Bitmap Heap Scan on ids + Recheck Cond: (id = ANY ('{6,1,7}'::integer[])) + -> Bitmap Index Scan on pgroonga_index + Index Cond: (id = ANY ('{6,1,7}'::integer[])) +(6 rows) + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + id +---- + 1 + 6 + 7 +(3 rows) + +DROP TABLE ids; Added: expected/compare/integer/single/any/equal/multiple/indexscan.out (+40 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/integer/single/any/equal/multiple/indexscan.out 2017-08-23 08:47:48 +0900 (fa7680e) @@ -0,0 +1,40 @@ +CREATE TABLE ids ( + id integer +); +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (7); +INSERT INTO ids VALUES (6); +INSERT INTO ids VALUES (4); +INSERT INTO ids VALUES (5); +INSERT INTO ids VALUES (8); +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (10); +INSERT INTO ids VALUES (3); +INSERT INTO ids VALUES (9); +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + QUERY PLAN +------------------------------------------------- + Index Only Scan using pgroonga_index on ids + Index Cond: (id = ANY ('{6,1,7}'::integer[])) +(2 rows) + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + id +---- + 1 + 6 + 7 +(3 rows) + +DROP TABLE ids; Added: sql/compare/integer/single/any/equal/empty/bitmapscan.sql (+26 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/integer/single/any/equal/empty/bitmapscan.sql 2017-08-23 08:47:48 +0900 (bec67f3) @@ -0,0 +1,26 @@ +CREATE TABLE ids ( + id integer +); + +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (3); + +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + +DROP TABLE ids; Added: sql/compare/integer/single/any/equal/empty/indexscan.sql (+26 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/integer/single/any/equal/empty/indexscan.sql 2017-08-23 08:47:48 +0900 (bb66bc1) @@ -0,0 +1,26 @@ +CREATE TABLE ids ( + id integer +); + +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (3); + +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[]::integer[]) + ORDER BY id ASC; + +DROP TABLE ids; Added: sql/compare/integer/single/any/equal/multiple/bitmapscan.sql (+33 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/integer/single/any/equal/multiple/bitmapscan.sql 2017-08-23 08:47:48 +0900 (573e714) @@ -0,0 +1,33 @@ +CREATE TABLE ids ( + id integer +); + +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (7); +INSERT INTO ids VALUES (6); +INSERT INTO ids VALUES (4); +INSERT INTO ids VALUES (5); +INSERT INTO ids VALUES (8); +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (10); +INSERT INTO ids VALUES (3); +INSERT INTO ids VALUES (9); + +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); + +SET enable_seqscan = off; +SET enable_indexscan = off; +SET enable_bitmapscan = on; + +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + +DROP TABLE ids; Added: sql/compare/integer/single/any/equal/multiple/indexscan.sql (+33 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/integer/single/any/equal/multiple/indexscan.sql 2017-08-23 08:47:48 +0900 (cd39be8) @@ -0,0 +1,33 @@ +CREATE TABLE ids ( + id integer +); + +INSERT INTO ids VALUES (2); +INSERT INTO ids VALUES (7); +INSERT INTO ids VALUES (6); +INSERT INTO ids VALUES (4); +INSERT INTO ids VALUES (5); +INSERT INTO ids VALUES (8); +INSERT INTO ids VALUES (1); +INSERT INTO ids VALUES (10); +INSERT INTO ids VALUES (3); +INSERT INTO ids VALUES (9); + +CREATE INDEX pgroonga_index ON ids USING pgroonga (id); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +EXPLAIN (COSTS OFF) +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + +SELECT id + FROM ids + WHERE id = ANY(ARRAY[6, 1, 7]) + ORDER BY id ASC; + +DROP TABLE ids; Modified: src/pgroonga.c (+29 -2) =================================================================== --- src/pgroonga.c 2017-08-17 13:49:20 +0900 (5690abf) +++ src/pgroonga.c 2017-08-23 08:47:48 +0900 (f9ee1a9) @@ -3166,14 +3166,41 @@ PGrnSearchBuildConditionIn(PGrnSearchData *data, grn_obj *targetColumn, Form_pg_attribute attribute) { + ArrayType *values; + int n_dimensions; grn_id domain; unsigned char flags = 0; - ArrayType *values; int i, n; + values = DatumGetArrayTypeP(key->sk_argument); + n_dimensions = ARR_NDIM(values); + switch (n_dimensions) + { + case 0 : + grn_obj_reinit(ctx, &(buffers->general), GRN_DB_BOOL, 0); + GRN_BOOL_SET(ctx, &(buffers->general), GRN_FALSE); + grn_expr_append_const(ctx, + data->expression, + &(buffers->general), + GRN_OP_PUSH, + 0); + PGrnCheck("ANY: failed to push false value"); + return true; + break; + case 1 : + /* OK */ + break; + default : + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("pgroonga: IN: " + "2 or more dimensions array isn't supported yet: %d", + n_dimensions))); + break; + } + domain = PGrnPGTypeToGrnType(attribute->atttypid, &flags); grn_obj_reinit(ctx, &(buffers->general), domain, flags); - values = DatumGetArrayTypeP(key->sk_argument); n = ARR_DIMS(values)[0]; grn_expr_append_obj(ctx, data->expression, -------------- next part -------------- HTML����������������������������...Download