Open JaySon-Huang opened 8 months ago
The execution plan from another database.
select a.factory, a.goods, sum(b.num)
from comp1 a
inner join comp2 b
on a.goods=b.goods and a.factory=b.factory
group by a.factory, a.goods
=======================================================
|ID|OPERATOR |NAME |EST.ROWS |EST.TIME(us)|
-------------------------------------------------------
|0 |HASH JOIN | |256 |44074020 |
|1 |├─SUBPLAN SCAN |VIEW1|130 |37090580 |
|2 |│ └─HASH GROUP BY | |130 |37090579 |
|3 |│ └─TABLE FULL SCAN|a |300000001|5107107 |
|4 |└─SUBPLAN SCAN |VIEW2|201 |6983257 |
|5 | └─HASH GROUP BY | |201 |6983256 |
|6 | └─TABLE FULL SCAN|b |50000000 |1652634 |
=======================================================
Outputs & filters:
-------------------------------------
0 - output([VIEW1.a.factory], [VIEW1.a.good], [cast(VIEW1.T_FUN_COUNT(*), DECIMAL(20, 0)) * VIEW2.T_FUN_SUM(b.num)]), filter(nil), rowset=256
equal_conds([VIEW1.a.good = VIEW2.b.good], [VIEW1.a.factory = VIEW2.b.comp]), other_conds(nil)
1 - output([VIEW1.a.good], [VIEW1.a.factory], [VIEW1.T_FUN_COUNT(*)]), filter(nil), rowset=256
access([VIEW1.a.good], [VIEW1.a.factory], [VIEW1.T_FUN_COUNT(*)])
2 - output([a.good], [a.factory], [T_FUN_COUNT(*)]), filter(nil), rowset=256
group([a.good], [a.factory]), agg_func([T_FUN_COUNT(*)])
3 - output([a.good], [a.factory]), filter(nil), rowset=256
access([a.good], [a.factory]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([a.__pk_increment]), range(MIN ; MAX)always true
4 - output([VIEW2.b.good], [VIEW2.b.comp], [VIEW2.T_FUN_SUM(b.num)]), filter(nil), rowset=256
access([VIEW2.b.good], [VIEW2.b.comp], [VIEW2.T_FUN_SUM(b.num)])
5 - output([b.good], [b.comp], [T_FUN_SUM(b.num)]), filter(nil), rowset=256
group([b.good], [b.comp]), agg_func([T_FUN_SUM(b.num)])
6 - output([b.good], [b.comp], [b.num]), filter(nil), rowset=256
access([b.good], [b.comp], [b.num]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([b.__pk_increment]), range(MIN ; MAX)always true
Yes, the oceanbase can write agg to both side of join table. select xxx, sum(a.sum) from a join b on a.id=b.id group by a.id => write to select xxx, sum(a.sum b.cnt) from (select a.id , sum(a.sum) from a group by a.id) join (select b.id, count() from b group by b.id)
Enhancement
In some scenarios, the user will execute join on two tables with a large amount of duplicated join keys.
In a testing data set, the 1st plan took more than 20 minutes and failed to be executed. The 2nd plan took about 7 minutes, and the 3rd plan took only 3 seconds!
It would be best that:
tidb_opt_agg_push_down
to be true by defaultFor example: