{"id":2082,"date":"2025-11-20T12:53:28","date_gmt":"2025-11-20T04:53:28","guid":{"rendered":"https:\/\/www.tqazy.com\/?p=2082"},"modified":"2025-11-20T15:08:14","modified_gmt":"2025-11-20T07:08:14","slug":"%e9%9d%a2%e8%af%95%e7%ac%94%e8%ae%b0%ef%bc%9amysql-%e7%9b%b8%e5%85%b302-%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/www.tqazy.com\/?p=2082","title":{"rendered":"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 &#8211; \u7d22\u5f15"},"content":{"rendered":"<h1>\u7d22\u5f15<\/h1>\n<blockquote>\n<p>\u56de\u76ee\u5f55\uff1a <a href=\"https:\/\/www.tqazy.com\/?p=1972\" target=\"_blank\">\u300a\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u5173\u76ee\u5f55\u300b<\/a><br \/>\n\u4e0a\u4e00\u7bc7\uff1a <a href=\"https:\/\/www.tqazy.com\/?p=2077\" target=\"_blank\">\u300a\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517301 &#8211; \u57fa\u7840\u6838\u5fc3\u300b<\/a><br \/>\n\u4e0b\u4e00\u7bc7\uff1a <a href=\"https:\/\/www.tqazy.com\/?p=2087\" target=\"_blank\">\u300a\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517303 \u2013 SQL\u8bed\u6cd5\u4e0e\u67e5\u8be2\u4f18\u5316\u300b<\/a><\/p>\n<\/blockquote>\n<hr\/>\n<h1>01. \u5404\u79cd\u6811\u7684\u539f\u7406\u548c\u7279\u6027<\/h1>\n<p>\u5b66\u4e60\u6811\uff0c\u662f\u4e3a\u4e86\u4fbf\u4e8e\u5b66\u4e60\u7d22\u5f15\u3002\u7d22\u5f15\u7684\u6838\u5fc3\u4f5c\u7528\u662f\u201c\u52a0\u901f\u67e5\u8be2\u201d\uff0c\u800c\u9ad8\u6548\u7684\u6811\u7ed3\u6784\u6b63\u662f\u5b9e\u73b0\u8fd9\u4e00\u70b9\u7684\u5173\u952e\u3002<\/p>\n<p>\u7b54\uff1a<\/p>\n<h2>1. \u201c\u6811\u201d\u5f62\u8c61\u7684\u7406\u89e3<\/h2>\n<p>\u53ef\u4ee5\u4ece\u201c\u73b0\u5b9e\u4e2d\u7684\u6811\u201d\u7c7b\u6bd4\u6570\u636e\u7ed3\u6784\u7684\u201c\u6811\u201d\uff0c\u5b83\u548c\u8def\u8fb9\u7684\u6811\u957f\u5f97\u5f88\u50cf\uff0c\u53ea\u662f\u201c\u5012\u8fc7\u6765\u201d\u4e86\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u68f5\u7b80\u5316\u7684\u82f9\u679c\u6811\uff1a<\/p>\n<ul>\n<li>\u6700\u5e95\u4e0b\u7684 \u201c\u6811\u6839\u201d \u662f\u8d77\u70b9\uff0c\u5bf9\u5e94\u6570\u636e\u7ed3\u6784\u4e2d\u6811\u7684\u6839\u8282\u70b9\uff08\u53ea\u6709\u4e00\u4e2a\uff09\uff1b<\/li>\n<li>\u4ece\u6811\u6839\u5f80\u4e0a\u957f\u7684 \u201c\u6811\u5e72\u201d \u4f1a\u5206\u6748\u51fa \u201c\u6811\u679d\u201d\uff0c\u8fd9\u4e9b\u6811\u679d\u5c31\u662f\u7236\u8282\u70b9\uff1b<\/li>\n<li>\u6811\u679d\u518d\u5206\u6748\u51fa\u66f4\u7ec6\u7684\u679d\u6860\uff0c\u8fd9\u4e9b\u7ec6\u679d\u6860\u5c31\u662f\u5b50\u8282\u70b9\uff08\u4e00\u4e2a\u7236\u8282\u70b9\u53ef\u4ee5\u6709\u591a\u4e2a\u5b50\u8282\u70b9\uff09\uff1b<\/li>\n<li>\u6700\u9876\u7aef\u7684 \u201c\u82f9\u679c\u201d\uff08\u6ca1\u6709\u518d\u5206\u6748\u7684\u90e8\u5206\uff09\uff0c\u5c31\u662f\u53f6\u5b50\u8282\u70b9\u3002<br \/>\n\u6570\u636e\u7ed3\u6784\u91cc\u7684 \u201c\u6811\u201d\uff0c\u5c31\u662f\u8fd9\u6837\u4e00\u79cd \u201c\u5206\u5c42\u3001\u6709\u5206\u652f\u201d \u7684\u7ed3\u6784\uff1a<\/li>\n<li>\u6240\u6709\u8282\u70b9\uff08\u6839\u3001\u7236\u3001\u5b50\u3001\u53f6\u5b50\uff09\u90fd\u50cf \u201c\u679c\u5b9e\u201d \u4e00\u6837\uff0c\u5b58\u50a8\u7740\u6570\u636e\uff08\u6216\u7d22\u5f15\uff09\uff1b<\/li>\n<li>\u8282\u70b9\u4e4b\u95f4\u7684 \u201c\u8fde\u63a5\u201d\uff08\u6bd4\u5982\u6839\u5230\u7236\u3001\u7236\u5230\u5b50\uff09\u50cf \u201c\u6811\u679d\u201d\uff0c\u8868\u793a\u6570\u636e\u4e4b\u95f4\u7684\u5173\u7cfb\uff1b<\/li>\n<li>\u6574\u4e2a\u7ed3\u6784\u662f \u201c\u5355\u5411\u201d \u7684\uff1a\u53ea\u80fd\u4ece\u6839\u5f80\u4e0b\u627e\u5b50\u8282\u70b9\uff0c\u4e0d\u80fd\u4ece\u5b50\u8282\u70b9\u53cd\u63a8\u56de\u6839\uff08\u5c31\u50cf\u82f9\u679c\u4e0d\u4f1a\u81ea\u5df1\u957f\u56de\u6811\u679d\uff09\u3002<\/li>\n<\/ul>\n<p>\u4e3e\u4e2a\u66f4\u5177\u4f53\u7684\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u7528\u6811\u5b58 \u201c\u73ed\u7ea7\u5b66\u751f\u540d\u5355\u201d\uff0c\u6839\u8282\u70b9\u53ef\u4ee5\u662f \u201c\u4e09\u5e74\u7ea7\u201d\uff1b<\/li>\n<li>\u6839\u8282\u70b9\u7684\u5b50\u8282\u70b9\uff08\u7236\u8282\u70b9\uff09\u53ef\u4ee5\u662f \u201c\u4e09\u73ed\u201d\u201c\u4e94\u73ed\u201d\uff1b<\/li>\n<li>\u201c\u4e09\u73ed\u201d \u7684\u5b50\u8282\u70b9\u53ef\u4ee5\u662f \u201c\u7537\u751f\u7ec4\u201d\u201c\u5973\u751f\u7ec4\u201d\uff1b<\/li>\n<li>\u201c\u7537\u751f\u7ec4\u201d \u7684\u5b50\u8282\u70b9\uff08\u53f6\u5b50\u8282\u70b9\uff09\u5c31\u662f\u5177\u4f53\u7684\u5b66\u751f\uff1a\u201c\u5c0f\u660e\u201d\u201c\u5c0f\u674e\u201d&#8230;<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u7ed3\u6784\u7684\u6838\u5fc3\u597d\u5904\u662f\uff1a<strong>\u67e5\u627e\u6548\u7387\u9ad8\u3002<\/strong><br \/>\n\u6bd4\u5982\u60f3\u627e \u201c\u4e09\u5e74\u7ea7\u4e09\u73ed\u7537\u751f\u7ec4\u7684\u5c0f\u660e\u201d\uff0c\u4f60\u4e0d\u7528\u904d\u5386\u6240\u6709\u5b66\u751f\uff0c\u53ea\u9700\u4ece\u6839\uff08\u4e09\u5e74\u7ea7\uff09\u2192 \u4e09\u73ed \u2192 \u7537\u751f\u7ec4 \u2192 \u5c0f\u660e\uff0c\u4e00\u6b65\u4e00\u6b65\u6309 \u201c\u5206\u652f\u201d \u627e\uff0c\u6bd4\u5728\u4e00\u5806\u4e71\u5e8f\u7684\u540d\u5355\u91cc\u7ffb\u5feb\u5f97\u591a\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>2. \u4e8c\u53c9\u67e5\u627e\u6811<\/h2>\n<p>\u201c\u4e0d\u5408\u9002\u201d\u7684\u6811\uff08Binary Search Tree\uff09<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong>\u6bcf\u4e2a\u8282\u70b9\u6700\u591a 2 \u4e2a\u5b50\u8282\u70b9\uff08\u5de6\u5c0f\u53f3\u5927\uff09\uff0c\u67e5\u8be2\u65f6\u4ece\u6839\u8282\u70b9\u5f00\u59cb\uff0c\u6bd4\u5f53\u524d\u8282\u70b9\u5c0f\u5c31\u8d70\u5de6\u5b50\u6811\uff0c\u5927\u5c31\u8d70\u53f3\u5b50\u6811\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u5bb9\u6613 \u201c\u5931\u8861\u201d\u3002\u6bd4\u5982\u63d2\u5165\u4e00\u4e32\u9012\u589e\u6570\u636e\uff0c\u4f1a\u9000\u5316\u6210\u94fe\u8868\uff08\u5de6\u5b50\u6811\u4e3a\u7a7a\uff0c\u53ea\u6709\u53f3\u5b50\u6811\uff09\uff0c\u67e5\u8be2\u6548\u7387\u4ece O (logn) \u66b4\u8dcc\u5230 O (n)\uff08\u548c\u904d\u5386\u94fe\u8868\u4e00\u6837\u6162\uff09\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48 MySQL \u4e0d\u7528\uff1a<\/strong>\u6570\u636e\u5e93\u7d22\u5f15\u9700\u8981\u7a33\u5b9a\u9ad8\u6548\u7684\u67e5\u8be2\uff0c\u4e8c\u53c9\u6811\u7684\u5931\u8861\u95ee\u9898\u65e0\u6cd5\u6ee1\u8db3\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1em\"><\/div>\n<h2>3. \u5e73\u8861\u4e8c\u53c9\u6811<\/h2>\n<p>\u53c8\u53eb\uff1aAVL\u6811\/\u7ea2\u9ed1\u6811<br \/>\n\u89e3\u51b3 \u201c\u5931\u8861\u201d\uff0c\u4f46\u4ecd\u6709\u5c40\u9650<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong>\u5728\u4e8c\u53c9\u67e5\u627e\u6811\u57fa\u7840\u4e0a\uff0c\u901a\u8fc7\u65cb\u8f6c\u4fdd\u6301 \u201c\u5e73\u8861\u201d\uff08\u5de6\u53f3\u5b50\u6811\u9ad8\u5ea6\u5dee\u4e0d\u8d85\u8fc7 1\uff09\uff0c\u786e\u4fdd\u67e5\u8be2\u6548\u7387\u7a33\u5b9a\u5728 O (logn)\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u8fd8\u662f \u201c\u4e8c\u53c9\u201d\uff08\u6bcf\u4e2a\u8282\u70b9\u6700\u591a 2 \u4e2a\u5b50\u8282\u70b9\uff09\uff0c\u5bfc\u81f4\u6811\u7684 \u201c\u9ad8\u5ea6\u8fc7\u9ad8\u201d\u3002<br \/>\n\u6bd4\u5982\u5b58 100 \u4e07\u6761\u6570\u636e\uff0c\u5e73\u8861\u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u5927\u6982\u662f 20 \u5c42\uff082^20\u2248100 \u4e07\uff09\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48 MySQL \u4e0d\u7528\uff1a<\/strong>\u7d22\u5f15\u6570\u636e\u5b58\u5728\u78c1\u76d8\u4e0a\uff0c\u6bcf\u6b21\u67e5\u8be2\u9700\u8981\u4ece\u78c1\u76d8\u8bfb\u6570\u636e\uff08\u4e00\u6b21 IO \u8bfb\u4e00\u4e2a \u201c\u9875\u201d\uff0c\u6bd4\u5982 4KB\uff09\u3002\u6811\u9ad8 20 \u5c31\u610f\u5473\u7740\u6700\u591a\u8981\u8bfb 20 \u6b21\u78c1\u76d8\uff0cIO \u6210\u672c\u592a\u9ad8\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032827685.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032827685.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1em\"><\/div>\n<h2>4. B \u6811<\/h2>\n<p>\u591a\u8def\u5e73\u8861\u67e5\u627e\u6811\uff0c\u964d\u4f4e\u9ad8\u5ea6<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u201c\u591a\u8def\u201d\uff1a\u6bcf\u4e2a\u8282\u70b9\u53ef\u4ee5\u6709\u591a\u4e2a\u5b50\u8282\u70b9\uff08\u6bd4\u5982 100 \u4e2a\uff09\uff0c\u4e0d\u518d\u662f\u4e8c\u53c9\u3002<\/li>\n<li>\u201c\u5e73\u8861\u201d\uff1a\u6240\u6709\u53f6\u5b50\u8282\u70b9\u5728\u540c\u4e00\u5c42\uff0c\u907f\u514d\u67d0\u6761\u8def\u5f84\u8fc7\u957f\u3002<\/li>\n<li>\u8282\u70b9\u5b58 \u201c\u6570\u636e\u201d\uff1a\u6bcf\u4e2a\u8282\u70b9\u4e0d\u4ec5\u5b58\u7d22\u5f15\u952e\uff0c\u8fd8\u76f4\u63a5\u5b58\u5bf9\u5e94\u7684\u6570\u636e\uff08\u6216\u6570\u636e\u5730\u5740\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u4f18\u52bf\uff1a<\/strong>\u9ad8\u5ea6\u5927\u5927\u964d\u4f4e\u3002\u6bd4\u5982\u6bcf\u4e2a\u8282\u70b9\u6709 100 \u4e2a\u5b50\u8282\u70b9\uff0c\u5b58 100 \u4e07\u6570\u636e\uff0c\u6811\u9ad8\u53ea\u9700 3 \u5c42\uff08100^3=100 \u4e07\uff09\uff0c\u6700\u591a 3 \u6b21 IO \u5c31\u80fd\u67e5\u5230\u6570\u636e\uff0c\u6bd4\u5e73\u8861\u4e8c\u53c9\u6811\u9ad8\u6548\u5f97\u591a\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48 MySQL \u4e0d\u5b8c\u5168\u7528\u5b83\uff1a<\/strong>\u8303\u56f4\u67e5\u8be2\u4e0d\u65b9\u4fbf\u3002\u6bd4\u5982\u67e5 \u201cid \u4ece 100 \u5230 1000\u201d\uff0cB \u6811\u9700\u8981\u56de\u6eaf\u7236\u8282\u70b9\u627e\u4e0b\u4e00\u4e2a\u8303\u56f4\uff0c\u6548\u7387\u4f4e\u3002<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032424377.webp'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032424377.webp\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1em\"><\/div>\n<h2>5. B + \u6811<\/h2>\n<p>MySQL \u7d22\u5f15\u7684 \u201c\u6807\u51c6\u7b54\u6848\u201d<br \/>\nB + \u6811\u662f B \u6811\u7684\u53d8\u79cd\uff0c\u4e13\u95e8\u4e3a\u6570\u636e\u5e93\u7d22\u5f15\u4f18\u5316\u8bbe\u8ba1\uff0c\u6838\u5fc3\u7279\u6027\u5b8c\u7f8e\u9002\u914d\u7d22\u5f15\u9700\u6c42\uff1a<\/p>\n<p><strong>\u975e\u53f6\u5b50\u8282\u70b9\u53ea\u5b58\u7d22\u5f15\uff0c\u4e0d\u5b58\u6570\u636e\uff1a<\/strong><\/p>\n<ul>\n<li>\u975e\u53f6\u5b50\u8282\u70b9\u4ec5\u4fdd\u7559\u7d22\u5f15\u952e\uff08\u6bd4\u5982 id\uff09\uff0c\u4e0d\u5b58\u5b9e\u9645\u6570\u636e\uff0c\u8fd9\u6837\u4e00\u4e2a\u8282\u70b9\u80fd\u5b58\u66f4\u591a\u7d22\u5f15\u952e\uff0c\u5b50\u8282\u70b9\u6570\u91cf\u66f4\u591a\uff08\u6bd4\u5982 200 \u4e2a\uff09\uff0c\u6811\u9ad8\u66f4\u4f4e\uff08100 \u4e07\u6570\u636e\u53ea\u9700 2-3 \u5c42\uff09\uff0cIO \u6b21\u6570\u66f4\u5c11\u3002<\/li>\n<\/ul>\n<p><strong>\u53f6\u5b50\u8282\u70b9\u5b58\u5b8c\u6574\u6570\u636e\uff0c\u4e14\u9996\u5c3e\u76f8\u8fde\uff1a<\/strong><\/p>\n<ul>\n<li>\u6240\u6709\u5b9e\u9645\u6570\u636e\u53ea\u5b58\u5728\u53f6\u5b50\u8282\u70b9\uff0c\u4e14\u53f6\u5b50\u8282\u70b9\u4e4b\u95f4\u7528\u94fe\u8868\u8fde\u63a5\uff08\u5f62\u6210\u6709\u5e8f\u94fe\u8868\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u5bf9\u7d22\u5f15\u7684\u6838\u5fc3\u4ef7\u503c\uff1a<\/strong><\/p>\n<ul>\n<li>\u5355\u503c\u67e5\u8be2\u5feb\uff1a\u548c B \u6811\u4e00\u6837\uff0c\u901a\u8fc7\u7d22\u5f15\u952e\u5feb\u901f\u5b9a\u4f4d\u5230\u53f6\u5b50\u8282\u70b9\uff0cIO \u5c11\u3002<\/li>\n<li>\u8303\u56f4\u67e5\u8be2\u65e0\u654c\uff1a\u6bd4\u5982\u67e5 \u201cid&gt;100\u201d\uff0c\u627e\u5230\u7b2c\u4e00\u4e2a id=100 \u7684\u53f6\u5b50\u8282\u70b9\u540e\uff0c\u76f4\u63a5\u987a\u7740\u94fe\u8868\u5f80\u540e\u626b\uff0c\u4e0d\u7528\u56de\u6eaf\u7236\u8282\u70b9\uff0c\u6548\u7387\u6781\u9ad8\uff08MySQL \u4e2d\u8303\u56f4\u67e5\u8be2\u5f88\u9891\u7e41\uff0c\u8fd9\u662f\u5173\u952e\uff09\u3002<\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032535265.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032535265.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1em\"><\/div>\n<h2>6. MySQL \u4e3a\u4ec0\u4e48\u9009 B + \u6811\u505a\u7d22\u5f15\uff1f<\/h2>\n<ol>\n<li>\u6811\u9ad8\u4f4e\uff0cIO \u6b21\u6570\u5c11\uff08\u78c1\u76d8\u8bfb\u5199\u6548\u7387\u9ad8\uff09\uff1b<\/li>\n<li>\u53f6\u5b50\u8282\u70b9\u6709\u5e8f\u76f8\u8fde\uff0c\u8303\u56f4\u67e5\u8be2\uff08\u5982 between\u3001in\uff09\u6548\u7387\u8fdc\u8d85\u5176\u4ed6\u6811\uff1b<\/li>\n<li>\u975e\u53f6\u5b50\u8282\u70b9\u53ea\u5b58\u7d22\u5f15\uff0c\u8282\u70b9\u5b58\u50a8\u5bc6\u5ea6\u9ad8\uff0c\u8fdb\u4e00\u6b65\u964d\u4f4e\u6811\u9ad8\u3002<\/li>\n<\/ol>\n<div style=\"height:1.5em\"><\/div>\n<h1>02. \u7d22\u5f15\u7684\u4f5c\u7528<\/h1>\n<p>\u7b54\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u52a0\u901f\u67e5\u8be2\uff0c\u964d\u4f4eIO<\/strong>\uff1a\u7d22\u5f15\u901a\u8fc7\u6709\u5e8f\u7ed3\u6784\uff08\u5982B+\u6811\uff09\u5c06\u5206\u6563\u7684\u6570\u636e\u6309\u7d22\u5f15\u952e\u6392\u5e8f\uff0c\u67e5\u8be2\u65f6\u65e0\u9700\u5168\u8868\u626b\u63cf\uff0c\u800c\u662f\u901a\u8fc7\u7d22\u5f15\u5feb\u901f\u5b9a\u4f4d\u76ee\u6807\u6570\u636e\u6240\u5728\u7684\u78c1\u76d8\u4f4d\u7f6e\uff0c\u5927\u5e45\u51cf\u5c11\u78c1\u76d8IO\u6b21\u6570\uff08\u6bd4\u5982\u4ece\u626b\u63cf\u5168\u8868100\u4e07\u884c\u964d\u5230\u626b\u63cf\u51e0\u5341\u884c\uff09\uff1b<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u8bc1\u6570\u636e\u552f\u4e00\u6027\uff0c\u5f3a\u5316\u4e1a\u52a1\u7ea6\u675f<\/strong>\uff1a\u901a\u8fc7\u552f\u4e00\u7d22\u5f15\uff08\u542b\u4e3b\u952e\u7d22\u5f15\uff09\uff0c\u6570\u636e\u5e93\u4f1a\u5f3a\u5236\u7ea6\u675f\u7d22\u5f15\u952e\u7684\u503c\u4e0d\u91cd\u590d\uff0c\u76f4\u63a5\u5b9e\u73b0 \u201c\u4e1a\u52a1\u552f\u4e00\u6807\u8bc6\u201d \u9700\u6c42\uff08\u5982\u7528\u6237 ID\u3001\u8ba2\u5355\u53f7\u4e0d\u53ef\u91cd\u590d\uff09\uff0c\u907f\u514d\u624b\u52a8\u6821\u9a8c\u7684\u7e41\u7410\u548c\u98ce\u9669\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u5316\u6392\u5e8f\u4e0e\u5206\u7ec4\u64cd\u4f5c<\/strong>\uff1a\u7d22\u5f15\u672c\u8eab\u662f\u6709\u5e8f\u7684\uff0c\u5f53\u67e5\u8be2\u5305\u542b<code>order by<\/code>\uff08\u6392\u5e8f\uff09\u3001<code>group by<\/code>\uff08\u5206\u7ec4\uff09\u65f6\uff0c\u53ef\u76f4\u63a5\u5229\u7528\u7d22\u5f15\u7684\u6709\u5e8f\u6027\u907f\u514d\u5168\u8868\u6570\u636e\u7684\u989d\u5916\u6392\u5e8f\uff08\u51cf\u5c11\u5185\u5b58 \/ \u78c1\u76d8\u4e34\u65f6\u8868\u5f00\u9500\uff09\uff0c\u63d0\u5347\u8fd9\u7c7b\u64cd\u4f5c\u7684\u6548\u7387\u3002<\/p>\n<\/li>\n<\/ol>\n<div style=\"height:1.5em\"><\/div>\n<h1>03. \u5e38\u89c1\u7d22\u5f15\u7c7b\u578b\u53ca\u5176\u7279\u6027<\/h1>\n<p>\u7b54\uff1a<\/p>\n<h2>1. \u4e3b\u952e\u7d22\u5f15<\/h2>\n<p>Primary Key<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u5f3a\u5236\u552f\u4e00\u6027\uff08\u8868\u4e2d\u552f\u4e00\u6807\u8bc6\u4e00\u884c\u6570\u636e\uff09\uff0c\u4e14\u4e0d\u5141\u8bb8NULL\u503c\uff1b<\/li>\n<li>\u4e00\u5f20\u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u4e3b\u952e\u7d22\u5f15\uff1b<\/li>\n<li>InnoDB \u4e2d\u4e3b\u952e\u7d22\u5f15\u662f\u805a\u7c07\u7d22\u5f15\uff08\u53f6\u5b50\u8282\u70b9\u76f4\u63a5\u5b58\u50a8\u6574\u884c\u6570\u636e\uff09\uff0c\u65e0\u9700\u56de\u8868\uff0c\u67e5\u8be2\u6548\u7387\u6700\u9ad8\u3002<\/li>\n<\/ul>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u4f5c\u4e3a\u8868\u7684\u552f\u4e00\u6807\u8bc6\uff08\u5982\u7528\u6237 ID\u3001\u8ba2\u5355 ID\uff09\uff0c\u786e\u4fdd\u6570\u636e\u552f\u4e00\u6027\u5e76\u52a0\u901f\u884c\u67e5\u8be2\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>2. \u552f\u4e00\u7d22\u5f15<\/h2>\n<p>Unique Index<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u7d22\u5f15\u5217\u7684\u503c\u552f\u4e00\uff0c\u4f46\u5141\u8bb8NULL\u503c\uff08\u4e14NULL\u53ef\u51fa\u73b0\u591a\u6b21\uff09\uff1b<\/li>\n<li>\u4e00\u5f20\u8868\u53ef\u521b\u5efa\u591a\u4e2a\u552f\u4e00\u7d22\u5f15\uff1b<\/li>\n<li>\u57fa\u4e8e B + \u6811\u7ed3\u6784\uff0c\u975e\u805a\u7c07\u7d22\u5f15\uff08\u53f6\u5b50\u8282\u70b9\u5b58\u4e3b\u952e\u503c\uff0c\u9700\u56de\u8868\u67e5\u6570\u636e\uff09\uff1b<\/li>\n<li>\u67e5\u8be2\u65f6\u627e\u5230\u4e00\u4e2a\u5339\u914d\u503c\u5c31\u505c\u6b62\u626b\u63cf\uff08\u65e0\u9700\u786e\u8ba4\u662f\u5426\u6709\u91cd\u590d\uff09\uff0c\u6bd4\u666e\u901a\u7d22\u5f15\u5c11\u4e86 \u201c\u7ee7\u7eed\u6821\u9a8c\u201d \u7684\u6b65\u9aa4\uff0c\u56de\u8868\u524d\u7684\u7d22\u5f15\u5b9a\u4f4d\u6548\u7387\u66f4\u9ad8\u3002<\/li>\n<\/ul>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u9700\u552f\u4e00\u7ea6\u675f\u4f46\u975e\u4e3b\u952e\u7684\u5b57\u6bb5\uff08\u5982\u624b\u673a\u53f7\u3001\u90ae\u7bb1\uff0c\u5141\u8bb8\u672a\u586b\u5199\u5373NULL\uff09\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>3. \u666e\u901a\u7d22\u5f15<\/h2>\n<p>Normal Index<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u6700\u57fa\u7840\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u65e0\u552f\u4e00\u6027\u7ea6\u675f\uff0c\u5141\u8bb8\u91cd\u590d\u503c\u548cNULL\uff1b<\/li>\n<li>\u57fa\u4e8e B + \u6811\u7ed3\u6784\uff0c\u975e\u805a\u7c07\u7d22\u5f15\uff0c\u4ec5\u7528\u4e8e\u52a0\u901f\u67e5\u8be2\uff0c\u4e0d\u5f71\u54cd\u6570\u636e\u672c\u8eab\u7684\u7ea6\u675f\uff1b<\/li>\n<li>\u67e5\u8be2\u65f6\u9700\u626b\u63cf\u6240\u6709\u5339\u914d\u7684\u7d22\u5f15\u8282\u70b9\uff08\u53ef\u80fd\u6709\u591a\u4e2a\u91cd\u590d\u503c\uff09\uff0c\u518d\u6279\u91cf\u56de\u8868\u53d6\u6570\u636e\uff0c\u6bd4\u552f\u4e00\u7d22\u5f15\u591a\u4e86 \u201c\u626b\u63cf\u91cd\u590d\u7d22\u5f15\u201d \u7684\u5f00\u9500\u3002<\/li>\n<\/ul>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u9ad8\u9891\u67e5\u8be2\u7684\u975e\u552f\u4e00\u5b57\u6bb5\uff08\u5982\u5546\u54c1\u5206\u7c7b\u3001\u7528\u6237\u6635\u79f0\uff09\uff0c\u5355\u7eaf\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>4. \u8054\u5408\u7d22\u5f15<\/h2>\n<p>Composite Index<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u7531\u591a\u4e2a\u5b57\u6bb5\u7ec4\u5408\u521b\u5efa\uff08\u5982(a, b, c)\uff09\uff0c\u9075\u5faa<strong>\u6700\u5de6\u524d\u7f00\u539f\u5219<\/strong>\uff08\u67e5\u8be2\u9700\u5305\u542b\u6700\u5de6\u5b57\u6bb5\u624d\u80fd\u547d\u4e2d\u7d22\u5f15\uff09\uff1b<\/li>\n<li>\u7d22\u5f15\u6309\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u6392\u5e8f\uff0c\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u76f8\u540c\u5219\u6309\u7b2c\u4e8c\u4e2a\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff1b<\/li>\n<li>\u53ef\u8986\u76d6\u591a\u5b57\u6bb5\u67e5\u8be2\uff0c\u51cf\u5c11\u56de\u8868\uff08\u5982\u67e5\u8be2a, b\u65f6\uff0c\u82e5\u8054\u5408\u7d22\u5f15\u5305\u542ba, b\uff0c\u5219\u65e0\u9700\u56de\u8868\uff09\uff1b<\/li>\n<li>\u6548\u7387\u4f9d\u8d56\u67e5\u8be2\u6761\u4ef6\uff1a\u4ec5\u547d\u4e2d\u6700\u5de6\u524d\u7f00\u4e14\u4e3a\u8986\u76d6\u7d22\u5f15\u65f6\uff08\u65e0\u9700\u56de\u8868\uff09\uff0c\u6548\u7387\u63a5\u8fd1\u666e\u901a\u7d22\u5f15\uff1b\u82e5\u672a\u547d\u4e2d\u5168\u90e8\u524d\u7f00\u6216\u9700\u56de\u8868\uff0c\u6548\u7387\u4f1a\u4e0b\u964d\u3002<\/li>\n<li>\u6574\u4f53\u6bd4\u666e\u901a\u7d22\u5f15\u6162\u7684\u6838\u5fc3\uff1a\u7d22\u5f15\u7ed3\u6784\u662f\u591a\u5b57\u6bb5\u6392\u5e8f\uff0c\u5b9a\u4f4d\u65f6\u9700\u5339\u914d\u591a\u4e2a\u5b57\u6bb5\u7684\u6709\u5e8f\u6027\uff0c\u903b\u8f91\u6bd4\u5355\u5b57\u6bb5\u7d22\u5f15\u590d\u6742\u3002<\/li>\n<\/ul>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u591a\u5b57\u6bb5\u7ec4\u5408\u67e5\u8be2\uff08\u5982 \u201c\u6309\u7528\u6237 ID + \u8ba2\u5355\u72b6\u6001\u67e5\u8be2\u201d\uff09\uff0c\u9700\u5408\u7406\u8bbe\u8ba1\u5b57\u6bb5\u987a\u5e8f\uff08\u533a\u5206\u5ea6\u9ad8\u7684\u5b57\u6bb5\u653e\u5de6\u4fa7\uff09\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>5. \u524d\u7f00\u7d22\u5f15<\/h2>\n<p>Prefix Index<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u4ec5\u5bf9\u5b57\u7b26\u4e32\u5b57\u6bb5\u7684\u524d N \u4e2a\u5b57\u7b26\u521b\u5efa\u7d22\u5f15\uff08\u5982index(name(10))\uff09\uff0c\u5927\u5e45\u8282\u7701\u5b58\u50a8\u7a7a\u95f4\uff0c\u4f46\u7d22\u5f15\u9009\u62e9\u6027\u4f4e\uff08\u91cd\u590d\u7387\u9ad8\uff09\uff1b<\/li>\n<li>\u9002\u7528\u4e8e\u957f\u5b57\u7b26\u4e32\uff08\u5982 URL\u3001\u957f\u6587\u672c\uff09\uff0c\u4f46\u53ef\u80fd\u964d\u4f4e\u7d22\u5f15\u9009\u62e9\u6027\uff08\u91cd\u590d\u7387\u5347\u9ad8\uff09\uff0c\u4e14\u65e0\u6cd5\u7528\u4e8eorder by\/group by\u6216\u8986\u76d6\u7d22\u5f15\u3002<\/li>\n<li>\u67e5\u8be2\u65f6\u9700\u626b\u63cf\u66f4\u591a\u7d22\u5f15\u8282\u70b9\u624d\u80fd\u5b9a\u4f4d\u76ee\u6807\uff0c\u4e14\u65e0\u6cd5\u4f7f\u7528\u8986\u76d6\u7d22\u5f15\uff08\u5fc5\u987b\u56de\u8868\uff09\uff0c\u989d\u5916\u589e\u52a0 IO \u5f00\u9500\u3002<\/li>\n<\/ul>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u957f\u5b57\u7b26\u4e32\u5b57\u6bb5\u7684\u6a21\u7cca\u67e5\u8be2\uff08\u5982like &#8216;abc%&#8217;\uff09\uff0c\u5e73\u8861\u7a7a\u95f4\u4e0e\u67e5\u8be2\u6548\u7387\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>6. \u5168\u6587\u7d22\u5f15<\/h2>\n<p>Full-Text Index<\/p>\n<p><strong>\u7279\u6027\uff1a<\/strong><\/p>\n<ul>\n<li>\u9488\u5bf9\u5927\u6587\u672c\u5185\u5bb9\uff08\u5982\u6587\u7ae0\u3001\u8bc4\u8bba\uff09\u7684\u5173\u952e\u8bcd\u641c\u7d22\uff0c\u9488\u5bf9\u5927\u6587\u672c\u5206\u8bcd\u5339\u914d\uff08\u800c\u975elike\u7684\u5b57\u7b26\u5339\u914d\uff0c\u975e B + \u6811\u7cbe\u786e\u67e5\u627e\uff0c\u9700\u5148\u5206\u8bcd\u3001\u5339\u914d\u5012\u6392\u7d22\u5f15\uff0c\u518d\u5173\u8054\u539f\u8868\u6570\u636e\uff09\uff1b<\/li>\n<li>\u6548\u7387\u8fdc\u9ad8\u4e8elike &#8216;%\u5173\u952e\u8bcd%&#8217;\uff0c\u4f46\u4ec5\u652f\u6301MATCH() AGAINST()\u8bed\u6cd5\uff0c\u4e14\u6709\u6700\u5c0f \/ \u6700\u5927\u8bcd\u957f\u9650\u5236\u3002<\/li>\n<li>\u903b\u8f91\u590d\u6742\u5ea6\u8fdc\u9ad8\u4e8e\u5176\u4ed6\u7d22\u5f15\uff0c\u4ec5\u9002\u5408\u5173\u952e\u8bcd\u68c0\u7d22\uff0c\u5355\u503c\u7cbe\u786e\u67e5\u8be2\u6548\u7387\u8fdc\u4f4e\u4e8e B + \u6811\u7ed3\u6784\u7684\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u5168\u6587\u68c0\u7d22\u9700\u6c42\uff08\u5982\u535a\u5ba2\u7cfb\u7edf\u7684\u6587\u7ae0\u5173\u952e\u8bcd\u641c\u7d22\uff09\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>7. \u7d22\u5f15\u6548\u7387\u6392\u5e8f<\/h2>\n<p>\u8fd9\u4e9b\u7d22\u5f15\u7c7b\u578b\uff0c\u6309\u7167\u67e5\u8be2\u901f\u5ea6\u548c\u6548\u7387\uff0c\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f<\/p>\n<p>\u57fa\u4e8eInnoDB\u5f15\u64ce\u3001\u4f46\u662f\u7cbe\u786e\u67e5\u8be2\u573a\u666f\uff1a<br \/>\n\u67e5\u8be2\u6548\u7387\u4ece\u9ad8\u5230\u4f4e\u6392\u5e8f\uff1a\u4e3b\u952e\u7d22\u5f15 &gt; \u552f\u4e00\u7d22\u5f15 &gt; \u666e\u901a\u7d22\u5f15 &gt; \u8054\u5408\u7d22\u5f15\uff08\u547d\u4e2d\u6700\u5de6\u524d\u7f00 + \u8986\u76d6\u7d22\u5f15\uff09&gt; \u524d\u7f00\u7d22\u5f15 &gt; \u5168\u6587\u7d22\u5f15<br \/>\n\u4f46\u662f\u5e76\u975e\u7edd\u5bf9\uff0c\u4f9d\u65e7\u9700\u8981\u7ed3\u5408\u4f7f\u7528\u573a\u666f\u8fdb\u884c\u5224\u65ad\u3002<br \/>\n\u6392\u5e8f\u524d\u63d0\uff1a\u9ed8\u8ba4\u662f\u300c\u5355\u503c\u7cbe\u786e\u67e5\u8be2\u300d\uff0c\u82e5\u4e3a\u300c\u8303\u56f4\u67e5\u8be2\u300d\uff0c\u4e3b\u952e\u7d22\u5f15\u548c\u552f\u4e00\u7d22\u5f15\u7684\u5dee\u8ddd\u4f1a\u7f29\u5c0f\uff08\u8303\u56f4\u67e5\u8be2\u9700\u626b\u63cf\u591a\u4e2a\u8282\u70b9\uff09\u3002<\/p>\n<div style=\"height:1.5em\"><\/div>\n<h1>04. \u805a\u7c07\u7d22\u5f15\u4e0e\u975e\u805a\u7c07\u7d22\u5f15<\/h1>\n<p>\u7b54\uff1a<br \/>\n\u805a\u7c07\u7d22\u5f15\u4e0e\u975e\u805a\u7c07\u7d22\u5f15\u7684\u6838\u5fc3\u533a\u522b\u662f\uff1a<strong>\u6570\u636e\u5b58\u50a8\u4f4d\u7f6e<\/strong>\u3002<br \/>\n\u805a\u7c07\u7d22\u5f15\uff0c\u53c8\u53eb\u505a\u805a\u96c6\u7d22\u5f15\uff0c\u5b83\u7684\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u6574\u884c\u6570\u636e\uff1b<br \/>\n\u975e\u805a\u7c07\u7d22\u5f15\u7684\u53f6\u5b50\u8282\u70b9\u4ec5\u5b58\u50a8 \u201c\u7d22\u5f15\u952e + \u4e3b\u952e\u503c\u201d\uff0c\u9700\u901a\u8fc7\u4e3b\u952e\u56de\u8868\u67e5\u8be2\u5b8c\u6574\u6570\u636e\uff08\u8986\u76d6\u7d22\u5f15\u9664\u5916\uff09\u3002<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114043240817.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114043240817.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1.5em\"><\/div>\n<h1>05. \u6700\u5de6\u524d\u7f00\u539f\u5219<\/h1>\n<p>\u7b54\uff1a<br \/>\n<strong>\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1a<\/strong><br \/>\n\u67e5\u8be2\u6761\u4ef6\u5fc5\u987b\u4ece\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u5b57\u6bb5\u5f00\u59cb\u5339\u914d\uff0c\u4e14\u8fde\u7eed\u5339\u914d\uff0c\u624d\u80fd\u7528\u5230\u7d22\u5f15\u7684\u5bf9\u5e94\u90e8\u5206\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u8054\u5408\u7d22\u5f15(name, age, score)<\/p>\n<ul>\n<li>\n<p>\u80fd\u547d\u4e2d\u7d22\u5f15\u7684\u60c5\u51b5\uff08\u4ece\u5de6\u5230\u53f3\u8fde\u7eed\u5339\u914d\uff09\uff1a<\/p>\n<ul>\n<li><code>where name = &#039;\u5f20\u4e09&#039;<\/code>\uff08\u53ea\u7528name\uff0c\u547d\u4e2d\u7d22\u5f15\u7684name\u90e8\u5206\uff09\uff1b<\/li>\n<li><code>where name = &#039;\u5f20\u4e09&#039; and age = 20<\/code>\uff08\u7528name+age\uff0c\u547d\u4e2d\u7d22\u5f15\u7684name+age\u90e8\u5206\uff09\uff1b<\/li>\n<li><code>where name = &#039;\u5f20\u4e09&#039; and age = 20 and score &gt; 90<\/code>\uff08\u7528name+age+score\uff0c\u547d\u4e2d\u7d22\u5f15\u7684\u5168\u90e8\u4e09\u90e8\u5206\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e0d\u80fd\u547d\u4e2d\u7d22\u5f15\u7684\u60c5\u51b5\uff08\u8df3\u8fc7\u5de6\u5b57\u6bb5\u6216\u4e0d\u8fde\u7eed\uff09\uff1a<\/p>\n<ul>\n<li><code>where age = 20<\/code>\uff08\u8df3\u8fc7\u6700\u5de6\u7684name\uff0c\u5b8c\u5168\u65e0\u6cd5\u547d\u4e2d\uff09\uff1b<\/li>\n<li><code>where name = &#039;\u5f20\u4e09&#039; and score &gt; 90<\/code>\uff08\u8df3\u8fc7\u4e2d\u95f4\u7684age\uff0c\u53ea\u80fd\u547d\u4e2dname\u90e8\u5206\uff0cscore\u65e0\u6cd5\u5229\u7528\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<p><strong>\u8054\u5408\u7d22\u5f15\u542b\u8303\u56f4\u67e5\u8be2\u6216\u6a21\u7cca\u67e5\u8be2\u80fd\u5426\u547d\u4e2d\u7d22\u5f15\uff1f<\/strong><br \/>\n\u5bf9\u4e8e\u8303\u56f4\u67e5\u8be2\uff08\u5927\u4e8e\u3001\u5c0f\u4e8e\u7b49\uff09\u4f1a\u5bfc\u81f4\u201c\u5f53\u524d\u5b57\u6bb5\u53f3\u4fa7\u7684\u7d22\u5f15\u5b57\u6bb5\u5931\u6548\u201d\uff0c\u4f46\u5de6\u4fa7\u5df2\u5339\u914d\u7684\u5b57\u6bb5\u4ecd\u80fd\u547d\u4e2d\uff0c\uff08\u5f53\u524d\u5b57\u6bb5\u4e5f\u80fd\u547d\u4e2d\uff09\uff1b<br \/>\n\u5bf9\u4e8e\u6a21\u7cca\u67e5\u8be2\uff0c\u5982\u679c\u662f\u524d\u7f00\u6a21\u7cca\uff08\u4f8b\u5982\uff1a&quot;\u5feb\u4e50\u5927\u672c\u8425&quot;\uff0c<code>like &#039;\u5feb\u4e50%&#039;<\/code>\uff09\uff0c\u80fd\u547d\u4e2d\u5f53\u524d\u5b57\u6bb5\u53ca\u5de6\u4fa7\u7684\u7d22\u5f15\uff0c\u4f46\u5f53\u524d\u5b57\u6bb5\u53f3\u4fa7\u7684\u7d22\u5f15\u5931\u6548\uff1b\u5982\u679c\u662f\u540e\u7f00\/\u5168\u6a21\u7cca\u67e5\u8be2\uff08\u4f8b\u5982\uff1a<code>%\u5927\u672c\u8425<\/code>\u3001<code>%\u4e50\u5927%<\/code>\uff09\uff0c\u4f1a\u5bfc\u81f4\u5f53\u524d\u5b57\u6bb5\u53ca\u53f3\u4fa7\u5b57\u6bb5\u7684\u7d22\u5f15\u90fd\u5931\u6548\uff0c\u4ec5\u5f53\u524d\u5b57\u6bb5\u5de6\u4fa7\u5df2\u5339\u914d\u7d22\u5f15\u6709\u6548\u3002<\/p>\n<div style=\"height:1.5em\"><\/div>\n<h1>06. \u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c<\/h1>\n<p>\u7b54\uff1a<br \/>\nMySQL\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u672c\u8d28\u662f\u201c\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u7684\u4ee3\u4ef7\uff0c\u4e3b\u8981\u96c6\u4e2d\u5728\u201c\u5199\u5165\u6027\u80fd\u635f\u8017\u201d\u3001\u201c\u5b58\u50a8\u7a7a\u95f4\u5360\u7528\u201d\u3001\u201c\u7d22\u5f15\u788e\u7247\u7ef4\u62a4\u201d\u3002\u7d22\u5f15\u6570\u91cf\u8d8a\u591a\uff0c\u7ed3\u6784\u8d8a\u590d\u6742\uff0c\u5219\u7ef4\u62a4\u6210\u672c\u8d8a\u9ad8\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>1. \u5199\u5165\u64cd\u4f5c\uff08\u63d2\u5165\/\u66f4\u65b0\/\u5220\u9664\uff09\u7684\u6027\u80fd\u635f\u8017<\/h2>\n<ul>\n<li>\u5199\u5165\u6570\u636e\u65f6\uff0c\u4e0d\u4ec5\u8981\u4fee\u6539\u8868\u6570\u636e\uff0c\u8fd8\u9700\u540c\u6b65\u7ef4\u62a4\u7d22\u5f15\u7684 B + \u6811\u7ed3\u6784\u3002<\/li>\n<li>\u63d2\u5165\uff1a\u53ef\u80fd\u89e6\u53d1 B + \u6811\u8282\u70b9\u5206\u88c2\uff08\u5982\u8282\u70b9\u6ee1\u65f6\uff09\uff0c\u9700\u91cd\u65b0\u7ec4\u7ec7\u7d22\u5f15\u6392\u5e8f\uff1b\u82e5\u4e3a\u552f\u4e00\u7d22\u5f15\uff0c\u8fd8\u9700\u989d\u5916\u6821\u9a8c\u552f\u4e00\u6027\uff08\u626b\u63cf\u7d22\u5f15\u786e\u8ba4\u65e0\u91cd\u590d\uff09\u3002<\/li>\n<li>\u66f4\u65b0\uff1a\u82e5\u66f4\u65b0\u7684\u662f\u7d22\u5f15\u5217\uff0c\u9700\u5148\u5220\u9664\u65e7\u7d22\u5f15\u6761\u76ee\uff0c\u518d\u63d2\u5165\u65b0\u7d22\u5f15\u6761\u76ee\uff0c\u76f8\u5f53\u4e8e\u4e24\u6b21\u7d22\u5f15\u64cd\u4f5c\uff1b\u975e\u7d22\u5f15\u5217\u66f4\u65b0\u4e0d\u5f71\u54cd\u7d22\u5f15\uff0c\u4f46\u4ecd\u9700\u7ef4\u62a4\u805a\u7c07\u7d22\u5f15\u7684\u7269\u7406\u987a\u5e8f\uff08InnoDB\uff09\u3002<\/li>\n<li>\u5220\u9664\uff1a\u4e0d\u4f1a\u7acb\u5373\u91ca\u653e\u7d22\u5f15\u7a7a\u95f4\uff0c\u4ec5\u6807\u8bb0\u4e3a \u201c\u5220\u9664\u201d\uff0c\u540e\u7eed\u9700\u901a\u8fc7\u788e\u7247\u6574\u7406\u56de\u6536\uff0c\u4e14\u53ef\u80fd\u89e6\u53d1 B + \u6811\u8282\u70b9\u5408\u5e76\uff08\u5982\u8282\u70b9\u6570\u636e\u8fc7\u5c11\u65f6\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>2. \u5b58\u50a8\u7a7a\u95f4\u7684\u989d\u5916\u5360\u7528<\/h2>\n<ul>\n<li>\u7d22\u5f15\u9700\u72ec\u7acb\u5b58\u50a8 B + \u6811\u7ed3\u6784\uff0c\u4e00\u5f20\u8868\u7684\u7d22\u5f15\u8d8a\u591a\u3001\u5b57\u6bb5\u8d8a\u957f\uff0c\u5360\u7528\u7684\u78c1\u76d8\u7a7a\u95f4\u8d8a\u5927\u3002<\/li>\n<li>\u793a\u4f8b\uff1a\u5927\u8868\u7684\u8054\u5408\u7d22\u5f15\u3001\u957f\u5b57\u7b26\u4e32\u7684\u524d\u7f00\u7d22\u5f15\uff0c\u53ef\u80fd\u5360\u7528\u4e0e\u6570\u636e\u672c\u8eab\u76f8\u5f53\u7684\u5b58\u50a8\u7a7a\u95f4\uff1b\u805a\u7c07\u7d22\u5f15\u867d\u65e0\u9700\u989d\u5916\u5b58\u6570\u636e\uff0c\u4f46\u975e\u805a\u7c07\u7d22\u5f15\uff08\u5982\u552f\u4e00\u3001\u666e\u901a\u7d22\u5f15\uff09\u9700\u5b58\u50a8\u4e3b\u952e\u503c\uff0c\u53e0\u52a0\u540e\u7a7a\u95f4\u5f00\u9500\u663e\u8457\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>3. \u7d22\u5f15\u788e\u7247\u4e0e\u5b9a\u671f\u7ef4\u62a4\u5f00\u9500<\/h2>\n<ul>\n<li>\u9891\u7e41\u63d2\u5165 \/ \u5220\u9664\u540e\uff0cB + \u6811\u4f1a\u4ea7\u751f \u201c\u7a7a\u6d1e\u201d\uff08\u5df2\u5220\u9664\u4f46\u672a\u91ca\u653e\u7684\u7a7a\u95f4\uff09\uff0c\u5bfc\u81f4\u7d22\u5f15\u788e\u7247\u589e\u591a\u3002<\/li>\n<li>\u788e\u7247\u4f1a\u964d\u4f4e\u67e5\u8be2\u6548\u7387\uff08\u78c1\u76d8 IO \u589e\u591a\uff09\uff0c\u9700\u5b9a\u671f\u6267\u884c\u7ef4\u62a4\u64cd\u4f5c\uff08\u5982<code>OPTIMIZE TABLE<\/code>\u3001\u91cd\u5efa\u7d22\u5f15\uff09\uff0c\u8fd9\u4e9b\u64cd\u4f5c\u4f1a\u9501\u8868\u6216\u5360\u7528\u5927\u91cf IO \u8d44\u6e90\uff0c\u5f71\u54cd\u4e1a\u52a1\u9ad8\u5cf0\u671f\u6027\u80fd\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>4. \u4f18\u5316\u5668\u7684\u51b3\u7b56\u8d1f\u62c5<\/h2>\n<ul>\n<li>\u8868\u4e2d\u7d22\u5f15\u8fc7\u591a\u65f6\uff0cMySQL \u4f18\u5316\u5668\u9700\u904d\u5386\u6240\u6709\u53ef\u80fd\u7684\u7d22\u5f15\u7ec4\u5408\uff0c\u8bc4\u4f30\u6700\u4f18\u67e5\u8be2\u8ba1\u5212\uff0c\u5bfc\u81f4\u67e5\u8be2\u89e3\u6790\u65f6\u95f4\u53d8\u957f\uff08\u5c24\u5176\u590d\u6742\u67e5\u8be2\u573a\u666f\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>5. \u5982\u4f55\u4f18\u5316\u7ef4\u62a4\u7b56\u7565<\/h2>\n<ul>\n<li>\u4e0d\u540c\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u5dee\u5f02\uff1a\u8054\u5408\u7d22\u5f15 &gt; \u666e\u901a\u7d22\u5f15 &gt; \u552f\u4e00\u7d22\u5f15 &gt; \u4e3b\u952e\u7d22\u5f15\uff08\u7ed3\u6784\u8d8a\u590d\u6742\uff0c\u7ef4\u62a4\u65f6 B + \u6811\u8c03\u6574\u903b\u8f91\u8d8a\u7e41\u7410\uff09\uff1b\u524d\u7f00\u7d22\u5f15\u3001\u5168\u6587\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u9ad8\u4e8e\u5355\u5b57\u6bb5\u7d22\u5f15\uff08\u524d\u8005\u9700\u5904\u7406\u90e8\u5206\u5b57\u7b26\uff0c\u540e\u8005\u9700\u7ef4\u62a4\u5206\u8bcd\u5012\u6392\u7d22\u5f15\uff09\u3002<\/li>\n<li>\u5e73\u8861\u7ef4\u62a4\u6210\u672c\u7684\u6838\u5fc3\u539f\u5219\uff1a<strong>\u907f\u514d \u201c\u8fc7\u5ea6\u7d22\u5f15\u201d<\/strong>\uff0c\u4ec5\u4e3a\u9ad8\u9891\u67e5\u8be2\u5b57\u6bb5\u521b\u5efa\u7d22\u5f15\uff1b\u4f18\u5148\u9009\u62e9\u7a84\u7d22\u5f15\uff08\u77ed\u5b57\u6bb5\u3001\u5c11\u5b57\u6bb5\u7ec4\u5408\uff09\uff0c\u51cf\u5c11\u5b58\u50a8\u7a7a\u95f4\u548c\u7ef4\u62a4\u5f00\u9500\uff1b\u5b9a\u671f\u76d1\u63a7\u7d22\u5f15\u4f7f\u7528\u7387\uff0c\u5220\u9664\u65e0\u6548\u7d22\u5f15\uff08\u5982\u957f\u671f\u672a\u88ab\u4f7f\u7528\u7684\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1.5em\"><\/div>\n<h1>07. \u56de\u8868\u67e5\u8be2\u4e0e\u7d22\u5f15\u8986\u76d6<\/h1>\n<p>\u7b54\uff1a<br \/>\n\u56de\u8868\u67e5\u8be2\u662f \u201c\u975e\u805a\u7c07\u7d22\u5f15\u67e5\u8be2\u540e\u9700\u4e8c\u6b21\u67e5\u805a\u7c07\u7d22\u5f15\u62ff\u5b8c\u6574\u6570\u636e\u201d \u7684\u8fc7\u7a0b\uff1b<br \/>\n\u7d22\u5f15\u8986\u76d6\u662f \u201c\u67e5\u8be2\u5b57\u6bb5\uff08\u5373\u6240\u9700\u7684\u8fd4\u56de\u5b57\u6bb5\uff09\u5168\u5728\u7d22\u5f15\u4e2d\uff0c\u65e0\u9700\u4e8c\u6b21\u67e5\u8be2\u201d \u7684\u4f18\u5316\u573a\u666f\u3002<br \/>\n\u4e8c\u8005\u662f \u201c\u9700\u56de\u8868\u201d \u4e0e \u201c\u514d\u56de\u8868\u201d \u7684\u5bf9\u7acb\u5173\u7cfb\uff0c\u76f4\u63a5\u5f71\u54cd\u67e5\u8be2\u6548\u7387\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>1. \u56de\u8868\u67e5\u8be2\uff08Bookmark Lookup\uff09<\/h2>\n<p><strong>1. \u5b9a\u4e49<\/strong><br \/>\n\u5f53\u4f7f\u7528\u975e\u805a\u7c07\u7d22\u5f15\uff08\u5982\u552f\u4e00\u7d22\u5f15\u3001\u666e\u901a\u7d22\u5f15\u3001\u8054\u5408\u7d22\u5f15\uff09\u67e5\u8be2\u65f6\uff0c\u82e5\u67e5\u8be2\u5b57\u6bb5\u672a\u5b8c\u5168\u5305\u542b\u5728\u8be5\u7d22\u5f15\u4e2d\uff0c\u9700\u5148\u901a\u8fc7\u975e\u805a\u7c07\u7d22\u5f15\u627e\u5230 \u201c\u7d22\u5f15\u952e + \u4e3b\u952e\u503c\u201d\uff0c\u518d\u7528\u4e3b\u952e\u503c\u67e5\u8be2\u805a\u7c07\u7d22\u5f15\uff08\u4e3b\u952e\u7d22\u5f15\uff09 \uff0c\u624d\u80fd\u83b7\u53d6\u6574\u884c\u5b8c\u6574\u6570\u636e\uff0c\u8fd9\u4e2a \u201c\u4e8c\u6b21\u67e5\u8be2\u201d \u7684\u8fc7\u7a0b\u5c31\u662f\u56de\u8868\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>2. \u6838\u5fc3\u903b\u8f91\uff08\u7ed3\u5408 InnoDB \u5f15\u64ce\uff09<\/strong><\/p>\n<ul>\n<li>\u975e\u805a\u7c07\u7d22\u5f15\u7684\u53f6\u5b50\u8282\u70b9\u4ec5\u5b58\u50a8 \u201c\u7d22\u5f15\u952e + \u4e3b\u952e\u503c\u201d\uff0c\u4e0d\u5b58\u5b8c\u6574\u884c\u6570\u636e\u3002<\/li>\n<li>\u82e5\u67e5\u8be2\u9700\u8981\u975e\u7d22\u5f15\u5b57\u6bb5\uff08\u5982\u7528\u552f\u4e00\u7d22\u5f15<code>email<\/code>\u67e5user\u8868\u7684\u4e3b\u952e<code>id<\/code>\u548c\u975e\u7d22\u5f15\u5b57\u6bb5<code>name<\/code>\uff09\uff0c\u5fc5\u987b\u901a\u8fc7\u4e3b\u952e\u503c\u56de\u805a\u7c07\u7d22\u5f15 \u201c\u515c\u5e95\u201d\uff0c\u624d\u80fd\u62ff\u5230name\u3002<\/li>\n<\/ul>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>3. \u793a\u4f8b<\/strong><\/p>\n<pre><code class=\"language-sql\">-- \u8868\u7ed3\u6784\uff1aid\uff08\u4e3b\u952e\uff09\u3001email\uff08\u552f\u4e00\u7d22\u5f15\uff09\u3001name\uff08\u975e\u7d22\u5f15\u5b57\u6bb5\uff09\nselect id, name from user where email = &#039;a@test.com&#039;;<\/code><\/pre>\n<p>\u7b2c\u4e00\u6b65\uff1a\u901a\u8fc7\u552f\u4e00\u7d22\u5f15<code>email<\/code>\uff08\u975e\u805a\u7c07\uff09\u627e\u5230\u4e3b\u952e<code>id=100<\/code>\uff1b<br \/>\n\u7b2c\u4e8c\u6b65\uff1a\u7528<code>id=100<\/code>\u67e5\u8be2\u805a\u7c07\u7d22\u5f15\uff0c\u62ff\u5230<code>name<\/code>\u5b57\u6bb5\uff0c\u5b8c\u6210\u67e5\u8be2\uff1b<br \/>\n\u8fd9\u4e24\u6b65\u5171\u540c\u6784\u6210\u56de\u8868\u67e5\u8be2\uff0c\u989d\u5916\u589e\u52a0\u4e86\u4e00\u6b21\u805a\u7c07\u7d22\u5f15\u67e5\u8be2\u7684 IO \u5f00\u9500\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>2. \u7d22\u5f15\u8986\u76d6\uff08Covering Index\uff09<\/h2>\n<p><strong>1. \u5b9a\u4e49<\/strong><br \/>\n\u5f53\u67e5\u8be2\u7684<strong>\u6240\u6709\u5b57\u6bb5<\/strong>\uff08\u5305\u62ec\u7b5b\u9009\u6761\u4ef6\u3001\u8fd4\u56de\u5b57\u6bb5\uff09\u90fd\u5305\u542b\u5728\u67d0<strong>\u4e00\u4e2a<\/strong>\u7d22\u5f15\u4e2d\u65f6\uff0c\u5219\u65e0\u9700\u56de\u8868\uff0c\u4ec5\u901a\u8fc7\u8be5\u7d22\u5f15\u5c31\u80fd\u83b7\u53d6\u6240\u6709\u9700\u8981\u7684\u6570\u636e\uff0c\u8fd9\u4e2a\u7d22\u5f15\u5c31\u662f \u201c<strong>\u8986\u76d6\u7d22\u5f15<\/strong>\u201d\uff0c\u4e5f\u53eb\u7d27\u51d1\u7d22\u5f15\uff0c\u5bf9\u5e94\u7684\u67e5\u8be2\u5c31\u662f<strong>\u8986\u76d6\u7d22\u5f15\u67e5\u8be2<\/strong>\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>2. \u6838\u5fc3\u4f18\u52bf<\/strong><br \/>\n\u907f\u514d\u56de\u8868\uff0c\u51cf\u5c11\u4e00\u6b21\u78c1\u76d8 IO\uff08\u805a\u7c07\u7d22\u5f15\u67e5\u8be2\uff09\uff0c\u5927\u5e45\u63d0\u5347\u6548\u7387\uff1b<br \/>\n\u7d22\u5f15\u6570\u636e\u91cf\u8fdc\u5c0f\u4e8e\u5168\u8868\u6570\u636e\uff0c\u67e5\u8be2\u65f6\u626b\u63cf\u7684\u6570\u636e\u91cf\u66f4\u5c11\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>3. \u793a\u4f8b<\/strong><\/p>\n<pre><code class=\"language-sql\">-- \u8054\u5408\u7d22\u5f15\uff1aidx_email_name(email, name)\uff08\u5305\u542bemail\u548cname\u5b57\u6bb5\uff09\nselect email, name from user where email = &#039;a@test.com&#039;;<\/code><\/pre>\n<p>\u67e5\u8be2\u7684\u7b5b\u9009\u5b57\u6bb5<code>email<\/code>\u3001\u8fd4\u56de\u5b57\u6bb5<code>name<\/code>\u5747\u5728\u8054\u5408\u7d22\u5f15\u4e2d\uff1b<br \/>\n<strong>\u76f4\u63a5\u901a\u8fc7\u8be5\u8054\u5408\u7d22\u5f15\u5c31\u80fd\u62ff\u5230\u6240\u6709\u9700\u8981\u7684\u6570\u636e\uff08\u8fd4\u56de\u5b57\u6bb5\uff09<\/strong>\uff0c\u65e0\u9700\u56de\u805a\u7c07\u7d22\u5f15\uff0c\u5b9e\u73b0 \u201c\u4e00\u6b21\u67e5\u8be2\u5b8c\u6210\u201d\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>3. \u8865\u5145\u9879<\/h2>\n<p><strong>\u89e6\u53d1\u6761\u4ef6\u5bf9\u6bd4\uff1a<\/strong><\/p>\n<ul>\n<li>\u56de\u8868\uff1a\u975e\u805a\u7c07\u7d22\u5f15 + \u67e5\u8be2\u5b57\u6bb5\u8d85\u51fa\u7d22\u5f15\u8303\u56f4\uff1b<\/li>\n<li>\u7d22\u5f15\u8986\u76d6\uff1a\u67e5\u8be2\u5b57\u6bb5\uff08\u7b5b\u9009 + \u8fd4\u56de\uff09\u5b8c\u5168\u5339\u914d\u67d0\u4e00\u7d22\u5f15\uff08\u5355\u5b57\u6bb5\u7d22\u5f15\u6216\u8054\u5408\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>\u5b9e\u6218\u4ef7\u503c\uff1a<\/strong><br \/>\n\u7d22\u5f15\u8986\u76d6\u662f\u4f18\u5316\u56de\u8868\u5f00\u9500\u7684\u6838\u5fc3\u624b\u6bb5\uff0c\u8bbe\u8ba1\u7d22\u5f15\u65f6\u53ef\u5c06\u9ad8\u9891\u67e5\u8be2\u5b57\u6bb5\u52a0\u5165\u8054\u5408\u7d22\u5f15\uff08\u5982<code>idx_userid_status(user_id, status)<\/code>\uff09\uff0c\u907f\u514d\u56de\u8868\uff1b<br \/>\n\u805a\u7c07\u7d22\u5f15\u67e5\u8be2\u5929\u7136\u652f\u6301 \u201c\u7d22\u5f15\u8986\u76d6\u201d\uff08\u53f6\u5b50\u8282\u70b9\u5b58\u5b8c\u6574\u6570\u636e\uff09\uff0c\u65e0\u9700\u56de\u8868\uff0c\u8fd9\u4e5f\u662f\u5176\u67e5\u8be2\u6548\u7387\u6700\u9ad8\u7684\u539f\u56e0\u4e4b\u4e00\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>\u6613\u6df7\u70b9\uff1a<\/strong><br \/>\n\u7d22\u5f15\u8986\u76d6\u7684\u5173\u952e\u662f \u201c\u5b57\u6bb5\u5168\u5305\u542b\u201d\uff0c\u4e0e\u7d22\u5f15\u7c7b\u578b\u65e0\u5173\uff08\u5355\u5b57\u6bb5\u7d22\u5f15\u3001\u8054\u5408\u7d22\u5f15\u5747\u53ef\u4f5c\u4e3a\u8986\u76d6\u7d22\u5f15\uff09\uff1b<br \/>\n\u524d\u7f00\u7d22\u5f15\u65e0\u6cd5\u5b9e\u73b0\u7d22\u5f15\u8986\u76d6\uff08\u4ec5\u5b58\u5b57\u6bb5\u524d N \u4e2a\u5b57\u7b26\uff0c\u65e0\u6cd5\u8fd4\u56de\u5b8c\u6574\u5b57\u6bb5\u503c\uff09\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>4. \u4e0d\u80fd\u89e6\u53d1\u7d22\u5f15\u8986\u76d6\u793a\u4f8b<\/h2>\n<pre><code class=\"language-sql\">SELECT id, name, email FROM user WHERE email = &#039;xxx@qq.com&#039;;\n-- \u5728user\u8868\u4e2d\uff0cid\u662f\u4e3b\u952e\uff0cemail\u662f\u552f\u4e00\u7d22\u5f15\uff0cname\u662f\u666e\u901a\u7d22\u5f15<\/code><\/pre>\n<p>\u7ed3\u8bba\uff1a\u4e0d\u80fd\u89e6\u53d1\u7d22\u5f15\u8986\u76d6\u3002<br \/>\n\u7d22\u5f15\u8986\u76d6\u7684\u6838\u5fc3\u8981\u6c42\u662f<strong>\u67e5\u8be2\u7684\u6240\u6709\u5b57\u6bb5\uff08\u7b5b\u9009\u6761\u4ef6 + \u8fd4\u56de\u5b57\u6bb5\uff09\u5fc5\u987b\u5b8c\u5168\u5305\u542b\u5728\u540c\u4e00\u4e2a\u7d22\u5f15\u4e2d<\/strong>\uff0c\u8de8\u7d22\u5f15\u65e0\u6cd5\u5b9e\u73b0\u8986\u76d6\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<p><strong>\u5982\u4f55\u4fee\u6539\u624d\u80fd\u89e6\u53d1\u7d22\u5f15\u8986\u76d6\uff1f<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u8054\u5408\u552f\u4e00\u7d22\u5f15 <code>unique index idx_email_name(email, name)<\/code><\/li>\n<li>\u7b5b\u9009\u5b57\u6bb5<code>email<\/code>\u3001\u8fd4\u56de\u5b57\u6bb5<code>email<\/code>\u3001<code>name<\/code>\u3001<code>id<\/code>\uff08\u4e3b\u952e\u4f1a\u81ea\u52a8\u5305\u542b\u5728\u975e\u805a\u7c07\u7d22\u5f15\u4e2d\uff09\uff0c\u5168\u90e8\u5305\u542b\u5728\u8fd9\u4e2a\u8054\u5408\u7d22\u5f15\u91cc\uff1b<\/li>\n<li>\u67e5\u8be2\u65f6\u65e0\u9700\u56de\u8868\uff0c\u76f4\u63a5\u901a\u8fc7\u8be5\u8054\u5408\u7d22\u5f15\u5c31\u80fd\u83b7\u53d6\u6240\u6709\u9700\u8981\u7684\u6570\u636e\uff0c\u89e6\u53d1\u7d22\u5f15\u8986\u76d6\u3002<\/li>\n<\/ul>\n<div style=\"height:1.5em\"><\/div>\n<h1>08. \u5982\u4f55\u5408\u7406\u4f7f\u7528\u7d22\u5f15\uff1f<\/h1>\n<p>\u4ee5\u4e1a\u52a1\u67e5\u8be2\u4e3a\u5bfc\u5411\uff0c\u5e73\u8861\u67e5\u8be2\u6548\u7387\u4e0e\u7ef4\u62a4\u6210\u672c\uff0c\u907f\u514d \u201c\u8fc7\u5ea6\u7d22\u5f15\u201d \u6216 \u201c\u65e0\u6548\u7d22\u5f15\u201d\u3002<\/p>\n<ol>\n<li>\u4f18\u5148\u4e3a \u201c\u9ad8\u9891\u67e5\u8be2\u5b57\u6bb5\u201d \u5efa\u7d22\u5f15\uff0c\u4f4e\u9891\u67e5\u8be2\u4e0d\u5efa\uff1b<\/li>\n<li>\u8054\u5408\u7d22\u5f15\u9700\u9075\u5faa \u201c\u6700\u5de6\u524d\u7f00 + \u533a\u5206\u5ea6\u4f18\u5148\uff08\u533a\u5206\u5ea6\u9ad8\uff0c\u91cd\u590d\u503c\u5c11\uff09\u201d \u539f\u5219\uff1b<\/li>\n<li>\u907f\u514d\u7d22\u5f15\u5931\u6548\u573a\u666f\uff0c\u786e\u4fdd\u7d22\u5f15\u88ab\u6b63\u786e\u4f7f\u7528\uff1b<\/li>\n<li>\u5229\u7528 \u201c\u7d22\u5f15\u8986\u76d6\u201d \u51cf\u5c11\u56de\u8868\uff0c\u63d0\u5347\u6548\u7387\uff1b<\/li>\n<li>\u6839\u636e\u5b57\u6bb5\u7279\u6027\u9009\u62e9\u5408\u9002\u7684\u7d22\u5f15\u7c7b\u578b\uff1b<\/li>\n<li>\u5b9a\u671f\u7ef4\u62a4\u7d22\u5f15\uff0c\u6e05\u7406\u65e0\u6548\u7d22\u5f15\u3002<\/li>\n<\/ol>\n<p>\u5408\u7406\u4f7f\u7528\u7d22\u5f15\u7684\u6838\u5fc3\u662f \u201c\u6309\u9700\u8bbe\u8ba1\u3001\u907f\u514d\u5931\u6548\u3001\u6ce8\u91cd\u7ef4\u62a4\u201d\u3002<br \/>\n\u201c\u7d22\u5f15\u4e0d\u662f\u8d8a\u591a\u8d8a\u597d\uff0c\u800c\u662f\u8d8a\u5408\u9002\u8d8a\u597d\u201d\u3002<\/p>\n<div style=\"height:1.5em\"><\/div>\n<h1>09. \u7d22\u5f15\u5931\u6548\u573a\u666f<\/h1>\n<p>MySQL \u7d22\u5f15\u5931\u6548\u7684\u672c\u8d28\u662f\uff1a\u67e5\u8be2\u6761\u4ef6\u7834\u574f\u4e86\u7d22\u5f15\u7684\u6709\u5e8f\u6027\u6216\u5339\u914d\u89c4\u5219\uff1b<br \/>\n\u5e38\u89c1\u573a\u666f\u96c6\u4e2d\u5728\uff1a\u201c\u5b57\u6bb5\u64cd\u4f5c\u201d\u3001\u201c\u7c7b\u578b\u4e0d\u5339\u914d\u201d\u3001\u201c\u67e5\u8be2\u8bed\u6cd5\u4e0d\u5f53\u201d\u4e09\u7c7b\uff1b<br \/>\n\u907f\u514d\u6838\u5fc3\u662f\uff1a\u8ba9\u67e5\u8be2\u6761\u4ef6\u8d34\u5408\u7d22\u5f15\u8bbe\u8ba1\u89c4\u5219\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5e38\u89c1\u7d22\u5f15\u5931\u6548\u573a\u666f + \u907f\u514d\u65b9\u6cd5\uff1a<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>1. \u5bf9\u7d22\u5f15\u5b57\u6bb5\u505a\u51fd\u6570 \/ \u8fd0\u7b97\u64cd\u4f5c<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong>\u67e5\u8be2\u65f6\u5bf9\u7d22\u5f15\u5b57\u6bb5\u7528\u51fd\u6570\uff08\u5982<code>substr<\/code>\u3001<code>date_format<\/code>\uff09\u6216\u6570\u5b66\u8fd0\u7b97\uff0c\u4f1a\u5bfc\u81f4 MySQL \u65e0\u6cd5\u5229\u7528\u7d22\u5f15\u7684\u6709\u5e8f\u6027\uff0c\u53ea\u80fd\u5168\u8868\u626b\u63cf\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where substr(name, 1, 3) = &#039;\u5f20\u4e09&#039;<\/code>\uff08name\u662f\u666e\u901a\u7d22\u5f15\uff09\u3001<code>where age + 1 = 20<\/code>\uff08age\u662f\u666e\u901a\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u5c06\u51fd\u6570 \/ \u8fd0\u7b97\u79fb\u5230\u7b49\u53f7\u53f3\u4fa7\uff0c\u6216\u63d0\u524d\u8ba1\u7b97\u7ed3\u679c\u3002<\/p>\n<ul>\n<li>\u4f18\u5316\u540e\uff1a<code>where name like &#039;\u5f20\u4e09%&#039;<\/code>\u3001<code>where age = 19<\/code>\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>2. \u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong>\u67e5\u8be2\u6761\u4ef6\u4e2d\u5b57\u6bb5\u7c7b\u578b\u4e0e\u4f20\u5165\u503c\u7c7b\u578b\u4e0d\u5339\u914d\uff0cMySQL \u4f1a\u81ea\u52a8\u505a\u7c7b\u578b\u8f6c\u6362\uff0c\u5bfc\u81f4\u7d22\u5f15\u5931\u6548\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where phone = &#039;13800138000&#039;<\/code>\uff08phone\u662fint\u7c7b\u578b\uff0c\u5b57\u7b26\u4e32\u8f6c\u6570\u5b57\uff09\u3001<code>where id = &#039;100&#039;<\/code>\uff08id\u662fint\uff0c\u5b57\u7b26\u4e32\u8f6c\u6570\u5b57\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u786e\u4fdd\u67e5\u8be2\u503c\u7c7b\u578b\u4e0e\u5b57\u6bb5\u7c7b\u578b\u5b8c\u5168\u4e00\u81f4\u3002<\/li>\n<li>\u4f18\u5316\u540e\uff1a<code>where phone = 13800138000<\/code>\u3001<code>where id = 100<\/code>\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>3. \u6a21\u7cca\u67e5\u8be2\uff08\u975e\u524d\u7f00\u5339\u914d\uff09<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong><code>like<\/code>\u7684\u6a21\u7cca\u67e5\u8be2\u82e5\u4ee5%\u5f00\u5934\uff08\u540e\u7f00\u6a21\u7cca \/ \u5168\u6a21\u7cca\uff09\uff0c\u4f1a\u7834\u574f\u7d22\u5f15\u6709\u5e8f\u6027\uff0c\u5bfc\u81f4\u7d22\u5f15\u5931\u6548\uff1b\u524d\u7f00\u6a21\u7cca\uff08<code>%<\/code>\u5728\u672b\u5c3e\uff09\u53ef\u6b63\u5e38\u4f7f\u7528\u7d22\u5f15\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where name like &#039;%\u5f20\u4e09&#039;<\/code>\uff08\u540e\u7f00\u6a21\u7cca\uff0c\u5931\u6548\uff09\u3001<code>where name like &#039;%\u5f20\u4e09%&#039;<\/code>\uff08\u5168\u6a21\u7cca\uff0c\u5931\u6548\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u4f18\u5148\u7528\u524d\u7f00\u6a21\u7cca\u67e5\u8be2\uff1b\u82e5\u9700\u5168\u6a21\u7cca\uff0c\u6539\u7528\u5168\u6587\u7d22\u5f15\uff08\u5982<code>fulltext index<\/code>\uff09\u6216\u5e94\u7528\u5c42\u5206\u8bcd\u3002<\/li>\n<li>\u4f18\u5316\u540e\uff1a<code>where name like &#039;\u5f20\u4e09%&#039;<\/code>\uff08\u524d\u7f00\u6a21\u7cca\uff09\u3001<code>MATCH(name) AGAINST(&#039;\u5f20\u4e09&#039;)<\/code>\uff08\u5168\u6587\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>4. \u8054\u5408\u7d22\u5f15\u4e0d\u6ee1\u8db3\u6700\u5de6\u524d\u7f00\u539f\u5219<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong>\u8054\u5408\u7d22\u5f15\uff08\u5982<code>(a, b, c)<\/code>\uff09\u9700\u4ece\u5de6\u5230\u53f3\u8fde\u7eed\u5339\u914d\uff0c\u8df3\u8fc7\u5de6\u4fa7\u5b57\u6bb5\u6216\u4e0d\u8fde\u7eed\u5339\u914d\uff0c\u4f1a\u5bfc\u81f4\u7d22\u5f15\u5931\u6548\u6216\u90e8\u5206\u5931\u6548\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where b = 2 and c = 3<\/code>\uff08\u8df3\u8fc7\u6700\u5de6a\uff0c\u5168\u5931\u6548\uff09\u3001<code>where a = 1 and c = 3<\/code>\uff08\u8df3\u8fc7\u4e2d\u95f4b\uff0c\u4ec5a\u90e8\u5206\u751f\u6548\uff0cc\u5931\u6548\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u67e5\u8be2\u6761\u4ef6\u9700\u5305\u542b\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u5b57\u6bb5\uff0c\u4e14\u6309\u7d22\u5f15\u5b57\u6bb5\u987a\u5e8f\u5339\u914d\uff1b\u82e5\u9ad8\u9891\u67e5\u8be2<code>b + c<\/code>\uff0c\u53ef\u5355\u72ec\u5efa\u8054\u5408\u7d22\u5f15<code>(b, c)<\/code>\u3002<\/li>\n<li>\u4f18\u5316\u540e\uff1a<code>where a = 1 and b = 2 and c = 3<\/code>\uff08\u5168\u751f\u6548\uff09\u3001<code>where b = 2 and c = 3<\/code>\uff08\u6539\u7528(<code>b, c<\/code>)\u8054\u5408\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>5. \u8303\u56f4\u67e5\u8be2\u540e\u5b57\u6bb5\u5931\u6548<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong>\u8054\u5408\u7d22\u5f15\u4e2d\uff0c\u67d0\u5b57\u6bb5\u7528<code>&gt;<\/code>\u3001<code>&lt;<\/code>\u3001<code>&gt;=<\/code>\u3001<code>&lt;=<\/code>\u3001<code>between<\/code>\u505a\u8303\u56f4\u67e5\u8be2\u540e\uff0c\u5176\u53f3\u4fa7\u7684\u7d22\u5f15\u5b57\u6bb5\u4f1a\u5931\u6548\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where a = 1 and b &gt; 2 and c = 3<\/code>\uff08\u8054\u5408\u7d22\u5f15<code>(a, b, c)<\/code>\uff0c<code>c<\/code>\u5931\u6548\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u5c06\u8303\u56f4\u67e5\u8be2\u5b57\u6bb5\u653e\u5728\u8054\u5408\u7d22\u5f15\u7684\u6700\u53f3\u4fa7\uff1b\u82e5\u9700\u591a\u5b57\u6bb5\u8303\u56f4\u67e5\u8be2\uff0c\u6539\u7528\u8986\u76d6\u7d22\u5f15\u6216\u62c6\u5206\u67e5\u8be2\u3002<\/li>\n<li>\u4f18\u5316\u540e\uff1a<code>where a = 1 and b &gt; 2<\/code>\uff08\u4ec5\u7528<code>a + b<\/code>\u7d22\u5f15\uff09\u3001\u5efa\u8054\u5408\u7d22\u5f15<code>(a, b, c)<\/code>\u5e76\u786e\u4fdd\u67e5\u8be2\u5b57\u6bb5\u8986\u76d6\uff08<code>select a, b, c\uff0c<\/code>\u907f\u514d\u56de\u8868\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>6. or\u8fde\u63a5\u975e\u7d22\u5f15\u5b57\u6bb5<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong><code>or<\/code>\u8fde\u63a5\u7684\u67e5\u8be2\u6761\u4ef6\u4e2d\uff0c\u82e5\u6709\u4e00\u4e2a\u5b57\u6bb5\u65e0\u7d22\u5f15\uff0c\u4f1a\u5bfc\u81f4\u6574\u4e2a\u67e5\u8be2\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15\uff08MySQL \u4f1a\u9009\u62e9\u5168\u8868\u626b\u63cf\uff09\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where name = &#039;\u5f20\u4e09&#039; or address = &#039;\u5317\u4eac&#039;<\/code>\uff08<code>name<\/code>\u6709\u7d22\u5f15\uff0c<code>address<\/code>\u65e0\u7d22\u5f15\uff0c\u5168\u5931\u6548\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u786e\u4fdd<code>or<\/code>\u8fde\u63a5\u7684\u6240\u6709\u5b57\u6bb5\u90fd\u6709\u7d22\u5f15\uff1b\u6216\u6539\u7528<code>union all<\/code>\u62c6\u5206\u67e5\u8be2\uff08\u9700\u5b57\u6bb5\u4e00\u81f4\uff09\u3002<\/li>\n<li>\u4f18\u5316\u540e\uff1a<code>where name = &#039;\u5f20\u4e09&#039; union all where address = &#039;\u5317\u4eac&#039;<\/code>\uff08<code>address<\/code>\u8865\u5efa\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>7. <code>is not null<\/code>\/<code>not in<\/code>\/<code>not exists<\/code><\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong>\u5bf9\u7d22\u5f15\u5b57\u6bb5\u7528<code>is not null<\/code>\uff08\u90e8\u5206\u573a\u666f\u5931\u6548\uff09\u3001<code>not in<\/code>\u3001<code>not exists<\/code>\uff0c\u4f1a\u7834\u574f\u7d22\u5f15\u7684\u5339\u914d\u903b\u8f91\uff0c\u5bfc\u81f4\u5931\u6548\uff08<code>is null<\/code>\u901a\u5e38\u53ef\u4f7f\u7528\u7d22\u5f15\uff09\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where name is not null<\/code>\uff08<code>name<\/code>\u662f\u666e\u901a\u7d22\u5f15\uff0c\u53ef\u80fd\u5931\u6548\uff09\u3001<code>where id not in (1,2,3)<\/code>\uff08<code>id<\/code>\u662f\u4e3b\u952e\u7d22\u5f15\uff0c\u5927\u6570\u636e\u91cf\u4e0b\u5931\u6548\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong><code>is not null<\/code>\u6539\u7528<code>union<\/code>\u62fc\u63a5\u975e\u7a7a\u7ed3\u679c\uff1b<code>not in<\/code>\u6539\u7528<code>left join ... on ... is null<\/code>\uff1b\u5c0f\u6570\u636e\u91cf<code>not in<\/code>\u53ef\u63a5\u53d7\uff0c\u5927\u6570\u636e\u91cf\u5fc5\u4f18\u5316\u3002<\/li>\n<li>\u4f18\u5316\u540e\uff1a<code>where id in (select id from user) union ...<\/code>\uff08<code>is not null<\/code>\u66ff\u4ee3\uff09\u3001<code>select * from user u left join tmp t on u.id = t.id where t.id is null<\/code>\uff08<code>not in<\/code>\u66ff\u4ee3\uff09\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>8. \u7d22\u5f15\u9009\u62e9\u6027\u5dee\uff08\u5931\u6548\u7b49\u4ef7\u573a\u666f\uff09<\/h2>\n<p><strong>\u5931\u6548\u573a\u666f\uff1a<\/strong>\u7d22\u5f15\u5b57\u6bb5\u91cd\u590d\u7387\u6781\u9ad8\uff08\u5982 \u201c\u6027\u522b\u201d \u5b57\u6bb5\uff0c\u4ec5\u7537 \/ \u5973\uff09\uff0cMySQL \u4f18\u5316\u5668\u4f1a\u5224\u65ad \u201c\u5168\u8868\u626b\u63cf\u6bd4\u7d22\u5f15\u67e5\u8be2\u66f4\u5feb\u201d\uff0c\u4e3b\u52a8\u653e\u5f03\u4f7f\u7528\u7d22\u5f15\u3002<\/p>\n<ul>\n<li>\u793a\u4f8b\uff1a<code>where gender = &#039;\u7537&#039;<\/code>\uff08<code>gender<\/code>\u5efa\u4e86\u7d22\u5f15\uff0c\u4f46\u5168\u8868 80% \u662f\u7537\u6027\uff0c\u7d22\u5f15\u5931\u6548\uff09\u3002<br \/>\n<strong>\u907f\u514d\u65b9\u6cd5\uff1a<\/strong>\u4e0d\u9488\u5bf9\u4f4e\u9009\u62e9\u6027\u5b57\u6bb5\u5efa\u5355\u5b57\u6bb5\u7d22\u5f15\uff1b\u82e5\u9700\u67e5\u8be2\uff0c\u5c06\u5176\u4f5c\u4e3a\u8054\u5408\u7d22\u5f15\u7684\u53f3\u4fa7\u5b57\u6bb5\uff08\u5982<code>(age, gender)<\/code>\uff09\uff0c\u901a\u8fc7\u9ad8\u9009\u62e9\u6027\u5b57\u6bb5\u5148\u8fc7\u6ee4\u3002<\/li>\n<\/ul>\n<div style=\"height:1em\"><\/div>\n<h2>9. \u8865\u5145<\/h2>\n<ol>\n<li>\u9a8c\u8bc1\u7d22\u5f15\u662f\u5426\u5931\u6548\u7684\u6838\u5fc3\u65b9\u6cd5\uff1a<strong>\u7528<code>explain<\/code>\u5206\u6790\u6267\u884c\u8ba1\u5212<\/strong>\uff0c\u82e5key\u5b57\u6bb5\u4e3aNULL\u6216\u975e\u76ee\u6807\u7d22\u5f15\uff0c\u8bf4\u660e\u7d22\u5f15\u5931\u6548\u3002<\/li>\n<li>\u7279\u6b8a\u60c5\u51b5\uff1a<code>Innodb<\/code>\u7684\u805a\u7c07\u7d22\u5f15\uff08\u4e3b\u952e\uff09\u5373\u4f7f\u6709\u4e0a\u8ff0\u573a\u666f\uff08\u5982<code>is not null<\/code>\uff09\uff0c\u901a\u5e38\u4e5f\u4e0d\u4f1a\u5b8c\u5168\u5931\u6548\uff0c\u56e0\u805a\u7c07\u7d22\u5f15\u7684\u7269\u7406\u5b58\u50a8\u7279\u6027\uff0c\u4f18\u5316\u5668\u66f4\u503e\u5411\u4f7f\u7528\u3002<\/li>\n<li>\u907f\u514d\u5931\u6548\u7684\u6838\u5fc3\u539f\u5219\uff1a\u4e0d\u7834\u574f\u7d22\u5f15\u7684\u6709\u5e8f\u6027\u3001\u4e0d\u6539\u53d8\u5b57\u6bb5\u7684\u539f\u59cb\u5f62\u6001\u3001\u8ba9\u67e5\u8be2\u6761\u4ef6\u8d34\u5408\u7d22\u5f15\u8bbe\u8ba1\u3002<\/li>\n<\/ol>\n<div style=\"height:1.5em\"><\/div>\n<h1>10. <code>explain<\/code>\u6267\u884c\u8ba1\u5212\u5206\u6790<\/h1>\n<p><code>explain<\/code> \u662f MySQL \u5206\u6790 SQL \u6267\u884c\u8ba1\u5212\u7684\u6838\u5fc3\u5de5\u5177\u3002<br \/>\n\u901a\u8fc7\u8f93\u51fa 12 \u4e2a\u5b57\u6bb5\uff08\u9762\u8bd5\u91cd\u70b9\u5173\u6ce8 7 \u4e2a\u6838\u5fc3\u5b57\u6bb5\uff09\uff0c\u53ef\u5224\u65ad\u7d22\u5f15\u662f\u5426\u751f\u6548\u3001\u67e5\u8be2\u662f\u5426\u5168\u8868\u626b\u63cf\u3001\u662f\u5426\u5b58\u5728\u6587\u4ef6\u6392\u5e8f \/ \u4e34\u65f6\u8868\u7b49\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>1. explain \u6838\u5fc3\u4f5c\u7528<\/h2>\n<ol>\n<li>\u5224\u65ad SQL \u662f\u5426\u4f7f\u7528\u4e86\u76ee\u6807\u7d22\u5f15\uff08\u907f\u514d\u7d22\u5f15\u5931\u6548\uff09\uff1b<\/li>\n<li>\u8bc6\u522b\u5168\u8868\u626b\u63cf\u3001\u6587\u4ef6\u6392\u5e8f\u3001\u4e34\u65f6\u8868\u7b49\u4f4e\u6548\u64cd\u4f5c\uff1b<\/li>\n<li>\u5206\u6790\u8868\u7684\u8fde\u63a5\u987a\u5e8f\u3001\u67e5\u8be2\u7c7b\u578b\uff08\u7b80\u5355 \/ \u590d\u6742\u67e5\u8be2\uff09\uff1b<\/li>\n<li>\u9884\u4f30\u67e5\u8be2\u626b\u63cf\u7684\u884c\u6570\uff0c\u8bc4\u4f30\u67e5\u8be2\u6548\u7387\u3002<\/li>\n<\/ol>\n<div style=\"height:1em\"><\/div>\n<h2>2. 7 \u4e2a\u6838\u5fc3\u5b57\u6bb5\u89e3\u6790<\/h2>\n<h3>1. <code>type<\/code>\uff1a\u8bbf\u95ee\u7c7b\u578b<\/h3>\n<p>\u6838\u5fc3\uff0c\u5224\u65ad\u67e5\u8be2\u6548\u7387\u7684\u5173\u952e<\/p>\n<p><strong>\u542b\u4e49\uff1a<\/strong>\u8868\u793a MySQL \u5982\u4f55\u8bbf\u95ee\u8868\u4e2d\u7684\u6570\u636e\uff08\u5373\u67e5\u8be2\u65b9\u5f0f\uff09\uff0c\u53d6\u503c\u51b3\u5b9a\u67e5\u8be2\u6548\u7387\uff0c\u4ece\u4f18\u5230\u5dee\u6392\u5e8f\uff1a<br \/>\n<code>system<\/code> &gt; <code>const<\/code> &gt; <code>eq_ref<\/code> &gt; <code>ref<\/code> &gt; <code>range<\/code> &gt; <code>index<\/code> &gt; <code>ALL<\/code><\/p>\n<p><strong>\u5173\u952e\u53d6\u503c\u89e3\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><code>system<\/code>\uff1a\u8868\u4e2d\u53ea\u6709 1 \u884c\u6570\u636e\uff08\u5982\u7cfb\u7edf\u8868\uff09\uff0c\u6548\u7387\u6700\u9ad8\uff08\u7f55\u89c1\uff09\uff1b<\/li>\n<li><code>const<\/code>\uff1a\u901a\u8fc7\u4e3b\u952e \/ \u552f\u4e00\u7d22\u5f15\u67e5\u8be2\uff0c\u5339\u914d 1 \u884c\u6570\u636e\uff08\u5982<code>where id=100<\/code>\uff09\uff0c\u9ad8\u6548\uff1b<\/li>\n<li><code>eq_ref<\/code>\uff1a\u591a\u8868\u8fde\u63a5\u65f6\uff0c\u88ab\u8fde\u63a5\u8868\u901a\u8fc7\u4e3b\u952e \/ \u552f\u4e00\u7d22\u5f15\u5339\u914d\uff0c\u6bcf\u884c\u53ea\u8fd4\u56de 1 \u884c\uff08\u5982<code>join on \u4e3b\u952e<\/code>\uff09\uff1b<\/li>\n<li><code>ref<\/code>\uff1a\u901a\u8fc7\u666e\u901a\u7d22\u5f15 \/ \u8054\u5408\u7d22\u5f15\u524d\u7f00\u5339\u914d\uff0c\u8fd4\u56de\u591a\u884c\u5339\u914d\u6570\u636e\uff08\u5982where name=&#8217;\u5f20\u4e09&#8217;\uff0cname \u662f\u666e\u901a\u7d22\u5f15\uff09\uff1b<\/li>\n<li><code>range<\/code>\uff1a\u8303\u56f4\u67e5\u8be2\uff08<code>&gt;<\/code>\u3001<code>&lt;<\/code>\u3001<code>between<\/code>\u3001<code>in<\/code>\uff09\uff0c\u53ea\u626b\u63cf\u7d22\u5f15\u7684\u67d0\u4e00\u8303\u56f4\uff08\u6bd4<code>ref<\/code>\u5dee\uff0c\u4f46\u6bd4\u5168\u8868\u626b\u63cf\u597d\uff09\uff1b<\/li>\n<li><code>index<\/code>\uff1a\u626b\u63cf\u6574\u4e2a\u7d22\u5f15\u6811\uff08\u7d22\u5f15\u5168\u626b\u63cf\uff09\uff0c\u6bd4<code>ALL<\/code>\u597d\uff08\u7d22\u5f15\u6570\u636e\u91cf\u5c0f\u4e8e\u5168\u8868\uff09\uff1b<\/li>\n<li><code>ALL<\/code>\uff1a\u5168\u8868\u626b\u63cf\uff08\u6700\u5dee\uff09\uff0c\u9700\u907f\u514d\uff08\u901a\u5e38\u662f\u7d22\u5f15\u5931\u6548\u6216\u672a\u5efa\u7d22\u5f15\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u5224\u65ad\u6807\u51c6\uff1a<\/strong><code>type<\/code>\u81f3\u5c11\u8981\u8fbe\u5230<code>range<\/code>\u7ea7\u522b\uff0c\u6700\u4f18\u662f<code>ref<\/code>\u6216<code>const<\/code>\uff0c\u51fa\u73b0<code>ALL<\/code>\u8bf4\u660e\u5b58\u5728\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<h3>2. <code>key<\/code>\uff1a\u5b9e\u9645\u4f7f\u7528\u7684\u7d22\u5f15<\/h3>\n<p><strong>\u542b\u4e49\uff1a<\/strong>\u8868\u793a MySQL \u5b9e\u9645\u9009\u62e9\u7684\u7d22\u5f15\uff08\u82e5\u4e3a<code>NULL<\/code>\uff0c\u8bf4\u660e\u672a\u4f7f\u7528\u4efb\u4f55\u7d22\u5f15\uff0c\u7d22\u5f15\u5931\u6548\u6216\u65e0\u5408\u9002\u7d22\u5f15\uff09\uff1b<br \/>\n\u5224\u65ad\u6807\u51c6\uff1a\u82e5<code>key<\/code>\u4e0d\u662f\u4f60\u8bbe\u8ba1\u7684\u76ee\u6807\u7d22\u5f15\uff08\u5982\u9884\u671f\u7528<code>idx_email<\/code>\uff0c\u4f46<code>key<\/code>\u4e3a<code>NULL<\/code>\uff09\uff0c\u8bf4\u660e\u7d22\u5f15\u5931\u6548\uff0c\u9700\u6392\u67e5\u539f\u56e0\uff08\u7ed3\u5408\u7d22\u5f15\u5931\u6548\u573a\u666f\uff09\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<h3>3. <code>rows<\/code>\uff1a\u9884\u4f30\u626b\u63cf\u884c\u6570<\/h3>\n<p><strong>\u542b\u4e49\uff1a<\/strong>MySQL \u4f18\u5316\u5668\u9884\u4f30\u7684\u3001\u67e5\u8be2\u9700\u8981\u626b\u63cf\u7684\u884c\u6570\uff08\u975e\u7cbe\u786e\u503c\uff0c\u4f46\u53ef\u53cd\u6620\u6548\u7387\uff09\uff1b<br \/>\n\u5224\u65ad\u6807\u51c6\uff1a\u884c\u6570\u8d8a\u5c11\u8d8a\u597d\uff0c\u82e5<code>rows<\/code>\u8fdc\u5927\u4e8e\u8868\u4e2d\u5b9e\u9645\u6570\u636e\u91cf\uff0c\u53ef\u80fd\u662f\u7edf\u8ba1\u4fe1\u606f\u8fc7\u65f6\uff08\u9700\u6267\u884c<code>analyze table<\/code>\u66f4\u65b0\uff09\uff0c\u6216\u7d22\u5f15\u8bbe\u8ba1\u4e0d\u5408\u7406\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<h3>4. <code>extra<\/code>\uff1a\u989d\u5916\u6267\u884c\u4fe1\u606f<\/h3>\n<p>\u6838\u5fc3\uff01\u66b4\u9732\u6027\u80fd\u9690\u60a3<\/p>\n<p><strong>\u542b\u4e49\uff1a<\/strong>\u8bb0\u5f55 SQL \u6267\u884c\u7684\u989d\u5916\u64cd\u4f5c\uff0c\u91cd\u70b9\u5173\u6ce8 \u201c\u597d\u7684\u6807\u8bc6\u201d \u548c \u201c\u574f\u7684\u6807\u8bc6\u201d\uff1a<\/p>\n<ul>\n<li>\u4f18\u8d28\u6807\u8bc6\uff1a\n<ul>\n<li><code>Using index<\/code>\uff1a\u89e6\u53d1\u8986\u76d6\u7d22\u5f15\uff0c\u65e0\u9700\u56de\u8868\uff08\u9ad8\u6548\uff0c\u9762\u8bd5\u52a0\u5206\u70b9\uff09\uff1b<\/li>\n<li><code>Using index condition<\/code>\uff1a\u7d22\u5f15\u4e0b\u63a8\uff08ICP\uff09\uff0c\u51cf\u5c11\u56de\u8868\u6b21\u6570\uff08\u9ad8\u6548\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6027\u80fd\u9690\u60a3\u6807\u8bc6\uff08\u5fc5\u987b\u907f\u514d\uff09\uff1a\n<ul>\n<li><code>Using filesort<\/code>\uff1a\u9700\u5728\u5185\u5b58 \/ \u78c1\u76d8\u4e2d\u6392\u5e8f\uff08\u672a\u5229\u7528\u7d22\u5f15\u6709\u5e8f\u6027\uff0c\u5982<code>order by<\/code>\u5b57\u6bb5\u65e0\u7d22\u5f15\uff09\uff1b<\/li>\n<li><code>Using temporary<\/code>\uff1a\u521b\u5efa\u4e34\u65f6\u8868\u5b58\u50a8\u4e2d\u95f4\u7ed3\u679c\uff08\u5982<code>group by<\/code>\u65e0\u7d22\u5f15\u3001\u591a\u8868\u8fde\u63a5\u65e0\u5408\u9002\u7d22\u5f15\uff0c\u6027\u80fd\u6781\u5dee\uff09\uff1b<\/li>\n<li><code>Using where<\/code>\uff1a\u5168\u8868\u626b\u63cf\u540e\u8fc7\u6ee4\u6570\u636e\uff08<code>type=ALL<\/code>\u65f6\u51fa\u73b0\uff0c\u8bf4\u660e\u65e0\u7d22\u5f15\u53ef\u7528\uff09\uff1b<\/li>\n<li><code>Using join buffer<\/code>\uff1a\u591a\u8868\u8fde\u63a5\u65f6\u672a\u7528\u7d22\u5f15\uff0c\u4f7f\u7528\u8fde\u63a5\u7f13\u51b2\u533a\uff08\u4f4e\u6548\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div style=\"height:0.7em\"><\/div>\n<h3>5. <code>id<\/code>\uff1a\u67e5\u8be2\u6267\u884c\u987a\u5e8f<\/h3>\n<p><strong>\u542b\u4e49\uff1a<\/strong>\u8868\u793a\u67e5\u8be2\u4e2d\u6bcf\u4e2a<code>select<\/code>\u5b50\u53e5\u7684\u6267\u884c\u987a\u5e8f\uff08\u6570\u5b57\u8d8a\u5927\u8d8a\u5148\u6267\u884c\uff0c\u76f8\u540c\u6570\u5b57\u6309\u4ece\u4e0a\u5230\u4e0b\u987a\u5e8f\uff09\uff1b<br \/>\n<strong>\u5e94\u7528\u573a\u666f\uff1a<\/strong>\u590d\u6742\u67e5\u8be2\uff08\u5b50\u67e5\u8be2\u3001<code>join<\/code>\uff09\u4e2d\uff0c\u5224\u65ad\u8868\u7684\u8fde\u63a5\u987a\u5e8f\u662f\u5426\u5408\u7406\uff08\u5982\u5c0f\u8868\u9a71\u52a8\u5927\u8868\uff09\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<h3>6. <code>select_type<\/code>\uff1a\u67e5\u8be2\u7c7b\u578b<\/h3>\n<p><strong>\u542b\u4e49\uff1a<\/strong>\u533a\u5206\u7b80\u5355\u67e5\u8be2\u548c\u590d\u6742\u67e5\u8be2\uff0c\u9762\u8bd5\u9ad8\u9891\u53d6\u503c\uff1a<\/p>\n<ul>\n<li><code>SIMPLE<\/code>\uff1a\u7b80\u5355\u67e5\u8be2\uff08\u65e0\u5b50\u67e5\u8be2\u3001\u65e0 <code>union<\/code>\uff09\uff1b<\/li>\n<li><code>SUBQUERY<\/code>\uff1a\u5b50\u67e5\u8be2\uff08<code>select<\/code>\u4e2d\u5d4c\u5957<code>select<\/code>\uff09\uff1b<\/li>\n<li><code>DERIVED<\/code>\uff1a\u6d3e\u751f\u8868\uff08<code>from<\/code>\u4e2d\u5d4c\u5957<code>select<\/code>\uff09\uff1b<\/li>\n<li><code>UNION<\/code>\uff1a<code>union<\/code>\u8fde\u63a5\u7684\u7b2c\u4e8c\u4e2a\u53ca\u4ee5\u540e\u7684\u67e5\u8be2\u3002<\/li>\n<\/ul>\n<p>\u9762\u8bd5\u4ef7\u503c\uff1a\u8bf4\u660e\u67e5\u8be2\u7684\u590d\u6742\u7a0b\u5ea6\uff0c\u590d\u6742\u67e5\u8be2\uff08\u5982\u591a\u5c42\u5b50\u67e5\u8be2\uff09\u53ef\u80fd\u5bfc\u81f4\u4f18\u5316\u5668\u9009\u62e9\u4f4e\u6548\u6267\u884c\u8ba1\u5212\uff0c\u9700\u8003\u8651\u62c6\u5206 SQL\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<h3>7. <code>table<\/code>\uff1a\u5f53\u524d\u67e5\u8be2\u7684\u8868<\/h3>\n<p><strong>\u542b\u4e49\uff1a<\/strong>\u663e\u793a SQL \u67e5\u8be2\u7684\u8868\u540d\uff08\u6216\u522b\u540d\uff09\uff0c\u591a\u8868\u8fde\u63a5\u65f6\u6309<code>id<\/code>\u987a\u5e8f\u663e\u793a\u8868\u7684\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<div style=\"height:0.7em\"><\/div>\n<h3>\u52a0\u9879<\/h3>\n<ol>\n<li>\n<p>\u5982\u4f55\u5224\u65ad\u7d22\u5f15\u662f\u5426\u751f\u6548\uff1a<br \/>\n\u770bkey\u5b57\u6bb5\u662f\u5426\u4e3a\u76ee\u6807\u7d22\u5f15\uff08\u975e<code>NULL<\/code>\uff09\uff0c\u540c\u65f6<code>type<\/code>\u4e0d\u662f<code>ALL<\/code>\/<code>index<\/code>\uff1b<\/p>\n<\/li>\n<li>\n<p>\u5982\u4f55\u5224\u65ad\u67e5\u8be2\u662f\u5426\u9ad8\u6548\uff1a<br \/>\n<code>type<\/code>\u2265<code>range<\/code> + <code>key<\/code>\u975e<code>NULL<\/code> + <code>rows<\/code>\u503c\u5c0f + <code>extra<\/code>\u65e0<code>filesort<\/code>\/<code>temporary<\/code>\uff1b<\/p>\n<\/li>\n<li>\n<p>\u5e38\u89c1\u95ee\u9898\u6392\u67e5\uff1a<\/p>\n<ul>\n<li>\u82e5<code>type=ALL<\/code> + <code>key=NULL<\/code>\uff1a\u7d22\u5f15\u5931\u6548\u6216\u672a\u5efa\u7d22\u5f15\uff0c\u6392\u67e5\u7d22\u5f15\u5931\u6548\u573a\u666f\uff1b<\/li>\n<li>\u82e5<code>extra<\/code>\u6709<code>filesort<\/code>\uff1a<code>order by<\/code>\/<code>group by<\/code>\u5b57\u6bb5\u672a\u5efa\u7d22\u5f15\uff0c\u9700\u6dfb\u52a0\u7d22\u5f15\uff1b<\/li>\n<li>\u82e5<code>extra<\/code>\u6709<code>temporary<\/code>\uff1a<code>group by<\/code>\u65e0\u7d22\u5f15\u6216\u591a\u8868\u8fde\u63a5\u65e0\u5408\u9002\u7d22\u5f15\uff0c\u4f18\u5316\u7d22\u5f15\u8bbe\u8ba1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><code>explain extended<\/code>\uff1a\u5728<code>explain<\/code>\u57fa\u7840\u4e0a\u589e\u52a0<code>filtered<\/code>\u5b57\u6bb5\uff08\u8fc7\u6ee4\u884c\u6570\u5360\u6bd4\uff09\uff0c<code>filtered<\/code>\u8d8a\u9ad8\u8bf4\u660e\u8fc7\u6ee4\u6548\u679c\u8d8a\u597d\uff1b<\/p>\n<\/li>\n<li>\n<p><code>explain format=json<\/code>\uff1a\u8f93\u51fa JSON \u683c\u5f0f\u7684\u8be6\u7ec6\u6267\u884c\u8ba1\u5212\uff0c\u9002\u5408\u590d\u6742\u67e5\u8be2\u5206\u6790\uff1b<\/p>\n<\/li>\n<li>\n<p>\u6267\u884c\u8ba1\u5212\u662f \u201c\u9884\u4f30\u201d \u800c\u975e \u201c\u5b9e\u9645\u201d\uff1a\u4f18\u5316\u5668\u53ef\u80fd\u56e0\u7edf\u8ba1\u4fe1\u606f\u8fc7\u65f6\u3001\u7d22\u5f15\u9009\u62e9\u6027\u5dee\u7b49\u8bef\u5224\uff0c\u9700\u7ed3\u5408\u5b9e\u9645\u6267\u884c\u8017\u65f6\u9a8c\u8bc1\u3002<\/p>\n<\/li>\n<\/ol>\n<div style=\"height:1.5em\"><\/div>\n<h1>11. \u5347\u5e8f\u7d22\u5f15\u4e0e\u964d\u5e8f\u7d22\u5f15<\/h1>\n<p>\u5728 MySQL \u4e2d\uff0c\u7d22\u5f15\u7684\u5347\u5e8f\uff08<code>ASC<\/code>\uff09\u548c\u964d\u5e8f\uff08<code>DESC<\/code>\uff09\u662f\u901a\u8fc7\u521b\u5efa\u7d22\u5f15\u65f6\u6307\u5b9a\u6392\u5e8f\u65b9\u5411\u6765\u8bbe\u7f6e\u7684\uff0c\u6838\u5fc3\u76ee\u7684\u662f\u5339\u914d\u67e5\u8be2\u4e2d<code>ORDER BY<\/code>\u7684\u6392\u5e8f\u9700\u6c42\uff0c\u907f\u514d\u989d\u5916\u7684\u6587\u4ef6\u6392\u5e8f\uff08<code>Using filesort<\/code>\uff09\u6216\u53cd\u5411\u626b\u63cf\u5e26\u6765\u7684\u989d\u5916\u5f00\u9500\u3002<\/p>\n<p>\u5728<code>ORDER BY<\/code>\u6392\u5e8f\u65f6\uff0c\u5982\u679c\u6392\u5e8f\u5b57\u6bb5\u5b58\u5728\u7d22\u5f15\uff0c\u4f46\u662f\u7d22\u5f15\u7684\u987a\u5e8f\u4e0e\u6392\u5e8f\u7684\u987a\u5e8f\u4e0d\u4e00\u81f4\uff0c\u5219\u6392\u5e8f\u65f6\u5bfc\u81f4\u4f18\u5316\u5668\u9009\u62e9\u201c\u53cd\u5411\u626b\u63cf\u7d22\u5f15\u201d\uff0c\u6027\u80fd\u867d\u7136\u6bd4\u6587\u4ef6\u6392\u5e8f\u5feb\u975e\u5e38\u591a\uff0c\u4f46\u662f\u4f9d\u65e7\u4e0d\u5982\u6392\u5e8f\u548c\u7d22\u5f15\u540c\u5411\u7684\u6548\u679c\u597d\u3002<\/p>\n<p>\u6bd4\u5982\uff1a<code>create_time<\/code>\u5b57\u6bb5\u5b58\u5728\u7d22\u5f15<code>idx_create_time<\/code>\uff0c\u7d22\u5f15\u662f\u5347\u5e8f\uff08<code>ASC<\/code>\uff09\u7684\uff0c\u4f46\u662f\u67e5\u8be2\u6392\u5e8f\u65f6\uff0c\u9700\u8981\u9006\u5e8f\u6392\u5e8f\uff08\u6bd4\u5982<code>ORDER BY create_time DESC<\/code>\uff09\uff0c\u90a3\u4e48\u4f18\u5316\u5668\u9009\u62e9\u201c\u53cd\u5411\u626b\u63cf\u7d22\u5f15\u201d\u3002<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>1. \u5347\u5e8f \/ \u964d\u5e8f\u7d22\u5f15\u7684\u521b\u5efa\u8bed\u6cd5<\/h2>\n<p>MySQL \u4e2d\u521b\u5efa\u7d22\u5f15\u65f6\uff0c\u9ed8\u8ba4\u662f\u5347\u5e8f\uff08<code>ASC<\/code>\uff09\uff0c\u53ef\u663e\u5f0f\u6307\u5b9a<code>ASC<\/code>\uff08\u5347\u5e8f\uff09\u6216<code>DESC<\/code>\uff08\u964d\u5e8f\uff09\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-sql\">-- \u5347\u5e8f\u7d22\u5f15\uff08\u9ed8\u8ba4\uff0c\u53ef\u7701\u7565ASC\uff09\nCREATE INDEX idx_create_time_asc ON \u8868\u540d(create_time ASC);\n\n-- \u964d\u5e8f\u7d22\u5f15\uff08\u663e\u5f0f\u6307\u5b9aDESC\uff09\nCREATE INDEX idx_create_time_desc ON \u8868\u540d(create_time DESC);<\/code><\/pre>\n<p><strong>\u5347\u5e8f\u7d22\u5f15\uff08<code>ASC<\/code>\uff09<\/strong>\uff1a\u7d22\u5f15\u4e2d\u5b57\u6bb5\u503c\u6309\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u9002\u7528\u4e8e<code>ORDER BY \u5b57\u6bb5 ASC<\/code>\u7684\u67e5\u8be2\u3002<br \/>\n<strong>\u964d\u5e8f\u7d22\u5f15\uff08<code>DESC<\/code>\uff09<\/strong>\uff1a\u7d22\u5f15\u4e2d\u5b57\u6bb5\u503c\u6309\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u9002\u7528\u4e8e<code>ORDER BY \u5b57\u6bb5 DESC<\/code>\u7684\u67e5\u8be2\uff08\u5982 \u201c\u6309\u521b\u5efa\u65f6\u95f4\u9006\u5e8f\u6392\u5e8f\u7684\u5217\u8868\u201d\uff09\u3002<\/p>\n<p>\u8fd9\u91cc\u9762\u8fd8\u5b58\u5728\u7740\u7248\u672c\u5dee\u5f02\uff1a<\/p>\n<div style=\"height:1em\"><\/div>\n<h2>2. 5.7\u7248\u672c<\/h2>\n<p>5.7\u7248\u672c\u7684\u9650\u5236\u4e0e\u5b9e\u8df5\u3002<\/p>\n<p>5.7 \u7248\u672c\u5bf9\u964d\u5e8f\u7d22\u5f15\u7684\u652f\u6301\u662f \u201c<strong>\u8bed\u6cd5\u5c42\u9762<\/strong>\u201d \u7684\uff0c<strong>\u5b9e\u9645\u5b58\u50a8\u4ecd\u4e3a\u5347\u5e8f<\/strong>\uff0c\u67e5\u8be2\u65f6\u82e5\u7528<code>ORDER BY \u5b57\u6bb5 DESC<\/code>\uff0c\u4f18\u5316\u5668\u4f1a \u201c\u53cd\u5411\u626b\u63cf\u5347\u5e8f\u7d22\u5f15\u201d\uff08\u800c\u975e\u76f4\u63a5\u4f7f\u7528\u964d\u5e8f\u7d22\u5f15\uff09\uff0c\u867d\u7136\u6bd4\u5168\u8868\u626b\u63cf + \u6587\u4ef6\u6392\u5e8f\u9ad8\u6548\uff0c\u4f46\u4ecd\u6709\u4e00\u5b9a\u5f00\u9500\u3002<\/p>\n<p>\u573a\u666f\uff1a\u67e5\u8be2\u5217\u8868\u7ecf\u5e38\u6309create_time\u9006\u5e8f\u6392\u5e8f\uff08<code>ORDER BY create_time DESC<\/code>\uff09<br \/>\n\u5728 5.7 \u4e2d\uff0c\u5373\u4f7f\u521b\u5efa<code>DESC<\/code>\u7d22\u5f15\uff0c\u5b9e\u9645\u6548\u679c\u4e0e<code>ASC<\/code>\u7d22\u5f15\u5dee\u5f02\u4e0d\u5927\uff0c\u4f46\u4ecd\u5efa\u8bae\u663e\u5f0f\u521b\u5efaDESC\u7d22\u5f15\uff08\u4e3a 8.0 \u5347\u7ea7\u517c\u5bb9\uff0c\u4e14\u4f18\u5316\u5668\u53ef\u80fd\u4f18\u5148\u9009\u62e9\uff09\uff1a<\/p>\n<pre><code class=\"language-sql\">-- 5.7\u4e2d\u521b\u5efa\u201c\u4f2a\u964d\u5e8f\u7d22\u5f15\u201d\uff08\u8bed\u6cd5\u652f\u6301\uff0c\u5b9e\u9645\u5347\u5e8f\u5b58\u50a8\uff09\nCREATE INDEX idx_create_time_desc ON order(create_time DESC);\n\n-- \u67e5\u8be2\u65f6\uff0c\u4f18\u5316\u5668\u4f1a\u53cd\u5411\u626b\u63cf\u8be5\u7d22\u5f15\uff0c\u907f\u514d\u6587\u4ef6\u6392\u5e8f\nSELECT id, order_no FROM order \nWHERE status = 1 \nORDER BY create_time DESC \nLIMIT 10;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><strong>5.7 \u7684\u66ff\u4ee3\u65b9\u6848\uff08\u6838\u5fc3\u4f18\u5316\uff09<\/strong><\/p>\n<p>\u82e5<code>ORDER BY create_time DESC<\/code>\u8fd8\u9700\u914d\u5408<code>WHERE<\/code>\u6761\u4ef6\uff08\u5982<code>status=1<\/code>\uff09\uff0c\u5efa\u8bae\u521b\u5efa\u8054\u5408\u7d22\u5f15\uff0c\u5c06\u8fc7\u6ee4\u5b57\u6bb5\u653e\u524d\u9762\uff0c\u6392\u5e8f\u5b57\u6bb5\u653e\u540e\u9762\uff08\u663e\u5f0f\u6307\u5b9aDESC\uff09\uff1a<\/p>\n<pre><code class=\"language-sql\">-- \u8054\u5408\u7d22\u5f15\uff1a\u5148\u8fc7\u6ee4\uff08status\uff09\uff0c\u518d\u6392\u5e8f\uff08create_time DESC\uff09\nCREATE INDEX idx_status_create_time_desc ON order(status, create_time DESC);\n\n-- \u8be5\u7d22\u5f15\u53ef\u540c\u65f6\u4f18\u5316WHERE\u548cORDER BY\uff0c\u907f\u514d\u5168\u8868\u626b\u63cf\u548c\u6587\u4ef6\u6392\u5e8f\nSELECT id, order_no FROM order \nWHERE status = 1 \nORDER BY create_time DESC \nLIMIT 10;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<h2>3. 8.0 \u7248\u672c<\/h2>\n<p>8.0 \u7248\u672c\u7684\u5173\u952e\u4f18\u5316\uff1a\u771f\u6b63\u652f\u6301\u964d\u5e8f\u7d22\u5f15\u3002<\/p>\n<p>8.0 \u7248\u672c\u5f00\u59cb\uff0c<code>DESC<\/code>\u7d22\u5f15\u4f1a\u771f\u6b63\u6309\u964d\u5e8f\u5b58\u50a8\uff0c\u67e5\u8be2\u65f6\u82e5<code>ORDER BY \u5b57\u6bb5 DESC<\/code>\uff0c\u53ef\u76f4\u63a5\u5339\u914d\u964d\u5e8f\u7d22\u5f15\uff0c\u65e0\u9700\u53cd\u5411\u626b\u63cf\uff0c\u6027\u80fd\u6bd4 5.7 \u63d0\u5347\u660e\u663e\uff08\u5c24\u5176\u5927\u6570\u636e\u91cf\u6392\u5e8f\u573a\u666f\uff09\u3002<\/p>\n<p>\u573a\u666f\uff1a\u540c\u6837\u6309<code>create_time<\/code>\u9006\u5e8f\u6392\u5e8f<\/p>\n<p>\u5728 8.0 \u4e2d\uff0c\u521b\u5efa<code>DESC<\/code>\u7d22\u5f15\u540e\uff0c<code>ORDER BY create_time DESC<\/code>\u4f1a\u76f4\u63a5\u4f7f\u7528\u8be5\u7d22\u5f15\uff0c<code>EXPLAIN<\/code>\u4e2d<code>Extra<\/code>\u5217\u65e0<code>Using filesort<\/code>\uff1a<\/p>\n<pre><code class=\"language-sql\">-- 8.0\u4e2d\u521b\u5efa\u201c\u771f\u964d\u5e8f\u7d22\u5f15\u201d\uff08\u5b9e\u9645\u6309create_time\u4ece\u5927\u5230\u5c0f\u5b58\u50a8\uff09\nCREATE INDEX idx_create_time_desc ON order(create_time DESC);\n\n-- \u67e5\u8be2\u65f6\u76f4\u63a5\u5339\u914d\u7d22\u5f15\uff0c\u65e0\u9700\u6392\u5e8f\nSELECT id, order_no FROM order \nORDER BY create_time DESC \nLIMIT 10;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><strong>\u8054\u5408\u7d22\u5f15\u7684\u964d\u5e8f\u652f\u6301\uff088.0 \u589e\u5f3a\uff09<\/strong><br \/>\n8.0 \u5141\u8bb8\u8054\u5408\u7d22\u5f15\u4e2d\u90e8\u5206\u5b57\u6bb5\u6307\u5b9a<code>DESC<\/code>\uff0c\u66f4\u7cbe\u51c6\u5339\u914d\u590d\u6742\u6392\u5e8f\u573a\u666f\u3002<\/p>\n<p>\u4f8b\u5982 \u201c\u6309<code>status<\/code>\u5347\u5e8f\u3001<code>create_time<\/code>\u964d\u5e8f\u6392\u5e8f\u201d\uff1a<\/p>\n<pre><code class=\"language-sql\">-- \u8054\u5408\u7d22\u5f15\uff1astatus\u5347\u5e8f\uff0ccreate_time\u964d\u5e8f\nCREATE INDEX idx_status_asc_create_time_desc ON order(status ASC, create_time DESC);\n\n-- \u5b8c\u5168\u5339\u914dORDER BY\uff0c\u65e0\u6587\u4ef6\u6392\u5e8f\nSELECT id, order_no FROM order \nORDER BY status ASC, create_time DESC \nLIMIT 10;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<h2>4. \u5b9e\u8df5\u5efa\u8bae<\/h2>\n<p><strong>1. \u4f18\u5148\u5339\u914d\u67e5\u8be2\u7684\u6392\u5e8f\u65b9\u5411\uff1a<\/strong><\/p>\n<ul>\n<li>\u82e5\u67e5\u8be2\u5e38\u7528<code>ORDER BY create_time DESC<\/code>\uff08\u5982\u8ba2\u5355\u5217\u8868\u9ed8\u8ba4 \u201c\u6700\u65b0\u5728\u524d\u201d\uff09\uff0c\u76f4\u63a5\u521b\u5efa<code>create_time DESC<\/code>\u7d22\u5f15\uff088.0 \u6700\u4f73\uff0c5.7 \u6b21\u4e4b\uff09\u3002<\/li>\n<li>\u82e5\u6392\u5e8f\u5b57\u6bb5\u540c\u65f6\u6709<code>ASC<\/code>\u548c<code>DESC<\/code>\u9700\u6c42\uff08\u6781\u5c11\uff09\uff0c\u53ef\u5206\u522b\u521b\u5efa\u5347\u5e8f\u548c\u964d\u5e8f\u7d22\u5f15\uff08\u4f46\u9700\u5e73\u8861\u7d22\u5f15\u7ef4\u62a4\u6210\u672c\uff09\u3002<\/li>\n<\/ul>\n<p><strong>2. \u8054\u5408\u7d22\u5f15\u7684\u6392\u5e8f\u5b57\u6bb5\u653e\u6700\u540e\uff1a<\/strong><\/p>\n<ul>\n<li>\u7d22\u5f15\u9075\u5faa \u201c\u6700\u5de6\u524d\u7f00\u539f\u5219\u201d\uff0c\u8fc7\u6ee4\u5b57\u6bb5\uff08<code>WHERE<\/code>\u6761\u4ef6\uff09\u653e\u524d\u9762\uff0c\u6392\u5e8f\u5b57\u6bb5\uff08<code>ORDER BY<\/code>\uff09\u653e\u540e\u9762\uff0c\u4f8b\u5982<code>WHERE status=1 ORDER BY create_time DESC<\/code>\uff0c\u8054\u5408\u7d22\u5f15\u4e3a(<code>status, create_time DESC<\/code>)\u3002<\/li>\n<\/ul>\n<p><strong>3. \u907f\u514d\u8fc7\u5ea6\u521b\u5efa\u964d\u5e8f\u7d22\u5f15\uff1a<\/strong><\/p>\n<ul>\n<li>\u964d\u5e8f\u7d22\u5f15\u4e0e\u5347\u5e8f\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u76f8\u540c\uff08\u90fd\u4f1a\u5360\u7528\u78c1\u76d8\u7a7a\u95f4\uff0c\u5f71\u54cd\u5199\u5165\u6027\u80fd\uff09\uff0c<strong>\u4ec5\u5bf9 \u201c\u9ad8\u9891\u9006\u5e8f\u6392\u5e8f\u201d \u7684\u5b57\u6bb5\u521b\u5efa\u964d\u5e8f\u7d22\u5f15<\/strong>\uff0c\u4f4e\u9891\u573a\u666f\u65e0\u9700\u5355\u72ec\u521b\u5efa\uff08\u4f9d\u8d56\u4f18\u5316\u5668\u53cd\u5411\u626b\u63cf\u5373\u53ef\uff09\u3002\n<div style=\"height:1em\"><\/div>\n<\/li>\n<\/ul>\n<h2>5. \u603b\u7ed3<\/h2>\n<ul>\n<li>\u521b\u5efa\u65b9\u5f0f\uff1a\u901a\u8fc7<code>ASC<\/code>\uff08\u9ed8\u8ba4\uff09\u6216<code>DESC<\/code>\u5173\u952e\u5b57\u6307\u5b9a\uff0c\u8bed\u6cd5\u7b80\u5355\u3002<\/li>\n<li>\u7248\u672c\u5dee\u5f02\uff1a5.7 \u4ec5\u8bed\u6cd5\u652f\u6301\u964d\u5e8f\u7d22\u5f15\uff08\u5b9e\u9645\u5347\u5e8f\u5b58\u50a8\uff09\uff0c8.0 \u771f\u6b63\u652f\u6301\uff08\u6309\u964d\u5e8f\u5b58\u50a8\uff0c\u6027\u80fd\u66f4\u4f18\uff09\u3002<\/li>\n<li>\u6838\u5fc3\u4ef7\u503c\uff1a\u5339\u914d<code>ORDER BY<\/code>\u7684\u6392\u5e8f\u65b9\u5411\uff0c\u907f\u514d\u6587\u4ef6\u6392\u5e8f\uff0c\u5c24\u5176\u5728\u5927\u6570\u636e\u91cf\u7684\u5217\u8868\u67e5\u8be2\uff08\u5982\u8ba2\u5355\u3001\u65e5\u5fd7\uff09\u4e2d\uff0c\u80fd\u663e\u8457\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<\/ul>\n<div style=\"height:1.5em\"><\/div>\n<blockquote>\n<p>\u56de\u76ee\u5f55\uff1a <a href=\"https:\/\/www.tqazy.com\/?p=1972\" target=\"_blank\">\u300a\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u5173\u76ee\u5f55\u300b<\/a><br \/>\n\u4e0a\u4e00\u7bc7\uff1a <a href=\"https:\/\/www.tqazy.com\/?p=2077\" target=\"_blank\">\u300a\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517301 &#8211; \u57fa\u7840\u6838\u5fc3\u300b<\/a><br \/>\n\u4e0b\u4e00\u7bc7\uff1a <a href=\"https:\/\/www.tqazy.com\/?p=2087\" target=\"_blank\">\u300a\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517303 \u2013 SQL\u8bed\u6cd5\u4e0e\u67e5\u8be2\u4f18\u5316\u300b<\/a><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u5404\u79cd\u6811\u3001\u7d22\u5f15\u7684\u4f5c\u7528\u3001\u5e38\u89c1\u7d22\u5f15\u7c7b\u578b\u3001\u805a\u7c07\u7d22\u5f15\u4e0e\u975e\u805a\u7c07\u7d22\u5f15\u3001\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\u3001\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u3001\u56de\u8868\u67e5\u8be2\u4e0e\u7d22\u5f15\u8986\u76d6\u3001\u5982\u4f55\u5408\u7406\u4f7f\u7528\u7d22\u5f15\u3001\u7d22\u5f15\u5931\u6548\u573a\u666f\u3001explain\u6267\u884c\u8ba1\u5212\u5206\u6790\u3001\u5347\u5e8f\u7d22\u5f15\u4e0e\u964d\u5e8f\u7d22\u5f15\u3002\u672c\u6587\u4f1a\u6301\u7eed\u66f4\u65b0&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84],"tags":[109,85],"class_list":["post-2082","post","type-post","status-publish","format-standard","hentry","category-interview","tag-mysql","tag-85"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 - \u7d22\u5f15 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tqazy.com\/?p=2082\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 - \u7d22\u5f15 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"\u5404\u79cd\u6811\u3001\u7d22\u5f15\u7684\u4f5c\u7528\u3001\u5e38\u89c1\u7d22\u5f15\u7c7b\u578b\u3001\u805a\u7c07\u7d22\u5f15\u4e0e\u975e\u805a\u7c07\u7d22\u5f15\u3001\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\u3001\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u3001\u56de\u8868\u67e5\u8be2\u4e0e\u7d22\u5f15\u8986\u76d6\u3001\u5982\u4f55\u5408\u7406\u4f7f\u7528\u7d22\u5f15\u3001\u7d22\u5f15\u5931\u6548\u573a\u666f\u3001explain\u6267\u884c\u8ba1\u5212\u5206\u6790\u3001\u5347\u5e8f\u7d22\u5f15\u4e0e\u964d\u5e8f\u7d22\u5f15\u3002\u672c\u6587\u4f1a\u6301\u7eed\u66f4\u65b0...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tqazy.com\/?p=2082\" \/>\n<meta property=\"og:site_name\" content=\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-20T04:53:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-20T07:08:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp\" \/>\n<meta name=\"author\" content=\"\u9676\u5176\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u9676\u5176\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=2082\"},\"author\":{\"name\":\"\u9676\u5176\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"headline\":\"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 &#8211; \u7d22\u5f15\",\"datePublished\":\"2025-11-20T04:53:28+00:00\",\"dateModified\":\"2025-11-20T07:08:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=2082\"},\"wordCount\":195,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"image\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#primaryimage\"},\"thumbnailUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp\",\"keywords\":[\"mysql\",\"\u9762\u8bd5\u516b\u80a1\"],\"articleSection\":[\"\u9762\u8bd5\u516b\u80a1\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tqazy.com\/?p=2082#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tqazy.com\/?p=2082\",\"url\":\"https:\/\/www.tqazy.com\/?p=2082\",\"name\":\"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 - \u7d22\u5f15 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#primaryimage\"},\"thumbnailUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp\",\"datePublished\":\"2025-11-20T04:53:28+00:00\",\"dateModified\":\"2025-11-20T07:08:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tqazy.com\/?p=2082\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#primaryimage\",\"url\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp\",\"contentUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tqazy.com\/?p=2082#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.tqazy.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 &#8211; \u7d22\u5f15\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tqazy.com\/#website\",\"url\":\"https:\/\/www.tqazy.com\/\",\"name\":\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"description\":\"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765\",\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"alternateName\":\"TaoQi's Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tqazy.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\",\"name\":\"\u9676\u5176\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"contentUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"width\":940,\"height\":940,\"caption\":\"\u9676\u5176\"},\"logo\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\"},\"description\":\"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458\",\"sameAs\":[\"https:\/\/www.tqazy.com\"],\"url\":\"https:\/\/www.tqazy.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 - \u7d22\u5f15 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tqazy.com\/?p=2082","og_locale":"zh_CN","og_type":"article","og_title":"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 - \u7d22\u5f15 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","og_description":"\u5404\u79cd\u6811\u3001\u7d22\u5f15\u7684\u4f5c\u7528\u3001\u5e38\u89c1\u7d22\u5f15\u7c7b\u578b\u3001\u805a\u7c07\u7d22\u5f15\u4e0e\u975e\u805a\u7c07\u7d22\u5f15\u3001\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\u3001\u7d22\u5f15\u7684\u7ef4\u62a4\u6210\u672c\u3001\u56de\u8868\u67e5\u8be2\u4e0e\u7d22\u5f15\u8986\u76d6\u3001\u5982\u4f55\u5408\u7406\u4f7f\u7528\u7d22\u5f15\u3001\u7d22\u5f15\u5931\u6548\u573a\u666f\u3001explain\u6267\u884c\u8ba1\u5212\u5206\u6790\u3001\u5347\u5e8f\u7d22\u5f15\u4e0e\u964d\u5e8f\u7d22\u5f15\u3002\u672c\u6587\u4f1a\u6301\u7eed\u66f4\u65b0...","og_url":"https:\/\/www.tqazy.com\/?p=2082","og_site_name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","article_published_time":"2025-11-20T04:53:28+00:00","article_modified_time":"2025-11-20T07:08:14+00:00","og_image":[{"url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp","type":"","width":"","height":""}],"author":"\u9676\u5176","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u9676\u5176","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tqazy.com\/?p=2082#article","isPartOf":{"@id":"https:\/\/www.tqazy.com\/?p=2082"},"author":{"name":"\u9676\u5176","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"headline":"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 &#8211; \u7d22\u5f15","datePublished":"2025-11-20T04:53:28+00:00","dateModified":"2025-11-20T07:08:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tqazy.com\/?p=2082"},"wordCount":195,"commentCount":0,"publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"image":{"@id":"https:\/\/www.tqazy.com\/?p=2082#primaryimage"},"thumbnailUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp","keywords":["mysql","\u9762\u8bd5\u516b\u80a1"],"articleSection":["\u9762\u8bd5\u516b\u80a1"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tqazy.com\/?p=2082#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tqazy.com\/?p=2082","url":"https:\/\/www.tqazy.com\/?p=2082","name":"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 - \u7d22\u5f15 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.tqazy.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.tqazy.com\/?p=2082#primaryimage"},"image":{"@id":"https:\/\/www.tqazy.com\/?p=2082#primaryimage"},"thumbnailUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp","datePublished":"2025-11-20T04:53:28+00:00","dateModified":"2025-11-20T07:08:14+00:00","breadcrumb":{"@id":"https:\/\/www.tqazy.com\/?p=2082#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tqazy.com\/?p=2082"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.tqazy.com\/?p=2082#primaryimage","url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp","contentUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/11\/20251114032236489.webp"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tqazy.com\/?p=2082#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.tqazy.com\/"},{"@type":"ListItem","position":2,"name":"\u9762\u8bd5\u7b14\u8bb0\uff1aMySQL \u76f8\u517302 &#8211; \u7d22\u5f15"}]},{"@type":"WebSite","@id":"https:\/\/www.tqazy.com\/#website","url":"https:\/\/www.tqazy.com\/","name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","description":"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765","publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"alternateName":"TaoQi's Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tqazy.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e","name":"\u9676\u5176","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/","url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","contentUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","width":940,"height":940,"caption":"\u9676\u5176"},"logo":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/"},"description":"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458","sameAs":["https:\/\/www.tqazy.com"],"url":"https:\/\/www.tqazy.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/2082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2082"}],"version-history":[{"count":6,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/2082\/revisions"}],"predecessor-version":[{"id":2112,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/2082\/revisions\/2112"}],"wp:attachment":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}