The Wayback Machine - https://web.archive.org/web/20240619064123/https://www.geeksforgeeks.org/mysql-drop-index-statetement/
Open In App

MySQL DROP INDEX Statetement

Last Updated : 04 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

MySQL is open-source and user-friendly. It creates a database to store and manipulate the data. To perform various operations users make requests by typing specific statements. The server responds to the information from the user and Displays it on the user side. One Of the commands in MySQL is DROP INDEX which is used for deleting an index in the table.

DROP INDEX in MySQL

DROP INDEX is a way of telling MySQL, “I don’t need this organization tool anymore.” Imagine it’s like throwing away old sticky notes that helped you find things quickly. Sometimes, you just need a fresh start.

DROP INDEX drops the index named index_name from the table tbl_name. This statement is mapped to an ALTER TABLE statement to drop the index.

Syntax:

DROP INDEX index_name ON tbl_name

[algorithm_option | lock_option] …

algorithm_option:

ALGORITHM [=] {DEFAULT | INPLACE | COPY}

lock_option:

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

Example of MYSQL DROP INDEX

Let’s consider a practical scenario where we have a table named “STUDENT” with an index named “name_index,” and we want to remove this index. The corresponding query would be:

Example:

ALTER TABLE Student
DROP INDEX name_index;
Drop Index Example

DROP INDEX

ALGORITHM Options in DROP INDEX

1) DEFAULT

The DEFAULT algorithm is like putting your trust in MySQL’s hands. When you specify ALGORITHM=DEFAULT, MySQL dynamically determines the most appropriate method for index removal based on the characteristics of your database. Opt for DEFAULT when you want MySQL to make the decision for you, adapting to the nature and size of your database.

Example:

DROP INDEX idx_example ON your_table ALGORITHM=DEFAULT;

2) INPLACE

The INPLACE algorithm is all about efficiency and minimal disruption. It removes the index with the least impact on concurrent operations, akin to a quiet ninja move during cleanup. Choose ALGORITHM=INPLACE when you want to discreetly remove the index, especially in scenarios where there are ongoing database activities.

Example:

DROP INDEX idx_example ON your_table ALGORITHM=INPLACE;

3) COPY

The COPY algorithm involves creating a temporary copy of the table, dropping the index in the copy, and then renaming the copy to replace the original table. This method allows for more extensive changes during the index removal but can be resource-intensive. Select ALGORITHM=COPY when you need to make significant changes to the table structure during index removal, and you’re willing to tolerate the additional resource usage.

Example:

DROP INDEX idx_example ON your_table ALGORITHM=COPY;

Each algorithm option serves a specific purpose, offering a balance between hands-off convenience (DEFAULT), minimal disruption (INPLACE), and the ability to make extensive changes (COPY). Your choice depends on the nature of your database and the level of control and resources you’re willing to allocate for the index removal process.

LOCK Options in DROP INDEX

1) DEFAULT

The DEFAULT option delegates the decision-making to MySQL. It dynamically determines the appropriate level of locking based on the nature of the operation and the characteristics of the database. Choose DEFAULT when you prefer MySQL to handle the locking strategy, adapting to the specific conditions of the operation.

Example:

DROP INDEX idx_example ON your_table LOCK=DEFAULT;

2) NONE

The NONE option minimizes locking during the execution of the statement. It allows other operations to proceed concurrently with minimal interference. Opt for NONE when you want to perform the operation with the least impact on concurrent activities.

Example:

DROP INDEX idx_example ON your_table LOCK=NONE;

3) SHARED

The SHARED option involves acquiring shared read locks. Multiple operations can access the table concurrently, ensuring data consistency during the execution of the statement. Choose SHARED when you want to share the read locks, allowing multiple operations to access the table simultaneously.

Example:

DROP INDEX idx_example ON your_table LOCK=SHARED;

4) EXCLUSIVE

The EXCLUSIVE option acquires exclusive locks, preventing any other operations on the table during the execution of the statement. It ensures exclusive access to the table for the operation’s duration. Opt for EXCLUSIVE when you need exclusive control over the table, preventing any concurrent operations during the statement’s execution.

Example:

DROP INDEX idx_example ON your_table LOCK=EXCLUSIVE;

Each LOCK option serves a specific purpose, providing flexibility in managing the balance between data consistency and the impact on concurrent operations. Your choice depends on the specific requirements of the operation and the desired level of control over locking behavior.

Dropping PRIMARY Key Index

To drop a primary key index in MySQL, you can use the DROP INDEX command along with the name of the primary key index and the ALTER TABLE statement.

Syntax:

ALTER TABLE your_table DROP PRIMARY KEY;

Example of Dropping PRIMARY Key Index

Let’s consider a practical scenario where we have a table named “STUDENT” with a PRIMARY KEY, and we want to remove this index. The corresponding query would be

Drop Primary Key

Drop Primary Key

Conclusion

It is essential to manage the indices in a MySQL Database for better performance. DROP INDEX command in MySQL helps us to remove indices when needed. We can also use the Algorithm and Lock Option along with DROP INDEX for meeting certain requirements while removing indices. It’s important to exercise caution while using this command to ensure that only the intended indexes are removed, avoiding unintended consequences on query performance.


Previous Article
Next Article

Similar Reads

MySQL Drop Database
In Database Management Systems managing databases involves not only creating and modifying the data but also removing the databases when they are no longer needed and freeing the space occupied by them. MySQL offers a feature called DROP DATABASE, allowing users to delete databases. In this article, We will see How to Drop Databases in MySQL, vario
3 min read
MySQL DROP TABLE Statement
MySQL is a free and open-source relational database management system written in C and C++ that is extremely popular among developers. Like other relational database management systems, MySQL provides a variety of rich features to create databases and tables, insert data in them, and further manipulate them as the system evolves. In this article, w
5 min read
MySQL - Drop View
MySQL is a powerful open-source relational database management system that is widely used for building scalable and high-performance databases. Developed by MySQL AB, which is currently owned by Oracle Corporation, MySQL has been around since 1995. It is known for its robust, easy-to-use, and reliable features, as well as its quick processing speed
3 min read
Functions in MySQL | Numeric, String and Date Time Functions in MySQL
MySQL functions are powerful tools that help in performing complex calculations and data manipulation with ease. The functions in MySQL can edit rows and tables, alter strings, and help you manage organized and easy-to-navigate databases. A function is a special type of predefined command set that performs some operation and returns a value. Functi
3 min read
MySQL Unique Index
In MySQL, a unique index is a crucial tool for ensuring that values in a specific column or a group of columns within a table are unique. This feature is essential to maintain data integrity by preventing duplicate entries where uniqueness is required. In this guide, we'll explore MySQL's unique index, covering its syntax, usage, benefits, and impo
6 min read
MySQL CREATE INDEX Statement
MySQL is an open-source relational database management system that uses Structured Query Language (SQL) to manipulate databases. CREATE INDEX statement is used to retrieve data from the database more quickly. CREATE INDEX statement is used to create an Index that allows MySQL to quickly locate and retrieve relevant data by reducing the need for ful
3 min read
MySQL SHOW INDEX
MySQL is a popular open-source relational database management system (RDBMS) that is uniquely used to construct expandable and high-productivity databases. MySQL, which was created by MySQL AB and later acquired by its current owner Oracle Corporation, was originally introduced in 1995. MySQL is reputed for its sturdy and quick functioning attribut
6 min read
Queries to find Maximum index R with bitwise AND from index L at least K
Given array A[] of size N and array Q[][2] of size M representing queries of the type {L, K}. The task for this problem is to answer queries for each query to find the largest index R such that bitwise AND of all elements from L to R is at least K. If there is no such index print -1 Examples: Input: A[] = {15, 14, 17, 42, 34}, Q[][2] = {{1, 7}, {2,
15+ min read
How to Make Scrollable Drop Down Lists in React-Bootstrap ?
In this article, we will learn how to make Scrollable Dropdown lists in React-Bootstrap. Drop-down lists allow users to choose an option from a list of available options visible whenever the corresponding component is clicked or triggered. Using React-bootstrap, we can customize the drop-down list as needed. Syntax:<Dropdown> <Dropdown.Tog
3 min read
Drag and Drop Sortable List Using ReactJS
In this article, we'll create a Drag and Drop sortable list using React JS. Within this web application, users can effortlessly rearrange­ a list of items through the simple act of dragging and dropping. Preview Image: PrerequisitesReact CSSClass Components in ReactReact HooksApproach:This React-based application, "Drag and Drop Sortable List," all
4 min read