Kouhei Sutou
null+****@clear*****
Mon Feb 23 14:49:23 JST 2015
Kouhei Sutou 2015-02-23 14:49:23 +0900 (Mon, 23 Feb 2015) New Revision: efe4a477d540ff4bdd97dab1f669bcd68ec85710 https://github.com/groonga/groonga/commit/efe4a477d540ff4bdd97dab1f669bcd68ec85710 Message: mrb: use inverted size for AND_NOT Modified files: lib/mrb/scripts/expression_size_estimator.rb test/query_optimizer/suite/test_estimate_size.rb Modified: lib/mrb/scripts/expression_size_estimator.rb (+6 -1) =================================================================== --- lib/mrb/scripts/expression_size_estimator.rb 2015-02-23 14:48:54 +0900 (621622b) +++ lib/mrb/scripts/expression_size_estimator.rb 2015-02-23 14:49:23 +0900 (f932842) @@ -14,7 +14,12 @@ module Groonga or_data_list = group_data_list(data_list) or_sizes = or_data_list.collect do |and_data_list| and_sizes = and_data_list.collect do |data| - estimate_data(data) + size = estimate_data(data) + if data.logical_op == Operator::AND_NOT + size = @table_size - size + size = 0 if size < 0 + end + size end and_sizes.min end Modified: test/query_optimizer/suite/test_estimate_size.rb (+65 -0) =================================================================== --- test/query_optimizer/suite/test_estimate_size.rb 2015-02-23 14:48:54 +0900 (1771cc6) +++ test/query_optimizer/suite/test_estimate_size.rb 2015-02-23 14:49:23 +0900 (e68886d) @@ -304,6 +304,71 @@ class TestEstimateSize < QueryOptimizerTestCase end end + class TestAndNot < self + def setup + Groonga::Schema.define do |schema| + schema.create_table("Logs") do |table| + table.text("message") + table.time("timestamp") + table.int32("type") + end + + schema.create_table("Terms", + :type => :patricia_trie, + :default_tokenizer => "TokenBigramSplitSymbolAlpha", + :normalizer => "NormalizerAuto") do |table| + table.index("Logs", "message") + end + + schema.create_table("Times", + :type => :patricia_trie, + :key_type => :time) do |table| + table.index("Logs", "timestamp") + end + + schema.create_table("Types", + :type => :patricia_trie, + :key_type => :int32) do |table| + table.index("Logs", "type") + end + end + super + end + + def test_two + @logs.add(:message => "Groonga is fast") + @logs.add(:message => "Rroonga is fast") + @logs.add(:message => "Mroonga is fast") + @logs.add(:timestamp => "2015-02-19 02:17:00") + @logs.add(:timestamp => "2015-02-19 02:17:00") + @logs.add(:timestamp => "2015-02-19 02:18:00") + @logs.add(:timestamp => "2015-02-19 02:18:00") + @logs.add(:timestamp => "2015-02-19 02:19:00") + @logs.add(:timestamp => "2015-02-19 02:19:00") + + assert_equal(1, estimate_size("message @ 'Groonga' &! " + + "timestamp < '2015-02-19 02:19:00'")) + end + + def test_three + @logs.add(:message => "Groonga is fast", :type => 1) + @logs.add(:message => "Rroonga is fast", :type => 1) + @logs.add(:message => "Mroonga is fast", :type => 1) + @logs.add(:timestamp => "2015-02-19 02:17:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:17:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:18:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:18:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + + assert_equal(3, estimate_size("message @ 'Groonga' &! " + + "timestamp < '2015-02-19 02:19:00' &! " + + "type == 1")) + end + end + class TestOr < self def setup Groonga::Schema.define do |schema| -------------- next part -------------- HTML����������������������������...Download