Kouhei Sutou
null+****@clear*****
Mon Nov 3 18:36:06 JST 2014
Kouhei Sutou 2014-11-03 18:36:06 +0900 (Mon, 03 Nov 2014) New Revision: 9a49a5aebc14db4d823e5c7105ad100d224ed42a https://github.com/groonga/groonga/commit/9a49a5aebc14db4d823e5c7105ad100d224ed42a Message: Support index search even if arithmetic operators exist GitHub: maybe fix #235 [groonga-dev,02902] Reported by Atsushi Shinoda. Thanks!!! Added files: test/command/suite/select/filter/index/arithmetic_operation/plus.expected test/command/suite/select/filter/index/arithmetic_operation/plus.test Modified files: lib/expr.c lib/mrb/scripts/scan_info_builder.rb test/query_optimizer/suite/test_index.rb Modified: lib/expr.c (+14 -0) =================================================================== --- lib/expr.c 2014-11-03 18:25:11 +0900 (93813dc) +++ lib/expr.c 2014-11-03 18:36:06 +0900 (65c033b) @@ -4437,6 +4437,20 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n, stat = SCAN_START; m++; break; + case GRN_OP_BITWISE_OR : + case GRN_OP_BITWISE_XOR : + case GRN_OP_BITWISE_AND : + case GRN_OP_BITWISE_NOT : + case GRN_OP_SHIFTL : + case GRN_OP_SHIFTR : + case GRN_OP_SHIFTRR : + case GRN_OP_PLUS : + case GRN_OP_MINUS : + case GRN_OP_STAR : + case GRN_OP_MOD : + if (stat < SCAN_COL1 || SCAN_CONST < stat) { return NULL; } + stat = SCAN_START; + break; case GRN_OP_AND : case GRN_OP_OR : case GRN_OP_AND_NOT : Modified: lib/mrb/scripts/scan_info_builder.rb (+18 -0) =================================================================== --- lib/mrb/scripts/scan_info_builder.rb 2014-11-03 18:25:11 +0900 (650be65) +++ lib/mrb/scripts/scan_info_builder.rb 2014-11-03 18:36:06 +0900 (48f5349) @@ -41,6 +41,20 @@ module Groonga Operator::TERM_EXTRACT, ] + ARITHMETIC_OPERATORS = [ + Operator::BITWISE_OR, + Operator::BITWISE_XOR, + Operator::BITWISE_AND, + Operator::BITWISE_NOT, + Operator::SHIFTL, + Operator::SHIFTR, + Operator::SHIFTRR, + Operator::PLUS, + Operator::MINUS, + Operator::STAR, + Operator::MOD, + ] + LOGICAL_OPERATORS = [ Operator::AND, Operator::OR, @@ -140,6 +154,10 @@ module Groonga return false if status > Status::CONST status = Status::START n_relation_expressions += 1 + when *ARITHMETIC_OPERATORS + return false if status < Status::COL1 + return false if status > Status::CONST + status = Status::START when *LOGICAL_OPERATORS return false if status != Status::START n_logical_expressions += 1 Added: test/command/suite/select/filter/index/arithmetic_operation/plus.expected (+19 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/index/arithmetic_operation/plus.expected 2014-11-03 18:36:06 +0900 (7f864b8) @@ -0,0 +1,19 @@ +table_create Memos TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Memos title COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Memos content COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Memos flags COLUMN_SCALAR Int8 +[[0,0.0,0.0],true] +table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto +[[0,0.0,0.0],true] +column_create Terms memos_index COLUMN_INDEX|WITH_POSITION|WITH_SECTION Memos title,content +[[0,0.0,0.0],true] +load --table Memos +[ +{"title": "Groonga", "content": "Groonga is fast!", "flags": 1} +] +[[0,0.0,0.0],1] +select Memos --match_columns Terms.memos_index --query groonga --filter '(flags + 1) == 2' --output_columns 'content' +[[0,0.0,0.0],[[[1],[["content","ShortText"]],["Groonga is fast!"]]]] Added: test/command/suite/select/filter/index/arithmetic_operation/plus.test (+21 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/index/arithmetic_operation/plus.test 2014-11-03 18:36:06 +0900 (8d5890f) @@ -0,0 +1,21 @@ +table_create Memos TABLE_NO_KEY +column_create Memos title COLUMN_SCALAR ShortText +column_create Memos content COLUMN_SCALAR ShortText +column_create Memos flags COLUMN_SCALAR Int8 + +table_create Terms TABLE_PAT_KEY ShortText \ + --default_tokenizer TokenBigram \ + --normalizer NormalizerAuto +column_create Terms memos_index COLUMN_INDEX|WITH_POSITION|WITH_SECTION \ + Memos title,content + +load --table Memos +[ +{"title": "Groonga", "content": "Groonga is fast!", "flags": 1} +] + +select Memos \ + --match_columns Terms.memos_index \ + --query groonga \ + --filter '(flags + 1) == 2' \ + --output_columns 'content' Modified: test/query_optimizer/suite/test_index.rb (+15 -0) =================================================================== --- test/query_optimizer/suite/test_index.rb 2014-11-03 18:25:11 +0900 (10dcb10) +++ test/query_optimizer/suite/test_index.rb 2014-11-03 18:36:06 +0900 (d750b06) @@ -30,4 +30,19 @@ class TestIndex < QueryOptimizerTestCase expr: <0..2> DUMP end + + def test_with_arithmetic_operator + assert_equal(<<-DUMP, dump_plan("message @ 'Groonga' && ((1 + 1) == 2)")) +[0] + op: <match> + logical_op: <or> + query: <"Groonga"> + expr: <0..2> +[1] + op: <equal> + logical_op: <and> + query: <2> + expr: <3..7> + DUMP + end end -------------- next part -------------- HTML����������������������������...Download