From 7cb240c9e86ff4cecdeb7cba40a373556f7f4738 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger <60744015+Lloyd-Pottiger@users.noreply.github.com> Date: Mon, 27 May 2024 14:04:19 +0800 Subject: [PATCH] *: fix tipb::ColumnInfo to TiDB::ColumnInfo (#9086) close pingcap/tiflash#9084 fix the issue that query result may be wrong when query missing columns with default value in Disaggrate TiFlash. Signed-off-by: Lloyd-Pottiger Co-authored-by: JaySon --- dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp | 2 +- dbms/src/TiDB/Schema/TiDB.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp b/dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp index fa2a438efd6..94046daae2c 100644 --- a/dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp +++ b/dbms/src/Flash/Coprocessor/GenSchemaAndColumn.cpp @@ -18,6 +18,7 @@ #include #include + namespace DB { namespace @@ -121,7 +122,6 @@ std::tuple genColumnDefinesForDisaggregatedRead(const break; } default: - // TODO: Is it ok to use the default value here? column_defines->emplace_back(DM::ColumnDefine{ column_info.id, output_name, diff --git a/dbms/src/TiDB/Schema/TiDB.cpp b/dbms/src/TiDB/Schema/TiDB.cpp index 78709fefdc3..9d3f143251a 100644 --- a/dbms/src/TiDB/Schema/TiDB.cpp +++ b/dbms/src/TiDB/Schema/TiDB.cpp @@ -1264,6 +1264,11 @@ ColumnInfo toTiDBColumnInfo(const tipb::ColumnInfo & tipb_column_info) tidb_column_info.flag = tipb_column_info.flag(); tidb_column_info.flen = tipb_column_info.columnlen(); tidb_column_info.decimal = tipb_column_info.decimal(); + // TiFlash get default value from origin_default_value, check `Field ColumnInfo::defaultValueToField() const` + // So we need to set origin_default_value to tipb_column_info.default_val() + // Related logic in tidb, https://github.com/pingcap/tidb/blob/45318da24d8e4c0c6aab836d291a33f949dd18bf/pkg/table/tables/tables.go#L2303-L2329 + tidb_column_info.origin_default_value = tipb_column_info.default_val(); + tidb_column_info.collate = tipb_column_info.collation(); for (int i = 0; i < tipb_column_info.elems_size(); ++i) tidb_column_info.elems.emplace_back(tipb_column_info.elems(i), i + 1); return tidb_column_info;