指定INL_JOIN，但执行计划并不走

buddyyuan
Fri, 28 Oct 2022 02:25:50 +0000

你可以这样改造试试。

mysql> explain with b as (select id,count(1) as num from sbtest2 t2 group by t2.id) select a.id ,b.num  from sbtest1 a, b where a.id=b.id;
+--------------------------------+----------+-----------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
| id                             | estRows  | task      | access object          | operator info                                                                                                                                   |
+--------------------------------+----------+-----------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
| Projection_19                  | 44513.60 | root      |                        | sbtest.sbtest1.id, Column#11                                                                                                                    |
| └─IndexHashJoin_26             | 44513.60 | root      |                        | inner join, inner:TableReader_21, outer key:sbtest.sbtest2.id, inner key:sbtest.sbtest1.id, equal cond:eq(sbtest.sbtest2.id, sbtest.sbtest1.id) |
|   ├─Selection_31(Build)        | 44513.60 | root      |                        | not(isnull(sbtest.sbtest2.id))                                                                                                                  |
|   │ └─CTEFullScan_32           | 55642.00 | root      | CTE:b                  | data:CTE_0                                                                                                                                      |
|   └─TableReader_21(Probe)      | 1.00     | root      |                        | data:TableRangeScan_20                                                                                                                          |
|     └─TableRangeScan_20        | 1.00     | cop[tikv] | table:a                | range: decided by [sbtest.sbtest2.id], keep order:false                                                                                         |
| CTE_0                          | 55642.00 | root      |                        | Non-Recursive CTE                                                                                                                               |
| └─Projection_11(Seed Part)     | 55642.00 | root      |                        | sbtest.sbtest2.id, 1->Column#5                                                                                                                  |
|   └─IndexReader_15             | 55642.00 | root      |                        | index:IndexFullScan_14                                                                                                                          |
|     └─IndexFullScan_14         | 55642.00 | cop[tikv] | table:t2, index:k_2(k) | keep order:false                                                                                                                                |
+--------------------------------+----------+-----------+------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
10 rows in set (0.01 sec)

阅读完整话题