{"id":2483,"date":"2026-10-16T10:43:08","date_gmt":"2026-10-16T02:43:08","guid":{"rendered":"http:\/\/www.spiceandwolf.com.cn\/?p=2483"},"modified":"2026-10-29T10:04:07","modified_gmt":"2026-10-29T02:04:07","slug":"mysql-book-zy-1415","status":"publish","type":"post","link":"http:\/\/www.spiceandwolf.com.cn\/index.php\/mysql-book-zy-1415\/","title":{"rendered":"\u300aMySQL\u600e\u8fd0&#8230;\u300b\u7b2c\u5341\u56db\u7ae0&amp;\u5341\u4e94\u7ae0 \u67e5\u8be2\u4f18\u5316\u7684\u767e\u79d1\u5168\u4e66-Explain\u8be6\u89e3\uff08\u6458\u8981\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e00\u6761\u67e5\u8be2\u8bed\u53e5\u5728\u7ecf\u8fc7 MySQL \u67e5\u8be2\u4f18\u5316\u5668\u7684\u5404\u79cd\u57fa\u4e8e\u6210\u672c\u548c\u89c4\u5219\u7684\u4f18\u5316\u4f1a\u540e\u751f\u6210\u4e00\u4e2a\u6240\u8c13\u7684 \u6267\u884c\u8ba1\u5212 \uff0c\u8fd9\u4e2a\u6267\u884c\u8ba1\u5212\u5c55\u793a\u4e86\u63a5\u4e0b\u6765\u5177\u4f53\u6267\u884c\u67e5\u8be2\u7684\u65b9\u5f0f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6267\u884c\u8ba1\u5212\u5404\u5217\u8be6\u89e3<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>table<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8bba\u6211\u4eec\u7684\u67e5\u8be2\u8bed\u53e5\u6709\u591a\u590d\u6742\uff0c\u91cc\u8fb9\u513f\u5305\u542b\u4e86\u591a\u5c11\u4e2a\u8868\uff0c\u5230\u6700\u540e\u4e5f\u662f\u9700\u8981\u5bf9\u6bcf\u4e2a\u8868\u8fdb\u884c\u5355\u8868\u8bbf\u95ee\u7684\uff0c\u6240\u4ee5MySQL \u89c4\u5b9aEXPLAIN\u8bed\u53e5\u8f93\u51fa\u7684\u6bcf\u6761\u8bb0\u5f55\u90fd\u5bf9\u5e94\u7740\u67d0\u4e2a\u5355\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\uff0c\u8be5\u6761\u8bb0\u5f55\u7684table\u5217\u4ee3\u8868\u7740\u8be5\u8868\u7684\u8868\u540d<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>id<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u8bed\u53e5\u4e2d\u6bcf\u51fa\u73b0\u4e00\u4e2a SELECT \u5173\u952e\u5b57\uff0cMySQL \u5c31\u4f1a\u4e3a\u5b83\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684 id \u503c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fde\u63a5\u67e5\u8be2\u4e2d\uff0c\u4e00\u4e2aselect\u540e\u9762\u53ef\u80fd\u4f1a\u8ddf\u591a\u4e2a\u8868\uff0c\u6bcf\u4e00\u4e2a\u8868\u90fd\u5bf9\u5e94\u4e00\u6761\u8bb0\u5f55\uff0c\u4f46\u8fd9\u4e9b\u8bb0\u5f55\u7684id\u90fd\u662f\u76f8\u540c\u7684\uff0c\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; EXPLAIN SELECT * FROM s1 INNER JOIN s2;\n+----+-------------+-------+------------+------+---------------+------+---------+------+--\n----+----------+---------------------------------------+\n| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | r\nows | filtered | Extra |\n+----+-------------+-------+------------+------+---------------+------+---------+------+--\n----+----------+---------------------------------------+\n| 1 | SIMPLE | s1 | NULL | ALL | NULL | NULL | NULL | NULL | 9\n688 | 100.00 | NULL |\n| 1 | SIMPLE | s2 | NULL | ALL | NULL | NULL | NULL | NULL | 9\n954 | 100.00 | Using join buffer (Block Nested Loop) |\n+----+-------------+-------+------------+------+---------------+------+---------+------+--\n----+----------+---------------------------------------+\n2 rows in set, 1 warning (0.01 sec)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5b58\u5728\u5b50\u67e5\u8be2\u7684\u67e5\u8be2\u4e2d\uff0c\u5982\u679c\u4f18\u5316\u5668\u5224\u65ad\u53ef\u4ee5\u5c06\u7236\u5b50\u67e5\u8be2\u4f18\u5316\u4e3a\u4e00\u4e2aselect\u67e5\u8be2\uff0c\u90a3\u4e48\u6267\u884c\u8ba1\u5212\u4e2d\u53ef\u80fd\u53ea\u6709\u4e00\u4e2aid\u503c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; EXPLAIN SELECT * FROM s1 WHERE key1 IN (SELECT key3 FROM s2 WHERE common_field =\n'a');\n+----+-------------+-------+------------+------+---------------+----------+---------+-----\n--------------+------+----------+------------------------------+\n| id | select_type | table | partitions | type | possible_keys | key | key_len | ref\n| rows | filtered | Extra |\n+----+-------------+-------+------------+------+---------------+----------+---------+-----\n--------------+------+----------+------------------------------+\n| 1 | SIMPLE | s2 | NULL | ALL | idx_key3 | NULL | NULL | NULL\n| 9954 | 10.00 | Using where; Start temporary |\n| 1 | SIMPLE | s1 | NULL | ref | idx_key1 | idx_key1 | 303 | xiao\nhaizi.s2.key3 | 1 | 100.00 | End temporary |\n+----+-------------+-------+------------+------+---------------+----------+---------+-----\n--------------+------+----------+------------------------------+\n2 rows in set, 1 warning (0.00 sec)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53UNION\u521b\u5efa\u4e00\u4e2a\u7528\u6765\u53bb\u91cd\u7684\u4e34\u65f6\u8868\u65f6\uff0c\u67e5\u8be2\u7ed3\u679c\u4f1a\u662f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; EXPLAIN SELECT * FROM s1 UNION SELECT * FROM s2;\n+----+--------------+------------+------------+------+---------------+------+---------+---\n---+------+----------+-----------------+\n| id | select_type | table | partitions | type | possible_keys | key | key_len | re\nf | rows | filtered | Extra |\n+----+--------------+------------+------------+------+---------------+------+---------+---\n---+------+----------+-----------------+\n| 1 | PRIMARY | s1 | NULL | ALL | NULL | NULL | NULL | NU\nLL | 9688 | 100.00 | NULL |\n| 2 | UNION | s2 | NULL | ALL | NULL | NULL | NULL | NU\nLL | 9954 | 100.00 | NULL |\n| NULL | UNION RESULT | &lt;union1,2&gt; | NULL | ALL | NULL | NULL | NULL |\nNULL | NULL | NULL | Using temporary |\n+----+--------------+------------+------------+------+---------------+------+---------+---\n---+------+----------+-----------------+\n3 rows in set, 1 warning (0.00 sec)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">UNION ALL\u4e0d\u9700\u8981\u505a\u53bb\u91cd\uff0c\u6240\u4ee5\u6ca1\u6709\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; EXPLAIN SELECT * FROM s1 UNION ALL SELECT * FROM s2;\n+----+-------------+-------+------------+------+---------------+------+---------+------+--\n----+----------+-------+\n| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | r\nows | filtered | Extra |\n+----+-------------+-------+------------+------+---------------+------+---------+------+--\n----+----------+-------+\n| 1 | PRIMARY | s1 | NULL | ALL | NULL | NULL | NULL | NULL | 9\n688 | 100.00 | NULL |\n| 2 | UNION | s2 | NULL | ALL | NULL | NULL | NULL | NULL | 9\n954 | 100.00 | NULL |\n+----+-------------+-------+------------+------+---------------+------+---------+------+--\n----+----------+-------+\n2 rows in set, 1 warning (0.01 sec)<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>select_type<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL\u4e3a\u6bcf\u4e00\u4e2a SELECT \u5173\u952e\u5b57\u4ee3\u8868\u7684\u5c0f\u67e5\u8be2\u90fd\u5b9a\u4e49\u4e86\u4e00\u4e2a\u79f0\u4e4b\u4e3a select_type \u7684\u5c5e\u6027\uff0c\u610f\u601d\u662f\u6211\u4eec\u53ea\u8981\u77e5\u9053\u4e86\u67d0\u4e2a\u5c0f\u67e5\u8be2\u7684 select_type \u5c5e\u6027\uff0c\u5c31\u77e5\u9053\u4e86\u8fd9\u4e2a\u5c0f\u67e5\u8be2\u5728\u6574\u4e2a\u5927\u67e5\u8be2\u4e2d\u626e\u6f14\u4e86\u4e00\u4e2a\u4ec0\u4e48\u89d2\u8272<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">SIMPLE<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u8bed\u53e5\u4e2d\u4e0d\u5305\u542b UNION \u6216\u8005\u5b50\u67e5\u8be2\u7684\u67e5\u8be2\u90fd\u7b97\u4f5c\u662f SIMPLE \u7c7b\u578b<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">PRIMARY<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u5305\u542b UNION \u3001 UNION ALL \u6216\u8005\u5b50\u67e5\u8be2\u7684\u5927\u67e5\u8be2\u6765\u8bf4\uff0c\u5b83\u662f\u7531\u51e0\u4e2a\u5c0f\u67e5\u8be2\u7ec4\u6210\u7684\uff0c\u5176\u4e2d\u6700\u5de6\u8fb9\u7684\u90a3\u4e2a\u67e5\u8be2\u7684 select_type \u503c\u5c31\u662f PRIMARY<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">UNION<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u5305\u542b UNION \u6216\u8005 UNION ALL \u7684\u5927\u67e5\u8be2\u6765\u8bf4\uff0c\u5b83\u662f\u7531\u51e0\u4e2a\u5c0f\u67e5\u8be2\u7ec4\u6210\u7684\uff0c\u5176\u4e2d\u9664\u4e86\u6700\u5de6\u8fb9\u7684\u90a3\u4e2a\u5c0f\u67e5\u8be2\u4ee5\u5916\uff0c\u5176\u4f59\u7684\u5c0f\u67e5\u8be2\u7684 select_type \u503c\u5c31\u662f UNION<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">UNION RESULT<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL \u9009\u62e9\u4f7f\u7528\u4e34\u65f6\u8868\u6765\u5b8c\u6210 UNION \u67e5\u8be2\u7684\u53bb\u91cd\u5de5\u4f5c\uff0c\u9488\u5bf9\u8be5\u4e34\u65f6\u8868\u7684\u67e5\u8be2\u7684 select_type \u5c31\u662f UNION RESULT<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">SUBQUERY<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5305\u542b\u5b50\u67e5\u8be2\u7684\u67e5\u8be2\u8bed\u53e5\u4e0d\u80fd\u591f\u8f6c\u4e3a\u5bf9\u5e94\u7684 semi-join \u7684\u5f62\u5f0f\uff0c\u5e76\u4e14\u8be5\u5b50\u67e5\u8be2\u662f<strong>\u4e0d\u76f8\u5173\u5b50\u67e5\u8be2<\/strong>\uff0c\u5e76\u4e14\u67e5\u8be2\u4f18\u5316\u5668\u51b3\u5b9a\u91c7\u7528\u5c06\u8be5\u5b50\u67e5\u8be2\u7269\u5316\u7684\u65b9\u6848\u6765\u6267\u884c\u8be5\u5b50\u67e5\u8be2\u65f6\uff0c\u8be5\u5b50\u67e5\u8be2\u7684\u7b2c\u4e00\u4e2a SELECT \u5173\u952e\u5b57\u4ee3\u8868\u7684\u90a3\u4e2a\u67e5\u8be2\u7684 select_type \u5c31\u662f SUBQUERY<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">DEPENDENT SUBQUERY<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5305\u542b\u5b50\u67e5\u8be2\u7684\u67e5\u8be2\u8bed\u53e5\u4e0d\u80fd\u591f\u8f6c\u4e3a\u5bf9\u5e94\u7684 semi-join \u7684\u5f62\u5f0f\uff0c\u5e76\u4e14\u8be5\u5b50\u67e5\u8be2\u662f<strong>\u76f8\u5173\u5b50\u67e5\u8be2<\/strong>\uff0c\u5219\u8be5\u5b50\u67e5\u8be2\u7684\u7b2c\u4e00\u4e2a SELECT \u5173\u952e\u5b57\u4ee3\u8868\u7684\u90a3\u4e2a\u67e5\u8be2\u7684 select_type \u5c31\u662f DEPENDENT SUBQUERY<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">DEPENDENT UNION<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5305\u542b UNION \u6216\u8005 UNION ALL \u7684\u5927\u67e5\u8be2\u4e2d\uff0c\u5982\u679c\u5404\u4e2a\u5c0f\u67e5\u8be2\u90fd\u4f9d\u8d56\u4e8e\u5916\u5c42\u67e5\u8be2\u7684\u8bdd\uff0c\u90a3\u9664\u4e86\u6700\u5de6\u8fb9\u7684\u90a3\u4e2a\u5c0f\u67e5\u8be2\u4e4b\u5916\uff0c\u5176\u4f59\u7684\u5c0f\u67e5\u8be2\u7684 select_type \u7684\u503c\u5c31\u662f DEPENDENT UNION&nbsp;DERIVED<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">DERIVED<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u91c7\u7528\u7269\u5316\u7684\u65b9\u5f0f\u6267\u884c\u7684\u5305\u542b\u6d3e\u751f\u8868\u7684\u67e5\u8be2\uff0c\u8be5\u6d3e\u751f\u8868\u5bf9\u5e94\u7684\u5b50\u67e5\u8be2\u7684 select_type \u5c31\u662f DERIVED<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">MATERIALIZED<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u67e5\u8be2\u4f18\u5316\u5668\u5728\u6267\u884c\u5305\u542b\u5b50\u67e5\u8be2\u7684\u8bed\u53e5\u65f6\uff0c\u9009\u62e9\u5c06\u5b50\u67e5\u8be2\u7269\u5316\u4e4b\u540e\u4e0e\u5916\u5c42\u67e5\u8be2\u8fdb\u884c\u8fde\u63a5\u67e5\u8be2\u65f6\uff0c\u8be5\u5b50\u67e5\u8be2\u5bf9\u5e94\u7684 select_type \u5c5e\u6027\u5c31\u662f MATERIALIZED<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>partitions<\/strong>(\u7565)<\/h5>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>type<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL\u6267\u884c\u67e5\u8be2\u7684\u8bbf\u95ee\u65b9\u6cd5<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">system<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u8868\u4e2d\u53ea\u6709\u4e00\u6761\u8bb0\u5f55\u5e76\u4e14\u8be5\u8868\u4f7f\u7528\u7684\u5b58\u50a8\u5f15\u64ce\u7684\u7edf\u8ba1\u6570\u636e\u662f\u7cbe\u786e\u7684\uff0c\u6bd4\u5982MyISAM\u3001Memory\uff0c\u90a3\u4e48\u5bf9\u8be5\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\u5c31\u662f system<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">const<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u6211\u4eec\u524d\u8fb9\u5520\u53e8\u8fc7\uff0c\u5c31\u662f\u5f53\u6211\u4eec\u6839\u636e\u4e3b\u952e\u6216\u8005\u552f\u4e00\u4e8c\u7ea7\u7d22\u5f15\u5217\u4e0e\u5e38\u6570\u8fdb\u884c\u7b49\u503c\u5339\u914d\u65f6\uff0c\u5bf9\u5355\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\u5c31\u662f const<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">eq_ref<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fde\u63a5\u67e5\u8be2\u65f6\uff0c\u5982\u679c\u88ab\u9a71\u52a8\u8868\u662f\u901a\u8fc7\u4e3b\u952e\u6216\u8005\u552f\u4e00\u4e8c\u7ea7\u7d22\u5f15\u5217\u7b49\u503c\u5339\u914d\u7684\u65b9\u5f0f\u8fdb\u884c\u8bbf\u95ee\u7684\uff08\u5982\u679c\u8be5\u4e3b\u952e\u6216\u8005\u552f\u4e00\u4e8c\u7ea7\u7d22\u5f15\u662f\u8054\u5408\u7d22\u5f15\u7684\u8bdd\uff0c\u6240\u6709\u7684\u7d22\u5f15\u5217\u90fd\u5fc5\u987b\u8fdb\u884c\u7b49\u503c\u6bd4\u8f83\uff09\uff0c\u5219\u5bf9\u8be5\u88ab\u9a71\u52a8\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\u5c31\u662feq_ref<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">ref<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u901a\u8fc7\u666e\u901a\u7684\u4e8c\u7ea7\u7d22\u5f15\u5217\u4e0e\u5e38\u91cf\u8fdb\u884c\u7b49\u503c\u5339\u914d\u65f6\u6765\u67e5\u8be2\u67d0\u4e2a\u8868\uff0c\u90a3\u4e48\u5bf9\u8be5\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\u5c31\u53ef\u80fd\u662f ref<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">ref_or_null<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u5bf9\u666e\u901a\u4e8c\u7ea7\u7d22\u5f15\u8fdb\u884c\u7b49\u503c\u5339\u914d\u67e5\u8be2\uff0c\u8be5\u7d22\u5f15\u5217\u7684\u503c\u4e5f\u53ef\u4ee5\u662f NULL \u503c\u65f6\uff0c\u90a3\u4e48\u5bf9\u8be5\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\u5c31\u53ef\u80fd\u662fref_or_null<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">index_merge<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u53ef\u4ee5\u4f7f\u7528 Intersection \u3001 Union \u3001 Sort-Union \u8fd9\u4e09\u79cd\u7d22\u5f15\u5408\u5e76\u7684\u65b9\u5f0f\u6765\u6267\u884c\u67e5\u8be2\uff0c\u8fd9\u65f6\u5019\u7684type\u5c31\u662findex_merge<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">unique_subquery<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u7c7b\u4f3c\u4e8e\u4e24\u8868\u8fde\u63a5\u4e2d\u88ab\u9a71\u52a8\u8868\u7684 eq_ref \u8bbf\u95ee\u65b9\u6cd5\uff0c unique_subquery \u662f\u9488\u5bf9\u5728\u4e00\u4e9b\u5305\u542b IN \u5b50\u67e5\u8be2\u7684\u67e5\u8be2\u8bed\u53e5\u4e2d\uff0c\u5982\u679c\u67e5\u8be2\u4f18\u5316\u5668\u51b3\u5b9a\u5c06 IN \u5b50\u67e5\u8be2\u8f6c\u6362\u4e3a EXISTS \u5b50\u67e5\u8be2\uff0c\u800c\u4e14\u5b50\u67e5\u8be2\u53ef\u4ee5\u4f7f\u7528\u5230\u4e3b\u952e\u8fdb\u884c\u7b49\u503c\u5339\u914d\u7684\u8bdd\uff0c\u90a3\u4e48\u8be5\u5b50\u67e5\u8be2\u6267\u884c\u8ba1\u5212\u7684 type \u5217\u7684\u503c\u5c31\u662f unique_subquery<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">index_subquery<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">index_subquery \u4e0e unique_subquery \u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u8bbf\u95ee\u5b50\u67e5\u8be2\u4e2d\u7684\u8868\u65f6\u4f7f\u7528\u7684\u662f\u666e\u901a\u7684\u7d22\u5f15<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">range<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f7f\u7528\u7d22\u5f15\u83b7\u53d6\u67d0\u4e9b \u8303\u56f4\u533a\u95f4 \u7684\u8bb0\u5f55\uff0c\u90a3\u4e48\u5c31\u53ef\u80fd\u4f7f\u7528\u5230 range \u8bbf\u95ee\u65b9\u6cd5<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">index<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u8986\u76d6\uff0c\u4f46\u9700\u8981\u626b\u63cf\u5168\u90e8\u7684\u7d22\u5f15\u8bb0\u5f55\u65f6\uff0c\u8be5\u8868\u7684\u8bbf\u95ee\u65b9\u6cd5\u5c31\u662f index<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">ALL<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5168\u8868\u626b\u63cf<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>possible_keys<\/strong>\u548c<strong>key<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">possible_keys \u5217\u8868\u793a\u5728\u67d0\u4e2a\u67e5\u8be2\u8bed\u53e5\u4e2d\uff0c\u5bf9\u67d0\u4e2a\u8868\u6267\u884c\u5355\u8868\u67e5\u8be2\u65f6\u53ef\u80fd\u7528\u5230\u7684\u7d22\u5f15\u6709\u54ea\u4e9b\uff0c key \u5217\u8868\u793a\u5b9e\u9645\u7528\u5230\u7684\u7d22\u5f15\u6709\u54ea\u4e9b<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>key_len<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">key_len \u5217\u8868\u793a\u5f53\u4f18\u5316\u5668\u51b3\u5b9a\u4f7f\u7528\u67d0\u4e2a\u7d22\u5f15\u6267\u884c\u67e5\u8be2\u65f6\uff0c\u8be5\u7d22\u5f15\u8bb0\u5f55\u7684\u6700\u5927\u957f\u5ea6\uff0c\u5b83\u662f\u7531\u8fd9\u4e09\u4e2a\u90e8\u5206\u6784\u6210\u7684\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e\u4f7f\u7528\u56fa\u5b9a\u957f\u5ea6\u7c7b\u578b\u7684\u7d22\u5f15\u5217\u6765\u8bf4\uff0c\u5b83\u5b9e\u9645\u5360\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u7684\u6700\u5927\u957f\u5ea6\u5c31\u662f\u8be5\u56fa\u5b9a\u503c\uff0c\u5bf9\u4e8e\u6307\u5b9a\u5b57\u7b26\u96c6\u7684\u53d8\u957f\u7c7b\u578b\u7684\u7d22\u5f15\u5217\u6765\u8bf4\uff0c\u6bd4\u5982\u67d0\u4e2a\u7d22\u5f15\u5217\u7684\u7c7b\u578b\u662f VARCHAR(100) \uff0c\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u662f utf8 \uff0c\u90a3\u4e48\u8be5\u5217\u5b9e\u9645\u5360\u7528\u7684\u6700\u5927\u5b58\u50a8\u7a7a\u95f4\u5c31\u662f 100 \u00d7 3 = 300 \u4e2a\u5b57\u8282\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u8be5\u7d22\u5f15\u5217\u53ef\u4ee5\u5b58\u50a8 NULL \u503c\uff0c\u5219 key_len \u6bd4\u4e0d\u53ef\u4ee5\u5b58\u50a8 NULL \u503c\u65f6\u591a1\u4e2a\u5b57\u8282\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u53d8\u957f\u5b57\u6bb5\u6765\u8bf4\uff0c\u90fd\u4f1a\u67092\u4e2a\u5b57\u8282\u7684\u7a7a\u95f4\u6765\u5b58\u50a8\u8be5\u53d8\u957f\u5217\u7684\u5b9e\u9645\u957f\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>ref<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4f7f\u7528\u7d22\u5f15\u5217\u7b49\u503c\u5339\u914d\u7684\u6761\u4ef6\u53bb\u6267\u884c\u67e5\u8be2\u65f6\uff0c\u4e5f\u5c31\u662f\u5728\u8bbf\u95ee\u65b9\u6cd5\u662f const \u3001 eq_ref\u3001 ref \u3001 ref_or_null\u3001<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">unique_subquery\u3001 index_subquery \u5176\u4e2d\u4e4b\u4e00\u65f6\uff0c ref \u5217\u5c55\u793a\u7684\u5c31\u662f\u4e0e\u7d22\u5f15\u5217\u4f5c\u7b49\u503c\u5339\u914d\u7684\u662f\u4ec0\u4e48<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>const\u3002\u5e38\u6570<\/li>\n\n\n\n<li>func\u3002\u4e00\u4e2a\u51fd\u6570<\/li>\n\n\n\n<li>\u5177\u4f53\u5217\u3002\u5982\u6570\u636e\u5e93\u540d.\u8868\u540d.\u5217\u540d<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>rows<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u662f\u5168\u8868\u626b\u63cf\u5c31\u4ee3\u8868\u9884\u4f30\u7684\u5168\u8868\u626b\u63cf\u884c\u6570\uff0c\u5982\u679c\u662f\u7d22\u5f15\u67e5\u8be2\u5c31\u4ee3\u8868\u9884\u8ba1\u626b\u63cf\u7684\u7d22\u5f15\u8bb0\u5f55\u884c\u6570<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>filtered<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fde\u63a5\u67e5\u8be2\u4e2d\u9a71\u52a8\u8868\u5bf9\u5e94\u7684\u6267\u884c\u8ba1\u5212\u8bb0\u5f55\u7684\u6247\u51fa\u6bd4\u4f8b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u662f\u5168\u8868\u626b\u63cf\uff0c\u5c31\u662f\u6ee1\u8db3\u641c\u7d22\u6761\u4ef6\u7684\u8bb0\u5f55\/\u5168\u8868\u626b\u63cf\u7684\u6761\u6570<\/li>\n\n\n\n<li>\u5982\u679c\u662f\u7d22\u5f15\u6267\u884c\u7684\u5355\u8868\u626b\u63cf\uff0c\u5c31\u662f\u8ba1\u7b97\u9a71\u52a8\u8868\u6247\u51fa\u7684\u65f6\u5019\u9700\u8981\u4f30\u8ba1\u51fa\u6ee1\u8db3\u9664\u4f7f\u7528\u5230\u5bf9\u5e94\u7d22\u5f15\u7684\u641c\u7d22\u6761\u4ef6\u5916\u7684\u5176\u4ed6\u641c\u7d22\u6761\u4ef6\u7684\u8bb0\u5f55\/\u626b\u63cf\u7d22\u5f15\u7684\u6761\u6570<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">Extra<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Extra \u5217\u662f\u7528\u6765\u8bf4\u660e\u4e00\u4e9b\u989d\u5916\u4fe1\u606f\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e9b\u989d\u5916\u4fe1\u606f\u6765\u66f4\u51c6\u786e\u7684\u7406\u89e3 MySQL \u5230\u5e95\u5c06\u5982\u4f55<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u7ed9\u5b9a\u7684\u67e5\u8be2\u8bed\u53e5<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">No tables used<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Impossible WHERE<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">No matching min\/max row<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Using index<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Using index condition<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5728\u67e5\u8be2\u8bed\u53e5\u7684\u6267\u884c\u8fc7\u7a0b\u4e2d\u5c06\u8981\u4f7f\u7528 <strong><em>\u7d22\u5f15\u6761\u4ef6\u4e0b\u63a8<\/em><\/strong> \u8fd9\u4e2a\u7279\u6027\uff0c\u5728 Extra \u5217\u4e2d\u5c06\u4f1a\u663e\u793a Using index<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">condition<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Using where<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Using join buffer (Block Nested Loop)<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Not exists<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Using intersect(&#8230;)\u3001 Using union(&#8230;) \u548c Using sort_union(&#8230;)<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Zero limit<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Using filesort<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Using temporary<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">Start temporary, End temporary<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">LooseScan<\/h6>\n\n\n\n<h6 class=\"wp-block-heading\">FirstMatch(tbl_name)<\/h6>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Json<\/strong>\u683c\u5f0f\u7684\u6267\u884c\u8ba1\u5212<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f1a\u5c06\u6267\u884c\u8ba1\u5212\u4ee5Json\u683c\u5f0f\u663e\u793a\uff0c\u4e14\u80fd\u770b\u5230\u6267\u884c\u8ba1\u5212\u7684\u6210\u672c\uff0c\u6267\u884cJson\u683c\u5f0f\u6267\u884c\u8ba1\u5212\u7684\u65b9\u5f0f\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EXPLAIN FORMAT=JSON xxx<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u7684cost info\u4e2d\u663e\u793a\u4e86\u6210\u672c\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"cost_info\": {\n    \"read_cost\": \"1840.84\",\n    \"eval_cost\": \"193.76\",\n    \"prefix_cost\": \"2034.60\",\n    \"data_read_per_join\": \"1M\"\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u6570\u7684\u542b\u4e49\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>read_cost\n<ul class=\"wp-block-list\">\n<li>IO \u6210\u672c<\/li>\n\n\n\n<li>\u68c0\u6d4b rows \u00d7 (1 &#8211; filter) \u6761\u8bb0\u5f55\u7684 CPU \u6210\u672c<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>eval_cost\u3002\u68c0\u6d4b&nbsp;rows \u00d7 filter \u6761\u8bb0\u5f55\u7684\u6210\u672c\u3002<\/li>\n\n\n\n<li>prefix_cost\u3002\u5355\u8868\u67e5\u8be2\u7684\u603b\u6210\u672c\uff0c\u5373read_cost + eval_cost<\/li>\n\n\n\n<li>data_read_per_join \u8868\u793a\u5728\u6b64\u6b21\u67e5\u8be2\u4e2d\u9700\u8981\u8bfb\u53d6\u7684\u6570\u636e\u91cf<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u6761\u67e5\u8be2\u8bed\u53e5\u5728\u7ecf\u8fc7 MySQL \u67e5\u8be2\u4f18\u5316\u5668\u7684\u5404\u79cd\u57fa\u4e8e\u6210\u672c\u548c\u89c4\u5219\u7684\u4f18\u5316\u4f1a\u540e\u751f\u6210\u4e00\u4e2a\u6240\u8c13\u7684 \u6267\u884c\u8ba1\u5212 \uff0c\u8fd9\u4e2a\u6267\u884c\u8ba1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,88],"tags":[],"class_list":["post-2483","post","type-post","status-publish","format-standard","hentry","category-code","category-mysql"],"_links":{"self":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2483"}],"version-history":[{"count":11,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2483\/revisions"}],"predecessor-version":[{"id":2657,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/2483\/revisions\/2657"}],"wp:attachment":[{"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2483"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.spiceandwolf.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}