Closed songrijie closed 2 years ago
It's initially from https://asktug.com/t/topic/694310
/assign
it can be duplicated if it is a nested CTE. i.e.
mysql> desc with cte1 as (with cte1 as (select 1) select * from cte1) select * from cte1;
+---------------------------------+---------+------+---------------+-------------------+
| id | estRows | task | access object | operator info |
+---------------------------------+---------+------+---------------+-------------------+
| CTEFullScan_12 | 1.00 | root | CTE:cte1 | data:CTE_0 |
| CTE_0 | 1.00 | root | | Non-Recursive CTE |
| └─CTEFullScan_10(Seed Part) | 1.00 | root | CTE:cte1 | data:CTE_1 |
| CTE_1 | 1.00 | root | | Non-Recursive CTE |
| └─Projection_7(Seed Part) | 1.00 | root | | 1->Column#1 |
| └─TableDual_8 | 1.00 | root | | rows:1 |
+---------------------------------+---------+------+---------------+-------------------+
6 rows in set (0.00 sec)
So it is should be changed to CTE_<actual name>_IDForStorage
?
And this change seems to have broken a lot of tests, I don't know if I should continue. :(
I prefer to add the real name to access object
, for now only the alias is shown. it can be CTE: books_with_orders as bo
And this change seems to have broken a lot of tests, I don't know if I should continue. :(
check_dev
and check_dev_2
can be update:
cmd/explaintest
./run-tests.sh -s $TIDB_BINARY -r all
mysql-test
is internal, we will update it for you once your pr is ready to merge
Okay, I'll try to update
it's better we have both alias and actual tablename in access object
Enhancement
Current behavior
In execution plan, CTE is marked with random names like CTE_x in
id
column. In a few complex scenarios, it's not easy to map the identifier to SQL block. Here is an example from official doc.CTE_0
,CTE_1
andCTE_2
are generated by planner.Expected behavior
It's expected all
CTE_x
identifiers are replaced withCTE_<actual name in upper case>
in bothid
andoperator info
. In above example:CTE_0
->CTE_ BOOKS_AUTHORED_BY_RM
CTE_1
->CTE_BOOKS_WITH_AVERAGE_RATINGS
CTE_2
->CTE_BOOKS_WITH_ORDERS