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

fix(query): union all panic in mysql client #17095

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

zhyass
Copy link
Member

@zhyass zhyass commented Dec 20, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Fix panic bug in Union All due to incorrect output projection.

This PR addresses a panic issue that occurs when executing a Union All operation. The root cause of the bug was that the out project for Union All was not correctly set, leading to panic.

mysql> create table t1(a int, b int);
Query OK, 0 rows affected (0.18 sec)

mysql> insert into t1 values(1,1),(2,2);
+-------------------------+
| number of rows inserted |
+-------------------------+
|                       2 |
+-------------------------+
1 row in set (0.19 sec)
Read 2 rows, 18.00 B in 0.112 sec., 17.82 rows/sec., 160.42 B/sec.

mysql> create table t2(a int, b int);
Query OK, 0 rows affected (0.05 sec)

mysql> insert into t2 values(3,3),(4,4);
+-------------------------+
| number of rows inserted |
+-------------------------+
|                       2 |
+-------------------------+
1 row in set (0.22 sec)
Read 2 rows, 18.00 B in 0.123 sec., 16.27 rows/sec., 146.41 B/sec.

mysql> select a from (select a, b from t1 where a>1 union all select a, b from t2 where b<4);
+------+
| a    |
+------+
|    3 |
|    2 |
+------+
2 rows in set (0.21 sec)
Read 4 rows, 27.00 B in 0.076 sec., 52.64 rows/sec., 355.35 B/sec.

mysql> explain select a from (select a, b from t1 where a>1 union all select a, b from t2 where b<4);
+---------------------------------------------------------------------------------------------------------+
| explain                                                                                                 |
+---------------------------------------------------------------------------------------------------------+
| UnionAll                                                                                                |
| ├── output columns: [t1.a (#0)]                                                                         |
| ├── estimated rows: 2.00                                                                                |
| ├── Filter                                                                                              |
| │   ├── output columns: [t1.a (#0)]                                                                     |
| │   ├── filters: [is_true(t1.a (#0) > 1)]                                                               |
| │   ├── estimated rows: 1.00                                                                            |
| │   └── TableScan                                                                                       |
| │       ├── table: default.default.t1                                                                   |
| │       ├── output columns: [a (#0)]                                                                    |
| │       ├── read rows: 2                                                                                |
| │       ├── read size: < 1 KiB                                                                          |
| │       ├── partitions total: 1                                                                         |
| │       ├── partitions scanned: 1                                                                       |
| │       ├── pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>]         |
| │       ├── push downs: [filters: [is_true(t1.a (#0) > 1)], limit: NONE]                                |
| │       └── estimated rows: 2.00                                                                        |
| └── Filter                                                                                              |
|     ├── output columns: [t2.a (#2)]                                                                     |
|     ├── filters: [is_true(t2.b (#3) < 4)]                                                               |
|     ├── estimated rows: 1.00                                                                            |
|     └── TableScan                                                                                       |
|         ├── table: default.default.t2                                                                   |
|         ├── output columns: [a (#2), b (#3)]                                                            |
|         ├── read rows: 2                                                                                |
|         ├── read size: < 1 KiB                                                                          |
|         ├── partitions total: 1                                                                         |
|         ├── partitions scanned: 1                                                                       |
|         ├── pruning stats: [segments: <range pruning: 1 to 1>, blocks: <range pruning: 1 to 1>]         |
|         ├── push downs: [filters: [is_true(t2.b (#3) < 4)], limit: NONE]                                |
|         └── estimated rows: 2.00                                                                        |
+---------------------------------------------------------------------------------------------------------+
31 rows in set (0.13 sec)
Read 0 rows, 0.00 B in 0.017 sec., 0 rows/sec., 0.00 B/sec.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Dec 20, 2024
@zhyass zhyass marked this pull request as draft December 21, 2024 01:04
@zhyass zhyass marked this pull request as ready for review December 22, 2024 16:40
@zhyass zhyass added this pull request to the merge queue Dec 23, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request Dec 23, 2024
@BohuTANG BohuTANG merged commit 793e2ae into databendlabs:main Dec 23, 2024
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: union all panic in mysql client
3 participants