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

The DataType instances are not shared when creating by TiDB::ColumnInfo #9991

Open
JaySon-Huang opened this issue Mar 11, 2025 · 0 comments
Open
Assignees
Labels

Comments

@JaySon-Huang
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

2. What did you expect to see? (Required)

3. What did you see instead (Required)

The way TiFlash handle newly create table is:

std::tuple<NamesAndTypes, Strings> parseColumnsFromTableInfo(const TiDB::TableInfo & table_info)
{
NamesAndTypes columns;
std::vector<String> primary_keys;
for (const auto & column : table_info.columns)
{
DataTypePtr type = getDataTypeByColumnInfo(column);
columns.emplace_back(column.name, type);
if (column.hasPriKeyFlag())
{
primary_keys.emplace_back(column.name);
}
}
if (!table_info.pk_is_handle)
{
// Make primary key as a column, and make the handle column as the primary key.
if (table_info.is_common_handle)
columns.emplace_back(MutSup::extra_handle_column_name, std::make_shared<DataTypeString>());
else
columns.emplace_back(MutSup::extra_handle_column_name, std::make_shared<DataTypeInt64>());
primary_keys.clear();
primary_keys.emplace_back(MutSup::extra_handle_column_name);
}
return std::make_tuple(std::move(columns), std::move(primary_keys));
}

// Get the data type according to column_info, respecting
// the nullable flag.
// This does not support the "duration" type.
DataTypePtr getDataTypeByColumnInfo(const ColumnInfo & column_info)
{
DataTypePtr base = TypeMapping::instance().getDataType(column_info);
if (!column_info.hasNotNullFlag())
{
return std::make_shared<DataTypeNullable>(base);
}
return base;
}

template <typename T>
std::enable_if_t<
!IsSignedType<T> && !IsDecimalType<T> && !IsEnumType<T> && !std::is_same_v<T, DataTypeMyDateTime>
&& !IsArrayType<T>,
DataTypePtr> //
getDataTypeByColumnInfoBase(const ColumnInfo &, const T *)
{
return std::make_shared<T>();
}

4. What is your TiFlash version? (Required)

nightly

@JaySon-Huang JaySon-Huang self-assigned this Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant