Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain Format = "dot" does not show CTE #37401

Open
yilongrong opened this issue Aug 26, 2022 · 2 comments
Open

Explain Format = "dot" does not show CTE #37401

yilongrong opened this issue Aug 26, 2022 · 2 comments
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/moderate sig/planner SIG: Planner type/bug This issue is a bug.

Comments

@yilongrong
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. import bookshop
    https://docs.pingcap.com/tidb/stable/dev-guide-bookshop-schema-design#import-table-structures-and-data
  2. create temp table top_50_eldest_authors
CREATE TEMPORARY TABLE top_50_eldest_authors (
    id BIGINT,
    name VARCHAR(255),
    age INT,
    PRIMARY KEY(id)
);
  1. execute
explain format = "dot"
WITH top_50_eldest_authors_cte AS (
    SELECT a.id, a.name, (IFNULL(a.death_year, YEAR(NOW())) - a.birth_year) AS age
    FROM authors a
    ORDER BY age DESC
    LIMIT 50
)
SELECT
    ANY_VALUE(ta.id) AS author_id,
    ANY_VALUE(ta.age) AS author_age,
    ANY_VALUE(ta.name) AS author_name,
    COUNT(*) AS books
FROM top_50_eldest_authors_cte ta
LEFT JOIN book_authors ba ON ta.id = ba.author_id
GROUP BY ta.id;

2. What did you expect to see? (Required)

show CTE

-----------------------------------------------------------------------------------------------------------------------------+
| id                                   | estRows  | task      | access object | operator info                                                                                                                                                                                                       |
+--------------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Projection_23                        | 40.00    | root      |               | any_value(bookshop.authors.id)->Column#13, any_value(Column#9)->Column#14, any_value(bookshop.authors.name)->Column#15, Column#12                                                                                   |
| └─HashAgg_24                         | 40.00    | root      |               | group by:bookshop.authors.id, funcs:count(1)->Column#12, funcs:firstrow(bookshop.authors.id)->bookshop.authors.id, funcs:firstrow(bookshop.authors.name)->bookshop.authors.name, funcs:firstrow(Column#9)->Column#9 |
|   └─HashJoin_26                      | 61.95    | root      |               | left outer join, equal:[eq(bookshop.authors.id, bookshop.book_authors.author_id)]                                                                                                                                   |
|     ├─CTEFullScan_30(Build)          | 40.00    | root      | CTE:ta        | data:CTE_0                                                                                                                                                                                                          |
|     └─TableReader_29(Probe)          | 20000.00 | root      |               | data:TableFullScan_28                                                                                                                                                                                               |
|       └─TableFullScan_28             | 20000.00 | cop[tikv] | table:ba      | keep order:false                                                                                                                                                                                                    |
| CTE_0                                | 40.00    | root      |               | Non-Recursive CTE                                                                                                                                                                                                   |
| └─Selection_12(Seed Part)            | 40.00    | root      |               | 1                                                                                                                                                                                                                   |
|   └─Projection_13                    | 50.00    | root      |               | bookshop.authors.id, bookshop.authors.name, minus(ifnull(bookshop.authors.death_year, 2022), bookshop.authors.birth_year)->Column#6                                                                                 |
|     └─Projection_20                  | 50.00    | root      |               | bookshop.authors.id, bookshop.authors.name, bookshop.authors.birth_year, bookshop.authors.death_year                                                                                                                |
|       └─TopN_14                      | 50.00    | root      |               | Column#19:desc, offset:0, count:50                                                                                                                                                                                  |
|         └─Projection_21              | 50.00    | root      |               | bookshop.authors.id, bookshop.authors.name, bookshop.authors.birth_year, bookshop.authors.death_year, minus(ifnull(bookshop.authors.death_year, 2022), bookshop.authors.birth_year)->Column#19                      |
|           └─TableReader_19           | 50.00    | root      |               | data:TopN_18                                                                                                                                                                                                        |
|             └─TopN_18                | 50.00    | cop[tikv] |               | minus(ifnull(bookshop.authors.death_year, 2022), bookshop.authors.birth_year):desc, offset:0, count:50                                                                                                              |
|               └─TableFullScan_17     | 20000.00 | cop[tikv] | table:a       | keep order:false                                                                                                                                                                                                    |
+--------------------------------------+----------+-----------+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

3. What did you see instead (Required)

not include CTE

| 
digraph Projection_23 {
subgraph cluster23{
node [style=filled, color=lightgrey]
color=black
label = "root"
"Projection_23" -> "HashAgg_24"
"HashAgg_24" -> "HashJoin_26"
"HashJoin_26" -> "CTEFullScan_30"
"HashJoin_26" -> "TableReader_29"
}
subgraph cluster28{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableFullScan_28"
}
"TableReader_29" -> "TableFullScan_28"
}

|

4. What is your TiDB version? (Required)

6.1.0

@yilongrong yilongrong added the type/bug This issue is a bug. label Aug 26, 2022
@xiongjiwei xiongjiwei added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Aug 29, 2022
@xiongjiwei
Copy link
Contributor

how about
image

@yilongrong
Copy link
Author

https://asktug.com/t/topic/903224
result just include └─TableFullScan_28,not include └─TopN_18 / └─TableFullScan_17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/moderate sig/planner SIG: Planner type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants