Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] (inverted index) fix the error result in the compound query #41297

Draft
wants to merge 2 commits into
base: branch-2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions be/src/olap/rowset/segment_v2/segment_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,10 @@ bool SegmentIterator::_need_read_data(ColumnId cid) {
// occurring, return true here that column data needs to be read
return true;
}

if (_must_read_data_indices.count(cid)) {
return true;
}
// Check the following conditions:
// 1. If the column represented by the unique ID is an inverted index column (indicated by '_need_read_data_indices.count(unique_id) > 0 && !_need_read_data_indices[unique_id]')
// and it's not marked for projection in '_output_columns'.
Expand Down Expand Up @@ -2517,14 +2521,14 @@ bool SegmentIterator::_check_column_pred_all_push_down(const std::string& column
}

void SegmentIterator::_calculate_pred_in_remaining_conjunct_root(
const vectorized::VExprSPtr& expr) {
const vectorized::VExprSPtr& expr, const vectorized::VExprSPtr& parent) {
if (expr == nullptr) {
return;
}

auto& children = expr->children();
for (int i = 0; i < children.size(); ++i) {
_calculate_pred_in_remaining_conjunct_root(children[i]);
_calculate_pred_in_remaining_conjunct_root(children[i], expr);
}

auto node_type = expr->node_type();
Expand Down Expand Up @@ -2561,6 +2565,10 @@ void SegmentIterator::_calculate_pred_in_remaining_conjunct_root(
}

if (!_column_predicate_info->is_empty()) {
if (parent != nullptr && parent->node_type() != TExprNodeType::COMPOUND_PRED) {
int cid = _opts.tablet_schema->field_index(_column_predicate_info->column_name);
_must_read_data_indices.insert(cid);
}
_column_pred_in_remaining_vconjunct[_column_predicate_info->column_name].push_back(
*_column_predicate_info);
_column_predicate_info.reset(new ColumnPredicateInfo());
Expand Down Expand Up @@ -2589,6 +2597,10 @@ bool SegmentIterator::_no_need_read_key_data(ColumnId cid, vectorized::MutableCo
return false;
}

if (_must_read_data_indices.count(cid)) {
return false;
}

std::set<uint32_t> cids;
for (auto* pred : _col_predicates) {
cids.insert(pred->column_id());
Expand Down
4 changes: 3 additions & 1 deletion be/src/olap/rowset/segment_v2/segment_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ class SegmentIterator : public RowwiseIterator {
// return true means one column's predicates all pushed down
bool _check_column_pred_all_push_down(const std::string& column_name, bool in_compound = false,
bool is_match = false);
void _calculate_pred_in_remaining_conjunct_root(const vectorized::VExprSPtr& expr);
void _calculate_pred_in_remaining_conjunct_root(const vectorized::VExprSPtr& expr,
const vectorized::VExprSPtr& parent = nullptr);

// todo(wb) remove this method after RowCursor is removed
void _convert_rowcursor_to_short_key(const RowCursor& key, size_t num_keys) {
Expand Down Expand Up @@ -369,6 +370,7 @@ class SegmentIterator : public RowwiseIterator {
_short_cir_pred_column_ids; // keep columnId of columns for short circuit predicate evaluation
std::vector<bool> _is_pred_column; // columns hold _init segmentIter
std::map<uint32_t, bool> _need_read_data_indices;
std::unordered_set<uint32_t> _must_read_data_indices;
std::vector<bool> _is_common_expr_column;
vectorized::MutableColumns _current_return_columns;
std::vector<ColumnPredicate*> _pre_eval_block_predicate;
Expand Down
3 changes: 1 addition & 2 deletions be/src/olap/task/engine_storage_migration_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
#ifndef DORIS_BE_SRC_OLAP_TASK_ENGINE_STORAGE_MIGRATION_TASK_H
#define DORIS_BE_SRC_OLAP_TASK_ENGINE_STORAGE_MIGRATION_TASK_H

#include <stdint.h>

#include <gen_cpp/olap_file.pb.h>
csun5285 marked this conversation as resolved.
Show resolved Hide resolved
#include <stdint.h>

#include <mutex>
#include <shared_mutex>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
2

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("test_index_rqg_bug7", "test_index_rqg_bug"){
def table = "test_index_rqg_bug7"

sql "drop table if exists ${table}"

sql """
create table ${table} (
pk int,
col_int_undef_signed int null ,
col_int_undef_signed_not_null_index_inverted int not null ,
INDEX col_int_undef_signed_not_null_index_inverted_idx (`col_int_undef_signed_not_null_index_inverted`) USING INVERTED
) engine=olap
DUPLICATE KEY(pk)
distributed by hash(pk) buckets 10
properties("replication_num" = "1");
"""

sql """ insert into ${table} values (1, 7, 7), (2, 7, -2), (3, 4, -2)"""


sql """ sync"""
sql """ set enable_inverted_index_query = true """
sql """ set inverted_index_skip_threshold = 0 """
sql """ set enable_no_need_read_data_opt = true """
qt_sql """
select count(*) from ${table} where col_int_undef_signed_not_null_index_inverted = -2 AND ((CASE WHEN col_int_undef_signed_not_null_index_inverted = -2 THEN 1 ELSE NULL END = 1) OR col_int_undef_signed != 7);
"""
}
Loading