[Groonga-commit] groonga/groonga at 9fe2ae0 [master] mrb: move estimation for call to tree

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Thu Apr 7 15:24:59 JST 2016


Kouhei Sutou	2016-04-07 15:24:59 +0900 (Thu, 07 Apr 2016)

  New Revision: 9fe2ae00a89db60cd8cc73040b4b622f15437c45
  https://github.com/groonga/groonga/commit/9fe2ae00a89db60cd8cc73040b4b622f15437c45

  Message:
    mrb: move estimation for call to tree

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

  Modified: lib/mrb/scripts/expression_size_estimator.rb (+11 -25)
===================================================================
--- lib/mrb/scripts/expression_size_estimator.rb    2016-04-07 15:22:38 +0900 (c883ef3)
+++ lib/mrb/scripts/expression_size_estimator.rb    2016-04-07 15:24:59 +0900 (4b7a139)
@@ -74,10 +74,7 @@ module Groonga
            Operator::GREATER_EQUAL
         size = estimate_range(data, index_column)
       when Operator::CALL
-        procedure = data.args.first
-        if procedure.is_a?(Procedure) and procedure.name == "between"
-          size = estimate_between(data, index_column)
-        end
+        size = estimate_call(data, index_column)
       end
       size || @table_size
     end
@@ -137,28 +134,17 @@ module Groonga
       end
     end
 
-    def estimate_between(data, index_column)
-      lexicon = index_column.lexicon
-      _, _, min, min_border, max, max_border = data.args
-      options = {
-        :min => min,
-        :max => max,
-        :flags => 0,
-      }
-      if min_border == "include"
-        options[:flags] |= TableCursorFlags::LT
-      else
-        options[:flags] |= TableCursorFlags::LE
-      end
-      if max_border == "include"
-        options[:flags] |= TableCursorFlags::GT
-      else
-        options[:flags] |= TableCursorFlags::GE
-      end
-
-      TableCursor.open(lexicon, options) do |cursor|
-        index_column.estimate_size(:lexicon_cursor => cursor)
+    def estimate_call(data, index_column)
+      procedure = data.args[0]
+      arguments = data.args[1..-1].collect do |arg|
+        if arg.is_a?(::Groonga::Object)
+          ExpressionTree::Variable.new(arg)
+        else
+          ExpressionTree::Constant.new(arg)
+        end
       end
+      node = ExpressionTree::FunctionCall.new(procedure, arguments)
+      node.estimate_size(@table)
     end
   end
 end

  Modified: lib/mrb/scripts/expression_tree/function_call.rb (+30 -0)
===================================================================
--- lib/mrb/scripts/expression_tree/function_call.rb    2016-04-07 15:22:38 +0900 (b3bfff6)
+++ lib/mrb/scripts/expression_tree/function_call.rb    2016-04-07 15:24:59 +0900 (d09da0a)
@@ -15,6 +15,36 @@ module Groonga
         end
         expression.append_operator(Operator::CALL, @arguments.size)
       end
+
+      def estimate_size(table)
+        return table.size unles****@proce***** == "between"
+
+        column, min, min_border, max, max_border = @arguments
+        index_info = column.column.find_index(Operator::CALL)
+        return table.size if index_info.nil?
+
+        index_column = index_info.index
+        lexicon = index_column.lexicon
+        options = {
+          :min => min.value,
+          :max => max.value,
+          :flags => 0,
+        }
+        if min_border.value == "include"
+          options[:flags] |= TableCursorFlags::LT
+        else
+          options[:flags] |= TableCursorFlags::LE
+        end
+        if max_border.value == "include"
+          options[:flags] |= TableCursorFlags::GT
+        else
+          options[:flags] |= TableCursorFlags::GE
+        end
+
+        TableCursor.open(lexicon, options) do |cursor|
+          index_column.estimate_size(:lexicon_cursor => cursor)
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る