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 columns_to_read contains _tidb_rowid #7283

Merged
merged 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,14 @@ std::tuple<Names, NamesAndTypes, std::vector<ExtraCastAfterTSMode>> DAGStorageIn
required_columns_tmp.emplace_back(std::move(name));
}

std::unordered_set<String> col_name_set;
std::unordered_set<ColumnID> col_id_set;
for (const auto & expr : table_scan.getPushedDownFilters())
{
getColumnNamesFromExpr(expr, source_columns_tmp, col_name_set);
getColumnIDsFromExpr(expr, table_scan.getColumns(), col_id_set);
}
for (const auto & col : table_scan.getColumns())
{
if (col_name_set.contains(col.name))
if (col_id_set.contains(col.id))
{
need_cast_column.push_back(ExtraCastAfterTSMode::None);
}
Expand Down
36 changes: 31 additions & 5 deletions dbms/src/Flash/Coprocessor/DAGUtils.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include <Functions/FunctionHelpers.h>
#include <Interpreters/Context.h>
#include <Storages/Transaction/Datum.h>
#include <Storages/Transaction/TiDB.h>
#include <Storages/Transaction/TypeMapping.h>

#include <unordered_map>
namespace DB
Expand Down Expand Up @@ -1141,20 +1139,48 @@ String getColumnNameForColumnExpr(const tipb::Expr & expr, const std::vector<Nam
return input_col[column_index].name;
}

void getColumnNamesFromExpr(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col, std::unordered_set<String> & col_name_set)
ColumnID getColumnIDForColumnExpr(const tipb::Expr & expr, const std::vector<ColumnInfo> & input_col)
{
auto column_index = decodeDAGInt64(expr.val());
if (column_index < 0 || column_index >= static_cast<Int64>(input_col.size()))
{
throw TiFlashException("Column index out of bound", Errors::Coprocessor::BadRequest);
Copy link
Contributor

@JaySon-Huang JaySon-Huang Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show the expr.ShortDebugString() and input_col.size() when error happen

}
return input_col[column_index].id;
}

void getColumnIDsFromExpr(const tipb::Expr & expr, const std::vector<ColumnInfo> & input_col, std::unordered_set<ColumnID> & col_id_set)
{
if (expr.children_size() == 0)
{
if (isColumnExpr(expr))
{
col_id_set.insert(getColumnIDForColumnExpr(expr, input_col));
}
}
else
{
for (const auto & child : expr.children())
{
getColumnIDsFromExpr(child, input_col, col_id_set);
}
}
}

void getColumnNamesFromExpr(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col, std::unordered_set<String> & col_id_set)
{
if (expr.children_size() == 0)
{
if (isColumnExpr(expr))
{
col_name_set.insert(getColumnNameForColumnExpr(expr, input_col));
col_id_set.insert(getColumnNameForColumnExpr(expr, input_col));
}
}
else
{
for (const auto & child : expr.children())
{
getColumnNamesFromExpr(child, input_col, col_name_set);
getColumnNamesFromExpr(child, input_col, col_id_set);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Core/SortDescription.h>
#include <Storages/Transaction/Collator.h>
#include <Storages/Transaction/TiDB.h>
#include <Storages/Transaction/TypeMapping.h>
#include <Storages/Transaction/Types.h>
#include <grpcpp/impl/codegen/status_code_enum.h>
#include <tipb/executor.pb.h>
Expand All @@ -46,7 +47,8 @@ String getFieldTypeName(Int32 tp);
String getJoinExecTypeName(const tipb::JoinExecType & tp);
bool isColumnExpr(const tipb::Expr & expr);
String getColumnNameForColumnExpr(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col);
void getColumnNamesFromExpr(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col, std::unordered_set<String> & col_name_set);
void getColumnIDsFromExpr(const tipb::Expr & expr, const std::vector<ColumnInfo> & input_col, std::unordered_set<ColumnID> & col_id_set);
void getColumnNamesFromExpr(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col, std::unordered_set<String> & col_id_set);
NameAndTypePair getColumnNameAndTypeForColumnExpr(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col);
const String & getTypeName(const tipb::Expr & expr);
String exprToString(const tipb::Expr & expr, const std::vector<NameAndTypePair> & input_col);
Expand Down
19 changes: 18 additions & 1 deletion dbms/src/Storages/StorageDeltaMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,28 @@ DM::PushDownFilterPtr StorageDeltaMerge::parsePushDownFilter(const SelectQueryIn
const auto & table_infos = tidb_table_info.columns;
for (const auto & col : columns_to_read)
{
// table_infos does not contain EXTRA_HANDLE_COLUMN and EXTRA_TABLE_ID_COLUMN
if (col.id == EXTRA_HANDLE_COLUMN_ID)
{
auto handle = ColumnInfo();
handle.id = EXTRA_HANDLE_COLUMN_ID;
handle.name = EXTRA_HANDLE_COLUMN_NAME;
table_scan_column_info.push_back(handle);
continue;
}
else if (col.id == ExtraTableIDColumnID)
{
auto col = ColumnInfo();
col.id = ExtraTableIDColumnID;
col.name = EXTRA_TABLE_ID_COLUMN_NAME;
table_scan_column_info.push_back(col);
continue;
}
auto iter = std::find_if(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better show the col.id and col.name in L783 in case similar problem happen again

auto iter = std::find_if(
table_infos.begin(),
table_infos.end(),
[col](const ColumnInfo & c) -> bool { return c.id == col.id; });
RUNTIME_CHECK(iter != table_infos.end());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also L761

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better show the col.id and col.name in L783 in case similar problem happen again

done

And also L761

columns_to_read will contain extre column, so there is no need to check in L761

table_infos.begin(),
table_infos.end(),
[col](const ColumnInfo & c) -> bool { return c.id == col.id; });
RUNTIME_CHECK(iter != table_infos.end());
RUNTIME_CHECK_MSG(iter != table_infos.end(), "column: [id: {}, name: {}] not found in table info", col.id, col.name);
table_scan_column_info.push_back(*iter);
}

Expand Down