Logo
Section 1 / 4

问题:执行计划

通过执行计划检查你对 MySQL 如何评估和比较查询性能的理解。

导入

问题:执行计划

通过执行计划检查你对 MySQL 如何评估和比较查询性能的理解。

表

字段类型
ProductIDINT
ProductNameVARCHAR(50)
CategoryIDINT
PriceDECIMAL(10,2)
StockINT
LastRestockDateDATE

表

字段类型
OrderDetailIDINT
OrderIDINT
ProductIDINT
QuantityINT
TotalItemPriceDECIMAL(10,2)

表

EXPLAIN
-> Nested loop semijoin (cost=12 rows=26) (actual time=0.0459..0.115 rows=21 loops=1)\n -> Covering index scan on p using ProductName (cost=2.85 rows=26) (actual time=0.0179..0.0282 rows=26 loops=1)\n -> Covering index lookup on od using ProductID (ProductID=p.ProductID) (cost=0.254 rows=1) (actual time=0.0031..0.0031 rows=0.808 loops=26)\n

表

EXPLAIN
-> Table scan on (cost=14.7..17.4 rows=26) (actual time=0.169..0.172 rows=21 loops=1)\n -> Temporary table with deduplication (cost=14.6..14.6 rows=26) (actual time=0.168..0.168 rows=21 loops=1)\n -> Nested loop inner join (cost=12 rows=26) (actual time=0.0268..0.078 rows=21 loops=1)\n -> Covering index scan on p using ProductName (cost=2.85 rows=26) (actual time=0.0153..0.0226 rows=26 loops=1)\n -> Limit: 1 row(s) (cost=0.254 rows=1) (actual time=0.00187..0.00189 rows=0.808 loops=26)\n -> Covering index lookup on od using ProductID (ProductID=p.ProductID) (cost=0.254 rows=1) (actual time=0.00174..0.00174 rows=0.808 loops=26)\n
1/*Write your queries below*/ 2-- Version A: EXISTS based plan 3 4 5-- Version B: JOIN based plan (distinct products that appear in Order_Details) 6 7 8-- Optional: Run each SELECT without EXPLAIN to confirm they return the same set of products

所需技能如下:

  • 理解执行计划
  • 能够使用 EXPLAIN 和 EXPLAIN ANALYZE 检查查询
  • 基本熟悉在计划中阅读索引使用和连接策略

所需技能如下:

  • 理解执行计划
  • 能够使用 EXPLAIN 和 EXPLAIN ANALYZE 检查查询
  • 基本熟悉在计划中阅读索引使用和连接策略

No configuration found for ID: 65b68a493a656c1fee74d7339496b5b4afbf13739d76b5552bb81e836a8c33da

高级数据库对象

Answer: 执行计划