matrixorigin / matrixorigin/matrixone
MySQL Compatibility: UNION queries with LIMIT clauses not supported
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
## Description
MatrixOne does not support UNION queries with LIMIT clauses in each SELECT statement. When executing UNION queries where each SELECT has a LIMIT clause, MatrixOne returns a SQL syntax error.
## Error Message
```
ERROR 1064 (HY000) at line 1: SQL parser error: You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. syntax error at line 1 column 63 near " UNION SELECT company_id as id FROM company_patent WHERE status = '授权' LIMIT 10";
```
## Affected Cases
This issue affects **19 test cases** from our MySQL compatibility testing on the `industry_radar_test` database.
## Related Table DDL
### Table: company
```sql
CREATE TABLE `company` (
`id` int NOT NULL,
`full_name` varchar(200) DEFAULT NULL,
`short_name` varchar(128) DEFAULT NULL,
`update_time` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '最后修改时间',
`address` varchar(255) DEFAULT NULL,
`board_id` int DEFAULT NULL,
`business_scope` text DEFAULT NULL,
`city` varchar(32) DEFAULT NULL,
`company_profile` text DEFAULT NULL,
`company_type_tags` varchar(255) DEFAULT NULL,
`country` varchar(20) DEFAULT NULL,
`directory_label` varchar(512) DEFAULT NULL,
`district` varchar(32) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`english_name` varchar(255) DEFAULT NULL,
`enterprises_type` varchar(50) DEFAULT NULL,
`founded_time` datetime(6) DEFAULT NULL,
`industry` varchar(32) DEFAULT NULL,
`industry_paqu` varchar(1000) DEFAULT NULL,
`insured_num` varchar(32) DEFAULT NULL,
`product_label` varchar(512) DEFAULT NULL,
`province` varchar(32) DEFAULT NULL,
`registered_capital` varchar(50) DEFAULT NULL,
`representative` varchar(32) DEFAULT NULL,
`taxpayer_num` varchar(50) DEFAULT NULL,
`telephone` varchar(255) DEFAULT NULL,
`website` varchar(500) DEFAULT NULL,
`industry_web_label` varchar(512) DEFAULT NULL COMMENT '国标行业标签',
`industry_domain_label` varchar(512) DEFAULT NULL COMMENT '素问产业链标签',
`scale` varchar(255) DEFAULT NULL COMMENT '规模标签',
`policy_type` varchar(512) DEFAULT NULL COMMENT '政策类型标签',
PRIMARY KEY (`id`),
UNIQUE KEY `company_full_name_idx` (`full_name`),
UNIQUE KEY `company_short_name_idx` (`short_name`),
KEY `company_board_id_idx` (`board_id`),
KEY `company_city_idx` (`city`),
KEY `company_province_idx` (`province`)
)
```
### Table: company_patent
```sql
CREATE TABLE `company_patent` (
`id` bigint NOT NULL AUTO_INCREMENT,
`company_id` bigint DEFAULT '1212',
`name` varchar(512) DEFAULT NULL,
`status` varchar(50) DEFAULT NULL,
`patent_type` varchar(50) DEFAULT NULL,
`num` varchar(50) NOT NULL,
`patenter` varchar(255) DEFAULT NULL,
`patenter_now` varchar(255) DEFAULT NULL,
`inventor` varchar(512) DEFAULT NULL,
`ipc` text DEFAULT NULL,
`cpc` text DEFAULT NULL,
`info` text DEFAULT NULL,
`public_date` varchar(25) DEFAULT NULL,
`application_date` varchar(25) DEFAULT NULL,
`tags` varchar(5000) DEFAULT NULL,
`claims` text DEFAULT NULL COMMENT '权利要求书',
`instructions` text DEFAULT NULL COMMENT '说明书',
`update_time` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `ad` (`application_date`),
KEY `patent_num` (`num`),
KEY `public_date` (`public_date`),
KEY `id` (`id`),
KEY `update_time_idx` (`update_time`),
KEY `company_id` (`company_id`)
)
```
### Table: news_company
```sql
CREATE TABLE `news_company` (
`id` int NOT NULL,
`company_id` int DEFAULT NULL,
`release_time` datetime(6) DEFAULT NULL,
`extract_type` int DEFAULT NULL,
`is_hot` int DEFAULT NULL,
`polarity` int DEFAULT NULL,
`update_time` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '最后修改时间',
`news_id` int DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_company_news_idx` (`company_id`,`news_id`),
KEY `news_id_652ab8d1_fk_news_detail_id` (`news_id`),
KEY `company_id_idx` (`company_id`),
KEY `release_time_idx` (`release_time`)
)
```
## Failing SQL Statements
### Example 1
```sql
SELECT id FROM company WHERE province = '广东' LIMIT 10 UNION SELECT company_id as id FROM company_patent WHERE status = '授权' LIMIT 10;
```
### Example 2
```sql
SELECT company_id FROM company_patent WHERE status = '授权' LIMIT 10 UNION SELECT company_id FROM news_company LIMIT 10;
```
## Expected Behavior
In MySQL, UNION queries with LIMIT clauses in each SELECT statement are valid and should execute successfully. The LIMIT should be applied to each SELECT before the UNION operation.
## Impact
- **MySQL Compatibility**: This is a standard MySQL feature that should be supported
- **Migration**: Applications using UNION with LIMIT will fail when migrating to MatrixOne
- **Functionality**: Users cannot combine results from multiple queries with individual limits
## Test Context
This issue was discovered during MySQL compatibility testing using the `industry_radar_test` database, which contains real-world market intelligence data with millions of records.
## Suggested Fix
1. Support UNION queries with LIMIT clauses in each SELECT statement
2. Ensure proper parsing and execution order (LIMIT before UNION)
3. Handle both UNION and UNION ALL cases
Contributor guide
Assessment
This issue has not been assessed yet.