{"id":2380,"date":"2025-03-04T20:45:22","date_gmt":"2025-03-04T12:45:22","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2380"},"modified":"2025-03-04T20:45:22","modified_gmt":"2025-03-04T12:45:22","slug":"sqlite-explain%ef%bc%88%e8%a7%a3%e9%87%8a%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/03\/04\/sqlite-explain%ef%bc%88%e8%a7%a3%e9%87%8a%ef%bc%89\/","title":{"rendered":"SQLite Explain\uff08\u89e3\u91ca\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728 SQLite \u4e2d\uff0c<code>EXPLAIN<\/code> \u8bed\u53e5\u7528\u4e8e\u5206\u6790 SQL \u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u67e5\u8be2\u7684\u6267\u884c\u65b9\u5f0f\uff0c\u5e76\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u3002<code>EXPLAIN<\/code> \u53ef\u4ee5\u663e\u793a\u67e5\u8be2\u7684\u6267\u884c\u6b65\u9aa4\uff0c\u5305\u62ec\u626b\u63cf\u7684\u8868\u3001\u4f7f\u7528\u7684\u7d22\u5f15\u3001\u8fde\u63a5\u7c7b\u578b\u7b49\u4fe1\u606f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <code>EXPLAIN<\/code> \u7684\u57fa\u672c\u7528\u6cd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4f60\u4f7f\u7528 <code>EXPLAIN<\/code> \u65f6\uff0c\u5b83\u4f1a\u8fd4\u56de\u5173\u4e8e\u5982\u4f55\u6267\u884c SQL \u67e5\u8be2\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u901a\u8fc7 <code>EXPLAIN<\/code>\uff0c\u4f60\u53ef\u4ee5\u4e86\u89e3\u6570\u636e\u5e93\u5728\u6267\u884c\u67e5\u8be2\u65f6\u7684\u5177\u4f53\u6b65\u9aa4\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u6267\u884c\u67e5\u8be2\u5e76\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>EXPLAIN SELECT * FROM users WHERE username = 'John';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u6b64\u67e5\u8be2\u540e\uff0cSQLite \u4f1a\u8fd4\u56de\u6709\u5173\u67e5\u8be2\u6267\u884c\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5305\u62ec\u4f7f\u7528\u7684\u8868\u3001\u7d22\u5f15\u7b49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <code>EXPLAIN QUERY PLAN<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>EXPLAIN<\/code> \u7684\u8f93\u51fa\u8f83\u4e3a\u4f4e\u7ea7\uff0c\u901a\u5e38\u4e0d\u592a\u9002\u5408\u76f4\u63a5\u4f7f\u7528\u3002\u4e3a\u4e86\u83b7\u5f97\u66f4\u6613\u8bfb\u7684\u6267\u884c\u8ba1\u5212\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>EXPLAIN QUERY PLAN<\/code>\u3002\u8fd9\u4e2a\u7248\u672c\u7684 <code>EXPLAIN<\/code> \u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684\u6267\u884c\u8ba1\u5212\uff0c\u663e\u793a SQLite \u67e5\u8be2\u7684\u6267\u884c\u6b65\u9aa4\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>EXPLAIN QUERY PLAN SELECT * FROM users WHERE username = 'John';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u67e5\u8be2\u4f1a\u8fd4\u56de\u4e00\u4e2a\u8868\u683c\uff0c\u663e\u793a\u6709\u5173\u67e5\u8be2\u5982\u4f55\u6267\u884c\u7684\u4fe1\u606f\uff0c\u901a\u5e38\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6267\u884c\u8ba1\u5212\u7684\u6bcf\u4e2a\u6b65\u9aa4\u3002<\/li>\n\n\n\n<li>\u662f\u5426\u4f7f\u7528\u4e86\u7d22\u5f15\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u4e86\u54ea\u4e9b\u8868\u3002<\/li>\n\n\n\n<li>\u6267\u884c\u7684\u987a\u5e8f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <code>EXPLAIN<\/code> \u7684\u8f93\u51fa\u89e3\u6790<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>EXPLAIN<\/code> \u548c <code>EXPLAIN QUERY PLAN<\/code> \u7684\u8f93\u51fa\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5217\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ID<\/strong>\uff1a\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u7528\u4e8e\u6807\u8bc6\u67e5\u8be2\u7684\u67d0\u4e2a\u6b65\u9aa4\u3002<\/li>\n\n\n\n<li><strong>Parent<\/strong>\uff1a\u5f53\u524d\u6b65\u9aa4\u7684\u7236\u6b65\u9aa4 ID\u3002<\/li>\n\n\n\n<li><strong>SelectID<\/strong>\uff1a\u8868\u793a\u67e5\u8be2\u7684\u9009\u62e9\u9879\u3002<\/li>\n\n\n\n<li><strong>UseTemp<\/strong>\uff1a\u662f\u5426\u4f7f\u7528\u4e34\u65f6\u8868\u3002<\/li>\n\n\n\n<li><strong>Detail<\/strong>\uff1a\u63cf\u8ff0\u5177\u4f53\u7684\u6267\u884c\u6b65\u9aa4\uff08\u4f8b\u5982\uff0c\u8868\u626b\u63cf\u3001\u7d22\u5f15\u626b\u63cf\u7b49\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\u8f93\u51fa\uff08<code>EXPLAIN QUERY PLAN<\/code>\uff09\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>ID  |  Parent  |  SelectID  |  Order  |  Detail\n----|----------|------------|---------|----------------------------------------\n0   | NULL     | 0          | 0       | SCAN TABLE users<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>EXPLAIN QUERY PLAN<\/code> \u8868\u793a SQLite \u6267\u884c\u4e86\u4e00\u4e2a\u5168\u8868\u626b\u63cf\uff08<code>SCAN TABLE<\/code>\uff09\uff0c\u6ca1\u6709\u4f7f\u7528\u4efb\u4f55\u7d22\u5f15\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u4f7f\u7528 <code>EXPLAIN<\/code> \u4f18\u5316\u67e5\u8be2<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>EXPLAIN<\/code> \u7684\u8f93\u51fa\u6709\u52a9\u4e8e\u5206\u6790\u67e5\u8be2\u7684\u6267\u884c\u6548\u7387\u3002\u5982\u679c\u4f60\u53d1\u73b0\u67e5\u8be2\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\uff0c\u6216\u8005\u6267\u884c\u8ba1\u5212\u663e\u793a\u67e5\u8be2\u975e\u5e38\u4f4e\u6548\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u4f18\u5316\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u521b\u5efa\u7d22\u5f15<\/strong>\uff1a\u786e\u4fdd\u67e5\u8be2\u4e2d\u4f7f\u7528\u7684\u5217\u6709\u9002\u5f53\u7684\u7d22\u5f15\u3002<\/li>\n\n\n\n<li><strong>\u67e5\u8be2\u91cd\u5199<\/strong>\uff1a\u6709\u65f6\u901a\u8fc7\u91cd\u5199\u67e5\u8be2\uff0cSQLite \u53ef\u4ee5\u66f4\u6709\u6548\u5730\u6267\u884c\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u5168\u8868\u626b\u63cf<\/strong>\uff1a\u901a\u8fc7\u9002\u5f53\u7684\u7d22\u5f15\u548c\u6761\u4ef6\uff0c\u907f\u514d\u8fdb\u884c\u5168\u8868\u626b\u63cf\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. <code>EXPLAIN<\/code> \u4e0e\u6027\u80fd\u8c03\u4f18<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 <code>EXPLAIN<\/code> \u4f60\u53ef\u4ee5\u67e5\u770b SQLite \u5728\u67e5\u8be2\u8fc7\u7a0b\u4e2d\u662f\u5426\u91c7\u7528\u4e86\u6700\u4f73\u7684\u6267\u884c\u7b56\u7565\u3002\u901a\u8fc7\u5bf9\u6bd4\u4e0d\u540c\u67e5\u8be2\u8bed\u53e5\u7684\u6267\u884c\u8ba1\u5212\uff0c\u53ef\u4ee5\u4f18\u5316\u67e5\u8be2\u5e76\u63d0\u9ad8\u6027\u80fd\u3002\u7279\u522b\u662f\u5bf9\u4e8e\u590d\u6742\u7684\u67e5\u8be2\uff08\u5982\u591a\u8868\u8fde\u63a5\u3001\u5927\u6570\u636e\u96c6\u67e5\u8be2\u7b49\uff09\uff0c\u5206\u6790\u6267\u884c\u8ba1\u5212\u975e\u5e38\u6709\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u603b\u7ed3<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>EXPLAIN<\/code> \u663e\u793a SQL \u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u4e86\u89e3 SQLite \u5982\u4f55\u6267\u884c\u67e5\u8be2\u3002<\/li>\n\n\n\n<li><code>EXPLAIN QUERY PLAN<\/code> \u63d0\u4f9b\u66f4\u6613\u4e8e\u7406\u89e3\u7684\u6267\u884c\u8ba1\u5212\uff0c\u663e\u793a\u662f\u5426\u4f7f\u7528\u7d22\u5f15\u3001\u8868\u626b\u63cf\u7c7b\u578b\u7b49\u4fe1\u606f\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>EXPLAIN<\/code> \u8fdb\u884c\u67e5\u8be2\u4f18\u5316\u53ef\u4ee5\u5e2e\u52a9\u51cf\u5c11\u5168\u8868\u626b\u63cf\u3001\u52a0\u901f\u67e5\u8be2\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u5b9a\u671f\u5206\u6790\u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\u5e76\u8fdb\u884c\u4f18\u5316\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u5e94\u7528\u7a0b\u5e8f\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u6570\u636e\u5e93\u7684\u6548\u7387\u3002\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 SQLite \u4e2d\uff0cEXPLAIN \u8bed\u53e5\u7528\u4e8e\u5206\u6790 SQL \u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u67e5\u8be2\u7684\u6267\u884c\u65b9\u5f0f\uff0c\u5e76\u4f18 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-2380","post","type-post","status-publish","format-standard","hentry","category-sqlite"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=2380"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2380\/revisions"}],"predecessor-version":[{"id":2381,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2380\/revisions\/2381"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}