Kouhei Sutou
null+****@clear*****
Sun Feb 8 20:03:55 JST 2015
Kouhei Sutou 2015-02-08 20:03:55 +0900 (Sun, 08 Feb 2015) New Revision: b3b715fa094ee49dcbd2858b16a92f80b4328932 https://github.com/pgroonga/pgroonga/commit/b3b715fa094ee49dcbd2858b16a92f80b4328932 Message: Support multiple same operators in range search It requires Groonga at master. TODO: * Compare and equal case isn't supported yet. Added files: expected/compare/integer/single/greater-than-equal/multiple.out expected/compare/integer/single/less-than-equal/multiple.out sql/compare/integer/single/greater-than-equal/multiple.sql sql/compare/integer/single/less-than-equal/multiple.sql Modified files: .travis.yml Makefile pgroonga.c Modified: .travis.yml (+2 -2) =================================================================== --- .travis.yml 2015-02-08 18:07:27 +0900 (95d511b) +++ .travis.yml 2015-02-08 20:03:55 +0900 (fa96694) @@ -6,8 +6,8 @@ compiler: - gcc addons: postgresql: "9.3" -# env: -# - GROONGA_MASTER=yes +env: + - GROONGA_MASTER=yes install: - curl --silent --location https://github.com/groonga/groonga/raw/master/data/travis/setup.sh | sh - sudo apt-get install -qq -y postgresql-server-dev-9.3 Modified: Makefile (+3 -0) =================================================================== --- Makefile 2015-02-08 18:07:27 +0900 (a641ee3) +++ Makefile 2015-02-08 20:03:55 +0900 (994da55) @@ -33,6 +33,7 @@ installcheck: results/full-text-search/text/options/tokenizer installcheck: results/full-text-search/text/options/normalizer installcheck: results/compare/text/single/equal installcheck: results/compare/integer/single/less-than-equal +installcheck: results/compare/integer/single/greater-than-equal installcheck: results/compare/integer/single/between installcheck: results/compare/integer/order_by_limit @@ -52,6 +53,8 @@ results/compare/text/single/equal: @mkdir -p $@ results/compare/integer/single/less-than-equal: @mkdir -p $@ +results/compare/integer/single/greater-than-equal: + @mkdir -p $@ results/compare/integer/single/between: @mkdir -p $@ results/compare/integer/order_by_limit: Added: expected/compare/integer/single/greater-than-equal/multiple.out (+32 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/integer/single/greater-than-equal/multiple.out 2015-02-08 20:03:55 +0900 (ca8ad0c) @@ -0,0 +1,32 @@ +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 grnindex ON ids USING pgroonga (id); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id + FROM ids + WHERE id >= 3 AND id >= 5 + ORDER BY id ASC; + id +---- + 5 + 6 + 7 + 8 + 9 + 10 +(6 rows) + +DROP TABLE ids; Added: expected/compare/integer/single/less-than-equal/multiple.out (+29 -0) 100644 =================================================================== --- /dev/null +++ expected/compare/integer/single/less-than-equal/multiple.out 2015-02-08 20:03:55 +0900 (717b34a) @@ -0,0 +1,29 @@ +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 grnindex ON ids USING pgroonga (id); +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; +SELECT id + FROM ids + WHERE id <= 5 AND id <= 3 + ORDER BY id ASC; + id +---- + 1 + 2 + 3 +(3 rows) + +DROP TABLE ids; Modified: pgroonga.c (+61 -0) =================================================================== --- pgroonga.c 2015-02-08 18:07:27 +0900 (9476964) +++ pgroonga.c 2015-02-08 20:03:55 +0900 (31c1287) @@ -1003,6 +1003,40 @@ PGrnOpenTableCursor(IndexScanDesc scan, ScanDirection dir) GRN_COLUMN_NAME_KEY_LEN); } +static bool +PGrnIsMeaningfullMaxBorderValue(grn_obj *currentValue, + grn_obj *newValue, + int flags, + StrategyNumber strategy) +{ + if (((flags & GRN_CURSOR_LT) == GRN_CURSOR_LT) && + strategy == PGrnLessEqualStrategyNumber) + { + return grn_operator_exec_greater_equal(ctx, currentValue, newValue); + } + else + { + return grn_operator_exec_greater(ctx, currentValue, newValue); + } +} + +static bool +PGrnIsMeaningfullMinBorderValue(grn_obj *currentValue, + grn_obj *newValue, + int flags, + StrategyNumber strategy) +{ + if (((flags & GRN_CURSOR_GT) == GRN_CURSOR_GT) && + strategy == PGrnGreaterEqualStrategyNumber) + { + return grn_operator_exec_less_equal(ctx, currentValue, newValue); + } + else + { + return grn_operator_exec_less(ctx, currentValue, newValue); + } +} + static void PGrnFillBorder(IndexScanDesc scan, void **min, unsigned int *minSize, @@ -1029,10 +1063,23 @@ PGrnFillBorder(IndexScanDesc scan, { case PGrnLessStrategyNumber: case PGrnLessEqualStrategyNumber: + if (maxBorderValue->header.type != GRN_DB_VOID) + { + grn_obj_reinit(ctx, &buffer, domain, 0); + PGrnGetValue(index, attrNumber, &buffer, key->sk_argument); + if (!PGrnIsMeaningfullMaxBorderValue(maxBorderValue, + &buffer, + *flags, + key->sk_strategy)) + { + continue; + } + } grn_obj_reinit(ctx, maxBorderValue, domain, 0); PGrnGetValue(index, attrNumber, maxBorderValue, key->sk_argument); *max = GRN_BULK_HEAD(maxBorderValue); *maxSize = GRN_BULK_VSIZE(maxBorderValue); + *flags &= ~(GRN_CURSOR_LT | GRN_CURSOR_LE); if (key->sk_strategy == PGrnLessStrategyNumber) { *flags |= GRN_CURSOR_LT; @@ -1051,10 +1098,24 @@ PGrnFillBorder(IndexScanDesc scan, break; case PGrnGreaterEqualStrategyNumber: case PGrnGreaterStrategyNumber: + if (minBorderValue->header.type != GRN_DB_VOID) + { + grn_obj_reinit(ctx, &buffer, domain, 0); + PGrnGetValue(index, attrNumber, &buffer, + key->sk_argument); + if (!PGrnIsMeaningfullMinBorderValue(minBorderValue, + &buffer, + *flags, + key->sk_strategy)) + { + continue; + } + } grn_obj_reinit(ctx, minBorderValue, domain, 0); PGrnGetValue(index, attrNumber, minBorderValue, key->sk_argument); *min = GRN_BULK_HEAD(minBorderValue); *minSize = GRN_BULK_VSIZE(minBorderValue); + *flags &= ~(GRN_CURSOR_GT | GRN_CURSOR_GE); if (key->sk_strategy == PGrnGreaterEqualStrategyNumber) { *flags |= GRN_CURSOR_GE; Added: sql/compare/integer/single/greater-than-equal/multiple.sql (+27 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/integer/single/greater-than-equal/multiple.sql 2015-02-08 20:03:55 +0900 (3ea949d) @@ -0,0 +1,27 @@ +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 grnindex ON ids USING pgroonga (id); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id + FROM ids + WHERE id >= 3 AND id >= 5 + ORDER BY id ASC; + +DROP TABLE ids; Added: sql/compare/integer/single/less-than-equal/multiple.sql (+27 -0) 100644 =================================================================== --- /dev/null +++ sql/compare/integer/single/less-than-equal/multiple.sql 2015-02-08 20:03:55 +0900 (e31cc0c) @@ -0,0 +1,27 @@ +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 grnindex ON ids USING pgroonga (id); + +SET enable_seqscan = off; +SET enable_indexscan = on; +SET enable_bitmapscan = off; + +SELECT id + FROM ids + WHERE id <= 5 AND id <= 3 + ORDER BY id ASC; + +DROP TABLE ids; -------------- next part -------------- HTML����������������������������...Download