Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL explain for DELETE queries

Tags:

mysql

Is there a way to explain a DELETE query with MySQL like we can explain a SELECT query?

like image 410
user217631 Avatar asked Apr 29 '11 18:04

user217631


People also ask

What is delete query in MySQL?

DELETE is a DML statement that removes rows from a table. A DELETE statement can start with a WITH clause to define common table expressions accessible within the DELETE . See Section 13.2. 15, “WITH (Common Table Expressions)”.

How do you delete a query from a table in MySQL?

To permanently remove a table, enter the following statement within the MySQL shell: DROP TABLE table1; Replace table1 with the name of the table you want to delete. The output confirms that the table has been removed.

Why we use delete command in MySQL?

MySQL Delete command is used to delete rows that are no longer required from the database tables. It deletes the whole row from the table and returns count of deleted rows. Delete command comes in handy to delete temporary or obsolete data from your database.

Is deletion possible in MySQL?

In MySQL, DELETE is a Data Manipulation Language or DML, as we know. As the name itself suggests, the command is used to delete rows from the table. Using this command, we can delete one or more unwanted rows in one single transaction. There are multiple ways to delete records from a table using the DELETE command.


2 Answers

"As of MySQL 5.6.3, EXPLAIN provides information about SELECT, DELETE, INSERT, REPLACE, and UPDATE statements. Before MySQL 5.6.3, EXPLAIN provides information only about SELECT statements."

from http://dev.mysql.com/doc/refman/5.6/en/explain.html

like image 156
Niro Avatar answered Sep 21 '22 17:09

Niro


Wouldn't the plan for that be the same as for a select 1 where.... with the same condition as your delete query?

The 1 is so the optimizer isn't forced to pull any unneeded columns, it can only look at the columns it needs for the filtering conditions.

like image 23
Blindy Avatar answered Sep 21 '22 17:09

Blindy