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

Parsing CTE error with "doesn't yet support 'ORDER BY / LIMIT / SELECT DISTINCT in recursive query block" #56603

Closed
elsa0520 opened this issue Oct 12, 2024 · 2 comments · Fixed by #56609
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. report/customer Customers have encountered this bug. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@elsa0520
Copy link
Contributor

Bug Report

The CTE contain DISTINCT keyword could not be inlined by default when the CTE is referenced by recursive query block of another CTE.

1. Minimal reproduce step (Required)

create table test(a int);

explain 
WITH RECURSIVE 
CTE (x) AS (SELECT distinct a FROM test) ,
CTE1(x) AS (SELECT a FROM test UNION ALL select CTE.x from CTE join CTE1 on CTE.x=CTE1.x) 
SELECT * FROM CTE1;

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

CTE is not inlined.

+-----------------------------------+----------+-----------+---------------+----------------------------------------------------------------+
| id                                | estRows  | task      | access object | operator info                                                  |
+-----------------------------------+----------+-----------+---------------+----------------------------------------------------------------+
| CTEFullScan_42                    | 18000.00 | root      | CTE:cte1      | data:CTE_1                                                     |
| CTE_1                             | 18000.00 | root      |               | Recursive CTE                                                  |
| ├─TableReader_22(Seed Part)       | 10000.00 | root      |               | data:TableFullScan_21                                          |
| │ └─TableFullScan_21              | 10000.00 | cop[tikv] | table:test    | keep order:false, stats:pseudo                                 |
| └─HashJoin_36(Recursive Part)     | 8000.00  | root      |               | inner join, equal:[eq(test.test.a, test.test.a)]               |
|   ├─Selection_37(Build)           | 6400.00  | root      |               | not(isnull(test.test.a))                                       |
|   │ └─CTEFullScan_38              | 8000.00  | root      | CTE:cte       | data:CTE_0                                                     |
|   └─Selection_39(Probe)           | 8000.00  | root      |               | not(isnull(test.test.a))                                       |
|     └─CTETable_40                 | 10000.00 | root      |               | Scan on CTE_1                                                  |
| CTE_0                             | 8000.00  | root      |               | Non-Recursive CTE                                              |
| └─HashAgg_29(Seed Part)           | 8000.00  | root      |               | group by:test.test.a, funcs:firstrow(test.test.a)->test.test.a |
|   └─TableReader_30                | 8000.00  | root      |               | data:HashAgg_25                                                |
|     └─HashAgg_25                  | 8000.00  | cop[tikv] |               | group by:test.test.a,                                          |
|       └─TableFullScan_28          | 10000.00 | cop[tikv] | table:test    | keep order:false, stats:pseudo                                 |
+-----------------------------------+----------+-----------+---------------+----------------------------------------------------------------+
14 rows in set (5.94 sec)

3. What did you see instead (Required)

ERROR 1235 (42000): This version of TiDB doesn't yet support 'ORDER BY / LIMIT / SELECT DISTINCT in recursive query block of Common Table Expression'

4. What is your TiDB version? (Required)

after v6.5.10 (include)

@elsa0520 elsa0520 added the type/bug The issue is confirmed as a bug. label Oct 12, 2024
@elsa0520
Copy link
Contributor Author

The same problem with #47711

This pr #48188 only forbidden the agg and window function but the order by , distinct and limit forget to forbidden.

@elsa0520 elsa0520 added sig/planner SIG: Planner affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. and removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 labels Oct 12, 2024
ti-chi-bot bot pushed a commit that referenced this issue Oct 15, 2024
ti-chi-bot bot pushed a commit that referenced this issue Oct 16, 2024
…it/distinct and inside of view | tidb-test=e1d0c1e615f749e7139f5be95bc4a2b8cedb7380 (#56609) (#56666)

close #56582, close #56603
ti-chi-bot bot pushed a commit that referenced this issue Nov 7, 2024
…it/distinct and inside of view | tidb-test=pr/2422 (#56609) (#56696)

close #56582, close #56603
@seiya-annie
Copy link

/report customer

@ti-chi-bot ti-chi-bot bot added the report/customer Customers have encountered this bug. label Nov 12, 2024
ti-chi-bot bot pushed a commit that referenced this issue Dec 4, 2024
…it/distinct and inside of view | tidb-test=pr/2438 (#56609) (#56695)

close #56582, close #56603
ti-chi-bot bot pushed a commit that referenced this issue Dec 17, 2024
ti-chi-bot bot pushed a commit that referenced this issue Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. report/customer Customers have encountered this bug. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
2 participants