Skip to content

Commit

Permalink
*: Refine TiDBTableScan (#6448)
Browse files Browse the repository at this point in the history
ref #6233
  • Loading branch information
Lloyd-Pottiger authored Dec 8, 2022
1 parent 966e7e2 commit 1a69ba8
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ String DAGExpressionAnalyzer::appendTimeZoneCast(
bool DAGExpressionAnalyzer::buildExtraCastsAfterTS(
const ExpressionActionsPtr & actions,
const std::vector<ExtraCastAfterTSMode> & need_cast_column,
const ::google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & table_scan_columns)
const ColumnInfos & table_scan_columns)
{
bool has_cast = false;

Expand All @@ -867,9 +867,9 @@ bool DAGExpressionAnalyzer::buildExtraCastsAfterTS(

if (need_cast_column[i] == ExtraCastAfterTSMode::AppendDurationCast)
{
if (table_scan_columns[i].decimal() > 6)
if (table_scan_columns[i].decimal > 6)
throw Exception("fsp must <= 6", ErrorCodes::LOGICAL_ERROR);
auto fsp = table_scan_columns[i].decimal() < 0 ? 0 : table_scan_columns[i].decimal();
const auto fsp = table_scan_columns[i].decimal < 0 ? 0 : table_scan_columns[i].decimal;
tipb::Expr fsp_expr = constructInt64LiteralTiExpr(fsp);
fsp_col = getActions(fsp_expr, actions);
String casted_name = appendDurationCast(fsp_col, source_columns[i].name, dur_func_name, actions);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class DAGExpressionAnalyzer : private boost::noncopyable
bool buildExtraCastsAfterTS(
const ExpressionActionsPtr & actions,
const std::vector<ExtraCastAfterTSMode> & need_cast_column,
const ::google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & table_scan_columns);
const ColumnInfos & table_scan_columns);

std::pair<bool, Names> buildJoinKey(
const ExpressionActionsPtr & actions,
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ std::tuple<Names, NamesAndTypes, std::vector<ExtraCastAfterTSMode>> DAGStorageIn
for (Int32 i = 0; i < table_scan.getColumnSize(); ++i)
{
auto const & ci = table_scan.getColumns()[i];
ColumnID cid = ci.column_id();
const ColumnID cid = ci.id;

// Column ID -1 return the handle column
String name;
Expand All @@ -1062,9 +1062,9 @@ std::tuple<Names, NamesAndTypes, std::vector<ExtraCastAfterTSMode>> DAGStorageIn
source_columns_tmp.emplace_back(std::move(pair));
}
required_columns_tmp.emplace_back(std::move(name));
if (cid != -1 && ci.tp() == TiDB::TypeTimestamp)
if (cid != -1 && ci.tp == TiDB::TypeTimestamp)
need_cast_column.push_back(ExtraCastAfterTSMode::AppendTimeZoneCast);
else if (cid != -1 && ci.tp() == TiDB::TypeTime)
else if (cid != -1 && ci.tp == TiDB::TypeTime)
need_cast_column.push_back(ExtraCastAfterTSMode::AppendDurationCast);
else
need_cast_column.push_back(ExtraCastAfterTSMode::None);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NamesAndTypes genNamesAndTypes(const TiDBTableScan & table_scan, const StringRef
names_and_types.reserve(table_scan.getColumnSize());
for (Int32 i = 0; i < table_scan.getColumnSize(); ++i)
{
auto column_info = TiDB::toTiDBColumnInfo(table_scan.getColumns()[i]);
const auto column_info = table_scan.getColumns()[i];
switch (column_info.id)
{
case TiDBPkColumnID:
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/RemoteRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ RemoteRequest RemoteRequest::build(
for (int i = 0; i < table_scan.getColumnSize(); ++i)
{
const auto & col = table_scan.getColumns()[i];
auto col_id = col.column_id();
auto col_id = col.id;

if (col_id == DB::TiDBPkColumnID)
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/TiDBTableScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TiDBTableScan::TiDBTableScan(
: table_scan(table_scan_)
, executor_id(executor_id_)
, is_partition_table_scan(table_scan->tp() == tipb::TypePartitionTableScan)
, columns(is_partition_table_scan ? table_scan->partition_table_scan().columns() : table_scan->tbl_scan().columns())
, columns(is_partition_table_scan ? std::move(TiDB::toTiDBColumnInfos(table_scan->partition_table_scan().columns())) : std::move(TiDB::toTiDBColumnInfos(table_scan->tbl_scan().columns())))
// Only No-partition table need keep order when tablescan executor required keep order.
// If keep_order is not set, keep order for safety.
, keep_order(!is_partition_table_scan && (table_scan->tbl_scan().keep_order() || !table_scan->tbl_scan().has_keep_order()))
Expand Down
7 changes: 5 additions & 2 deletions dbms/src/Flash/Coprocessor/TiDBTableScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

namespace DB
{

using ColumnInfos = std::vector<TiDB::ColumnInfo>;

/// TiDBTableScan is a wrap to hide the difference of `TableScan` and `PartitionTableScan`
class TiDBTableScan
{
Expand All @@ -34,7 +37,7 @@ class TiDBTableScan
{
return columns.size();
}
const google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & getColumns() const
const ColumnInfos & getColumns() const
{
return columns;
}
Expand Down Expand Up @@ -65,7 +68,7 @@ class TiDBTableScan
const tipb::Executor * table_scan;
String executor_id;
bool is_partition_table_scan;
const google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & columns;
const ColumnInfos columns;
/// logical_table_id is the table id for a TiDB' table, while if the
/// TiDB table is partition, each partition is a physical table, and
/// the partition's table id is the physical table id.
Expand Down
9 changes: 9 additions & 0 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,4 +1143,13 @@ ColumnInfo toTiDBColumnInfo(const tipb::ColumnInfo & tipb_column_info)
return tidb_column_info;
}

std::vector<ColumnInfo> toTiDBColumnInfos(const ::google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & tipb_column_infos)
{
std::vector<ColumnInfo> tidb_column_infos;
tidb_column_infos.reserve(tipb_column_infos.size());
for (const auto & tipb_column_info : tipb_column_infos)
tidb_column_infos.emplace_back(toTiDBColumnInfo(tipb_column_info));
return tidb_column_infos;
}

} // namespace TiDB
1 change: 1 addition & 0 deletions dbms/src/Storages/Transaction/TiDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,6 @@ String genJsonNull();
tipb::FieldType columnInfoToFieldType(const ColumnInfo & ci);
ColumnInfo fieldTypeToColumnInfo(const tipb::FieldType & field_type);
ColumnInfo toTiDBColumnInfo(const tipb::ColumnInfo & tipb_column_info);
std::vector<ColumnInfo> toTiDBColumnInfos(const ::google::protobuf::RepeatedPtrField<tipb::ColumnInfo> & tipb_column_infos);

} // namespace TiDB

0 comments on commit 1a69ba8

Please sign in to comment.