{"id":1082,"date":"2023-03-12T11:03:43","date_gmt":"2023-03-12T03:03:43","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1082"},"modified":"2023-04-29T11:41:31","modified_gmt":"2023-04-29T03:41:31","slug":"summary-of-database-optimization-plan","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/summary-of-database-optimization-plan\/","title":{"rendered":"\u6570\u636e\u5e93\u4f18\u5316\u65b9\u6848\u603b\u7ed3"},"content":{"rendered":"<p>\u5e38\u7528\u4f18\u5316\u624b\u6bb5\uff1a<\/p>\n<ul>\n<li>\u5b9a\u4f4d\uff1a\u67e5\u627e\u5b9a\u4f4d\u6162\u67e5\u8be2<\/li>\n<li>\u521b\u5efa\u7d22\u5f15\uff1a\u521b\u5efa\u5408\u9002\u7684\u7d22\u5f15\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5148\u5728\u7d22\u5f15\u4e2d\u67e5\u8be2\uff0c\u67e5\u8be2\u5230\u4ee5\u540e\u76f4\u63a5\u627e\u5bf9\u5e94\u7684\u8bb0\u5f55<\/li>\n<li>\u5206\u5e93\u5206\u8868\uff1a\u5f53\u4e00\u5f20\u8868\u7684\u6570\u636e\u6bd4\u8f83\u591a\u6216\u8005\u4e00\u5f20\u8868\u7684\u67d0\u4e9b\u5b57\u6bb5\u7684\u503c\u6bd4\u8f83\u591a\u5e76\u4e14\u5f88\u5c11\u4f7f\u7528\u65f6\uff0c\u91c7\u7528\u6c34\u5e73\u548c\u5782\u76f4\u5206\u8868\u6765\u4f18\u5316<\/li>\n<li>\u8bfb\u5199\u5206\u79bb\uff1a\u5f53\u4e00\u53f0\u670d\u52a1\u5668\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\u65f6\uff0c\u91c7\u7528\u8bfb\u5199\u5206\u79bb\u7684\u65b9\u5f0f\u8fdb\u884c\u8fdb\u7fa4<\/li>\n<li>\u7f13\u5b58\uff1a\u4f7f\u7528redis\u6765\u8fdb\u884c\u7f13\u5b58<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<h3>\u67e5\u627e\u6162\u67e5\u8be2\u5e76\u5b9a\u4f4d\u6162\u67e5\u8be2<\/h3>\n<p>\u5728\u9879\u76ee\u6d4b\u8bd5\u524d\uff0c\u5728\u542f\u52a8MySQL\u6570\u636e\u5e93\u65f6\u5f00\u542f\u6162\u67e5\u8be2\uff0c\u5e76\u4e14\u628a\u6267\u884c\u6162\u7684\u8bed\u53e5\u5199\u5230\u65e5\u5fd7\u4e2d\uff0c\u5728\u8fd0\u884c\u4e00\u5b9a\u7684\u65f6\u95f4\u540e\uff0c\u901a\u8fc7\u67e5\u770b\u65e5\u5fd7\u627e\u5230\u6162\u67e5\u8be2\u7684\u8bed\u53e5<\/p>\n<h3>\u521b\u5efa\u5408\u9002\u7684\u7d22\u5f15<\/h3>\n<p>\u666e\u901a\u7d22\u5f15\uff1a\u5141\u8bb8\u91cd\u590d\u7684\u503c\u51fa\u73b0<br \/>\n\u552f\u4e00\u7d22\u5f15\uff1a\u9664\u4e86\u4e0d\u80fd\u6709\u91cd\u590d\u7684\u8bb0\u5f55\u5916\uff0c\u5176\u4ed6\u548c\u666e\u901a\u7d22\u5f15\u4e00\u6837<br \/>\n\u4e3b\u952e\u7d22\u5f15\uff1a\u662f\u968f\u7740\u8bbe\u5b9a\u4e3b\u952e\u800c\u521b\u5efa\u7684\uff0c\u4e5f\u5c31\u662f\u628a\u67d0\u4e2a\u5217\u8bbe\u4e3a\u4e3b\u952e\u7684\u65f6\u5019\uff0c\u6570\u636e\u5e93\u5c31\u4f1a\u7ed9\u8be5\u5217\u521b\u5efa\u7d22\u5f15<\/p>\n<p>\u5177\u4f53\u6280\u5de7\uff1a<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u521b\u5efa\u7684\u591a\u5217\u7d22\u5f15\uff08\u590d\u5408\u7d22\u5f15\uff09\uff0c\u4e0d\u662f\u4f7f\u7528\u7684\u7b2c\u4e00\u90e8\u5206\u5c31\u4e0d\u4f1a\u4f7f\u7528\u7d22\u5f15<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">alter table dept add index my_ind(dname\uff0cloc)  \/\/dname\u5de6\u8fb9\u7684\u5217\uff0cloc\u662f\u53f3\u8fb9\u7684\u5217\nselect * from dept where dname = &#039;aaa&#039;  \/\/\u4f1a\u4f7f\u7528\u5230\u7d22\u5f15\nselect * from dept where loc = &#039;aaa&#039;  \/\/\u4e0d\u4f1a\u4f7f\u7528\u5230\u7d22\u5f15<\/code><\/pre>\n<ul>\n<li>\u5bf9\u4e8e\u4f7f\u7528like\u7684\u67e5\u8be2\uff0c\u67e5\u8be2\u5982\u679c\u662f<code>%aaa<\/code>\u4e0d\u4f1a\u4f7f\u7528\u7d22\u5f15\uff0c\u800c<code>aaa%<\/code>\u4f1a\u4f7f\u7528\u7d22\u5f15<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">select * from dept where dname like = &#039;%aaa&#039;  \/\/\u4e0d\u4f1a\u4f7f\u7528\u5230\u7d22\u5f15\nselect * from dept where dname like = &#039;aaa%&#039;  \/\/\u4f1a\u4f7f\u7528\u5230\u7d22\u5f15<\/code><\/pre>\n<p>\u6240\u4ee5\u5728like\u67e5\u8be2\u65f6\uff0c\u2018\u5173\u952e\u5b57\u2019\u7684\u6700\u524d\u9762\u4e0d\u80fd\u4f7f\u7528<code>%<\/code>\u6216<code>_<\/code>\u8fd9\u6837\u7684\u5b57\u7b26<\/p>\n<ul>\n<li>\u5982\u679c\u6761\u4ef6\u4e2d\u6709or\uff0c\u6709\u6761\u4ef6\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\uff0c\u5373\u4f7f\u5176\u4e2d\u6709\u6761\u4ef6\u5e26\u6709\u7d22\u5f15\u4e5f\u4e0d\u4f1a\u4f7f\u7528\uff0c\u6362\u8a00\u4e4b\uff0c\u5c31\u662f\u8981\u6c42\u4f7f\u7528\u7684\u6240\u6709\u5b57\u6bb5\uff0c\u90fd\u5fc5\u987b\u5355\u72ec\u4f7f\u7528\u65f6\u80fd\u4f7f\u7528\u7d22\u5f15<\/li>\n<\/ul>\n<h3>\u6570\u636e\u5e93\u4f18\u5316\u4e4b\u5206\u8868<\/h3>\n<p>\u5206\u8868\u5206\u4e3a\u6c34\u5e73\uff08\u6309\u884c\uff09\u5206\u8868\u548c\u5782\u76f4\uff08\u6309\u5217\uff09\u5206\u8868<\/p>\n<p>\uff081\uff09\u6839\u636e\u7ecf\u9a8c\uff1aMySQL\u8868\u6570\u636e\u4e00\u822c\u8fbe\u5230\u767e\u4e07\u7ea7\u522b\uff0c\u67e5\u8be2\u6548\u7387\u4f1a\u5f88\u4f4e\uff0c\u5f88\u5bb9\u6613\u9020\u6210\u8868\u9501\uff0c\u9700\u6309\u884c\u6570\u636e\u8fdb\u884c\u5206\u8868<br \/>\n\uff082\uff09\u5982\u679c\u67d0\u4e2a\u5b57\u6bb5\u503c\u975e\u5e38\u591a\uff0c\u800c\u4e14\u53ea\u6709\u5728\u5f88\u5c11\u60c5\u51b5\u4e0b\u4f1a\u67e5\u8be2\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u53ef\u4ee5\u628a\u5b57\u6bb5\u591a\u7684\u5355\u72ec\u653e\u5230\u4e00\u5f20\u8868\uff0c\u901a\u8fc7\u5916\u952e\u5173\u8054\u8d77\u6765\uff0c\u5373\u5782\u76f4\u5206\u8868<\/p>\n<p>\u6c34\u5e73\u5206\u8868\u7b56\u7565\uff1a<\/p>\n<ul>\n<li>\u6309\u65f6\u95f4\u5206\u8868<\/li>\n<li>\u6309\u533a\u95f4\u8303\u56f4\u5206\u8868    <\/li>\n<li>hash\u5206\u8868<\/li>\n<\/ul>\n<h3>\u8bfb\u5199\u5206\u79bb<\/h3>\n<p>\u5f53\u4e00\u53f0\u670d\u52a1\u5668\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\u65f6\uff0c\u91c7\u7528\u8bfb\u5199\u5206\u79bb\u7684\u65b9\u5f0f\u8fdb\u884c\u96c6\u7fa4<\/p>\n<p>\u4e3b\u4ece\u540c\u6b65\uff1a\u6240\u6709\u7684\u5199\u90fd\u5f80\u4e3b\u4e0a\u64cd\u4f5c\uff0c\u800c\u4ece\u53ea\u8fdb\u884c\u540c\u6b65<br \/>\n\u8bfb\u5199\u5206\u79bb\uff1a\u4f7f\u7528\u8d1f\u8f7d\u5747\u8861\uff0c\u5199\u5f80\u4e3b\uff0c\u8bfb\u5f80\u4ece<\/p>\n<h3>\u5982\u4f55\u63d2\u5165\u767e\u4e07\u6761\u6570\u636e<\/h3>\n<p>\u4f7f\u7528\u6279\u91cf\u64cd\u4f5c\uff0c\u6279\u91cf\u64cd\u4f5c\u4e0d\u80fd\u4f7f\u7528\u4ee3\u7801\u64cd\u4f5c\u5c31\u4e0d\u4f7f\u7528\uff01\u5c3d\u91cf\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u6765\u5b9e\u73b0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e38\u7528\u4f18\u5316\u624b\u6bb5\uff1a \u5b9a\u4f4d\uff1a\u67e5\u627e\u5b9a\u4f4d\u6162\u67e5\u8be2 \u521b\u5efa\u7d22\u5f15\uff1a\u521b\u5efa\u5408\u9002\u7684\u7d22\u5f15\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5148\u5728\u7d22\u5f15\u4e2d\u67e5\u8be2\uff0c\u67e5\u8be2\u5230\u4ee5\u540e\u76f4\u63a5\u627e\u5bf9\u5e94 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[299,298],"class_list":["post-1082","post","type-post","status-publish","format-standard","hentry","category-database","tag-299","tag-298"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1082"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1082\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}