{"id":288,"date":"2012-01-14T21:11:15","date_gmt":"2012-01-14T13:11:15","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=288"},"modified":"2014-01-14T21:13:17","modified_gmt":"2014-01-14T13:13:17","slug":"sql%e8%b0%83%e4%bc%9801-sql%e4%bc%98%e5%8c%96%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=288","title":{"rendered":"SQL\u8c03\u4f1801&#8211;SQL\u4f18\u5316\u4ecb\u7ecd"},"content":{"rendered":"<p>Introduction to SQL Tuning<\/p>\n<div>\n<ol>\n<li>SQL\u6548\u7387\u592a\u4f4e\u7684\u539f\u56e0:\n<ol>\n<li>Stale or missing optimizer statistics:\u7f3a\u5931\u4f18\u5316\u7edf\u8ba1\u4fe1\u606f\u6216\u8005\u4fe1\u606f\u592a\u65e7;<\/li>\n<li>Missing access structures:\u7f3a\u5c11\u7d22\u5f15,\u8003\u8651\u7d22\u5f15\u7684\u6548\u7387;<\/li>\n<li>Suboptimal execution plan selection:\u4e0d\u662f\u6700\u597d\u7684\u6267\u884c\u8ba1\u5212;<\/li>\n<li>Poorly constructed SQL:SQL\u8bed\u53e5\u5199\u7684\u4e0d\u597d;<\/li>\n<li>\u6700\u91cd\u8981\u7684\u662f\u8868\u7684\u6570\u636e\u91cf\u592a\u5927,\u5f52\u6863\u5386\u53f2\u6570\u636e.\u5c0f\u7684\u6570\u636e\u91cf\u53ef\u4ee5\u89e3\u51b3\u4e00\u5207\u95ee\u9898;<\/li>\n<li>\u89e3\u51b3\u529e\u6cd5:\n<ol>\n<li>\u5c3d\u91cf\u4e0d\u8981\u7528\u5b50\u67e5\u8be2,\u53ef\u4ee5\u901a\u8fc7\u5173\u8054\u67e5\u8be2\u89e3\u51b3;<\/li>\n<li>\u4e0d\u8981\u518d\u8868\u5217\u4e0a\u9762\u4f7f\u7528\u51fd\u6570,\u5bfc\u81f4\u7d22\u5f15\u65e0\u6548;<\/li>\n<li>\u5982\u679c\u53d1\u751f\u9690\u5f0f\u8f6c\u6362\u4e5f\u4e0d\u8d70\u7d22\u5f15,\u56e0\u4e3aoracle\u5185\u90e8\u603b\u662f\u8f6c\u6362\u8868\u7684\u5217;<\/li>\n<li>\u5c3d\u91cf\u4f7f\u7528UNION ALL\u800c\u4e0d\u7528UNION;<\/li>\n<li>\u6392\u5e8f,\u53bb\u91cd\u590d,\u5206\u7ec4\u73b0\u5728\u9ed8\u8ba4\u4f7f\u7528hash\u53bb\u9664\u91cd\u590d,\u5bf9CPU\u6d88\u8017\u5f88\u5927;<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>\u6027\u80fd\u76d1\u63a7\u7684\u89e3\u51b3\u65b9\u6848; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" alt=\"\" src=\"file:\/\/\/C:\/TEMP\/enhtmlclip\/Image(32).png\" \/><\/li>\n<li>Oracle\u4e2d\u76d1\u63a7\u548c\u8c03\u4f18\u7684\u5de5\u5177; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<img decoding=\"async\" alt=\"\" src=\"file:\/\/\/C:\/TEMP\/enhtmlclip\/Image(33).png\" \/><\/li>\n<li>\u8c03\u4f18\u7684\u5de5\u5177:\n<ol>\n<li>Automatic Database Diagnostic Monitor (ADDM);<\/li>\n<li><span style=\"color: #e30000;\">SQL Tuning Advisor;<\/span><\/li>\n<li>SQL Tuning Sets;<\/li>\n<li>SQL Access Advisor;<\/li>\n<li>SQL Performance Analyzer;<\/li>\n<li>SQL Monitoring;<\/li>\n<li>SQL Plan Management:\u572811g\u4e2d\u7684\u5de5\u5177,\u53ef\u4ee5\u63a7\u5236\u67d0\u4e2asql\u7684\u6267\u884c\u8ba1\u5212;<\/li>\n<\/ol>\n<\/li>\n<li>SQL\u8c03\u4f18\u7684\u4efb\u52a1:\n<ol>\n<li>\u67e5\u627e\u9ad8\u8d1f\u8f7d\u7684SQL\u8bed\u53e5;<\/li>\n<li>\u6536\u96c6\u7edf\u8ba1\u4fe1\u606f;<\/li>\n<li>\u6536\u96c6\u7cfb\u7edf\u7edf\u8ba1\u4fe1\u606f;<\/li>\n<li>\u91cd\u5efa\u5df2\u5b58\u5728\u7684\u7d22\u5f15;<\/li>\n<li>\u7ef4\u62a4\u6267\u884c\u8ba1\u5212;<\/li>\n<li>\u521b\u5efa\u65b0\u7684\u7d22\u5f15;<\/li>\n<\/ol>\n<\/li>\n<li>CPU\u548cWait Time\u7684\u8c03\u4f18\n<ol>\n<li>db_time=cpu_time+wait_time;<\/li>\n<li>\u5982\u679cdb_time\u589e\u52a0,cpu_time\u548cwait_time\u7b49\u6bd4\u4f8b\u589e\u52a0,\u8bf4\u660e\u8fd9\u662f\u4e00\u4e2a\u53ef\u6269\u5c55\u7684\u7cfb\u7edf,\u53ea\u9700\u589e\u52a0\u786c\u4ef6\u5373\u53ef;<\/li>\n<li>\u5982\u679cdb_time\u589e\u52a0,cpu_time\u8fdc\u5927\u4e8ewait_time\u7684\u589e\u52a0,\u8bf4\u660eSQL\u6548\u7387\u4e0d\u9ad8,\u9700\u8981SQL\u7684\u4f18\u5316;<\/li>\n<li>\u5982\u679cdb_time\u589e\u52a0,cpu_time\u8fdc\u5c0f\u4e8ewait_time\u7684\u589e\u52a0,\u8bf4\u660e\u5185\u90e8\u6709\u4e89\u7528\u6216\u8005IO\u6548\u7387\u592a\u4f4e;<\/li>\n<\/ol>\n<\/li>\n<li>\u5ba2\u6237\u7cfb\u7edf\u7684\u5e38\u89c1\u95ee\u9898:\n<ol>\n<li>Bad connection management:\u53ef\u4ee5\u4f7f\u7528\u8fde\u63a5\u6c60\u89e3\u51b3;<\/li>\n<li>Bad use of cursors and the shared pool:\u9002\u5f53\u8c03\u5927SGA\u548cPGA,\u5e76\u6307\u5b9a\u52a8\u6001\u7ba1\u7406;<\/li>\n<li>Excess of resources consuming SQL statements:sql\u8981\u53cd\u590d\u6267\u884c;<\/li>\n<li>Use of nonstandard initialization parameters:\u4f7f\u7528\u4e86\u9690\u542b\u53c2\u6570\u6216\u8005\u53c2\u6570\u4f7f\u7528\u4e0d\u5f53;<\/li>\n<li>Poor database disk configuration:IO\u95ee\u9898;<\/li>\n<li>Redo log setup problems:\u81f3\u5c11\u4f7f\u7528\u4e09\u7ec4\u5728\u7ebf\u65e5\u5fd7\u7ec4,\u6bcf\u7ec4\u8bbe\u7f6e\u8db3\u591f\u5927,\u4fdd\u8bc120\u5206\u949f\u5207\u6362\u4e00\u6b21;<\/li>\n<li>Excessive serialization:\u4e32\u884c\u5316\u626b\u63cf,\u6dfb\u52a0\u7d22\u5f15,<span style=\"color: #ff0000;\">\u5c3d\u91cf\u4f7f\u7528\u5355\u5217\u7d22\u5f15,\u53ef\u63a7\u6027\u6bd4\u8f83\u5f3a;<\/span><\/li>\n<li>Inappropriate full table scans:\u5168\u8868\u626b\u63cf,\u4e3b\u8981\u662f\u52a0\u7d22\u5f15\u89e3\u51b3;<\/li>\n<li>Large number of space-management or parse-related\u00a0generated SQL statements:\u5982\u679c\u4f7f\u7528\u672c\u5730\u7ba1\u7406\u8868\u7a7a\u95f4\u7684\u7684\u8bdd\u4e00\u822c\u4e0d\u4f1a\u51fa\u73b0\u9012\u5f52SQL;<\/li>\n<li>Deployment and migration errors:\u90e8\u7f72\u65f6\u51fa\u9519,\u8fd9\u4e2a\u662f\u4eba\u4e3a\u539f\u56e0;<\/li>\n<\/ol>\n<\/li>\n<li>\u5e94\u7528\u7684\u8bbe\u8ba1:\n<ol>\n<li>\u7b80\u5316\u8bbe\u8ba1;<\/li>\n<li>\u6570\u636e\u6a21\u578b:\n<ol>\n<li>\u4e3b\u8981\u8fd8\u662f\u8981\u4e0e\u4e1a\u52a1\u903b\u8f91\u76f8\u7ed3\u5408;<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528\u5efa\u6a21\u5de5\u5177\u5982Oracle Designer,\u4f46\u662f\u6700\u597d\u662f\u4f7f\u7528\u8be6\u7ec6\u7684\u6587\u6863;<\/li>\n<li>\u8003\u8651\u662fOLTP\u7cfb\u7edf\u8fd8\u662fDW\u7cfb\u7edf;<\/li>\n<\/ol>\n<\/li>\n<li>\u8868\u8bbe\u8ba1:\n<ol>\n<li>\u8003\u8651\u4f7f\u7528\u9ed8\u8ba4\u503c,\u7ea6\u675f,\u7269\u5316\u89c6\u56fe,\u5206\u533a\u8868\u7b49\u7279\u6027;<\/li>\n<li>\u5206\u533a\u5217\u4e00\u5b9a\u8981\u5728where\u6761\u4ef6\u4e0a,\u800c\u4e14\u6700\u597d\u4e0d\u8981\u66f4\u65b0;<\/li>\n<li>\u4e0d\u5efa\u8bae\u4f7f\u7528\u89e6\u53d1\u5668;,\u89e6\u53d1\u5668\u7684\u76ee\u7684\u662f\u505acheck,\u800c\u4e0d\u662f\u505aDML;<\/li>\n<li>\u4e0d\u5efa\u8bae\u4f7f\u7528\u5916\u952e,\u53ef\u4ee5\u4f7f\u7528\u7a0b\u5e8f\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027;<\/li>\n<\/ol>\n<\/li>\n<li>\u7d22\u5f15\u8bbe\u8ba1:\n<ol>\n<li>\u7d22\u5f15\u7684\u5217\u4e00\u5b9a\u8981\u7ecf\u5e38\u51fa\u73b0\u5728WHERE\u540e\u9762;<\/li>\n<li>\u5728DW\u4e2d\u5efa\u8bae\u4f7f\u7528\u5916\u952e,\u5728OLTP\u4e2d\u8003\u8651\u5230\u6027\u80fd\u53ef\u4ee5\u4e0d\u7528\u5916\u952e,\u52a0\u5916\u952e\u7684\u8bdd\u5c31\u4e00\u5b9a\u8981\u52a0\u7d22\u5f15;<\/li>\n<\/ol>\n<\/li>\n<li>\u89c6\u56fe:\n<ol>\n<li>\u53ef\u4ee5\u4f7f\u7528\u89c6\u56fe,\u4f46\u662f\u6700\u597d\u4e0d\u8981\u5d4c\u5957\u89c6\u56fe;<\/li>\n<li>\u5d4c\u5957\u89c6\u56fe\u5f71\u54cd\u6267\u884c\u8ba1\u5212;<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<li>Share Cursors\n<ol>\n<li>\u5c3d\u91cf\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u548c\u51fd\u6570;<\/li>\n<li>cursor_sharing\u521d\u59cb\u5316\u53c2\u6570\u5c3d\u91cf\u4e0d\u8981\u4fee\u6539; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0<img decoding=\"async\" alt=\"\" src=\"file:\/\/\/C:\/TEMP\/enhtmlclip\/Image(34).png\" \/><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to SQL Tuning SQL\u6548\u7387\u592a\u4f4e\u7684\u539f\u56e0: Stale or missing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[8],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-performance"],"_links":{"self":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288"}],"version-history":[{"count":0,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}