apache / apache/datafusion-sqlparser-rs

mysql: `DROP INDEX idx_xxx on t` and an error occurs

未关闭
#1,863 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
3.5k
派生
772
平均合并
4 天 9 小时
30 天内合并 PR
17

描述

With v0.56.0 using the mysql dialect, use the `parse_sql` function to parse `DROP INDEX idx_name ON table_demo;` or `ALTER TABLE tbl_name DROP INDEX idx_name;` and an error occurs.

```rust
use sqlparser::dialect::MySqlDialect;
use sqlparser::parser::Parser;

fn main() {
let sql = "DROP INDEX idx_name ON table_demo;";

let dialect = MySqlDialect {}; // or AnsiDialect, or your own dialect ...

let ast = Parser::parse_sql(&dialect, sql).unwrap();

println!("AST: {:?}", ast);
}

```

Report the following error:

```
called `Result::unwrap()` on an `Err` value: ParserError("Expected: end of statement, found: ON at Line: 1, Column: 21")
```

In the official documentation of MySQL, when deleting an index, you need to specify the table where the index is located.

```sql
DROP INDEX index_name ON tbl_name
[algorithm_option | lock_option] ...

algorithm_option:
ALGORITHM [=] {DEFAULT | INPLACE | COPY}

lock_option:
LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}

```

https://dev.mysql.com/doc/refman/8.0/en/drop-index.html

Would you classify this as a bug?

贡献指南

这个仓库没有索引到贡献指南

调研方向

通过 MySqlDialect 和 Parser::parse_sql,分别使用 DROP INDEX ... ON ... 和 ALTER TABLE ... DROP INDEX 两种形式重现该故障。跟踪这些语句的解析过程,并验证回归测试覆盖能够接受文档所述的 MySQL 语法,而不会出现报告中的解析器错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
mysql, rust
领域
databases
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。