This is an automated email from the ASF dual-hosted git repository.

iffyio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 80d47eee Adds support for mysql's drop index (#1864)
80d47eee is described below

commit 80d47eee84f0954ad24918b046e47f08e3762142
Author: Dmitriy Mazurin <dimas.m...@gmail.com>
AuthorDate: Fri May 30 08:16:36 2025 +0100

    Adds support for mysql's drop index (#1864)
    
    Co-authored-by: Ifeanyi Ubah <ify1...@yahoo.com>
---
 src/ast/mod.rs           | 32 +++++++++++++++++++++-----------
 src/parser/mod.rs        |  6 ++++++
 tests/sqlparser_mysql.rs | 31 +++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 8e7bec3f..653f58e4 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -3405,6 +3405,9 @@ pub enum Statement {
         purge: bool,
         /// MySQL-specific "TEMPORARY" keyword
         temporary: bool,
+        /// MySQL-specific drop index syntax, which requires table 
specification  
+        /// See <https://dev.mysql.com/doc/refman/8.4/en/drop-index.html>
+        table: Option<ObjectName>,
     },
     /// ```sql
     /// DROP FUNCTION
@@ -5242,17 +5245,24 @@ impl fmt::Display for Statement {
                 restrict,
                 purge,
                 temporary,
-            } => write!(
-                f,
-                "DROP {}{}{} {}{}{}{}",
-                if *temporary { "TEMPORARY " } else { "" },
-                object_type,
-                if *if_exists { " IF EXISTS" } else { "" },
-                display_comma_separated(names),
-                if *cascade { " CASCADE" } else { "" },
-                if *restrict { " RESTRICT" } else { "" },
-                if *purge { " PURGE" } else { "" }
-            ),
+                table,
+            } => {
+                write!(
+                    f,
+                    "DROP {}{}{} {}{}{}{}",
+                    if *temporary { "TEMPORARY " } else { "" },
+                    object_type,
+                    if *if_exists { " IF EXISTS" } else { "" },
+                    display_comma_separated(names),
+                    if *cascade { " CASCADE" } else { "" },
+                    if *restrict { " RESTRICT" } else { "" },
+                    if *purge { " PURGE" } else { "" },
+                )?;
+                if let Some(table_name) = table.as_ref() {
+                    write!(f, " ON {}", table_name)?;
+                };
+                Ok(())
+            }
             Statement::DropFunction {
                 if_exists,
                 func_desc,
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 6d642384..f2da659f 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -6255,6 +6255,11 @@ impl<'a> Parser<'a> {
                 loc
             );
         }
+        let table = if self.parse_keyword(Keyword::ON) {
+            Some(self.parse_object_name(false)?)
+        } else {
+            None
+        };
         Ok(Statement::Drop {
             object_type,
             if_exists,
@@ -6263,6 +6268,7 @@ impl<'a> Parser<'a> {
             restrict,
             purge,
             temporary,
+            table,
         })
     }
 
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs
index 71a5d905..337707c9 100644
--- a/tests/sqlparser_mysql.rs
+++ b/tests/sqlparser_mysql.rs
@@ -3987,3 +3987,34 @@ fn parse_straight_join() {
     mysql()
         .verified_stmt("SELECT a.*, b.* FROM table_a STRAIGHT_JOIN table_b AS 
b ON a.b_id = b.id");
 }
+
+#[test]
+fn parse_drop_index() {
+    let sql = "DROP INDEX idx_name ON table_name";
+    match mysql().verified_stmt(sql) {
+        Statement::Drop {
+            object_type,
+            if_exists,
+            names,
+            cascade,
+            restrict,
+            purge,
+            temporary,
+            table,
+        } => {
+            assert!(!if_exists);
+            assert_eq!(ObjectType::Index, object_type);
+            assert_eq!(
+                vec!["idx_name"],
+                names.iter().map(ToString::to_string).collect::<Vec<_>>()
+            );
+            assert!(!cascade);
+            assert!(!restrict);
+            assert!(!purge);
+            assert!(!temporary);
+            assert!(table.is_some());
+            assert_eq!("table_name", table.unwrap().to_string());
+        }
+        _ => unreachable!(),
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@datafusion.apache.org
For additional commands, e-mail: commits-h...@datafusion.apache.org

Reply via email to