Sha256: 66526857e1399fb90397ee69ce70331fbcc3f81a06871a878867feb42726472b

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

module Groonga
  module ExpressionTree
    class BinaryOperation
      attr_reader :operator
      attr_reader :left
      attr_reader :right
      def initialize(operator, left, right)
        @operator = operator
        @left = left
        @right = right
      end

      def build(expression)
        @left.build(expression)
        @right.build(expression)
        expression.append_operator(@operator, 2)
      end

      RANGE_OPERATORS = [
        Operator::LESS,
        Operator::GREATER,
        Operator::LESS_EQUAL,
        Operator::GREATER_EQUAL,
      ]
      def estimate_size(table)
        case @operator
        when *RANGE_OPERATORS
          estimate_size_range(table)
        else
          table.size
        end
      end

      private
      def estimate_size_range(table)
        return table.size unless @left.is_a?(Variable)
        return table.size unless @right.is_a?(Constant)

        column = @left.column
        value = @right.value
        index_info = column.find_index(@operator)
        return table.size if index_info.nil?

        index_column = index_info.index
        lexicon = index_column.lexicon
        options = {}
        case @operator
        when Operator::LESS
          options[:max] = value
          options[:flags] = TableCursorFlags::LT
        when Operator::LESS_EQUAL
          options[:max] = value
          options[:flags] = TableCursorFlags::LE
        when Operator::GREATER
          options[:min] = value
          options[:flags] = TableCursorFlags::GT
        when Operator::GREATER_EQUAL
          options[:min] = value
          options[:flags] = TableCursorFlags::GE
        end
        TableCursor.open(lexicon, options) do |cursor|
          index_column.estimate_size(:lexicon_cursor => cursor)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rroonga-7.1.1-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-7.1.1-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-7.0.2-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-7.0.2-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.1.3-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.1.3-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.1.0-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.1.0-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.9-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.9-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.7-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.7-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.5-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.5-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.4-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.4-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.2-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb
rroonga-6.0.2-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/expression_tree/binary_operation.rb