Skip to content

Expand operator may incorrectly convert column to nullable, causing exceptions or crashes #10110

@gengliqi

Description

@gengliqi

Bug Report

mysql> create table t(a int not null, b int);
Query OK, 0 rows affected (0.04 sec)

mysql> insert into t values(1,2),(3,4);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> alter table t set tiflash replica 1;
Query OK, 0 rows affected (0.06 sec)

mysql> set tidb_enforce_mpp=1;
Query OK, 0 rows affected (0.00 sec)

mysql> explain select sum(a), max(b) from t group by a with rollup;
+----------------------------------------+----------+--------------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                     | estRows  | task         | access object | operator info                                                                                                                                   |
+----------------------------------------+----------+--------------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
| TableReader_59                         | 8000.00  | root         |               | MppVersion: 2, data:ExchangeSender_58                                                                                                           |
| └─ExchangeSender_58                    | 8000.00  | mpp[tiflash] |               | ExchangeType: PassThrough                                                                                                                       |
|   └─Projection_53                      | 8000.00  | mpp[tiflash] |               | Column#6, Column#7                                                                                                                              |
|     └─HashAgg_51                       | 8000.00  | mpp[tiflash] |               | group by:Column#18, Column#19, funcs:sum(Column#16)->Column#6, funcs:max(Column#17)->Column#7, stream_count: 10                                 |
|       └─Projection_60                  | 10000.00 | mpp[tiflash] |               | cast(test.t.a, decimal(10,0) BINARY)->Column#16, test.t.b->Column#17, Column#4->Column#18, gid->Column#19, stream_count: 10                     |
|         └─ExchangeReceiver_37          | 10000.00 | mpp[tiflash] |               | stream_count: 10                                                                                                                                |
|           └─ExchangeSender_36          | 10000.00 | mpp[tiflash] |               | ExchangeType: HashPartition, Compression: FAST, Hash Cols: [name: Column#4, collate: binary], [name: gid, collate: binary], stream_count: 10    |
|             └─Expand_35                | 10000.00 | mpp[tiflash] |               | level-projection:[test.t.a, test.t.b, <nil>->Column#4, 0->gid],[test.t.a, test.t.b, Column#4, 1->gid]; schema: [test.t.a,test.t.b,Column#4,gid] |
|               └─Projection_20          | 10000.00 | mpp[tiflash] |               | test.t.a, test.t.b, test.t.a->Column#4                                                                                                          |
|                 └─TableFullScan_21     | 10000.00 | mpp[tiflash] | table:t       | keep order:false, stats:pseudo                                                                                                                  |
+----------------------------------------+----------+--------------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.02 sec)

mysql> select sum(a), max(b) from t group by a with rollup;
ERROR 1105 (HY000): other error for mpp stream: Code: 0, e.displayText() = DB::Exception: Receiver state: ERROR, error message: Code: 0, e.displayText() = DB::Exception: Block schema mismatch in FineGrainedShuffleWriter-V1: different types: expected Nullable(Int32), got Int32; col_index: 2; col_name: ExchangeSender_36_table_scan_0_1, e.what() = DB::Exception,, e.what() = DB::Exception,

The example throws an exception because the ExchangeSender above Expand can check the schema. However, if there are some other operators(e.g. HashAgg) above Expand, TiFlash may crash due to the wrong schema output produced by Expand.

This bug only occurs when a non-nullable column is used in a GROUP BY WITH ROLLUP clause together with an aggregate function on that column.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions