After enabling TiFlash replicas for a table, query errors occur

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 某个表启用tiflash副本后,查询报错。

| username: TIDB-Learner

[TiDB Usage Environment] Production Environment
[TiDB Version]
[Description] An error occurs when querying data from a table after enabling the TiFlash replica.
[Encountered Problem: Symptoms and Impact]
After enabling the TiFlash replica, the program reports an error when querying, and direct database queries using select also report an error. After disabling the replica, the error no longer occurs.
Log:
[Error] [MPPTask.cpp:429] ["task running meets error: Code: 49, e.displayText() = DB::Exception: Check schema[i].type->equals(*storage_schema[i].type) failed, schema[i].name = table_scan_2, schema[i].type->getName() = Nullable(MyDateTime(3)), storage_schema[i].name = c_create_dt, storage_schema[i].type->getName() = Nullable(MyDateTime(0)), e.what() = DB::Exception, Stack trace:

0x172370e DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, int) [tiflash+24262414]
dbms/src/Common/Exception.h:46
0x6e927d2 DB::PhysicalTableScan::transformImpl(DB::DAGPipeline&, DB::Context&, unsigned long) [tiflash+115943378]
dbms/src/Flash/Planner/plans/PhysicalTableScan.cpp:69
0x6e6c1ce DB::PhysicalAggregation::transformImpl(DB::DAGPipeline&, DB::Context&, unsigned long) [tiflash+115786190]
dbms/src/Flash/Planner/plans/PhysicalAggregation.cpp:92
0x6e8f81a DB::PhysicalProjection::transformImpl(DB::DAGPipeline&, DB::Context&, unsigned long) [tiflash+115931162]
dbms/src/Flash/Planner/plans/PhysicalProjection.cpp:139
0x6e78bad DB::PhysicalExchangeSender::transformImpl(DB::DAGPipeline&, DB::Context&, unsigned long) [tiflash+115837869]
dbms/src/Flash/Planner/plans/PhysicalExchangeSender.cpp:55
0x6e5ab11 DB::Planner::execute() [tiflash+115714833]
dbms/src/Flash/Planner/Planner.cpp:36
0x6d444c9 DB::(anonymous namespace)::executeDAG(DB::IQuerySource&, DB::Context&, bool) [tiflash+114574537]
dbms/src/Flash/executeQuery.cpp:88
0x6d43fc0 DB::executeQuery(DB::Context&, bool) [tiflash+114573248]
dbms/src/Flash/executeQuery.cpp:108
0x6e28c1b DB::MPPTask::runImpl() [tiflash+115510299]
dbms/src/Flash/Mpp/MPPTask.cpp:365
0x1805f28 auto DB::wrapInvocable<std::__1::function<void ()> >(bool, std::__1::function<void ()>&&)::‘lambda’()::operator()() [tiflash+25190184]
dbms/src/Common/wrapInvocable.h:36
0x1809723 DB::DynamicThreadPool::executeTask(std::__1::unique_ptr<DB::IExecutableTask, std::__1::default_deleteDB::IExecutableTask >&) [tiflash+25204515]
dbms/src/Common/DynamicThreadPool.cpp:101
0x1808d80 DB::DynamicThreadPool::fixedWork(unsigned long) [tiflash+25202048]
dbms/src/Common/DynamicThreadPool.cpp:115
0x1809e72 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_deletestd::__1::__thread_struct >, std::__1::thread DB::ThreadFactory::newThread<void (DB::DynamicThreadPool::)(unsigned long), DB::DynamicThreadPool, unsigned long&>(bool, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, void (DB::DynamicThreadPool::&&)(unsigned long), DB::DynamicThreadPool&&, unsigned long&)::‘lambda’(auto&&…), DB::DynamicThreadPool*, unsigned long> >(void*) [tiflash+25206386]
/usr/local/bin/…/include/c++/v1/thread:291
0x7f9ebba88ea5 start_thread [libpthread.so.0+32421]
0x7f9ebae8db0d clone [libc.so.6+1043213]"] [source=MPPquery:446079017190424586:1,task] [thread_id=113]

| username: Jasper | Original post link

After setting up the replica, you need to wait for the TiFlash replica to complete synchronization before it can be used. You can check the specific status of the TiFlash replica with the following command:

select * from information_schema.tiflash_replica;
| username: TIDB-Learner | Original post link

The progress is already at 1. It was the previously configured TiFlash.

| username: TIDB-Learner | Original post link

It seems to be related to the date and time type fields. I can’t figure out what the problem is right now.

| username: dba远航 | Original post link

Please provide the query statement you used to see if it needs to go through TiFlash, so we can determine the cause. It would be best to include the execution plan.

| username: TIDB-Learner | Original post link

The query statement is just a simple select count(1) from table;
The business system query select * from table where … went through TiFlash, and then an error was reported.

| username: TIDB-Learner | Original post link

The issue cannot be reproduced in the production environment now.

| username: tidb菜鸟一只 | Original post link

Could you provide the table structure and a sample data? I want to test it.

| username: tidb菜鸟一只 | Original post link

Cannot reproduce

| username: TIDB-Learner | Original post link

Hmm, it might be that particular data or part of the data causing the issue. Let’s try enabling the TiFlash replica for the table again and see.