Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of "Select tables optimized away" in MySQL Explain plan

What is the meaning of Select tables optimized away in MySQL Explain plan?

explain select count(comment_count) from wp_posts;  +----+-------------+---------------------------+-----------------------------+ | id | select_type | table,type,possible_keys, | Extra                       | |    |             | key,key_len,ref,rows      |                             | +----+-------------+---------------------------+-----------------------------+ | 1  | SIMPLE      | all NULLs                 | Select tables optimized away|  +----+-------------+---------------------------+-----------------------------+ 1 row in set (0.00 sec) 

Note: explain plan output edited for legibility.

like image 634
Chandra Patni Avatar asked Jan 02 '10 18:01

Chandra Patni


People also ask

What is select type in MySQL?

The select_type value for non- SELECT statements displays the statement type for affected tables. For example, select_type is DELETE for DELETE statements. table (JSON name: table_name ) The name of the table to which the row of output refers.

Which column of explain plan output indicates the index used in query?

The key column in the output row indicates which index is used. The key_len contains the longest key part that was used.

What does filtered mean in MySQL explain?

The filtered column indicates an estimated percentage of table rows that will be filtered by the table condition. That is, rows shows the estimated number of rows examined and rows × filtered / 100 shows the number of rows that will be joined with previous tables.

What is explain statement in MySQL?

The EXPLAIN statement provides information about how MySQL executes statements: EXPLAIN works with SELECT , DELETE , INSERT , REPLACE , and UPDATE statements. When EXPLAIN is used with an explainable statement, MySQL displays information from the optimizer about the statement execution plan.


1 Answers

From the MySQL documentation:

The query contained only aggregate functions (MIN(), MAX()) that were all resolved using an index, or COUNT(*) for MyISAM, and no GROUP BY clause. The optimizer determined that only one row should be returned.

Basically this means your query uses data that is directly available to MySQL and the query will run in constant time.

like image 92
Leolo Avatar answered Sep 28 '22 11:09

Leolo