[Groonga-commit] groonga/groonga at 166cec3 [master] mrb: support estimating size for GREATER operator

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Feb 19 16:51:14 JST 2015


Kouhei Sutou	2015-02-19 16:51:14 +0900 (Thu, 19 Feb 2015)

  New Revision: 166cec3f53d66d943e60af34e96d2b2b65c0ccbd
  https://github.com/groonga/groonga/commit/166cec3f53d66d943e60af34e96d2b2b65c0ccbd

  Message:
    mrb: support estimating size for GREATER operator

  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-19 16:50:59 +0900 (2d45c15)
+++ lib/mrb/scripts/expression_size_estimator.rb    2015-02-19 16:51:14 +0900 (7c6d02b)
@@ -19,7 +19,9 @@ module Groonga
           case data.op
           when Operator::MATCH
             size = estimate_match(data, search_index)
-          when Operator::LESS, Operator::LESS_EQUAL
+          when Operator::LESS,
+               Operator::LESS_EQUAL,
+               Operator::GREATER
             size = estimate_range(data, search_index)
           end
           size || @table.size
@@ -56,6 +58,9 @@ module Groonga
       when Operator::LESS_EQUAL
         options[:max] = value
         options[:flags] = TableCursorFlags::LE
+      when Operator::GREATER
+        options[:min] = value
+        options[:flags] = TableCursorFlags::GT
       end
       TableCursor.open(lexicon, options) do |cursor|
         index_column.estimate_size(:lexicon_cursor => cursor)

  Modified: test/query_optimizer/suite/test_estimate_size.rb (+31 -0)
===================================================================
--- test/query_optimizer/suite/test_estimate_size.rb    2015-02-19 16:50:59 +0900 (43ef0eb)
+++ test/query_optimizer/suite/test_estimate_size.rb    2015-02-19 16:51:14 +0900 (6725253)
@@ -104,4 +104,35 @@ class TestEstimateSize < QueryOptimizerTestCase
       assert_equal(8, estimate_size("timestamp <= '2015-02-19 02:18:00'"))
     end
   end
+
+  class TestGreaterSearch < 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:17: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(8, estimate_size("timestamp > '2015-02-19 02:17:00'"))
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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