[Groonga-commit] groonga/groonga at 63fa59d [master] mrb: support estimating size for LESS_EQUAL operator

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Feb 19 16:47:40 JST 2015


Kouhei Sutou	2015-02-19 16:47:40 +0900 (Thu, 19 Feb 2015)

  New Revision: 63fa59d8a3e8c30a7e7b5ba663800084bdf2e229
  https://github.com/groonga/groonga/commit/63fa59d8a3e8c30a7e7b5ba663800084bdf2e229

  Message:
    mrb: support estimating size for LESS_EQUAL operator

  Modified files:
    lib/mrb/scripts/expression_size_estimator.rb

  Modified: lib/mrb/scripts/expression_size_estimator.rb (+17 -9)
===================================================================
--- lib/mrb/scripts/expression_size_estimator.rb    2015-02-19 16:41:01 +0900 (ce0cf98)
+++ lib/mrb/scripts/expression_size_estimator.rb    2015-02-19 16:47:40 +0900 (2d45c15)
@@ -15,14 +15,14 @@ module Groonga
         if search_index.nil?
           @table.size
         else
+          size = nil
           case data.op
           when Operator::MATCH
-            estimate_match(data, search_index) || @table.size
-          when Operator::LESS
-            estimate_less(data, search_index) || @table.size
-          else
-            @table.size
+            size = estimate_match(data, search_index)
+          when Operator::LESS, Operator::LESS_EQUAL
+            size = estimate_range(data, search_index)
           end
+          size || @table.size
         end
       end
       sizes.min
@@ -39,7 +39,7 @@ module Groonga
       index_column.estimate_size(:query => data.query.value)
     end
 
-    def estimate_less(data, search_index)
+    def estimate_range(data, search_index)
       index_column = search_index.index_column
       if index_column.is_a?(Accessor)
         # TODO
@@ -47,9 +47,17 @@ module Groonga
       end
 
       lexicon = index_column.lexicon
-      max = data.query.value
-      flags = TableCursorFlags::LT
-      TableCursor.open(lexicon, :max => max, :flags => flags) do |cursor|
+      value = data.query.value
+      options = {}
+      case data.op
+      when Operator::LESS
+        options[:max] = value
+        options[:flags] = TableCursorFlags::LT
+      when Operator::LESS_EQUAL
+        options[:max] = value
+        options[:flags] = TableCursorFlags::LE
+      end
+      TableCursor.open(lexicon, options) do |cursor|
         index_column.estimate_size(:lexicon_cursor => cursor)
       end
     end
-------------- next part --------------
HTML����������������������������...
Download 



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