|
3390 | 3390 | " └─CTETable 1.00 root Scan on CTE_4"
|
3391 | 3391 | ],
|
3392 | 3392 | "Warning": null
|
| 3393 | + }, |
| 3394 | + { |
| 3395 | + "SQL": "with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c", |
| 3396 | + "Plan": [ |
| 3397 | + "CTEFullScan 1.80 root CTE:tmp data:CTE_4", |
| 3398 | + "CTE_4 1.80 root Recursive CTE", |
| 3399 | + "├─Projection(Seed Part) 1.00 root 2->Column#37", |
| 3400 | + "│ └─HashAgg 1.00 root funcs:count(Column#46)->Column#44", |
| 3401 | + "│ └─TableReader 1.00 root data:HashAgg", |
| 3402 | + "│ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#46", |
| 3403 | + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", |
| 3404 | + "└─Projection(Recursive Part) 0.80 root cast(plus(Column#38, 1), bigint(1) BINARY)->Column#40", |
| 3405 | + " └─Selection 0.80 root lt(plus(Column#38, 1), 10)", |
| 3406 | + " └─CTETable 1.00 root Scan on CTE_4" |
| 3407 | + ], |
| 3408 | + "Warning": null |
| 3409 | + }, |
| 3410 | + { |
| 3411 | + "SQL": "with a as (select count(*) from t1), b as (select 2 as bb from a), c as (with recursive tmp as (select bb as res from b union all select res+1 from tmp where res +1 < 10) select * from tmp) select * from c; -- inline a, b, cannot be inline tmp, c", |
| 3412 | + "Plan": [ |
| 3413 | + "CTEFullScan 1.80 root CTE:tmp data:CTE_4", |
| 3414 | + "CTE_4 1.80 root Recursive CTE", |
| 3415 | + "├─Projection(Seed Part) 1.00 root 2->Column#37", |
| 3416 | + "│ └─HashAgg 1.00 root funcs:count(Column#46)->Column#44", |
| 3417 | + "│ └─TableReader 1.00 root data:HashAgg", |
| 3418 | + "│ └─HashAgg 1.00 cop[tikv] funcs:count(1)->Column#46", |
| 3419 | + "│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", |
| 3420 | + "└─Projection(Recursive Part) 0.80 root cast(plus(Column#38, 1), bigint(1) BINARY)->Column#40", |
| 3421 | + " └─Selection 0.80 root lt(plus(Column#38, 1), 10)", |
| 3422 | + " └─CTETable 1.00 root Scan on CTE_4" |
| 3423 | + ], |
| 3424 | + "Warning": null |
| 3425 | + }, |
| 3426 | + { |
| 3427 | + "SQL": "WITH RECURSIVE CTE (x) AS (SELECT 1 UNION ALL SELECT distinct a FROM test), CTE1 AS (SELECT x FROM CTE UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain distinct and ref by CET1 recursive part cannot be inlined;", |
| 3428 | + "Plan": [ |
| 3429 | + "CTEFullScan 14401.80 root CTE:cte1 data:CTE_1", |
| 3430 | + "CTE_1 14401.80 root Recursive CTE", |
| 3431 | + "├─CTEFullScan(Seed Part) 8001.00 root CTE:cte data:CTE_0", |
| 3432 | + "└─HashJoin(Recursive Part) 6400.80 root inner join, equal:[eq(Column#11, Column#12)]", |
| 3433 | + " ├─Selection(Build) 6400.80 root not(isnull(Column#12))", |
| 3434 | + " │ └─CTETable 8001.00 root Scan on CTE_1", |
| 3435 | + " └─Selection(Probe) 6400.80 root not(isnull(Column#11))", |
| 3436 | + " └─CTEFullScan 8001.00 root CTE:cte data:CTE_0", |
| 3437 | + "CTE_0 8001.00 root Non-Recursive CTE", |
| 3438 | + "└─Union(Seed Part) 8001.00 root ", |
| 3439 | + " ├─Projection 1.00 root 1->Column#7", |
| 3440 | + " │ └─TableDual 1.00 root rows:1", |
| 3441 | + " └─Projection 8000.00 root cast(test.test.a, bigint(11) BINARY)->Column#7", |
| 3442 | + " └─HashAgg 8000.00 root group by:test.test.a, funcs:firstrow(test.test.a)->test.test.a", |
| 3443 | + " └─TableReader 8000.00 root data:HashAgg", |
| 3444 | + " └─HashAgg 8000.00 cop[tikv] group by:test.test.a, ", |
| 3445 | + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" |
| 3446 | + ], |
| 3447 | + "Warning": null |
| 3448 | + }, |
| 3449 | + { |
| 3450 | + "SQL": "create definer='root'@'localhost' view test_cte(a) as WITH RECURSIVE CTE (x) AS (SELECT 1 UNION ALL SELECT distinct a FROM test) , CTE1 AS (SELECT x FROM CTE UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1;", |
| 3451 | + "Plan": null, |
| 3452 | + "Warning": null |
| 3453 | + }, |
| 3454 | + { |
| 3455 | + "SQL": "select * from test_cte; -- CTE (inside of view) cannot be inlined by default;", |
| 3456 | + "Plan": [ |
| 3457 | + "CTEFullScan 14401.80 root CTE:cte1 data:CTE_1", |
| 3458 | + "CTE_1 14401.80 root Recursive CTE", |
| 3459 | + "├─CTEFullScan(Seed Part) 8001.00 root CTE:cte data:CTE_0", |
| 3460 | + "└─HashJoin(Recursive Part) 6400.80 root inner join, equal:[eq(Column#11, Column#12)]", |
| 3461 | + " ├─Selection(Build) 6400.80 root not(isnull(Column#12))", |
| 3462 | + " │ └─CTETable 8001.00 root Scan on CTE_1", |
| 3463 | + " └─Selection(Probe) 6400.80 root not(isnull(Column#11))", |
| 3464 | + " └─CTEFullScan 8001.00 root CTE:cte data:CTE_0", |
| 3465 | + "CTE_0 8001.00 root Non-Recursive CTE", |
| 3466 | + "└─Union(Seed Part) 8001.00 root ", |
| 3467 | + " ├─Projection 1.00 root 1->Column#7", |
| 3468 | + " │ └─TableDual 1.00 root rows:1", |
| 3469 | + " └─Projection 8000.00 root cast(test.test.a, bigint(11) BINARY)->Column#7", |
| 3470 | + " └─HashAgg 8000.00 root group by:test.test.a, funcs:firstrow(test.test.a)->test.test.a", |
| 3471 | + " └─TableReader 8000.00 root data:HashAgg", |
| 3472 | + " └─HashAgg 8000.00 cop[tikv] group by:test.test.a, ", |
| 3473 | + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" |
| 3474 | + ], |
| 3475 | + "Warning": null |
| 3476 | + }, |
| 3477 | + { |
| 3478 | + "SQL": "create definer='root'@'localhost' view test_inline_cte(a) as with CTE (x) as (select distinct a from test) select * from CTE;", |
| 3479 | + "Plan": null, |
| 3480 | + "Warning": null |
| 3481 | + }, |
| 3482 | + { |
| 3483 | + "SQL": "select * from test_inline_cte; -- CTE (inside of view) cannot be inlined by default;", |
| 3484 | + "Plan": [ |
| 3485 | + "CTEFullScan 8000.00 root CTE:cte data:CTE_0", |
| 3486 | + "CTE_0 8000.00 root Non-Recursive CTE", |
| 3487 | + "└─HashAgg(Seed Part) 8000.00 root group by:test.test.a, funcs:firstrow(test.test.a)->test.test.a", |
| 3488 | + " └─TableReader 8000.00 root data:HashAgg", |
| 3489 | + " └─HashAgg 8000.00 cop[tikv] group by:test.test.a, ", |
| 3490 | + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" |
| 3491 | + ], |
| 3492 | + "Warning": null |
| 3493 | + }, |
| 3494 | + { |
| 3495 | + "SQL": "create definer='root'@'localhost' view test_force_inline_cte(a) as with CTE (x) as (select /*+ merge() */ distinct a from test) select * from CTE;", |
| 3496 | + "Plan": null, |
| 3497 | + "Warning": null |
| 3498 | + }, |
| 3499 | + { |
| 3500 | + "SQL": "select * from test_force_inline_cte; -- CTE (inside of view) can be inlined by force;", |
| 3501 | + "Plan": [ |
| 3502 | + "HashAgg 8000.00 root group by:test.test.a, funcs:firstrow(test.test.a)->test.test.a", |
| 3503 | + "└─TableReader 8000.00 root data:HashAgg", |
| 3504 | + " └─HashAgg 8000.00 cop[tikv] group by:test.test.a, ", |
| 3505 | + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" |
| 3506 | + ], |
| 3507 | + "Warning": null |
| 3508 | + }, |
| 3509 | + { |
| 3510 | + "SQL": "WITH RECURSIVE CTE (x) AS (SELECT a FROM test limit 1) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain limit and ref by CET1 recursive part cannot be inlined;", |
| 3511 | + "Plan": [ |
| 3512 | + "CTEFullScan 16400.00 root CTE:cte1 data:CTE_1", |
| 3513 | + "CTE_1 16400.00 root Recursive CTE", |
| 3514 | + "├─TableReader(Seed Part) 10000.00 root data:TableFullScan", |
| 3515 | + "│ └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo", |
| 3516 | + "└─HashJoin(Recursive Part) 6400.00 root inner join, equal:[eq(test.test.a, test.test.a)]", |
| 3517 | + " ├─Selection(Build) 0.80 root not(isnull(test.test.a))", |
| 3518 | + " │ └─CTEFullScan 1.00 root CTE:cte data:CTE_0", |
| 3519 | + " └─Selection(Probe) 8000.00 root not(isnull(test.test.a))", |
| 3520 | + " └─CTETable 10000.00 root Scan on CTE_1", |
| 3521 | + "CTE_0 1.00 root Non-Recursive CTE", |
| 3522 | + "└─Limit(Seed Part) 1.00 root offset:0, count:1", |
| 3523 | + " └─TableReader 1.00 root data:Limit", |
| 3524 | + " └─Limit 1.00 cop[tikv] offset:0, count:1", |
| 3525 | + " └─TableFullScan 1.00 cop[tikv] table:test keep order:false, stats:pseudo" |
| 3526 | + ], |
| 3527 | + "Warning": null |
| 3528 | + }, |
| 3529 | + { |
| 3530 | + "SQL": "WITH RECURSIVE CTE (x) AS (SELECT a FROM test order by a) , CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) SELECT * FROM CTE1; -- CTE contain order by and ref by CET1 recursive part cannot be inlined;", |
| 3531 | + "Plan": [ |
| 3532 | + "CTEFullScan 20000.00 root CTE:cte1 data:CTE_1", |
| 3533 | + "CTE_1 20000.00 root Recursive CTE", |
| 3534 | + "├─TableReader(Seed Part) 10000.00 root data:TableFullScan", |
| 3535 | + "│ └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo", |
| 3536 | + "└─HashJoin(Recursive Part) 10000.00 root inner join, equal:[eq(test.test.a, test.test.a)]", |
| 3537 | + " ├─Selection(Build) 8000.00 root not(isnull(test.test.a))", |
| 3538 | + " │ └─CTEFullScan 10000.00 root CTE:cte data:CTE_0", |
| 3539 | + " └─Selection(Probe) 8000.00 root not(isnull(test.test.a))", |
| 3540 | + " └─CTETable 10000.00 root Scan on CTE_1", |
| 3541 | + "CTE_0 10000.00 root Non-Recursive CTE", |
| 3542 | + "└─TableReader(Seed Part) 10000.00 root data:TableFullScan", |
| 3543 | + " └─TableFullScan 10000.00 cop[tikv] table:test keep order:false, stats:pseudo" |
| 3544 | + ], |
| 3545 | + "Warning": null |
3393 | 3546 | }
|
3394 | 3547 | ]
|
3395 | 3548 | },
|
|
0 commit comments