xiaokang commented on code in PR #38908:
URL: https://github.com/apache/doris/pull/38908#discussion_r1713103295


##########
be/src/olap/rowset/segment_v2/segment_iterator.cpp:
##########
@@ -2610,12 +2624,12 @@ Status 
SegmentIterator::_next_batch_internal(vectorized::Block* block) {
                 auto col_const =
                         vectorized::ColumnConst::create(std::move(res_column), 
selected_size);
                 block->replace_by_position(0, std::move(col_const));
-                _output_index_result_column(_sel_rowid_idx.data(), 
selected_size, block);
+                _output_index_result_column_for_expr(_sel_rowid_idx.data(), 
selected_size, block);

Review Comment:
   Is it right for non compound filter?



##########
be/src/olap/rowset/segment_v2/segment_iterator.cpp:
##########
@@ -1471,6 +1481,8 @@ Status SegmentIterator::_init_inverted_index_iterators() {
                     
_segment->_tablet_schema->get_inverted_index(_opts.tablet_schema->column(cid)),
                     _opts, &_inverted_index_iterators[cid]));
         }
+        _inverted_index_iterators_by_col_name[_schema->column(cid)->name()] =

Review Comment:
   Can you use name -> cid mapping instead of another mapping 
_inverted_index_iterators_by_col_name?



##########
be/src/olap/rowset/segment_v2/segment_iterator.cpp:
##########
@@ -2678,7 +2692,7 @@ Status SegmentIterator::_execute_common_expr(uint16_t* 
sel_rowid_idx, uint16_t&
 
     vectorized::IColumn::Filter filter;
     
RETURN_IF_ERROR(vectorized::VExprContext::execute_conjuncts_and_filter_block(
-            _common_expr_ctxs_push_down, block, _columns_to_filter, 
prev_columns, filter));
+            _compound_expr_ctxs, block, _columns_to_filter, prev_columns, 
filter));

Review Comment:
   mark



##########
be/src/vec/exprs/vcompound_pred.h:
##########
@@ -53,6 +54,94 @@ class VCompoundPred : public VectorizedFnCall {
 
     const std::string& expr_name() const override { return _expr_name; }
 
+    Status evaluate_inverted_index(VExprContext* context,
+                                   uint32_t segment_num_rows) const override {
+        segment_v2::InvertedIndexResultBitmap res;
+        bool all_pass = true;
+
+        switch (_op) {
+        case TExprOpcode::COMPOUND_OR: {
+            for (const auto& child : _children) {
+                LOG(ERROR) << "expr " << child->expr_name() << " " << child

Review Comment:
   check OR short circurit before each child



##########
be/src/vec/exprs/vectorized_fn_call.cpp:
##########
@@ -171,9 +212,25 @@ Status VectorizedFnCall::eval_inverted_index(
 Status VectorizedFnCall::_do_execute(doris::vectorized::VExprContext* context,
                                      doris::vectorized::Block* block, int* 
result_column_id,
                                      std::vector<size_t>& args) {
-    if (is_const_and_have_executed()) { // const have execute in open function
+    if (is_const_and_have_executed()) { // const have executed in open function
         return get_result_from_const(block, _expr_name, result_column_id);
     }
+    if (context->get_inverted_index_result_column().contains(this)) {
+        size_t num_columns_without_result = block->columns();
+        // prepare a column to save result
+        auto result_column = context->get_inverted_index_result_column()[this];
+        LOG(WARNING) << "hit result expr name:" << _expr_name

Review Comment:
   DEBUG



##########
be/src/vec/exprs/vcompound_pred.h:
##########
@@ -53,6 +54,94 @@ class VCompoundPred : public VectorizedFnCall {
 
     const std::string& expr_name() const override { return _expr_name; }
 
+    Status evaluate_inverted_index(VExprContext* context,
+                                   uint32_t segment_num_rows) const override {
+        segment_v2::InvertedIndexResultBitmap res;
+        bool all_pass = true;
+
+        switch (_op) {
+        case TExprOpcode::COMPOUND_OR: {
+            for (const auto& child : _children) {
+                LOG(ERROR) << "expr " << child->expr_name() << " " << child
+                           << " try to evaluate_inverted_index result";
+                if (Status st = child->evaluate_inverted_index(context, 
segment_num_rows);
+                    !st.ok()) {
+                    LOG(ERROR) << "expr:" << child->expr_name()
+                               << " evaluate_inverted_index error:" << 
st.to_string();
+                    all_pass = false;
+                    continue;
+                }
+                if (context->has_inverted_index_result_for_expr(child.get())) {
+                    auto index_result = 
context->get_inverted_index_result_for_expr(child.get());
+                    if (res.is_empty()) {
+                        res = std::move(index_result);
+                    } else {
+                        res |= index_result;
+                    }
+                } else {
+                    LOG(ERROR) << "expr:" << child->expr_name() << " does not 
have result";
+                    all_pass = false;
+                }
+            }
+            break;
+        }
+        case TExprOpcode::COMPOUND_AND: {
+            for (const auto& child : _children) {

Review Comment:
   check AND short circurit before each child



##########
be/src/vec/exprs/vectorized_fn_call.cpp:
##########
@@ -171,9 +212,25 @@ Status VectorizedFnCall::eval_inverted_index(
 Status VectorizedFnCall::_do_execute(doris::vectorized::VExprContext* context,
                                      doris::vectorized::Block* block, int* 
result_column_id,
                                      std::vector<size_t>& args) {
-    if (is_const_and_have_executed()) { // const have execute in open function
+    if (is_const_and_have_executed()) { // const have executed in open function
         return get_result_from_const(block, _expr_name, result_column_id);
     }
+    if (context->get_inverted_index_result_column().contains(this)) {

Review Comment:
   duplicate code for many type of predicate



##########
be/src/vec/exprs/vexpr.cpp:
##########
@@ -285,7 +286,11 @@ Status VExpr::create_expr(const TExprNode& expr_node, 
VExprSPtr& expr) {
         case TExprNodeType::NULL_AWARE_BINARY_PRED:
         case TExprNodeType::FUNCTION_CALL:
         case TExprNodeType::COMPUTE_FUNCTION_CALL: {
-            expr = VectorizedFnCall::create_shared(expr_node);
+            if (expr_node.fn.name.function_name == "multi_match") {

Review Comment:
   avoid special case



##########
be/src/vec/exprs/vectorized_fn_call.cpp:
##########
@@ -143,6 +139,51 @@ void VectorizedFnCall::close(VExprContext* context, 
FunctionContext::FunctionSta
     VExpr::close(context, scope);
 }
 
+Status VectorizedFnCall::evaluate_inverted_index(VExprContext* context,
+                                                 uint32_t segment_num_rows) 
const {
+    DCHECK_GE(get_num_children(), 1);
+    if (get_child(0)->is_slot_ref()) {
+        auto* column_slot_ref = assert_cast<VSlotRef*>(get_child(0).get());
+        auto* iter =
+                
context->get_inverted_index_iterators_by_column_name(column_slot_ref->expr_name());
+        //column does not have inverted index
+        if (iter == nullptr) {
+            return Status::OK();
+        }
+        auto result_bitmap = segment_v2::InvertedIndexResultBitmap();
+        auto storage_name_type =
+                
context->get_storage_name_and_type_by_column_name(column_slot_ref->expr_name());
+        vectorized::ColumnsWithTypeAndName arguments;
+        for (int right_children_size = get_num_children() - 1; 
right_children_size > 0;
+             --right_children_size) {
+            if (get_child(right_children_size)->is_literal()) {
+                auto* column_literal = 
assert_cast<VLiteral*>(get_child(right_children_size).get());
+                arguments.emplace_back(column_literal->get_column_ptr(),
+                                       column_literal->get_data_type(),
+                                       column_literal->expr_name());
+
+            } else {
+                return Status::NotSupported(
+                        "arguments in evaluate_inverted_index for 
VectorizedFnCall must be "
+                        "literal, but we got {}",
+                        get_child(right_children_size)->expr_name());
+            }
+        }
+        RETURN_IF_ERROR(_function->evaluate_inverted_index(arguments, 
storage_name_type, iter,
+                                                           segment_num_rows, 
result_bitmap));
+        result_bitmap.mask_out_null();
+        context->set_inverted_index_result_for_expr(this, result_bitmap);
+        LOG(ERROR) << "expr " << _expr_name << " " << this << " 
evaluate_inverted_index result:"

Review Comment:
   DEBUG



##########
be/src/vec/exprs/vectorized_fn_call.cpp:
##########
@@ -189,17 +246,12 @@ Status 
VectorizedFnCall::_do_execute(doris::vectorized::VExprContext* context,
     size_t num_columns_without_result = block->columns();
     // prepare a column to save result
     block->insert({nullptr, _data_type, _expr_name});
-    if (_can_fast_execute) {
-        auto can_fast_execute = fast_execute(*block, args, 
num_columns_without_result,
-                                             block->rows(), 
_function->get_name());
-        if (can_fast_execute) {
-            *result_column_id = num_columns_without_result;
-            return Status::OK();
-        }
-    }
     RETURN_IF_ERROR(_function->execute(context->fn_context(_fn_context_index), 
*block, args,
                                        num_columns_without_result, 
block->rows(), false));
     *result_column_id = num_columns_without_result;
+    auto result_column = 
block->get_by_position(num_columns_without_result).column;
+    LOG(WARNING) << "no hit result expr name:" << _expr_name

Review Comment:
   DEBUG



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to