diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:07:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:07:14 +0000 |
commit | a175314c3e5827eb193872241446f2f8f5c9d33c (patch) | |
tree | cd3d60ca99ae00829c52a6ca79150a5b6e62528b /storage/mroonga/vendor/groonga/lib/mrb/scripts/expression_tree/binary_operation.rb | |
parent | Initial commit. (diff) | |
download | mariadb-10.5-a175314c3e5827eb193872241446f2f8f5c9d33c.tar.xz mariadb-10.5-a175314c3e5827eb193872241446f2f8f5c9d33c.zip |
Adding upstream version 1:10.5.12.upstream/1%10.5.12upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/mroonga/vendor/groonga/lib/mrb/scripts/expression_tree/binary_operation.rb')
-rw-r--r-- | storage/mroonga/vendor/groonga/lib/mrb/scripts/expression_tree/binary_operation.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/storage/mroonga/vendor/groonga/lib/mrb/scripts/expression_tree/binary_operation.rb b/storage/mroonga/vendor/groonga/lib/mrb/scripts/expression_tree/binary_operation.rb new file mode 100644 index 00000000..d59c65c7 --- /dev/null +++ b/storage/mroonga/vendor/groonga/lib/mrb/scripts/expression_tree/binary_operation.rb @@ -0,0 +1,67 @@ +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 |