Skip to content

Commit

Permalink
*: Refine include of TiDB.h to speedup re-compiling (#9338)
Browse files Browse the repository at this point in the history
ref #6233

*: Refine include of TiDB.h to speedup re-compiling

  * Split `TiDB_fwd.h`, `TiDBTypes.h`
  * Include `TiDB.h`, `TypeMapping.h` in .cpp files instead of .h files as possible to reduce the re-compiling involve files
  • Loading branch information
JaySon-Huang authored Aug 21, 2024
1 parent 5500b35 commit cf5a204
Show file tree
Hide file tree
Showing 108 changed files with 436 additions and 296 deletions.
1 change: 1 addition & 0 deletions dbms/src/DataStreams/MockExchangeReceiverInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <DataStreams/MockExchangeReceiverInputStream.h>
#include <Flash/Coprocessor/ChunkCodec.h>
#include <TiDB/Decode/TypeMapping.h>

namespace DB
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataStreams/RuntimeFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool RuntimeFilter::updateStatus(RuntimeFilterStatus status_, const std::string
}

void RuntimeFilter::setTargetAttr(
const DM::ColumnInfos & scan_column_infos,
const TiDB::ColumnInfos & scan_column_infos,
const DM::ColumnDefines & table_column_defines)
{
target_attr = DM::FilterParser::createAttr(target_expr, scan_column_infos, table_column_defines);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataStreams/RuntimeFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RuntimeFilter

bool await(int64_t ms_remaining);

void setTargetAttr(const DM::ColumnInfos & scan_column_infos, const DM::ColumnDefines & table_column_defines);
void setTargetAttr(const TiDB::ColumnInfos & scan_column_infos, const DM::ColumnDefines & table_column_defines);
DM::RSOperatorPtr parseToRSOperator();

const int id;
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Debug/MockExecutor/AstToPB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

namespace DB
{
void literalFieldToTiPBExpr(const ColumnInfo & ci, const Field & val_field, tipb::Expr * expr, Int32 collator_id)
void literalFieldToTiPBExpr(const TiDB::ColumnInfo & ci, const Field & val_field, tipb::Expr * expr, Int32 collator_id)
{
*(expr->mutable_field_type()) = columnInfoToFieldType(ci);
expr->mutable_field_type()->set_collate(collator_id);
Expand Down Expand Up @@ -126,7 +126,7 @@ void literalFieldToTiPBExpr(const ColumnInfo & ci, const Field & val_field, tipb
void literalToPB(tipb::Expr * expr, const Field & value, int32_t collator_id)
{
DataTypePtr type = applyVisitor(FieldToDataType(), value);
ColumnInfo ci = reverseGetColumnInfo({"", type}, 0, Field(), true);
TiDB::ColumnInfo ci = reverseGetColumnInfo({"", type}, 0, Field(), true);
literalFieldToTiPBExpr(ci, value, expr, collator_id);
}

Expand Down Expand Up @@ -694,7 +694,7 @@ TiDB::ColumnInfo compileExpr(const DAGSchema & input, ASTPtr ast)
}
}

void compileFilter(const DAGSchema & input, ASTPtr ast, std::vector<ASTPtr> & conditions)
void compileFilter(const DAGSchema & input, ASTPtr ast, ASTs & conditions)
{
if (auto * func = typeid_cast<ASTFunction *>(ast.get()))
{
Expand Down
7 changes: 4 additions & 3 deletions dbms/src/Debug/MockExecutor/AstToPB.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#pragma once

#include <Flash/Coprocessor/ChunkCodec.h>
#include <TiDB/Schema/TiDB.h>
#include <Parsers/IAST_fwd.h>
#include <TiDB/Schema/TiDB_fwd.h>
#include <kvproto/mpp.pb.h>

namespace DB
Expand Down Expand Up @@ -86,7 +87,7 @@ struct TaskMeta
};

using TaskMetas = std::vector<TaskMeta>;
void literalFieldToTiPBExpr(const ColumnInfo & ci, const Field & field, tipb::Expr * expr, Int32 collator_id);
void literalFieldToTiPBExpr(const TiDB::ColumnInfo & ci, const Field & field, tipb::Expr * expr, Int32 collator_id);
void literalToPB(tipb::Expr * expr, const Field & value, int32_t collator_id);
String getFunctionNameForConstantFolding(tipb::Expr * expr);
void foldConstant(tipb::Expr * expr, int32_t collator_id, const Context & context);
Expand All @@ -100,7 +101,7 @@ void identifierToPB(const DAGSchema & input, ASTIdentifier * id, tipb::Expr * ex
void astToPB(const DAGSchema & input, ASTPtr ast, tipb::Expr * expr, int32_t collator_id, const Context & context);
void collectUsedColumnsFromExpr(const DAGSchema & input, ASTPtr ast, std::unordered_set<String> & used_columns);
TiDB::ColumnInfo compileExpr(const DAGSchema & input, ASTPtr ast);
void compileFilter(const DAGSchema & input, ASTPtr ast, std::vector<ASTPtr> & conditions);
void compileFilter(const DAGSchema & input, ASTPtr ast, ASTs & conditions);
void fillTaskMetaWithMPPInfo(mpp::TaskMeta & task_meta, const MPPInfo & mpp_info);

} // namespace DB
9 changes: 5 additions & 4 deletions dbms/src/Debug/MockExecutor/ExpandBinder2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/ExpandBinder2.h>
#include <Parsers/ASTAsterisk.h>
#include <Parsers/IAST_fwd.h>


namespace DB::mock
Expand Down Expand Up @@ -56,17 +57,17 @@ bool ExpandBinder2::toTiPBExecutor(
ExecutorBinderPtr compileExpand2(
ExecutorBinderPtr input,
size_t & executor_index,
ASTPtrVec level_select_list,
ASTs level_select_list,
std::vector<String> output_names,
std::vector<tipb::FieldType> fts)
{
DAGSchema output_schema;
std::vector<std::vector<ASTPtr>> expand_exprs;
std::vector<ASTs> expand_exprs;
auto input_col_size = input->output_schema.size();
for (size_t i = 0; i < level_select_list.size(); i++)
{
auto level_proj = level_select_list[i];
std::vector<ASTPtr> level_exprs;
ASTs level_exprs;
for (size_t j = 0; j < level_proj->children.size(); j++)
{
auto expr = level_proj->children[j];
Expand All @@ -85,7 +86,7 @@ ExecutorBinderPtr compileExpand2(
// base col ref (since ast can't derive the expression's field type, use the test injected one)
if (ft->second.hasNotNullFlag() && (fts[j].flag() & TiDB::ColumnFlagNotNull) == 0)
{
ColumnInfo ci;
TiDB::ColumnInfo ci;
ci.flag = ft->second.flag;
ci.tp = ft->second.tp;
ci.name = ft->second.name;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/MockExecutor/ExpandBinder2.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ExpandBinder2 : public ExecutorBinder
ExecutorBinderPtr compileExpand2(
ExecutorBinderPtr input,
size_t & executor_index,
std::vector<ASTPtr> level_select_list,
ASTs level_select_list,
std::vector<String> output_names,
std::vector<tipb::FieldType> fts);
} // namespace DB::mock
7 changes: 4 additions & 3 deletions dbms/src/Debug/MockExecutor/TableScanBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <Debug/MockExecutor/ExecutorBinder.h>
#include <Debug/MockExecutor/TableScanBinder.h>
#include <Storages/MutableSupport.h>
#include <TiDB/Schema/TiDB.h>

namespace DB::mock
{
Expand Down Expand Up @@ -114,7 +115,7 @@ void TableScanBinder::buildTable(tipb::Executor * tipb_executor)

ExecutorBinderPtr compileTableScan(
size_t & executor_index,
TableInfo & table_info,
TiDB::TableInfo & table_info,
const String & db,
const String & table_name,
bool append_pk_column,
Expand All @@ -123,7 +124,7 @@ ExecutorBinderPtr compileTableScan(
DAGSchema ts_output;
for (const auto & column_info : table_info.columns)
{
ColumnInfo ci;
TiDB::ColumnInfo ci;
ci.id = column_info.id;
ci.tp = column_info.tp;
ci.flag = column_info.flag;
Expand All @@ -139,7 +140,7 @@ ExecutorBinderPtr compileTableScan(
}
if (append_pk_column)
{
ColumnInfo ci;
TiDB::ColumnInfo ci;
ci.tp = TiDB::TypeLongLong;
ci.id = TiDBPkColumnID;
ci.setPriKeyFlag();
Expand Down
12 changes: 8 additions & 4 deletions dbms/src/Debug/MockExecutor/TableScanBinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@

namespace DB::mock
{
using TableInfo = TiDB::TableInfo;

class TableScanBinder : public ExecutorBinder
{
public:
TableScanBinder(size_t & index_, const DAGSchema & output_schema_, const TableInfo & table_info_, bool keep_order_)
TableScanBinder(
size_t & index_,
const DAGSchema & output_schema_,
const TiDB::TableInfo & table_info_,
bool keep_order_)
: ExecutorBinder(index_, "table_scan_" + std::to_string(index_), output_schema_)
, table_info(table_info_)
, keep_order(keep_order_)
Expand All @@ -47,7 +51,7 @@ class TableScanBinder : public ExecutorBinder
TableID getTableId() const;

private:
TableInfo table_info; /// used by column pruner
TiDB::TableInfo table_info; /// used by column pruner
bool keep_order;
std::vector<int> rf_ids;

Expand All @@ -59,7 +63,7 @@ class TableScanBinder : public ExecutorBinder

ExecutorBinderPtr compileTableScan(
size_t & executor_index,
TableInfo & table_info,
TiDB::TableInfo & table_info,
const String & db,
const String & table_name,
bool append_pk_column,
Expand Down
8 changes: 5 additions & 3 deletions dbms/src/Debug/MockStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,9 @@ CutColumnInfo getCutColumnInfo(size_t rows, Int64 partition_id, Int64 partition_
return {start, cur_rows};
}

ColumnsWithTypeAndName getUsedColumns(const ColumnInfos & used_columns, const ColumnsWithTypeAndName & all_columns)
ColumnsWithTypeAndName getUsedColumns(
const TiDB::ColumnInfos & used_columns,
const ColumnsWithTypeAndName & all_columns)
{
if (used_columns.empty())
/// if used columns is not set, just return all the columns
Expand Down Expand Up @@ -585,10 +587,10 @@ DM::ColumnDefines MockStorage::getStoreColumnDefines(Int64 table_id)
return storage_delta_merge_map[table_id]->getStoreColumnDefines();
}

ColumnInfos mockColumnInfosToTiDBColumnInfos(const MockColumnInfoVec & mock_column_infos)
TiDB::ColumnInfos mockColumnInfosToTiDBColumnInfos(const MockColumnInfoVec & mock_column_infos)
{
ColumnID col_id = 0;
ColumnInfos ret;
TiDB::ColumnInfos ret;
ret.reserve(mock_column_infos.size());
for (const auto & mock_column_info : mock_column_infos)
{
Expand Down
8 changes: 5 additions & 3 deletions dbms/src/Debug/MockStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <Flash/Pipeline/Exec/PipelineExecBuilder.h>
#include <Operators/Operator.h>
#include <Storages/DeltaMerge/ColumnDefine_fwd.h>
#include <TiDB/Schema/TiDB.h>
#include <TiDB/Schema/TiDB_fwd.h>
#include <common/types.h>

#include <atomic>
Expand Down Expand Up @@ -54,8 +54,10 @@ class MockTableIdGenerator : public ext::Singleton<MockTableIdGenerator>
std::atomic<Int64> current_id = 0;
};

ColumnInfos mockColumnInfosToTiDBColumnInfos(const MockColumnInfoVec & mock_column_infos);
ColumnsWithTypeAndName getUsedColumns(const ColumnInfos & used_columns, const ColumnsWithTypeAndName & all_columns);
TiDB::ColumnInfos mockColumnInfosToTiDBColumnInfos(const MockColumnInfoVec & mock_column_infos);
ColumnsWithTypeAndName getUsedColumns(
const TiDB::ColumnInfos & used_columns,
const ColumnsWithTypeAndName & all_columns);

/** Responsible for mock data for executor tests and mpp tests.
* 1. Use this class to add mock table schema and table column data.
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgFuncCoprocessorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DAGSchema getSelectSchema(Context & context)
auto result_field_types = dag_context->result_field_types;
for (size_t i = 0; i < result_field_types.size(); ++i)
{
ColumnInfo info = TiDB::fieldTypeToColumnInfo(result_field_types[i]);
TiDB::ColumnInfo info = TiDB::fieldTypeToColumnInfo(result_field_types[i]);
String col_name = "col_" + std::to_string(i);
schema.emplace_back(col_name, info);
}
Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Debug/dbgKVStore/dbgFuncInvestigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ void dbgFuncFindKey(Context & context, const ASTs & args, DBGInvoker::Printer ou
"start_col, [, start_col2, ..., end_col1, end_col2, ...]",
arg_size);
}
size_t handle_column_size = table_info.is_common_handle ? table_info.getPrimaryIndexInfo().idx_cols.size() : 1;
auto key_size = arg_size / 2;
std::vector<Field> start_field;
start_field.reserve(key_size);
std::vector<Field> end_field;
end_field.reserve(key_size);

for (size_t i = 0; i < handle_column_size; i++)
const auto & pk_index = table_info.getPrimaryIndexInfo();
for (size_t i = 0; i < pk_index.idx_cols.size(); i++)
{
auto & column_info = table_info.columns[table_info.getPrimaryIndexInfo().idx_cols[i].offset];
auto & column_info = table_info.columns[pk_index.idx_cols[i].offset];
auto start_datum = TiDB::DatumBumpy(
RegionBench::convertField(column_info, typeid_cast<const ASTLiteral &>(*args[OFFSET + i]).value),
column_info.tp);
Expand Down Expand Up @@ -305,4 +305,4 @@ BlockInputStreamPtr dbgFuncFindKeyDt(Context & context, const ASTs & args)
}


} // namespace DB
} // namespace DB
4 changes: 2 additions & 2 deletions dbms/src/Debug/dbgKVStore/dbgFuncMockRaftSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ RegionPtr GenDbgRegionSnapshotWithData(Context & context, const ASTs & args)
if (is_common_handle)
{
std::vector<Field> keys; // handle key
for (size_t i = 0; i < table_info.getPrimaryIndexInfo().idx_cols.size(); i++)
const auto & pk_index = table_info.getPrimaryIndexInfo();
for (const auto & idx_col : pk_index.idx_cols)
{
auto & idx_col = table_info.getPrimaryIndexInfo().idx_cols[i];
auto & column_info = table_info.columns[idx_col.offset];
auto start_field = RegionBench::convertField(column_info, fields[idx_col.offset]);
TiDB::DatumBumpy start_datum = TiDB::DatumBumpy(start_field, column_info.tp);
Expand Down
3 changes: 0 additions & 3 deletions dbms/src/Debug/dbgNaturalDag.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include <kvproto/coprocessor.pb.h>
#include <kvproto/mpp.pb.h>

#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>

namespace DB
Expand Down
5 changes: 2 additions & 3 deletions dbms/src/Debug/dbgTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,9 @@ void insert( //
if (table_info.is_common_handle)
{
std::vector<Field> keys;

for (size_t i = 0; i < table_info.getPrimaryIndexInfo().idx_cols.size(); i++)
const auto & pk_index = table_info.getPrimaryIndexInfo();
for (const auto & idx_col : pk_index.idx_cols)
{
const auto & idx_col = table_info.getPrimaryIndexInfo().idx_cols[i];
const auto & column_info = table_info.columns[idx_col.offset];
auto start_field = RegionBench::convertField(column_info, fields[idx_col.offset]);
TiDB::DatumBumpy start_datum = TiDB::DatumBumpy(start_field, column_info.tp);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <Storages/DeltaMerge/DeltaMergeInterfaces.h>
#include <Storages/KVStore/Decode/DecodedTiKVKeyValue.h>
#include <Storages/KVStore/FFI/ProxyFFI.h>
#include <TiDB/Schema/TiDB.h>
#include <TiDB/Schema/TiDB_fwd.h>
#include <kvproto/raft_cmdpb.pb.h>

#include <optional>
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Flash/Coprocessor/ArrowChunkCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Flash/Coprocessor/ArrowChunkCodec.h>
#include <Flash/Coprocessor/ArrowColCodec.h>
#include <IO/copyData.h>
#include <TiDB/Decode/TypeMapping.h>

namespace DB
{
Expand Down
4 changes: 4 additions & 0 deletions dbms/src/Flash/Coprocessor/ArrowColCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
#include <Flash/Coprocessor/DAGUtils.h>
#include <Functions/FunctionHelpers.h>
#include <IO/copyData.h>
#include <TiDB/Decode/TypeMapping.h>
#include <TiDB/Schema/TiDB.h>

namespace DB
{
using TiDB::ColumnInfo;

namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
Expand Down
3 changes: 1 addition & 2 deletions dbms/src/Flash/Coprocessor/ArrowColCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#pragma once

#include <Flash/Coprocessor/TiDBColumn.h>
#include <TiDB/Decode/TypeMapping.h>

namespace DB
{
Expand All @@ -32,7 +31,7 @@ const char * arrowColToFlashCol(
const std::vector<UInt8> & null_bitmap,
const std::vector<UInt64> & offsets,
const ColumnWithTypeAndName & flash_col,
const ColumnInfo & col_info,
const TiDB::ColumnInfo & col_info,
UInt32 length);

} // namespace DB
1 change: 1 addition & 0 deletions dbms/src/Flash/Coprocessor/CHBlockChunkCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Flash/Coprocessor/CHBlockChunkCodec.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <IO/Buffer/ReadBufferFromString.h>
#include <TiDB/Decode/TypeMapping.h>

namespace DB
{
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Flash/Coprocessor/CHBlockChunkCodecV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <IO/Buffer/ReadBufferFromString.h>
#include <IO/Compression/CompressionCodecFactory.h>
#include <IO/Compression/CompressionInfo.h>
#include <IO/ReadHelpers.h>
#include <IO/VarInt.h>
#include <IO/WriteHelpers.h>

namespace DB
{
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Flash/Coprocessor/ChunkCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#pragma once

#include <Core/Block.h>
#include <TiDB/Decode/TypeMapping.h>
#include <TiDB/Schema/TiDB.h>
#include <tipb/select.pb.h>

namespace DB
{
using DAGColumnInfo = std::pair<String, ColumnInfo>;
using DAGColumnInfo = std::pair<String, TiDB::ColumnInfo>;
using DAGSchema = std::vector<DAGColumnInfo>;

class ChunkCodecStream
Expand Down
Loading

0 comments on commit cf5a204

Please sign in to comment.