align null flags of union when making logical plans
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1k
- Forks
- 423
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 24
Description
Use test;
create table t (id int, d double, nd double not null);
Alter table t set tiflash replica 1;
insert into t values (0,0,0),(1,1,1),(2,null,2);
create table tt like t;
alter table tt set tiflash replica 1;
insert into tt select * from t;
insert into tt select * from t;
insert into tt select * from t;
insert into tt select * from t;
mysql> desc Select IDD from tt join ( (select 127 as IDD from t) union all (select 1 as IDD from t) ) u on tt.id = u.IDD;
+--------------------------------------------+---------+--------------+---------------+----------------------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------------------------+---------+--------------+---------------+----------------------------------------------+
| Projection_13 | 48.00 | root | | Column#15 |
| └─TableReader_27 | 48.00 | root | | data:ExchangeSender_26 |
| └─ExchangeSender_26 | 48.00 | cop[tiflash] | | ExchangeType: PassThrough |
| └─HashJoin_14 | 48.00 | cop[tiflash] | | inner join, equal:[eq(fzh.tt.id, Column#15)] |
| ├─ExchangeReceiver_25(Build) | 12.00 | cop[tiflash] | | |
| │ └─ExchangeSender_24 | 12.00 | cop[tiflash] | | ExchangeType: Broadcast |
| │ └─Union_19 | 12.00 | cop[tiflash] | | |
| │ ├─Projection_48 | 6.00 | cop[tiflash] | | cast(Column#15, bigint(3) BINARY)->Column#15 |
| │ │ └─Projection_20 | 6.00 | cop[tiflash] | | 127->Column#15 |
| │ │ └─TableFullScan_21 | 6.00 | cop[tiflash] | table:t | keep order:false, stats:pseudo |
| │ └─Projection_22 | 6.00 | cop[tiflash] | | 1->Column#15 |
| │ └─TableFullScan_23 | 6.00 | cop[tiflash] | table:t | keep order:false, stats:pseudo |
| └─Selection_18(Probe) | 23.98 | cop[tiflash] | | not(isnull(fzh.tt.id)) |
| └─TableFullScan_17 | 24.00 | cop[tiflash] | table:tt | keep order:false, stats:pseudo |
+--------------------------------------------+---------+--------------+---------------+----------------------------------------------+
14 rows in set (0.00 sec)
| │ ├─Projection_48 | 6.00 | cop[tiflash] | | cast(Column#15, bigint(3) BINARY)->Column#15 |
the projection_48 is forced adding after making logical plan, actually at making MPP plan. In fact, we should enfoce the logic to union data types as well as null flags duing making logical plan. In details, when making logical plan, the 127 branch is the same as 1 branch, only one projection, but MPP considers null flags, then forcing a projection later.
why only 127 branch needs a proj? where added?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files, tests, or entry points are named. Start by reproducing the SQL plan in the issue and compare the logical and MPP plans, then trace where the extra Projection_48 is introduced. Done means the union's data types and null flags are aligned during logical-plan construction without the later forced projection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100