[Groonga-commit] groonga/groonga at 93f55b9 [master] mrb: support estimating EQUAL case

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 20 19:16:03 JST 2015


Kouhei Sutou	2015-02-20 19:16:03 +0900 (Fri, 20 Feb 2015)

  New Revision: 93f55b9b3ea9bfb04dc8bbc9d78328af1f1e555a
  https://github.com/groonga/groonga/commit/93f55b9b3ea9bfb04dc8bbc9d78328af1f1e555a

  Message:
    mrb: support estimating EQUAL case

  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 (+16 -0)
===================================================================
--- lib/mrb/scripts/expression_size_estimator.rb    2015-02-20 19:14:45 +0900 (234b05d)
+++ lib/mrb/scripts/expression_size_estimator.rb    2015-02-20 19:16:03 +0900 (f66f02a)
@@ -19,6 +19,8 @@ module Groonga
           case data.op
           when Operator::MATCH
             size = estimate_match(data, search_index)
+          when Operator::EQUAL
+            size = estimate_equal(data, search_index)
           when Operator::LESS,
                Operator::LESS_EQUAL,
                Operator::GREATER,
@@ -47,6 +49,20 @@ module Groonga
       index_column.estimate_size(:query => data.query.value)
     end
 
+    def estimate_equal(data, search_index)
+      index_column = search_index.index_column
+      if index_column.is_a?(Accessor)
+        # TODO
+        return nil
+      end
+
+      lexicon = index_column.lexicon
+      term_id = lexicon[data.query]
+      return 0 if term_id.nil?
+
+      index_column.estimate_size(:term_id => term_id)
+    end
+
     def estimate_range(data, search_index)
       index_column = search_index.index_column
       if index_column.is_a?(Accessor)

  Modified: test/query_optimizer/suite/test_estimate_size.rb (+31 -0)
===================================================================
--- test/query_optimizer/suite/test_estimate_size.rb    2015-02-20 19:14:45 +0900 (f13bb92)
+++ test/query_optimizer/suite/test_estimate_size.rb    2015-02-20 19:16:03 +0900 (051d98b)
@@ -43,6 +43,37 @@ class TestEstimateSize < QueryOptimizerTestCase
     end
   end
 
+  class TestEqualSearch < self
+    def setup
+      Groonga::Schema.define do |schema|
+        schema.create_table("Logs") do |table|
+          table.time("timestamp")
+        end
+
+        schema.create_table("Times",
+                            :type => :patricia_trie,
+                            :key_type => :time) do |table|
+          table.index("Logs", "timestamp")
+        end
+      end
+      super
+    end
+
+    def test_no_record
+      assert_equal(0, estimate_size("timestamp == '2015-02-19 02:18:00'"))
+    end
+
+    def test_have_record
+      @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(4, estimate_size("timestamp == '2015-02-19 02:18:00'"))
+    end
+  end
+
   class TestLessSearch < self
     def setup
       Groonga::Schema.define do |schema|
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index