{"id":93918,"date":"2024-10-19T18:00:25","date_gmt":"2024-10-19T10:00:25","guid":{"rendered":"https:\/\/server.hk\/cnblog\/93918\/"},"modified":"2024-10-19T18:00:26","modified_gmt":"2024-10-19T10:00:26","slug":"oracle-explain-plan%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e6%8a%80%e5%b7%a7%e5%bf%83%e5%be%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/93918\/","title":{"rendered":"Oracle EXPLAIN PLAN\u5be6\u969b\u61c9\u7528\u6280\u5de7\u5fc3\u5f97"},"content":{"rendered":"<h1 id=\"oracle-explain-plan%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e6%8a%80%e5%b7%a7%e5%bf%83%e5%be%97-xmLQrPTxjL\">Oracle EXPLAIN PLAN\u5be6\u969b\u61c9\u7528\u6280\u5de7\u5fc3\u5f97<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u6027\u80fd\u512a\u5316\u662f\u6bcf\u4f4d\u958b\u767c\u8005\u548c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u7684\u91cd\u8981\u4efb\u52d9\u3002Oracle\u6578\u64da\u5eab\u63d0\u4f9b\u4e86\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\u2014\u2014EXPLAIN PLAN\uff0c\u5e6b\u52a9\u7528\u6236\u5206\u6790SQL\u67e5\u8a62\u7684\u57f7\u884c\u8a08\u5283\u3002\u672c\u6587\u5c07\u63a2\u8a0eEXPLAIN PLAN\u7684\u5be6\u969b\u61c9\u7528\u6280\u5de7\uff0c\u4e26\u5206\u4eab\u4e00\u4e9b\u5fc3\u5f97\u9ad4\u6703\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afexplain-plan%ef%bc%9f-xmLQrPTxjL\">\u4ec0\u9ebc\u662fEXPLAIN PLAN\uff1f<\/h2>\n<p>EXPLAIN PLAN\u662f\u4e00\u500bOracle\u6578\u64da\u5eab\u7684\u529f\u80fd\uff0c\u7528\u65bc\u986f\u793aSQL\u67e5\u8a62\u7684\u57f7\u884c\u8a08\u5283\u3002\u5b83\u63d0\u4f9b\u4e86\u67e5\u8a62\u7684\u57f7\u884c\u8def\u5f91\u3001\u4f7f\u7528\u7684\u7d22\u5f15\u3001\u9023\u63a5\u65b9\u6cd5\u7b49\u4fe1\u606f\uff0c\u5e6b\u52a9\u7528\u6236\u7406\u89e3\u67e5\u8a62\u7684\u6027\u80fd\u74f6\u9838\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8explain-plan-xmLQrPTxjL\">\u5982\u4f55\u4f7f\u7528EXPLAIN PLAN<\/h2>\n<p>\u4f7f\u7528EXPLAIN PLAN\u975e\u5e38\u7c21\u55ae\uff0c\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u4f7f\u7528\u6b65\u9a5f\uff1a<\/p>\n<pre><code>EXPLAIN PLAN FOR\nSELECT * FROM employees WHERE department_id = 10;\n<\/code><\/pre>\n<p>\u57f7\u884c\u4e0a\u8ff0\u8a9e\u53e5\u5f8c\uff0cOracle\u6703\u751f\u6210\u4e00\u500b\u57f7\u884c\u8a08\u5283\uff0c\u5b58\u5132\u5728PLAN_TABLE\u4e2d\u3002\u8981\u67e5\u770b\u57f7\u884c\u8a08\u5283\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\uff1a<\/p>\n<pre><code>SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);\n<\/code><\/pre>\n<h2 id=\"%e5%88%86%e6%9e%90%e5%9f%b7%e8%a1%8c%e8%a8%88%e5%8a%83-xmLQrPTxjL\">\u5206\u6790\u57f7\u884c\u8a08\u5283<\/h2>\n<p>\u57f7\u884c\u8a08\u5283\u7684\u5206\u6790\u662f\u6027\u80fd\u512a\u5316\u7684\u95dc\u9375\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u57f7\u884c\u8a08\u5283\u5143\u7d20\uff1a<\/p>\n<ul>\n<li><strong>SELECT STATEMENT\uff1a<\/strong>\u986f\u793a\u67e5\u8a62\u7684\u985e\u578b\u3002<\/li>\n<li><strong>TABLE ACCESS\uff1a<\/strong>\u986f\u793a\u8a2a\u554f\u8868\u7684\u65b9\u5f0f\uff0c\u53ef\u80fd\u662f\u5168\u8868\u6383\u63cf\u6216\u7d22\u5f15\u6383\u63cf\u3002<\/li>\n<li><strong>JOIN\uff1a<\/strong>\u986f\u793a\u9023\u63a5\u7684\u985e\u578b\uff0c\u5982\u5d4c\u5957\u5faa\u74b0\u3001\u54c8\u5e0c\u9023\u63a5\u7b49\u3002<\/li>\n<\/ul>\n<p>\u901a\u904e\u5206\u6790\u9019\u4e9b\u5143\u7d20\uff0c\u7528\u6236\u53ef\u4ee5\u8b58\u5225\u51fa\u6027\u80fd\u74f6\u9838\u3002\u4f8b\u5982\uff0c\u5982\u679c\u57f7\u884c\u8a08\u5283\u986f\u793a\u5168\u8868\u6383\u63cf\uff0c\u5247\u53ef\u80fd\u9700\u8981\u8003\u616e\u6dfb\u52a0\u7d22\u5f15\u3002<\/p>\n<h2 id=\"explain-plan%e7%9a%84%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-xmLQrPTxjL\">EXPLAIN PLAN\u7684\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528EXPLAIN PLAN\u7684\u6700\u4f73\u5be6\u8e10\uff1a<\/p>\n<ul>\n<li><strong>\u5b9a\u671f\u6aa2\u67e5\u57f7\u884c\u8a08\u5283\uff1a<\/strong>\u96a8\u8457\u6578\u64da\u7684\u589e\u9577\u548c\u7d50\u69cb\u7684\u8b8a\u5316\uff0c\u67e5\u8a62\u7684\u57f7\u884c\u8a08\u5283\u53ef\u80fd\u6703\u767c\u751f\u8b8a\u5316\u3002\u5b9a\u671f\u6aa2\u67e5\u53ef\u4ee5\u53ca\u6642\u767c\u73fe\u554f\u984c\u3002<\/li>\n<li><strong>\u4f7f\u7528SQL\u63d0\u793a\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528SQL\u63d0\u793a\u4f86\u5f71\u97ff\u57f7\u884c\u8a08\u5283\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>USE_NL<\/code>\u63d0\u793a\u5f37\u5236\u4f7f\u7528\u5d4c\u5957\u5faa\u74b0\u9023\u63a5\u3002<\/li>\n<li><strong>\u6bd4\u8f03\u4e0d\u540c\u67e5\u8a62\u7684\u57f7\u884c\u8a08\u5283\uff1a<\/strong>\u5c0d\u65bc\u76f8\u4f3c\u7684\u67e5\u8a62\uff0c\u5206\u6790\u5176\u57f7\u884c\u8a08\u5283\u7684\u5dee\u7570\uff0c\u53ef\u4ee5\u5e6b\u52a9\u627e\u51fa\u6700\u4f73\u7684\u67e5\u8a62\u65b9\u5f0f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%a1%88%e4%be%8b%e5%88%86%e6%9e%90-xmLQrPTxjL\">\u5be6\u969b\u6848\u4f8b\u5206\u6790<\/h2>\n<p>\u5047\u8a2d\u6709\u4e00\u500b\u67e5\u8a62\u9700\u8981\u5f9e\u4e00\u500b\u5927\u578b\u54e1\u5de5\u8868\u4e2d\u6aa2\u7d22\u6578\u64da\uff1a<\/p>\n<pre><code>SELECT * FROM employees WHERE last_name = 'Smith';\n<\/code><\/pre>\n<p>\u4f7f\u7528EXPLAIN PLAN\u5f8c\uff0c\u767c\u73fe\u57f7\u884c\u8a08\u5283\u986f\u793a\u5168\u8868\u6383\u63cf\u3002\u9019\u6642\uff0c\u53ef\u4ee5\u8003\u616e\u5728<code>last_name<\/code>\u5217\u4e0a\u6dfb\u52a0\u7d22\u5f15\uff1a<\/p>\n<pre><code>CREATE INDEX idx_last_name ON employees(last_name);\n<\/code><\/pre>\n<p>\u91cd\u65b0\u57f7\u884cEXPLAIN PLAN\u5f8c\uff0c\u61c9\u8a72\u6703\u770b\u5230\u7d22\u5f15\u6383\u63cf\u7684\u6539\u8b8a\uff0c\u5f9e\u800c\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-xmLQrPTxjL\">\u7e3d\u7d50<\/h2>\n<p>EXPLAIN PLAN\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u6df1\u5165\u4e86\u89e3SQL\u67e5\u8a62\u7684\u57f7\u884c\u904e\u7a0b\u3002\u901a\u904e\u5b9a\u671f\u6aa2\u67e5\u57f7\u884c\u8a08\u5283\u3001\u4f7f\u7528SQL\u63d0\u793a\u4ee5\u53ca\u6bd4\u8f03\u4e0d\u540c\u67e5\u8a62\u7684\u57f7\u884c\u8a08\u5283\uff0c\u7528\u6236\u53ef\u4ee5\u6709\u6548\u5730\u512a\u5316\u6578\u64da\u5eab\u6027\u80fd\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u638c\u63e1EXPLAIN PLAN\u7684\u4f7f\u7528\u6280\u5de7\u7121\u7591\u662f\u63d0\u5347\u696d\u52d9\u6548\u7387\u7684\u91cd\u8981\u4e00\u6b65\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc<code>VPS<\/code>\u3001<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u53ca\u5176\u4ed6<code>\u670d\u52a1\u5668<\/code>\u89e3\u6c7a\u65b9\u6848\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Oracle EXPLAIN PLAN\u7684\u5be6\u969b\u61c9\u7528\u6280\u5de7\uff0c\u63d0\u5347\u67e5\u8a62\u6548\u80fd\uff0c\u512a\u5316\u6578\u64da\u5eab\u6027\u80fd\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-93918","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/93918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=93918"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/93918\/revisions"}],"predecessor-version":[{"id":93919,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/93918\/revisions\/93919"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=93918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=93918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=93918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}