Kouhei Sutou
null+****@clear*****
Wed Jul 8 12:17:02 JST 2015
Kouhei Sutou 2015-07-08 12:17:02 +0900 (Wed, 08 Jul 2015) New Revision: 41c335b200fff705497c96bad24e1b26bd2f4824 https://github.com/groonga/groonga/commit/41c335b200fff705497c96bad24e1b26bd2f4824 Message: logical_range_filter: force to use select mode when selector only proc exists Added files: test/command/suite/sharding/logical_range_filter/filter/sub_filter/force_index_search.expected test/command/suite/sharding/logical_range_filter/filter/sub_filter/force_index_search.test Modified files: plugins/sharding/logical_range_filter.rb Modified: plugins/sharding/logical_range_filter.rb (+39 -0) =================================================================== --- plugins/sharding/logical_range_filter.rb 2015-07-08 12:16:12 +0900 (bbcab7c) +++ plugins/sharding/logical_range_filter.rb 2015-07-08 12:17:02 +0900 (775e45d) @@ -295,12 +295,22 @@ module Groonga __LINE__, __method__) end + selector_only_procedure_reason = + "selector only procedure can't be used" estimated_n_records = 0 case @cover_type when :all if @filter create_expression(@table) do |expression| @expression_builder.build_all(expression) + selector_only_procedure = + find_selector_only_procedure(expression) + if selector_only_procedure + reason = "#{selector_only_procedure_reason}: " + reason << "<#{selector_only_procedure.name}>" + return decide_use_range_index(false, reason, + __LINE__, __method__) + end estimated_n_records = expression.estimate_size(@table) end else @@ -309,16 +319,37 @@ module Groonga when :partial_min create_expression(@table) do |expression| @expression_builder.build_partial_min(expression) + selector_only_procedure = find_selector_only_procedure(expression) + if selector_only_procedure + reason = "#{selector_only_procedure_reason}: " + reason << "<#{selector_only_procedure.name}>" + return decide_use_range_index(false, reason, + __LINE__, __method__) + end estimated_n_records = expression.estimate_size(@table) end when :partial_max create_expression(@table) do |expression| @expression_builder.build_partial_max(expression) + selector_only_procedure = find_selector_only_procedure(expression) + if selector_only_procedure + reason = "#{selector_only_procedure_reason}: " + reason << "<#{selector_only_procedure.name}>" + return decide_use_range_index(false, reason, + __LINE__, __method__) + end estimated_n_records = expression.estimate_size(@table) end when :partial_min_and_max create_expression(@table) do |expression| @expression_builder.build_partial_min_and_max(expression) + selector_only_procedure = find_selector_only_procedure(expression) + if selector_only_procedure + reason = "#{selector_only_procedure_reason}: " + reason << "<#{selector_only_procedure.name}>" + return decide_use_range_index(false, reason, + __LINE__, __method__) + end estimated_n_records = expression.estimate_size(@table) end end @@ -345,6 +376,14 @@ module Groonga __LINE__, __method__) end + def find_selector_only_procedure(expression) + expression.codes.each do |code| + value = code.value + return value if value.is_a?(Procedure) and value.selector_only? + end + nil + end + def filter_shard_all(range_index) if****@filte*****? if****@table***** <=****@conte*****_offset Added: test/command/suite/sharding/logical_range_filter/filter/sub_filter/force_index_search.expected (+86 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_range_filter/filter/sub_filter/force_index_search.expected 2015-07-08 12:17:02 +0900 (e5b5c07) @@ -0,0 +1,86 @@ +load --table Errors +[ +{ + "_key": "error1", + "level": "critical", + "action": "Shutdown" +} +] +[[0,0.0,0.0],1] +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00", + "action": "Start" +} +] +[[0,0.0,0.0],1] +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00", + "action": "Start" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00", + "action": "Shutdown" +} +] +[[0,0.0,0.0],2] +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00", + "action": "Start" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00", + "action": "Running" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00", + "action": "Shutdown" +} +] +[[0,0.0,0.0],3] +log_level --level debug +[[0,0.0,0.0],true] +logical_range_filter Logs timestamp --limit 1 --filter 'sub_filter(action.errors_action, "level == \\"critical\\"")' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + "action", + "Actions" + ], + [ + "memo", + "ShortText" + ], + [ + "timestamp", + "Time" + ] + ], + [ + "Shutdown", + "2015-02-04 13:50:00", + 1423025400.0 + ] + ] +] +#|d| [logical_range_filter][select] <Logs_20150203>: the number of required records (1) >= the number of records in shard (1) +#|d| [logical_range_filter][select] <Logs_20150204>: selector only procedure can't be used: <sub_filter> +log_level --level notice +[[0,0.0,0.0],true] Added: test/command/suite/sharding/logical_range_filter/filter/sub_filter/force_index_search.test (+60 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_range_filter/filter/sub_filter/force_index_search.test 2015-07-08 12:17:02 +0900 (50e7f94) @@ -0,0 +1,60 @@ +#@include fixture/sharding/logical_range_filter/use_range_index/schema.grn + +load --table Errors +[ +{ + "_key": "error1", + "level": "critical", + "action": "Shutdown" +} +] + +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00", + "action": "Start" +} +] + +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00", + "action": "Start" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00", + "action": "Shutdown" +} +] + +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00", + "action": "Start" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00", + "action": "Running" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00", + "action": "Shutdown" +} +] + +#@add-important-log-levels debug +log_level --level debug +logical_range_filter Logs timestamp \ + --limit 1 \ + --filter 'sub_filter(action.errors_action, "level == \\"critical\\"")' +log_level --level notice +#@remove-important-log-levels debug -------------- next part -------------- HTML����������������������������... Download