mysql 查询的 `id` 列的含义是什么?
What the meaning of the `id` column of the mysql query explain?
假设一个查询:
EXPLAIN
SELECT actor_id,
(SELECT 1 FROM sakila.film_actor WHERE film_actor.actor_id =
der_1.actor_id LIMIT 1)
FROM (
SELECT actor_id
FROM sakila.actor LIMIT 5
) AS der_1
UNION ALL
SELECT film_id,
(SELECT @var1 FROM sakila.rental LIMIT 1)
FROM (
SELECT film_id,
(SELECT 1 FROM sakila.store LIMIT 1)
FROM sakila.film LIMIT 5
) AS der_2;
给出以下包含 8 个步骤(行)的查询计划:
+------+----------------------+------------+...
| id | select_type | table |...
+------+----------------------+------------+...
| 1 | PRIMARY | <derived3> |...
| 3 | DERIVED | actor |...
| 2 | DEPENDENT SUBQUERY | film_actor |...
| 4 | UNION | <derived6> |...
| 6 | DERIVED | film |...
| 7 | SUBQUERY | store |...
| 5 | UNCACHEABLE SUBQUERY | rental |...
| NULL | UNION RESULT | <union1,4> |...
+------+----------------------+------------+...
官方文档定义了id列:
The SELECT identifier. This is the sequential number of the SELECT within the query. The value can be NULL if the row refers to the union result of other rows. In this case, the table column shows a value like <unionM,N> to indicate that the row refers to the union of the rows with id values of M and N.
根据doc,id只是序号(sn简写),这个sn有什么比喻吗?
- sn值是否反映了查询计划步骤的执行顺序? sn越大执行顺序越早?
- 如果两步的sn值相同,mysql先运行哪一步?
像 MySQL 这样的数据库系统内置了非常精细的查询计划/优化模块。 EXPLAIN
揭示了一点优化逻辑;特别是哪些指标是相关的。 EXPLAIN 不一定揭示服务器如何对其操作进行排序。
而且,SQL 是一种 声明式 语言。你用它来描述你想要什么,而不是如何得到它。。这使得它不同于大多数其他编程语言,后者是 过程性的 。你关于子查询执行顺序的问题是程序性问题,不是声明性问题。
子查询的执行顺序及其执行的并发性是一个实现细节,可能会随着数据库软件的发布而变化。
假设一个查询:
EXPLAIN
SELECT actor_id,
(SELECT 1 FROM sakila.film_actor WHERE film_actor.actor_id =
der_1.actor_id LIMIT 1)
FROM (
SELECT actor_id
FROM sakila.actor LIMIT 5
) AS der_1
UNION ALL
SELECT film_id,
(SELECT @var1 FROM sakila.rental LIMIT 1)
FROM (
SELECT film_id,
(SELECT 1 FROM sakila.store LIMIT 1)
FROM sakila.film LIMIT 5
) AS der_2;
给出以下包含 8 个步骤(行)的查询计划:
+------+----------------------+------------+...
| id | select_type | table |...
+------+----------------------+------------+...
| 1 | PRIMARY | <derived3> |...
| 3 | DERIVED | actor |...
| 2 | DEPENDENT SUBQUERY | film_actor |...
| 4 | UNION | <derived6> |...
| 6 | DERIVED | film |...
| 7 | SUBQUERY | store |...
| 5 | UNCACHEABLE SUBQUERY | rental |...
| NULL | UNION RESULT | <union1,4> |...
+------+----------------------+------------+...
官方文档定义了id列:
The SELECT identifier. This is the sequential number of the SELECT within the query. The value can be NULL if the row refers to the union result of other rows. In this case, the table column shows a value like <unionM,N> to indicate that the row refers to the union of the rows with id values of M and N.
根据doc,id只是序号(sn简写),这个sn有什么比喻吗?
- sn值是否反映了查询计划步骤的执行顺序? sn越大执行顺序越早?
- 如果两步的sn值相同,mysql先运行哪一步?
像 MySQL 这样的数据库系统内置了非常精细的查询计划/优化模块。 EXPLAIN
揭示了一点优化逻辑;特别是哪些指标是相关的。 EXPLAIN 不一定揭示服务器如何对其操作进行排序。
而且,SQL 是一种 声明式 语言。你用它来描述你想要什么,而不是如何得到它。。这使得它不同于大多数其他编程语言,后者是 过程性的 。你关于子查询执行顺序的问题是程序性问题,不是声明性问题。
子查询的执行顺序及其执行的并发性是一个实现细节,可能会随着数据库软件的发布而变化。