Add support for ALTER TABLE DROP INDEX (#1865)
Some checks are pending
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run

This commit is contained in:
vimko 2025-06-11 00:26:07 +08:00 committed by GitHub
parent 40d12b98bd
commit 559b7e36d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 0 deletions

View file

@ -187,6 +187,12 @@ pub enum AlterTableOperation {
DropForeignKey {
name: Ident,
},
/// `DROP INDEX <index_name>`
///
/// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
DropIndex {
name: Ident,
},
/// `ENABLE ALWAYS RULE rewrite_rule_name`
///
/// Note: this is a PostgreSQL-specific operation.
@ -606,6 +612,7 @@ impl fmt::Display for AlterTableOperation {
}
AlterTableOperation::DropPrimaryKey => write!(f, "DROP PRIMARY KEY"),
AlterTableOperation::DropForeignKey { name } => write!(f, "DROP FOREIGN KEY {name}"),
AlterTableOperation::DropIndex { name } => write!(f, "DROP INDEX {name}"),
AlterTableOperation::DropColumn {
has_column_keyword,
column_name,

View file

@ -1115,6 +1115,7 @@ impl Spanned for AlterTableOperation {
.union_opt(&with_name.as_ref().map(|n| n.span)),
AlterTableOperation::DropPrimaryKey => Span::empty(),
AlterTableOperation::DropForeignKey { name } => name.span,
AlterTableOperation::DropIndex { name } => name.span,
AlterTableOperation::EnableAlwaysRule { name } => name.span,
AlterTableOperation::EnableAlwaysTrigger { name } => name.span,
AlterTableOperation::EnableReplicaRule { name } => name.span,

View file

@ -8636,6 +8636,9 @@ impl<'a> Parser<'a> {
} else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::KEY]) {
let name = self.parse_identifier()?;
AlterTableOperation::DropForeignKey { name }
} else if self.parse_keyword(Keyword::INDEX) {
let name = self.parse_identifier()?;
AlterTableOperation::DropIndex { name }
} else if self.parse_keyword(Keyword::PROJECTION)
&& dialect_of!(self is ClickHouseDialect|GenericDialect)
{

View file

@ -4025,3 +4025,13 @@ fn parse_drop_index() {
_ => unreachable!(),
}
}
#[test]
fn parse_alter_table_drop_index() {
assert_matches!(
alter_table_op(
mysql_and_generic().verified_stmt("ALTER TABLE tab DROP INDEX idx_index")
),
AlterTableOperation::DropIndex { name } if name.value == "idx_index"
);
}