Kouhei Sutou 2019-04-25 17:40:45 +0900 (Thu, 25 Apr 2019) Revision: ec8cf8781b7c615144d1e62a838ac0ec0214541f https://github.com/groonga/groonga/commit/ec8cf8781b7c615144d1e62a838ac0ec0214541f Message: in_values: improve(?) estimation quality Modified files: lib/mrb/scripts/expression_tree/function_call.rb test/mruby/suite/query_optimizer/test_estimate_size.rb Modified: lib/mrb/scripts/expression_tree/function_call.rb (+8 -1) =================================================================== --- lib/mrb/scripts/expression_tree/function_call.rb 2019-04-25 17:33:49 +0900 (50ff3754e) +++ lib/mrb/scripts/expression_tree/function_call.rb 2019-04-25 17:40:45 +0900 (cc4e2219d) @@ -78,10 +78,17 @@ module Groonga def estimate_size_in_values(table) column, *values = @arguments - values.inject(0) do |sum, value| + total = values.inject(0) do |sum, value| node = BinaryOperation.new(Operator::EQUAL, column, value) sum + node.estimate_size(table) end + duplicated_ratio = 0.3 # No reason :p + estimated_size = (total * (1 - duplicated_ratio)).round + if estimated_size < table.size + estimated_size + else + table.size + end end end end Modified: test/mruby/suite/query_optimizer/test_estimate_size.rb (+1 -1) =================================================================== --- test/mruby/suite/query_optimizer/test_estimate_size.rb 2019-04-25 17:33:49 +0900 (5804eb116) +++ test/mruby/suite/query_optimizer/test_estimate_size.rb 2019-04-25 17:40:45 +0900 (be5dd83e0) @@ -304,7 +304,7 @@ class TestEstimateSize < QueryOptimizerTestCase @logs.add(:timestamp => "2015-02-19 02:20:00") @logs.add(:timestamp => "2015-02-19 02:21:00") @logs.add(:timestamp => "2015-02-19 02:21:00") - assert_equal(8, + assert_equal(6, estimate_size("in_values(timestamp, " + "'2015-02-19 02:18:00', " + "'2015-02-19 02:20:00')")) -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190425/88cc6fe8/attachment.html>