matrixorigin / matrixorigin/matrixone
MySQL Compatibility: LEFT/RIGHT/OUTER JOIN not supported in recursive CTE
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
## Description
MatrixOne does not support `LEFT JOIN`, `RIGHT JOIN`, or `OUTER JOIN` within recursive CTE (Common Table Expression) queries. Only `INNER JOIN` is supported. When using LEFT/RIGHT/OUTER JOIN in a recursive CTE, MatrixOne returns a syntax error.
## Error Message
```
ERROR 1064 (HY000) at line 1: SQL parser error: unsupport LEFT, RIGHT or OUTER JOIN in recursive CTE: *tree.JoinTableExpr
```
## Affected Cases
This issue affects **2 test cases** from our recursive CTE compatibility testing on the `industry_radar_test` database.
## Related Table DDL
### Table: industry_domain
```sql
CREATE TABLE `industry_domain` (
`id` int NOT NULL,
`name` varchar(50) DEFAULT NULL,
`desc` varchar(512) DEFAULT NULL,
`father_id` int DEFAULT NULL,
`downstream_id` int DEFAULT NULL,
`is_root` smallint DEFAULT NULL,
`level` int DEFAULT NULL,
`update_time` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '最后修改时间',
`guobiao_category` varchar(128) DEFAULT NULL COMMENT '国标行业门类',
`guobiao_major_category` varchar(128) DEFAULT NULL COMMENT '国标行业大类',
`guobiao_medium_category` varchar(128) DEFAULT NULL COMMENT '国标行业中类',
`guobiao_small_category` varchar(128) DEFAULT NULL COMMENT '国标行业小类',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_idx` (`name`,`father_id`,`level`)
)
```
### Table: industry_domain_company
```sql
CREATE TABLE `industry_domain_company` (
`id` int NOT NULL,
`node_id` int DEFAULT NULL,
`company_id` int DEFAULT NULL,
`update_time` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '最后修改时间',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_idx` (`node_id`,`company_id`),
KEY `company_id_idx` (`company_id`),
KEY `node_id_idx` (`node_id`)
)
```
## Failing SQL Statements
### Example 1
```sql
WITH RECURSIVE domain_companies AS (
SELECT id.id, id.name, id.father_id, COUNT(idc.company_id) as company_count, 1 as depth
FROM industry_domain id
LEFT JOIN industry_domain_company idc ON id.id = idc.node_id
WHERE id.is_root = 1
GROUP BY id.id, id.name, id.father_id
UNION ALL
SELECT child.id, child.name, child.father_id, COUNT(idc.company_id) as company_count, dc.depth + 1
FROM industry_domain child
INNER JOIN domain_companies dc ON child.father_id = dc.id
LEFT JOIN industry_domain_company idc ON child.id = idc.node_id
WHERE dc.depth < 3
GROUP BY child.id, child.name, child.father_id
)
SELECT * FROM domain_companies ORDER BY depth, id LIMIT 20;
```
**Error**: `ERROR 1064 (HY000) at line 1: SQL parser error: unsupport LEFT, RIGHT or OUTER JOIN in recursive CTE: *tree.JoinTableExpr`
## Expected Behavior
In MySQL, all types of JOINs (INNER, LEFT, RIGHT, FULL OUTER) are supported in recursive CTEs. LEFT JOIN is particularly useful for handling optional relationships in hierarchical data structures.
## Impact
- **MySQL Compatibility**: LEFT/RIGHT/OUTER JOIN in recursive CTEs is a standard MySQL feature
- **Migration**: Applications using LEFT/RIGHT/OUTER JOIN in recursive CTEs will fail when migrating to MatrixOne
- **Functionality**: Users cannot handle optional relationships in recursive CTEs, limiting data modeling flexibility
- **Hierarchical Analysis**: Cannot perform left-joined aggregations within recursive CTEs
## Test Context
This issue was discovered during recursive CTE compatibility testing using the `industry_radar_test` database, which contains:
- `industry_domain` table with ~1.5K records (hierarchical structure)
- `industry_domain_company` table with ~30K records (many-to-many relationship)
## Suggested Fix
1. **Parser Update**: Update the SQL parser to allow LEFT, RIGHT, and OUTER JOIN in recursive CTEs
2. **Query Planning**: Ensure the query planner can handle different JOIN types within recursive CTE execution
3. **Execution Engine**: Implement proper JOIN handling (including NULL handling for LEFT/RIGHT/OUTER JOINs) during recursive CTE iteration
4. **Documentation**: Update documentation to reflect support for all JOIN types in recursive CTEs
Contributor guide
Assessment
This issue has not been assessed yet.