Abnormal Partition Column Sorting

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

Original topic: 分区列排序异常

| username: rebelsre

【TiDB Usage Environment】Production Environment
【TiDB Version】v7.1.0
【Reproduction Path】Partition Column Sorting
【Encountered Issue: Issue Phenomenon and Impact】internal error: unionexec chunk column count mismatch, reg: 43, result: 44
【Resource Configuration】
【Attachments: Screenshots/Logs/Monitoring】

| username: zhanggame1 | Original post link

Is the partition column referring to the partition field of the partition table? Are there issues with sorting other fields?

| username: rebelsre | Original post link

I tested it, and the same error occurs with the field in the WHERE clause, but other fields are normal.

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

I found an issue in version 5.2, but your version is already 7.1. This bug shouldn’t still exist, right?
Internal error when pushdown agg into partitionUnion · Issue #29705 · pingcap/tidb (github.com)

| username: rebelsre | Original post link

Upgraded from v6.5.0, not sure if it has been reintroduced… It was normal before.

| username: rebelsre | Original post link

Upgrading to version 7.1.1 still has this issue.

| username: rebelsre | Original post link

I found that it can be executed without adding limit, but there will still be an error if limit is added… Does anyone else have this problem?

| username: redgame | Original post link

Are the number of columns returned by the involved SELECT statements consistent?

| username: rebelsre | Original post link

There are some inconsistencies, but it is possible within the same partition. There will be issues across partitions.

| username: aytrack | Original post link

How is the partition key defined?

| username: zhanggame1 | Original post link

Try adding jialimit to see if the execution plan is the same.

| username: TiDBer_Xin | Original post link

PARTITION BY RANGE (DateCode)

| username: aytrack | Original post link

Please post the execution plan.
It is highly likely that the static partition prune mode is being used. Can you try executing it in dynamic mode? Dynamic Pruning Mode

| username: TiDBer_Xin | Original post link

The image is not visible. Please provide the text you need translated.

| username: TiDBer_Xin | Original post link

Will changing to dynamic mode have any impact on the database?

| username: zhanggame1 | Original post link

The default for version 7.1 is dynamic mode.

| username: TiDBer_Xin | Original post link

I am also puzzled, but after checking the documentation, I guess the statistics are not fully collected.


So it’s still in static mode.

| username: aytrack | Original post link

There won’t be any impact. In higher versions, dynamic mode is already used by default. After switching to dynamic mode, you need to analyze the table to collect statistics, otherwise, it will still use static mode.

| username: aytrack | Original post link

This is a bug, follow up on this issue: UnionExec reports error with static pruning · Issue #45757 · pingcap/tidb · GitHub

| username: TiDBer_Xin | Original post link

Then do I still need to try dynamic?