{"id":104619,"date":"2026-09-12T20:41:53","date_gmt":"2026-09-12T12:41:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/104619.html"},"modified":"2026-09-12T20:41:53","modified_gmt":"2026-09-12T12:41:53","slug":"%e5%af%b9%e4%ba%8emysql%ef%bc%9a%e7%b4%a2%e5%bc%95%e7%9a%84%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/104619.html","title":{"rendered":"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790"},"content":{"rendered":"<h2>\u5f00\u7bc7\u4ecb\u7ecd&#xff1a;<\/h2>\n<p>hello \u5927\u5bb6&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&#xff0c;\u6700\u91cd\u8981\u7684\u5c31\u662f\u67e5\u8be2\u6570\u636e\u4e86&#xff0c;\u800c\u67e5\u8be2\u6570\u636e\u6700\u91cd\u8981\u7684\u53c8\u662f\u901f\u5ea6&#xff0c;\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f\u6548\u7387&#xff0c;\u800c\u5f53\u6570\u636e\u5e93\u4e2d\u6709\u5927\u91cf\u6570\u636e\u7684\u65f6\u5019&#xff0c;\u8bf6&#xff0c;\u4e0d\u53ef\u907f\u514d\u7684\u662f&#xff0c;\u6211\u4eec\u67e5\u8be2\u6307\u5b9a\u6570\u636e\u7684\u901f\u5ea6\u80af\u5b9a\u4e5f\u4f1a\u53d8\u6162&#xff0c;\u672c\u8d28\u8fd8\u662f\u56e0\u4e3a\u7b49\u5f85\u7cfb\u7edf\u4ece\u78c1\u76d8\u3001\u786c\u76d8\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u95f4\u6d88\u8017&#xff0c;\u8fd9\u4e00\u70b9\u6211\u4eec\u5728IO\u90a3\u91cc\u4e5f\u6709\u8bb2\u5230\u8fc7&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&#xff0c;\u6211\u4eec\u80af\u5b9a\u8981\u60f3\u529e\u6cd5\u89e3\u51b3\u8fd9\u4e2a\u5728\u5927\u91cf\u6570\u636e\u4e2d\u67e5\u8be2\u6307\u5b9a\u6570\u636e\u6548\u7387\u4f4e\u7684\u95ee\u9898&#xff0c;\u6240\u4ee5&#xff0c;\u7d22\u5f15&#xff0c;\u5c31\u8bde\u751f\u4e86&#xff0c;\u672c\u7bc7\u535a\u5ba2&#xff0c;\u6211\u4eec\u5c31\u5c06\u4e00\u8d77\u53bb\u5b66\u4e60\u7d22\u5f15!<\/p>\n<p>\u5728\u6570\u636e\u5e93\u5f00\u53d1\u4e2d&#xff0c;\u7d22\u5f15\u662f\u63d0\u5347\u67e5\u8be2\u6027\u80fd\u7684\u6838\u5fc3\u624b\u6bb5&#xff0c;\u4f46\u591a\u6570\u5f00\u53d1\u8005\u4ec5\u505c\u7559\u5728 \u201c\u521b\u5efa\u7d22\u5f15\u201d \u7684\u8868\u5c42\u4f7f\u7528&#xff0c;\u5bf9\u5176\u5e95\u5c42\u539f\u7406\u3001\u8bed\u6cd5\u7ec6\u8282\u3001\u4f18\u5316\u6280\u5de7\u77e5\u4e4b\u751a\u5c11&#xff0c;\u5bfc\u81f4\u9891\u7e41\u51fa\u73b0 \u201c\u7d22\u5f15\u5931\u6548\u201d\u201c\u8fc7\u5ea6\u7d22\u5f15\u201d\u201c\u67e5\u8be2\u7f13\u6162\u201d \u7b49\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ece \u201c\u65e0\u7d22\u5f15\u7684\u75db\u70b9\u201d \u51fa\u53d1&#xff0c;\u7528 \u201c\u56fe\u4e66\u9986\u627e\u4e66\u201d\u201c\u6587\u4ef6\u67dc\u6536\u7eb3\u201d \u7b49\u751f\u6d3b\u5316\u7c7b\u6bd4\u62c6\u89e3\u5e95\u5c42\u539f\u7406&#xff0c;\u7ed3\u5408 \u201c\u9010\u884c\u8bed\u6cd5\u89e3\u6790 &#043; \u6d77\u91cf\u5b9e\u6218\u6848\u4f8b &#043; \u9519\u8bef\u573a\u666f\u590d\u73b0\u201d&#xff0c;\u628a MySQL \u7d22\u5f15\u7684 \u201c\u5e95\u5c42\u903b\u8f91 &#8211; \u8bed\u6cd5\u89c4\u5219 &#8211; \u5b9e\u6218\u4f18\u5316\u201d \u8bb2\u900f \u2014\u2014 \u4e0d\u4ec5\u8ba9\u4f60 \u201c\u4f1a\u7528\u201d&#xff0c;\u66f4\u8ba9\u4f60 \u201c\u61c2\u539f\u7406\u3001\u77e5\u8bed\u6cd5\u3001\u80fd\u4f18\u5316\u201d\u3002<\/p>\n<h2>\u4e00\u3001\u65e0\u7d22\u5f15\u7684\u75db&#xff1a;\u6d77\u91cf\u6570\u636e\u67e5\u8be2\u7684 \u201c\u5669\u68a6\u201d<\/h2>\n<p>\u5728\u63a2\u8ba8\u7d22\u5f15\u8bed\u6cd5\u524d&#xff0c;\u6211\u4eec\u5148\u901a\u8fc7\u5b9e\u6218\u9a8c\u8bc1 \u201c\u65e0\u7d22\u5f15\u201d \u7684\u4f4e\u6548&#xff0c;\u540c\u65f6\u4ece\u5e95\u5c42 IO \u89d2\u5ea6\u89e3\u91ca \u201c\u4e3a\u4ec0\u4e48\u6162\u201d&#xff0c;\u4e3a\u540e\u7eed\u7d22\u5f15\u539f\u7406\u94fa\u57ab\u3002<\/p>\n<h4>1.1 \u57fa\u7840\u8bed\u6cd5&#xff1a;\u521b\u5efa\u6d4b\u8bd5\u8868 &#043; \u6279\u91cf\u63d2\u5165\u6570\u636e<\/h4>\n<h5>1.1.1 \u8bed\u6cd5\u51c6\u5907&#xff1a;\u5b58\u50a8\u8fc7\u7a0b\u4e0e\u51fd\u6570\u521b\u5efa\u8bed\u6cd5<\/h5>\n<p>MySQL \u4e2d\u6279\u91cf\u63d2\u5165\u6d77\u91cf\u6570\u636e\u9700\u501f\u52a9\u5b58\u50a8\u8fc7\u7a0b&#xff08;Procedure&#xff09; \u548c\u81ea\u5b9a\u4e49\u51fd\u6570&#xff08;Function&#xff09;&#xff0c;\u6838\u5fc3\u539f\u56e0\u662f&#xff1a;\u5355\u6b21INSERT\u8bed\u53e5\u63d2\u5165 1 \u6761\u6570\u636e\u4f1a\u89e6\u53d1 1 \u6b21\u78c1\u76d8 IO&#xff0c;\u800c\u5b58\u50a8\u8fc7\u7a0b\u53ef\u6279\u91cf\u5c01\u88c5\u64cd\u4f5c&#xff0c;\u5173\u95ed\u81ea\u52a8\u63d0\u4ea4\u540e\u4ec5\u89e6\u53d1 1 \u6b21 IO&#xff0c;\u6548\u7387\u63d0\u5347 100 \u500d\u4ee5\u4e0a\u3002<\/p>\n<h6>1. \u81ea\u5b9a\u4e49\u51fd\u6570&#xff1a;\u751f\u6210\u968f\u673a\u5b57\u7b26\u4e32<\/h6>\n<p>DELIMITER $$ &#8212; \u4e34\u65f6\u4fee\u6539\u8bed\u53e5\u7ed3\u675f\u7b26\u4e3a$$&#xff08;\u9ed8\u8ba4;&#xff0c;\u907f\u514d\u51fd\u6570\u4f53\u4e2d;\u4e0e\u7ed3\u675f\u7b26\u51b2\u7a81&#xff0c;\u5e95\u5c42\u662f\u9632\u6b62MySQL\u63d0\u524d\u89e3\u6790\u51fd\u6570\u4f53&#xff09;<br \/>\nCREATE FUNCTION rand_string(n INT)<br \/>\nRETURNS VARCHAR(255)<br \/>\nDETERMINISTIC &#8212; \u8f93\u5165\u76f8\u540c\u53c2\u6570\u8fd4\u56de\u76f8\u540c\u7ed3\u679c&#xff0c;MySQL\u4f1a\u7f13\u5b58\u51fd\u6570\u7ed3\u679c&#xff0c;\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97&#xff08;\u5e95\u5c42\u4f18\u5316\u70b9&#xff09;<br \/>\nBEGIN<br \/>\n    &#8212; \u58f0\u660e\u53d8\u91cf&#xff1a;chars_str&#xff08;\u5b57\u7b26\u96c6&#xff09;\u3001return_str&#xff08;\u7ed3\u679c&#xff09;\u3001i&#xff08;\u8ba1\u6570\u5668&#xff09;<br \/>\n    DECLARE chars_str VARCHAR(100) DEFAULT &#039;abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ&#039;;<br \/>\n    DECLARE return_str VARCHAR(255) DEFAULT &#039;&#039;;<br \/>\n    DECLARE i INT DEFAULT 0;<\/p>\n<p>    &#8212; WHILE\u5faa\u73af&#xff1a;\u6bd4FOR\u5faa\u73af\u66f4\u9002\u914dMySQL&#xff0c;\u5e95\u5c42\u662f\u9010\u884c\u6267\u884c&#xff0c;\u65e0\u9884\u7f16\u8bd1\u4f18\u5316<br \/>\n    WHILE i &lt; n DO<br \/>\n        &#8212; CONCAT&#xff1a;\u5b57\u7b26\u4e32\u62fc\u63a5&#xff0c;\u5e95\u5c42\u662f\u5185\u5b58\u7f13\u51b2\u533a\u62fc\u63a5&#xff0c;\u907f\u514d\u591a\u6b21\u78c1\u76d8\u5199\u5165<br \/>\n        &#8212; SUBSTRING&#043;RAND&#xff1a;\u968f\u673a\u622a\u53d6\u5b57\u7b26&#xff0c;RAND()\u5e95\u5c42\u662f\u57fa\u4e8e\u7cfb\u7edf\u65f6\u95f4\u7684\u4f2a\u968f\u673a\u6570\u751f\u6210<br \/>\n        SET return_str &#061; CONCAT(return_str, SUBSTRING(chars_str, FLOOR(1&#043;RAND()*52), 1));<br \/>\n        SET i &#061; i &#043; 1;<br \/>\n    END WHILE;<br \/>\n    RETURN return_str;<br \/>\nEND $$<br \/>\nDELIMITER ; &#8212; \u6062\u590d\u9ed8\u8ba4\u7ed3\u675f\u7b26&#xff0c;\u5e95\u5c42\u662f\u544a\u8bc9MySQL\u201c\u51fd\u6570\u5b9a\u4e49\u7ed3\u675f&#xff0c;\u53ef\u6267\u884c\u540e\u7eed\u8bed\u53e5\u201d<\/p>\n<h6>2. \u81ea\u5b9a\u4e49\u51fd\u6570&#xff1a;\u751f\u6210\u968f\u673a\u6570\u5b57<\/h6>\n<p>DELIMITER $$<br \/>\nCREATE FUNCTION rand_num()<br \/>\nRETURNS INT(5)<br \/>\nDETERMINISTIC<br \/>\nBEGIN<br \/>\n    DECLARE i INT DEFAULT 0;<br \/>\n    &#8212; FLOOR(10 &#043; RAND()*500)&#xff1a;\u751f\u621010~510\u7684\u968f\u673a\u6570&#xff0c;\u5e95\u5c42\u662f\u5c060~1\u7684\u5c0f\u6570\u6620\u5c04\u5230\u76ee\u6807\u533a\u95f4<br \/>\n    &#8212; \u4f18\u5316\u70b9&#xff1a;\u907f\u514d\u751f\u62100\u503c&#xff08;\u90e8\u95e8\u7f16\u53f7\u901a\u5e38\u4ece1\u5f00\u59cb&#xff0c;\u7b26\u5408\u4e1a\u52a1\u903b\u8f91&#xff09;<br \/>\n    SET i &#061; FLOOR(10 &#043; RAND()*500);<br \/>\n    RETURN i;<br \/>\nEND $$<br \/>\nDELIMITER ;<\/p>\n<h6>3. \u5b58\u50a8\u8fc7\u7a0b&#xff1a;\u6279\u91cf\u63d2\u5165\u6570\u636e<\/h6>\n<p>DELIMITER $$<br \/>\nCREATE PROCEDURE insert_emp(in start INT(10), in max_num INT(10))<br \/>\nBEGIN<br \/>\n    DECLARE i INT DEFAULT 0;<br \/>\n    SET autocommit &#061; 0; &#8212; \u5173\u95ed\u81ea\u52a8\u63d0\u4ea4&#xff1a;\u5e95\u5c42\u662f\u6682\u505cInnoDB\u7684\u4e8b\u52a1\u65e5\u5fd7&#xff08;redo log&#xff09;\u5237\u76d8&#xff0c;\u6279\u91cf\u63d2\u5165\u4ec5\u51991\u6b21\u65e5\u5fd7<\/p>\n<p>    &#8212; REPEAT\u5faa\u73af&#xff1a;\u5148\u6267\u884c\u540e\u5224\u65ad&#xff0c;\u6bd4WHILE\u66f4\u9002\u5408\u201c\u81f3\u5c11\u63d2\u51651\u6761\u6570\u636e\u201d\u7684\u573a\u666f<br \/>\n    REPEAT<br \/>\n        SET i &#061; i &#043; 1;<br \/>\n        INSERT INTO EMP VALUES (<br \/>\n            (start&#043;i), &#8212; \u5458\u5de5\u7f16\u53f7&#xff1a;\u81ea\u589e\u903b\u8f91&#xff0c;\u907f\u514d\u4e3b\u952e\u51b2\u7a81&#xff08;\u5e95\u5c42\u662fInnoDB\u7684\u4e3b\u952e\u552f\u4e00\u6027\u6821\u9a8c&#xff09;<br \/>\n            rand_string(6), &#8212; 6\u4f4d\u59d3\u540d&#xff1a;\u5e73\u8861\u201c\u533a\u5206\u5ea6\u201d\u548c\u201c\u5b58\u50a8\u7a7a\u95f4\u201d<br \/>\n            &#039;SALESMAN&#039;,<br \/>\n            0001,<br \/>\n            CURDATE(), &#8212; \u5e95\u5c42\u662f\u8c03\u7528MySQL\u7684\u65e5\u671f\u51fd\u6570&#xff0c;\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65e5\u671f&#xff08;\u65e0\u9700\u624b\u52a8\u8f93\u5165&#xff09;<br \/>\n            2000,<br \/>\n            400,<br \/>\n            rand_num()<br \/>\n        );<br \/>\n    UNTIL i &#061; max_num<br \/>\n    END REPEAT;<br \/>\n    COMMIT; &#8212; \u6279\u91cf\u63d0\u4ea4&#xff1a;\u5e95\u5c42\u662f\u5c06redo log\u5237\u76d8&#xff0c;\u540c\u65f6\u66f4\u65b0\u6570\u636e\u9875&#xff08;Page&#xff09;&#xff0c;\u4ec51\u6b21IO\u64cd\u4f5c<br \/>\nEND $$<br \/>\nDELIMITER ;<\/p>\n<h5>1.1.2 \u6838\u5fc3\u8bed\u6cd5&#xff1a;\u521b\u5efa EMP \u8868&#xff08;\u65e0\u7d22\u5f15&#xff09;<\/h5>\n<p>CREATE TABLE EMP (<br \/>\n    empno INT(10) NOT NULL, &#8212; \u975e\u7a7a\u7ea6\u675f&#xff1a;\u5e95\u5c42\u662fInnoDB\u5728\u6570\u636e\u9875\u4e2d\u6807\u8bb0\u8be5\u5b57\u6bb5\u201c\u4e0d\u5141\u8bb8NULL\u201d&#xff0c;\u8282\u7701NULL\u6807\u8bc6\u4f4d<br \/>\n    ename VARCHAR(6) NOT NULL,<br \/>\n    job VARCHAR(10) NOT NULL,<br \/>\n    mgr INT(10), &#8212; \u53ef\u7a7a&#xff1a;\u5e95\u5c42\u662f\u9884\u75591\u4e2a\u5b57\u8282\u7684NULL\u6807\u8bc6\u4f4d<br \/>\n    hiredate DATE NOT NULL,<br \/>\n    sal INT(10) NOT NULL,<br \/>\n    comm INT(10),<br \/>\n    deptno INT(5) NOT NULL<br \/>\n) ENGINE&#061;InnoDB DEFAULT CHARSET&#061;utf8;<br \/>\n&#8212; \u5173\u952e\u5e95\u5c42&#xff1a;<br \/>\n&#8212; 1. InnoDB\u5f15\u64ce&#xff1a;\u6570\u636e\u5b58\u50a8\u5728\u805a\u7c07\u7d22\u5f15\u7684\u53f6\u5b50\u8282\u70b9&#xff0c;\u65e0\u7d22\u5f15\u65f6\u6570\u636e\u65e0\u5e8f\u5b58\u50a8<br \/>\n&#8212; 2. utf8\u5b57\u7b26\u96c6&#xff1a;\u6bcf\u4e2a\u6c49\u5b57\u53603\u5b57\u8282&#xff0c;\u59d3\u540d\u5b57\u6bb5VARCHAR(6)\u6700\u591a\u5b582\u4e2a\u6c49\u5b57&#xff0c;\u7b26\u5408\u4e1a\u52a1\u573a\u666f<br \/>\n&#8212; 3. INT(10)&#xff1a;10\u662f\u663e\u793a\u5bbd\u5ea6&#xff08;\u4ec5\u5c55\u793a\u7528&#xff09;&#xff0c;\u5e95\u5c42\u5b58\u50a8\u4ecd\u4e3a4\u5b57\u8282&#xff08;INT\u56fa\u5b9a4\u5b57\u8282&#xff09;<\/p>\n<h5>1.1.3 \u6267\u884c\u5b58\u50a8\u8fc7\u7a0b&#xff1a;\u63d2\u5165 800 \u4e07\u6761\u6570\u636e<\/h5>\n<p>CALL insert_emp(100001, 8000000); &#8212; \u63d2\u5165800\u4e07\u6761&#xff0c;\u672c\u5730\u5355\u673a&#xff08;8\u683816G&#xff09;\u8017\u65f6\u7ea63\u5206\u949f<\/p>\n<p>&#8212; \u8865\u5145&#xff1a;\u76d1\u63a7\u63d2\u5165\u8fc7\u7a0b\u7684\u5e95\u5c42\u72b6\u6001&#xff08;\u8bed\u6cd5&#xff09;<br \/>\nSHOW PROCESSLIST; &#8212; \u67e5\u770b\u5b58\u50a8\u8fc7\u7a0b\u6267\u884c\u72b6\u6001&#xff0c;State\u5217\u663e\u793a\u201ccopy to tmp table\u201d\u8868\u793a\u6570\u636e\u5728\u5185\u5b58\u4e34\u65f6\u8868\u6574\u7406<br \/>\nSHOW ENGINE INNODB STATUS; &#8212; \u67e5\u770bInnoDB\u5e95\u5c42\u72b6\u6001&#xff0c;\u91cd\u70b9\u770b\u201cINSERT BUFFER\u201d&#xff08;\u63d2\u5165\u7f13\u51b2&#xff09;\u4f7f\u7528\u60c5\u51b5<\/p>\n<h4>1.2 \u65e0\u7d22\u5f15\u67e5\u8be2&#xff1a;<\/h4>\n<h5>1.2.1 \u57fa\u7840\u67e5\u8be2\u8bed\u6cd5&#xff08;\u65e0\u7d22\u5f15&#xff09;<\/h5>\n<p>SELECT * FROM EMP WHERE empno&#061;998877; <\/p>\n<h5>1.2.2 \u6267\u884c\u7ed3\u679c\u4e0e\u5e95\u5c42\u539f\u56e0<\/h5>\n<ul>\n<li>\u8017\u65f6&#xff1a;\u672c\u5730\u5355\u673a\u73af\u5883\u7ea6 4.93 \u79d2&#xff1b;<\/li>\n<li><span style=\"color:#b95514\">\u5e95\u5c42\u539f\u56e0&#xff1a;<\/span>\n<li><span style=\"color:#b95514\">\u65e0\u7d22\u5f15\u65f6&#xff0c;MySQL \u76f8\u5f53\u4e8e \u201c\u56fe\u4e66\u9986\u6ca1\u6709\u4e66\u76ee\u7d22\u5f15&#xff0c;\u8981\u627e\u300a998877 \u53f7\u5458\u5de5\u6863\u6848\u300b&#xff0c;\u53ea\u80fd\u4ece\u7b2c 1 \u672c\u4e66\u7ffb\u5230\u6700\u540e 1 \u672c\u201d&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">\u78c1\u76d8 IO \u5c42\u9762&#xff1a;800 \u4e07\u6761\u6570\u636e\u5b58\u50a8\u5728\u7ea6 5000 \u4e2a InnoDB Page&#xff08;16KB \/ \u9875&#xff09;\u4e2d&#xff0c;MySQL \u9700\u9010\u9875\u8bfb\u53d6&#xff08;5000 \u6b21\u78c1\u76d8 IO&#xff09;&#xff0c;\u6bcf\u6b21 IO \u8017\u65f6\u7ea6 1ms&#xff0c;\u603b\u8017\u65f6\u22485000*1ms&#061;5 \u79d2&#xff08;\u4e0e\u5b9e\u6d4b 4.93 \u79d2\u543b\u5408&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">\u5185\u5b58\u5c42\u9762&#xff1a;\u8bfb\u53d6\u7684 Page \u4f1a\u7f13\u5b58\u5230 Buffer Pool&#xff0c;\u4f46\u9996\u6b21\u67e5\u8be2\u65e0\u7f13\u5b58&#xff0c;\u5fc5\u987b\u8bfb\u78c1\u76d8&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">CPU \u5c42\u9762&#xff1a;\u9010\u884c\u6821\u9a8cempno&#061;998877&#xff0c;800 \u4e07\u6b21\u6bd4\u8f83\u64cd\u4f5c&#xff0c;\u5360\u7528 CPU \u8d44\u6e90\u3002<\/span><\/li>\n<\/li>\n<\/ul>\n<h5>1.2.3 \u7d22\u5f15\u6551\u573a&#xff1a;\u521b\u5efa\u7d22\u5f15\u540e\u8bed\u6cd5\u9a8c\u8bc1&#xff08;\u8865\u5145\u5e95\u5c42\u53d8\u5316&#xff09;<\/h5>\n<p>ALTER TABLE EMP ADD INDEX idx_empno(empno);<br \/>\n&#8212; \u5e95\u5c42\u53d8\u5316&#xff1a;<br \/>\n&#8212; 1. MySQL\u4e3aempno\u5b57\u6bb5\u6784\u5efaB&#043;\u6811\u7d22\u5f15&#xff0c;\u5b58\u50a8\u5728\u72ec\u7acb\u7684\u7d22\u5f15\u9875\u4e2d&#xff1b;<br \/>\n&#8212; 2. B&#043;\u6811\u9ad8\u5ea6\u7ea63\u5c42&#xff08;800\u4e07\u6570\u636e\u7684B&#043;\u6811\u9ad8\u5ea6\u8ba1\u7b97&#xff1a;\u7b2c1\u5c421\u4e2a\u8282\u70b9&#xff0c;\u7b2c2\u5c42\u7ea61000\u4e2a\u8282\u70b9&#xff0c;\u7b2c3\u5c42\u7ea68000\u4e2a\u8282\u70b9&#xff0c;\u8986\u76d6800\u4e07\u6570\u636e&#xff09;&#xff1b;<br \/>\n&#8212; 3. \u6784\u5efa\u7d22\u5f15\u8017\u65f6\u7ea610\u79d2&#xff08;\u9700\u904d\u5386\u6240\u6709\u6570\u636e\u9875&#xff0c;\u6392\u5e8f\u540e\u5199\u5165\u7d22\u5f15\u9875&#xff09;\u3002<\/p>\n<p>SELECT * FROM EMP WHERE empno&#061;123456; &#8212; \u8017\u65f60.01\u79d2\u4ee5\u5185<\/p>\n<h5>1.2.4 \u4f18\u5316\u7ed3\u679c\u5e95\u5c42\u89e3\u6790<\/h5>\n<ul>\n<li>\u8017\u65f6&#xff1a;0.01 \u79d2\u4ee5\u5185&#xff1b;<\/li>\n<li><span style=\"color:#b95514\">\u5e95\u5c42\u539f\u56e0&#xff1a;<\/span>\n<li><span style=\"color:#b95514\">B &#043; \u6811\u7d22\u5f15\u76f8\u5f53\u4e8e \u201c\u56fe\u4e66\u9986\u4e66\u76ee\u7d22\u5f15\u201d&#xff0c;\u901a\u8fc7 empno \u76f4\u63a5\u5b9a\u4f4d\u5230\u76ee\u6807 Page&#xff08;\u4ec5 3 \u6b21\u78c1\u76d8 IO&#xff1a;\u6839\u8282\u70b9\u2192\u5b50\u8282\u70b9\u2192\u53f6\u5b50\u8282\u70b9&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">3 \u6b21 IO \u8017\u65f6\u22483ms&#xff0c;\u52a0\u4e0a\u5185\u5b58\u7f13\u5b58&#xff0c;\u603b\u8017\u65f6 &lt; 10ms&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">CPU \u5c42\u9762&#xff1a;\u4ec5\u9700\u6821\u9a8c 1 \u6761\u6570\u636e&#xff0c;\u8d44\u6e90\u5360\u7528\u53ef\u5ffd\u7565\u3002<\/span><\/li>\n<\/li>\n<\/ul>\n<h4>1.3 \u6838\u5fc3\u8bed\u6cd5\u603b\u7ed3<\/h4>\n<table>\n<tr>\u64cd\u4f5c\u7c7b\u578b\u8bed\u6cd5\u7ed3\u6784\u5173\u952e\u53c2\u6570 \/ \u6ce8\u610f\u4e8b\u9879\u5e95\u5c42\u6838\u5fc3<\/tr>\n<tbody>\n<tr>\n<td>\u521b\u5efa\u81ea\u5b9a\u4e49\u51fd\u6570<\/td>\n<td>DELIMITER \u51fd\u6570\u540d\u53c2\u6570\u7c7b\u578b\u51fd\u6570\u4f53 DELIMITER ;<\/td>\n<td>\u9700\u4e34\u65f6\u4fee\u6539\u7ed3\u675f\u7b26&#xff1b;\u5fc5\u987b\u6307\u5b9a\u8fd4\u56de\u7c7b\u578b&#xff1b;DETERMINISTIC \u53ef\u9009&#xff08;\u63d0\u5347\u6548\u7387&#xff09;<\/td>\n<td>\u51fd\u6570\u7ed3\u679c\u7f13\u5b58&#xff0c;\u51cf\u5c11\u91cd\u590d\u8ba1\u7b97&#xff1b;\u907f\u514d\u5355\u6761 INSERT \u7684\u591a\u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b<\/td>\n<td>DELIMITER \u8fc7\u7a0b\u540d\u53c2\u6570\u8fc7\u7a0b\u4f53 DELIMITER ;<\/td>\n<td>\u652f\u6301\u6279\u91cf\u64cd\u4f5c&#xff1b;\u5173\u95ed autocommit \u63d0\u5347\u63d2\u5165\u6548\u7387&#xff1b;COMMIT \u7edf\u4e00\u63d0\u4ea4<\/td>\n<td>\u5173\u95ed\u81ea\u52a8\u63d0\u4ea4\u51cf\u5c11 redo log \u5237\u76d8\u6b21\u6570&#xff1b;\u6279\u91cf\u63d0\u4ea4\u4ec5 1 \u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>\u521b\u5efa\u8868<\/td>\n<td>CREATE TABLE \u8868\u540d (\u5b57\u6bb5 \u7c7b\u578b [\u7ea6\u675f]) ENGINE &#061; \u5f15\u64ce DEFAULT CHARSET &#061; \u5b57\u7b26\u96c6&#xff1b;<\/td>\n<td>InnoDB \u4e3a\u9ed8\u8ba4\u5f15\u64ce&#xff1b;NOT NULL \u7ea6\u675f\u786e\u4fdd\u5b57\u6bb5\u975e\u7a7a&#xff1b;INT (10) \u4e2d 10 \u662f\u663e\u793a\u5bbd\u5ea6&#xff0c;\u975e\u5b58\u50a8\u957f\u5ea6<\/td>\n<td>InnoDB \u6570\u636e\u5b58\u50a8\u5728\u805a\u7c07\u7d22\u5f15\u9875&#xff1b;NOT NULL \u8282\u7701 NULL \u6807\u8bc6\u4f4d&#xff1b;\u5b57\u7b26\u96c6\u51b3\u5b9a\u5b57\u8282\u5360\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u521b\u5efa\u666e\u901a\u7d22\u5f15<\/td>\n<td>ALTER TABLE \u8868\u540d ADD INDEX \u7d22\u5f15\u540d (\u5b57\u6bb5\u540d); \u6216 CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5\u540d);<\/td>\n<td>\u7d22\u5f15\u540d\u5efa\u8bae\u9075\u5faa \u201cidx_\u5b57\u6bb5\u540d\u201d \u89c4\u8303&#xff1b;\u5355\u4e2a\u5b57\u6bb5\u7d22\u5f15\u53ef\u7701\u7565\u7d22\u5f15\u540d<\/td>\n<td>\u6784\u5efa B &#043; \u6811\u7d22\u5f15&#xff0c;\u9ad8\u5ea6\u2248log (1000, \u6570\u636e\u91cf)&#xff1b;\u7d22\u5f15\u9875\u72ec\u7acb\u5b58\u50a8&#xff0c;\u51cf\u5c11\u67e5\u8be2 IO<\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u8be2\u6570\u636e<\/td>\n<td>SELECT \u5b57\u6bb5\u5217\u8868 FROM \u8868\u540d WHERE \u6761\u4ef6&#xff1b;<\/td>\n<td>* \u8868\u793a\u67e5\u8be2\u6240\u6709\u5b57\u6bb5&#xff1b;WHERE \u540e\u63a5\u7b5b\u9009\u6761\u4ef6&#xff0c;\u65e0\u7d22\u5f15\u65f6\u6761\u4ef6\u5b57\u6bb5\u4f1a\u89e6\u53d1\u5168\u8868\u626b\u63cf<\/td>\n<td>\u65e0\u7d22\u5f15&#xff1a;\u9010\u9875\u8bfb\u53d6 &#043; \u9010\u884c\u6821\u9a8c&#xff1b;\u6709\u7d22\u5f15&#xff1a;B &#043; \u6811\u5b9a\u4f4d &#043; \u4ec5\u6821\u9a8c\u76ee\u6807\u6570\u636e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4e8c\u3001\u5e95\u5c42\u57fa\u7840&#xff1a;\u7406\u89e3\u78c1\u76d8\u5b58\u50a8\u4e0e MySQL IO \u4ea4\u4e92<\/h3>\n<p>\u8981\u5f7b\u5e95\u61c2\u7d22\u5f15\u8bed\u6cd5&#xff0c;\u9700\u5148\u660e\u767d \u201c\u7d22\u5f15\u4e3a\u4f55\u80fd\u63d0\u5347\u6548\u7387\u201d\u2014\u2014 \u6838\u5fc3\u662f\u51cf\u5c11\u78c1\u76d8 IO \u6b21\u6570&#xff08;\u78c1\u76d8 IO \u662f\u6570\u636e\u5e93\u6700\u6162\u7684\u64cd\u4f5c&#xff0c;\u6bd4\u5185\u5b58\u64cd\u4f5c\u6162 10 \u4e07\u500d&#xff09;\u3002<\/p>\n<h4>2.1 \u78c1\u76d8\u7269\u7406\u7ed3\u6784\u4e0e\u6570\u636e\u5b9a\u4f4d<\/h4>\n<h5>2.1.1 \u78c1\u76d8\u7684\u4e09\u5c42\u5b58\u50a8\u7ed3\u6784<\/h5>\n<p>\u5176\u5b9e\u5173\u4e8e\u78c1\u76d8\u7684\u89e3\u6790\u5462&#xff0c;\u6211\u4eec\u4e4b\u524d\u4e5f\u6709\u4e00\u7bc7\u535a\u5ba2\u53bb\u8fdb\u884c\u4e86\u4e13\u95e8\u7684\u89e3\u6790&#xff0c;\u76f8\u4fe1\u5927\u5bb6\u5e94\u8be5\u8fd8\u8bb0\u5f97\u3002<\/p>\n<table>\n<tr><span style=\"color:#ff9900\">\u78c1\u76d8\u5c42\u7ea7<\/span><span style=\"color:#ff9900\">\u5927\u5c0f<\/span><span style=\"color:#ff9900\">\u7c7b\u6bd4&#xff08;\u6587\u4ef6\u67dc&#xff09;<\/span><span style=\"color:#ff9900\">MySQL \u5bf9\u5e94\u5355\u4f4d<\/span><span style=\"color:#ff9900\">\u6838\u5fc3\u4f5c\u7528<\/span><\/tr>\n<tbody>\n<tr>\n<td><span style=\"color:#ff9900\">\u6247\u533a&#xff08;Sector&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">512 \u5b57\u8282<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u6587\u4ef6\u67dc\u7684 \u201c\u62bd\u5c49\u683c\u5b50\u201d&#xff08;\u6700\u5c0f\u5b58\u50a8\u5355\u4f4d&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u65e0\u76f4\u63a5\u5bf9\u5e94<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u78c1\u76d8\u7684\u6700\u5c0f\u8bfb\u5199\u5355\u4f4d&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u5fc5\u987b\u6574\u6247\u533a\u8bfb\u5199<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ff9900\">\u6570\u636e\u5757&#xff08;Block&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">4KB&#xff08;8 \u4e2a\u6247\u533a&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u6587\u4ef6\u67dc\u7684 \u201c\u62bd\u5c49\u201d&#xff08;\u64cd\u4f5c\u7cfb\u7edf IO \u5355\u4f4d&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u65e0\u76f4\u63a5\u5bf9\u5e94<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u64cd\u4f5c\u7cfb\u7edf\u7f13\u5b58\u7684\u6700\u5c0f\u5355\u4f4d&#xff0c;\u51cf\u5c11\u6247\u533a\u7ea7\u522b\u7684 IO \u6b21\u6570<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ff9900\">\u9875&#xff08;Page&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">16KB&#xff08;InnoDB&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u6587\u4ef6\u67dc\u7684 \u201c\u6587\u4ef6\u5939\u201d&#xff08;MySQL IO \u5355\u4f4d&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">InnoDB Page<\/span><\/td>\n<td><span style=\"color:#ff9900\">MySQL \u7684\u6700\u5c0f\u8bfb\u5199\u5355\u4f4d&#xff0c;1 \u4e2a Page \u5305\u542b\u591a\u4e2a\u6570\u636e\u884c&#xff0c;\u51cf\u5c11\u6570\u636e\u5757\u7ea7\u522b\u7684 IO \u6b21\u6570<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>2.1.2 \u8bed\u6cd5\u9a8c\u8bc1&#xff1a;\u67e5\u770b InnoDB Page \u5927\u5c0f<\/h5>\n<p>SHOW GLOBAL STATUS LIKE &#039;innodb_page_size&#039;;<br \/>\n&#8212; \u6267\u884c\u7ed3\u679c&#xff1a;Innodb_page_size &#061; 16384&#xff08;16KB&#xff09;<br \/>\n&#8212; \u5e95\u5c42\u610f\u4e49&#xff1a;<br \/>\n&#8212; 1. 16KB\u662fInnoDB\u7ecf\u8fc7\u5b9e\u6d4b\u7684\u201c\u6700\u4f18IO\u5355\u4f4d\u201d&#xff1a;\u592a\u5c0f&#xff08;\u59824KB&#xff09;\u4f1a\u5bfc\u81f4Page\u6570\u91cf\u8fc7\u591a&#xff0c;IO\u6b21\u6570\u589e\u52a0&#xff1b;\u592a\u5927&#xff08;\u598232KB&#xff09;\u4f1a\u5bfc\u81f4\u5355\u6b21IO\u8017\u65f6\u8fc7\u957f&#xff1b;<br \/>\n&#8212; 2. 1\u4e2a16KB Page\u53ef\u5b58\u50a8\u7ea6100\u884cEMP\u8868\u6570\u636e&#xff08;\u6bcf\u884c\u7ea6150\u5b57\u8282&#xff09;&#xff0c;800\u4e07\u6570\u636e\u224880000\u4e2aPage&#xff08;1.25GB&#xff09;&#xff1b;<br \/>\n&#8212; 3. \u4fee\u6539Page\u5927\u5c0f&#xff1a;\u9700\u5728MySQL\u521d\u59cb\u5316\u65f6\u8bbe\u7f6e&#xff08;my.cnf\u4e2dinnodb_page_size&#061;16384&#xff09;&#xff0c;\u8fd0\u884c\u4e2d\u65e0\u6cd5\u4fee\u6539&#xff08;\u5e95\u5c42\u662f\u6570\u636e\u6587\u4ef6\u683c\u5f0f\u56fa\u5b9a&#xff09;\u3002<\/p>\n<h4>2.2 MySQL \u5185\u5b58\u7f13\u5b58&#xff1a;Buffer Pool<\/h4>\n<p>Buffer Pool \u662f InnoDB \u7684 \u201c\u5185\u5b58\u7f13\u51b2\u533a\u201d&#xff0c;\u76f8\u5f53\u4e8e \u201c\u628a\u6587\u4ef6\u67dc\u91cc\u5e38\u7528\u7684\u6587\u4ef6\u5939\u62ff\u5230\u684c\u9762\u4e0a\u201d&#xff0c;\u907f\u514d\u6bcf\u6b21\u90fd\u5f00\u62bd\u5c49\u3002<\/p>\n<h5>2.2.1 \u67e5\u770b Buffer Pool \u914d\u7f6e<\/h5>\n<p>&#8212; \u67e5\u770bBuffer Pool\u5927\u5c0f&#xff08;\u9ed8\u8ba4128MB&#xff09;<br \/>\nSHOW GLOBAL VARIABLES LIKE &#039;innodb_buffer_pool_size&#039;;<br \/>\n&#8212; \u6267\u884c\u7ed3\u679c&#xff1a;innodb_buffer_pool_size &#061; 134217728&#xff08;128MB &#061; 128*1024*1024&#xff09;<br \/>\n&#8212; \u5e95\u5c42\u89e3\u8bfb&#xff1a;<br \/>\n&#8212; 1. 128MB Buffer Pool\u53ef\u7f13\u5b58\u7ea68192\u4e2aPage&#xff08;128MB\/16KB&#xff09;&#xff0c;\u5360800\u4e07\u6570\u636e\u768410%&#xff1b;<br \/>\n&#8212; 2. \u751f\u4ea7\u73af\u5883\u5efa\u8bae\u8bbe\u7f6e\u4e3a\u7269\u7406\u5185\u5b58\u768450%~70%&#xff08;\u598216G\u5185\u5b58\u8bbe\u7f6e\u4e3a10G&#xff09;&#xff0c;\u6700\u5927\u5316\u7f13\u5b58Page\u3002<\/p>\n<p>&#8212; \u67e5\u770bBuffer Pool\u5b9e\u4f8b\u6570<br \/>\nSHOW GLOBAL VARIABLES LIKE &#039;innodb_buffer_pool_instances&#039;;<br \/>\n&#8212; \u6267\u884c\u7ed3\u679c&#xff1a;innodb_buffer_pool_instances &#061; 1<br \/>\n&#8212; \u5e95\u5c42\u89e3\u8bfb&#xff1a;<br \/>\n&#8212; 1. \u591a\u5b9e\u4f8b&#xff08;\u59828\u4e2a&#xff09;\u53ef\u51cf\u5c11\u5e76\u53d1\u7ade\u4e89&#xff08;\u6bcf\u4e2a\u5b9e\u4f8b\u6709\u72ec\u7acb\u9501&#xff09;&#xff0c;\u9002\u54088\u6838\u4ee5\u4e0aCPU&#xff1b;<br \/>\n&#8212; 2. \u5b9e\u4f8b\u6570\u5efa\u8bae\u7b49\u4e8eCPU\u6838\u5fc3\u6570&#xff08;\u59828\u6838\u8bbe\u7f6e8\u4e2a\u5b9e\u4f8b&#xff09;\u3002<\/p>\n<h5>2.2.2 \u4fee\u6539 Buffer Pool \u5927\u5c0f<\/h5>\n<p>&#8212; \u4fee\u6539\u4e3a512MB&#xff08;\u9700\u7ba1\u7406\u5458\u6743\u9650&#xff0c;\u91cd\u542fMySQL\u751f\u6548&#xff09;<br \/>\nSET GLOBAL innodb_buffer_pool_size &#061; 536870912; &#8212; 512*1024*1024&#061;536870912<\/p>\n<p>&#8212; \u9a8c\u8bc1\u4fee\u6539&#xff08;\u91cd\u542f\u540e&#xff09;<br \/>\nSHOW GLOBAL VARIABLES LIKE &#039;innodb_buffer_pool_size&#039;;<\/p>\n<p>&#8212; \u5e95\u5c42\u6ce8\u610f\u4e8b\u9879&#xff1a;<br \/>\n&#8212; 1. \u4fee\u6539\u540e\u9700\u91cd\u542fMySQL&#xff0c;\u56e0\u4e3aBuffer Pool\u662f\u521d\u59cb\u5316\u65f6\u5206\u914d\u7684\u5185\u5b58\u533a\u57df&#xff1b;<br \/>\n&#8212; 2. \u8fc7\u5927\u7684Buffer Pool\u4f1a\u5bfc\u81f4MySQL\u542f\u52a8\u7f13\u6162&#xff08;\u9700\u521d\u59cb\u5316\u5185\u5b58\u7ed3\u6784&#xff09;&#xff1b;<br \/>\n&#8212; 3. \u8fc7\u5c0f\u7684Buffer Pool\u4f1a\u5bfc\u81f4\u201c\u7f13\u5b58\u547d\u4e2d\u7387\u4f4e\u201d&#xff0c;\u9891\u7e41\u8bfb\u78c1\u76d8&#xff08;\u53ef\u901a\u8fc7SHOW ENGINE INNODB STATUS\u67e5\u770b\u547d\u4e2d\u7387&#xff09;\u3002<\/p>\n<h5>2.2.3 Buffer Pool \u7684\u5de5\u4f5c\u6d41\u7a0b&#xff08;\u7528 \u201c\u56fe\u4e66\u9986\u684c\u9762\u201d \u7c7b\u6bd4&#xff09;<\/h5>\n<li>\u9996\u6b21\u67e5\u8be2&#xff1a;MySQL \u5148\u67e5 Buffer Pool&#xff08;\u684c\u9762&#xff09;&#xff0c;\u65e0\u76ee\u6807 Page \u5219\u8bfb\u78c1\u76d8&#xff08;\u6587\u4ef6\u67dc&#xff09;&#xff0c;\u5c06 Page \u52a0\u8f7d\u5230 Buffer Pool&#xff1b;<\/li>\n<li>\u518d\u6b21\u67e5\u8be2&#xff1a;\u76f4\u63a5\u4ece Buffer Pool \u8bfb\u53d6&#xff0c;\u65e0\u9700\u78c1\u76d8 IO&#xff1b;<\/li>\n<li>Page \u6dd8\u6c70&#xff1a;Buffer Pool \u6ee1\u65f6&#xff0c;\u7528 \u201cLRU&#xff08;\u6700\u8fd1\u6700\u5c11\u4f7f\u7528&#xff09;\u201d \u7b97\u6cd5\u6dd8\u6c70\u4e0d\u5e38\u7528 Page&#xff08;\u76f8\u5f53\u4e8e\u628a\u684c\u9762\u4e0a\u6700\u4e45\u4e0d\u7528\u7684\u6587\u4ef6\u5939\u653e\u56de\u6587\u4ef6\u67dc&#xff09;&#xff1b;<\/li>\n<li>\u810f\u9875\u5237\u76d8&#xff1a;\u4fee\u6539 Buffer Pool \u4e2d\u7684 Page \u540e&#xff0c;Page \u53d8\u4e3a \u201c\u810f\u9875\u201d&#xff0c;InnoDB \u540e\u53f0\u7ebf\u7a0b\u5f02\u6b65\u5237\u76d8&#xff08;\u907f\u514d\u624b\u52a8 COMMIT \u65f6\u7684 IO \u963b\u585e&#xff09;\u3002<\/li>\n<h4>2.3 \u6838\u5fc3\u5171\u8bc6&#xff1a;\u7d22\u5f15\u8bed\u6cd5\u7684\u8bbe\u8ba1\u76ee\u6807<\/h4>\n<p><span style=\"color:#ff9900\">\u6240\u6709\u7d22\u5f15\u8bed\u6cd5\u7684\u6838\u5fc3\u76ee\u6807&#xff0c;\u90fd\u662f\u8ba9 MySQL \u80fd\u7528\u6700\u5c11\u7684 IO \u6b21\u6570\u627e\u5230\u76ee\u6807 Page&#xff1a;<\/span><\/p>\n<ul>\n<li><span style=\"color:#ff9900\">\u521b\u5efa\u7d22\u5f15\u65f6&#xff0c;\u8bed\u6cd5\u6307\u5b9a \u201c\u5b57\u6bb5\u540d\u201d\u2192 \u5e95\u5c42\u662f \u201c\u4ee5\u8be5\u5b57\u6bb5\u4e3a\u952e\u503c\u6784\u5efa B &#043; \u6811\u201d&#xff0c;B &#043; \u6811\u7684\u6bcf\u4e2a\u8282\u70b9\u5bf9\u5e94 1 \u4e2a Page&#xff0c;\u901a\u8fc7\u952e\u503c\u5feb\u901f\u5b9a\u4f4d\u76ee\u6807 Page&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u67e5\u8be2\u65f6&#xff0c;WHERE \u6761\u4ef6\u5339\u914d\u7d22\u5f15\u5b57\u6bb5\u2192 \u5e95\u5c42\u662f \u201c\u904d\u5386 B &#043; \u6811&#xff0c;\u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9&#xff0c;\u4ec5\u9700 3~4 \u6b21 IO\u201d&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u7d22\u5f15\u5931\u6548\u65f6\u2192 \u5e95\u5c42\u662f \u201c\u65e0\u6cd5\u901a\u8fc7 B &#043; \u6811\u5b9a\u4f4d Page&#xff0c;\u53ea\u80fd\u5168\u8868\u626b\u63cf&#xff08;N \u6b21 IO&#xff09;\u201d\u3002<\/span><\/li>\n<\/ul>\n<h2>\u5e95\u5c42\u539f\u7406&#xff1a;<\/h2>\n<p>\u9996\u5148\u8981\u660e\u786e\u4e00\u4e2a\u6838\u5fc3\u524d\u63d0&#xff1a;MySQL \u91cc\u7684\u6240\u6709\u6570\u636e&#xff0c;\u6700\u7ec8\u90fd\u662f\u5b58\u5728\u786c\u76d8\u4e0a\u7684&#xff0c;\u786c\u76d8\u7684\u7279\u70b9\u662f \u201c\u5b58\u5f97\u591a\u4f46\u627e\u5f97\u6162\u201d\u2014\u2014 \u5c31\u50cf\u56fe\u4e66\u9986\u7684\u4ed3\u5e93&#xff0c;\u4e66\u653e\u5f97\u518d\u591a&#xff0c;\u6ca1\u6709\u76ee\u5f55&#xff0c;\u627e\u4e00\u672c\u7279\u5b9a\u7684\u4e66\u4e5f\u8981\u7ffb\u904d\u6574\u4e2a\u4ed3\u5e93\u3002\u800c\u7d22\u5f15\u7684\u672c\u8d28&#xff0c;\u5c31\u662f\u7ed9\u786c\u76d8\u91cc\u7684\u6d77\u91cf\u6570\u636e&#xff0c;\u5efa\u4e00\u5957 \u201c\u56fe\u4e66\u9986\u5f0f\u7684\u591a\u7ea7\u76ee\u5f55\u201d&#xff0c;\u8ba9\u6570\u636e\u5e93\u627e\u6570\u636e\u4e0d\u7528\u7ffb\u904d\u786c\u76d8&#xff0c;\u800c\u662f\u6309\u76ee\u5f55\u4e00\u6b65\u6b65\u5b9a\u4f4d\u3002<\/p>\n<p>\u4f46\u6570\u636e\u5e93\u5efa\u76ee\u5f55\u4e0d\u662f\u968f\u4fbf\u5efa\u7684&#xff0c;\u56e0\u4e3a\u786c\u76d8\u548c\u56fe\u4e66\u9986\u4ed3\u5e93\u8fd8\u6709\u4e2a\u533a\u522b&#xff1a;\u786c\u76d8\u53ea\u80fd\u6309 \u201c\u56fa\u5b9a\u5927\u5c0f\u7684\u5c0f\u5757\u201d \u8bfb\u5199\u6570\u636e&#xff0c;\u5c31\u50cf\u56fe\u4e66\u9986\u53ea\u80fd\u6309 \u201c16 \u9875\u7684\u5c0f\u8584\u4e66\u201d \u4e3a\u5355\u4f4d\u501f\u4e66\u3001\u8fd8\u4e66&#xff0c;\u54ea\u6015\u4f60\u53ea\u770b 1 \u9875&#xff0c;\u4e5f\u8981\u628a\u6574\u672c 16 \u9875\u7684\u8584\u4e66\u62ff\u51fa\u6765\u3002\u8fd9\u4e2a \u201c\u56fa\u5b9a\u5927\u5c0f\u7684\u5c0f\u5757\u201d&#xff0c;\u5c31\u662f MySQL \u91cc\u7684\u9875&#xff08;Page&#xff09;&#xff0c;\u4e5f\u662f\u7d22\u5f15\u8bbe\u8ba1\u7684\u6700\u5c0f\u5355\u4f4d\u2014\u2014 \u6240\u6709\u7684\u6570\u636e\u3001\u6240\u6709\u7684\u76ee\u5f55&#xff0c;\u90fd\u5fc5\u987b\u88c5\u5728\u8fd9\u4e2a \u201c\u5c0f\u5757\u201d \u91cc&#xff0c;\u7d22\u5f15\u7684\u6240\u6709\u8bbe\u8ba1&#xff0c;\u90fd\u662f\u56f4\u7ed5\u8fd9\u4e2a \u201c\u5c0f\u5757\u201d \u5c55\u5f00\u7684\u3002<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u54b1\u4eec\u4ece \u201c\u9875\u662f\u4ec0\u4e48\u201d \u5f00\u59cb&#xff0c;\u4e00\u6b65\u6b65\u8bb2\u900f\u7d22\u5f15\u7684\u6574\u4e2a\u8bbe\u8ba1\u903b\u8f91&#xff0c;\u5168\u7a0b\u5927\u767d\u8bdd&#xff0c;\u7ec6\u8282\u62c9\u6ee1&#xff0c;\u4fdd\u8bc1\u8ba9\u4f60\u770b\u5230\u6700\u540e\u5f7b\u5e95\u660e\u767d \u201c\u7d22\u5f15\u5230\u5e95\u662f\u600e\u4e48\u8bbe\u8ba1\u51fa\u6765\u7684\u201d\u3002<\/p>\n<h3>\u4e00\u3001\u5148\u641e\u61c2\u7d22\u5f15\u8bbe\u8ba1\u7684\u6700\u5c0f\u5355\u4f4d&#xff1a;\u9875&#xff08;Page&#xff09;\u2014\u2014 \u786c\u76d8\u7684 \u201c\u56fa\u5b9a\u5927\u5c0f\u5c0f\u8584\u4e66\u201d<\/h3>\n<p><span style=\"color:#fe2c24\">MySQL \u7ed9\u9875\u5b9a\u4e86\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f&#xff1a;16KB&#xff08;16384 \u5b57\u8282&#xff0c;\u8fd9\u4e2a\u5927\u5c0f\u51e0\u4e4e\u4e0d\u4f1a\u6539&#xff0c;\u5c31\u50cf\u56fe\u4e66\u9986\u7edf\u4e00\u628a\u5c0f\u8584\u4e66\u505a\u6210 16 \u9875&#xff09;\u3002\u4e0d\u7ba1\u662f\u5b9e\u9645\u7684\u4e1a\u52a1\u6570\u636e&#xff08;\u6bd4\u5982\u7528\u6237 id\u3001\u59d3\u540d\u3001\u5e74\u9f84&#xff09;&#xff0c;\u8fd8\u662f\u7ed9\u6570\u636e\u5efa\u7684\u76ee\u5f55&#xff0c;\u90fd\u5fc5\u987b\u88c5\u5728\u8fd9\u4e2a 16KB \u7684\u9875\u91cc&#xff0c;\u786c\u76d8\u548c MySQL \u4ea4\u4e92&#xff0c;\u4e5f\u53ea\u80fd \u201c\u4e00\u9875\u4e00\u9875\u201d \u6765 \u2014\u2014 \u8bfb\u6570\u636e\u5c31\u662f\u8bfb\u6574\u9875&#xff0c;\u5199\u6570\u636e\u4e5f\u662f\u5199\u6574\u9875&#xff0c;\u6ca1\u6709 \u201c\u8bfb\u534a\u9875\u3001\u5199\u534a\u9875\u201d \u7684\u8bf4\u6cd5\u3002<\/span><\/p>\n<p>\u8fd9\u662f\u7d22\u5f15\u8bbe\u8ba1\u7684\u7b2c\u4e00\u539f\u5219&#xff1a;\u4e00\u5207\u7686\u9875&#xff0c;\u6240\u6709\u64cd\u4f5c\u56f4\u7ed5\u9875\u5c55\u5f00\u3002<\/p>\n<h4>1.1 \u9875\u7684\u4e24\u4e2a\u6838\u5fc3\u7c7b\u578b&#xff1a;\u6570\u636e\u9875&#xff08;\u5b58\u6b63\u6587\u7684\u8584\u4e66&#xff09;&#043; \u76ee\u5f55\u9875&#xff08;\u5b58\u6307\u5f15\u7684\u76ee\u5f55\u672c&#xff09;<\/h4>\n<p>\u5c31\u50cf\u56fe\u4e66\u9986\u7684\u8584\u4e66\u5206 \u201c\u5b58\u6b63\u6587\u7684\u6545\u4e8b\u4e66\u201d \u548c \u201c\u5b58\u6307\u5f15\u7684\u76ee\u5f55\u672c\u201d&#xff0c;MySQL \u7684\u9875\u4e5f\u5206\u4e24\u79cd\u6838\u5fc3\u7c7b\u578b&#xff0c;\u5404\u53f8\u5176\u804c&#xff0c;\u7edd\u4e0d\u6df7\u88c5 \u2014\u2014 \u8fd9\u662f\u7d22\u5f15\u8bbe\u8ba1\u7684\u7b2c\u4e8c\u539f\u5219&#xff0c;\u4e5f\u662f\u76ee\u5f55\u80fd\u9ad8\u6548\u6307\u5f15\u7684\u5173\u952e\u3002<\/p>\n<ul>\n<li><span style=\"color:#ff9900\">\u6570\u636e\u9875&#xff1a;\u4e13\u95e8\u5b58\u5b9e\u9645\u7684\u4e1a\u52a1\u6570\u636e&#xff0c;\u6bd4\u5982\u7528\u6237\u8868\u7684 id&#061;1\u3001\u59d3\u540d &#061; \u5f20\u4e09\u3001\u5e74\u9f84 &#061; 25&#xff0c;\u8ba2\u5355\u8868\u7684\u8ba2\u5355\u53f7 &#061; O123\u3001\u91d1\u989d &#061; 99&#xff0c;\u8fd9\u4e9b\u5b9e\u5b9e\u5728\u5728\u7684\u5185\u5bb9&#xff0c;\u90fd\u5b58\u5728\u6570\u636e\u9875\u91cc\u3002\u6570\u636e\u9875\u5c31\u50cf\u56fe\u4e66\u9986\u91cc\u5199\u6ee1\u6b63\u6587\u7684 16 \u9875\u5c0f\u8584\u4e66&#xff0c;\u662f\u6570\u636e\u7684\u6700\u7ec8\u8f7d\u4f53\u3002<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u76ee\u5f55\u9875&#xff1a;\u4e13\u95e8\u5b58\u6570\u636e\u7684\u6307\u5f15\u4fe1\u606f&#xff0c;\u4e0d\u5b58\u4efb\u4f55\u5b9e\u9645\u4e1a\u52a1\u6570\u636e&#xff0c;\u53ea\u8bb0 \u201c\u67d0\u6bb5\u6570\u636e\u5b58\u5728\u54ea\u4e2a\u6570\u636e\u9875\u91cc\u201d\u201c\u8fd9\u4e2a\u6570\u636e\u9875\u91cc\u7684\u6570\u8303\u56f4\u662f\u591a\u5c11\u201d\u3002\u76ee\u5f55\u9875\u5c31\u50cf\u56fe\u4e66\u9986\u91cc\u53ea\u5199\u76ee\u5f55\u7684\u5c0f\u672c\u5b50&#xff0c;\u672c\u5b50\u91cc\u53ea\u6709 \u201c\u300a\u5f20\u4e09\u7684\u8bb0\u5f55\u300b\u5728 3 \u6392 5 \u53f7\u8584\u4e66\u91cc\u201d\u201cid&#061;1-16 \u7684\u8bb0\u5f55\u5728\u9875\u53f7 100 \u7684\u8584\u4e66\u91cc\u201d \u8fd9\u79cd\u6307\u5f15&#xff0c;\u6ca1\u6709\u6b63\u6587\u3002<\/span><\/li>\n<\/ul>\n<p><span style=\"color:#a2e043\">\u9664\u6b64\u4e4b\u5916&#xff0c;\u6bcf\u4e2a\u9875\u8fd8\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u8eab\u4efd\u8bc1\u53f7 \u2014\u2014 \u9875\u53f7&#xff0c;\u5c31\u50cf\u56fe\u4e66\u9986\u7ed9\u6bcf\u672c\u8584\u4e66\u3001\u6bcf\u4e2a\u76ee\u5f55\u672c\u7f16\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u53f7&#xff08;\u6bd4\u5982\u9875\u53f7 100\u3001\u9875\u53f7 200&#xff09;&#xff0c;\u6570\u636e\u5e93\u53ea\u8981\u77e5\u9053\u9875\u53f7&#xff0c;\u5c31\u80fd\u76f4\u63a5\u5728\u786c\u76d8\u4e0a\u627e\u5230\u8fd9\u4e2a\u9875&#xff0c;\u4e0d\u7528\u518d\u7ffb\u627e \u2014\u2014 \u8fd9\u662f\u7d22\u5f15\u80fd\u5feb\u901f\u5b9a\u4f4d\u7684\u6838\u5fc3\u57fa\u7840&#xff0c;\u6240\u6709\u76ee\u5f55\u9875\u91cc\u7684\u6307\u5f15&#xff0c;\u6700\u7ec8\u90fd\u662f\u6307\u5411\u67d0\u4e2a\u9875\u7684\u9875\u53f7\u3002<\/span><\/p>\n<h4>1.2 \u9875\u7684\u4e24\u4e2a\u57fa\u7840\u8bbe\u8ba1&#xff1a;\u6709\u5e8f\u6392\u5217 &#043; \u53cc\u5411\u94fe\u8868&#xff0c;\u4e3a \u201c\u5efa\u76ee\u5f55\u201d \u6253\u57fa\u7840<\/h4>\n<p>\u4e0d\u7ba1\u662f\u6570\u636e\u9875\u8fd8\u662f\u76ee\u5f55\u9875&#xff0c;\u6570\u636e\u5e93\u90fd\u4f1a\u7ed9\u5b83\u4eec\u505a\u4e24\u4e2a\u57fa\u7840\u8bbe\u8ba1&#xff0c;\u8fd9\u4e24\u4e2a\u8bbe\u8ba1\u770b\u8d77\u6765\u7b80\u5355&#xff0c;\u5374\u662f\u540e\u7eed\u6240\u6709\u76ee\u5f55\u8bbe\u8ba1\u7684\u524d\u63d0&#xff0c;\u5c31\u50cf\u56fe\u4e66\u9986\u4f1a\u628a\u6240\u6709\u8584\u4e66\u6309\u7f16\u53f7\u6392\u597d&#xff0c;\u8fd8\u5728\u6bcf\u672c\u8584\u4e66\u7684\u5c01\u9762\u4e0a\u6807\u4e0a \u201c\u4e0a\u4e00\u672c\u7f16\u53f7\u201d\u201c\u4e0b\u4e00\u672c\u7f16\u53f7\u201d&#xff1a;<\/p>\n<li><span style=\"color:#ff9900\">\u6309\u5173\u952e\u5b57\u6709\u5e8f\u6392\u5217&#xff1a;\u6570\u636e\u9875\u4f1a\u6309\u4e3b\u952e\u4ece\u5c0f\u5230\u5927\u6392&#xff08;\u6bd4\u5982 id&#061;1-16 \u7684\u653e\u4e00\u4e2a\u6570\u636e\u9875&#xff0c;id&#061;17-32 \u7684\u653e\u4e0b\u4e00\u4e2a&#xff09;&#xff0c;\u76ee\u5f55\u9875\u4f1a\u6309\u81ea\u5df1\u7684\u6307\u5f15\u5173\u952e\u5b57\u4ece\u5c0f\u5230\u5927\u6392&#xff08;\u6bd4\u5982\u6309\u4e3b\u952e\u8303\u56f4\u6392&#xff09;\u2014\u2014 \u6709\u5e8f\u662f\u80fd\u5efa\u76ee\u5f55\u7684\u524d\u63d0&#xff0c;\u5982\u679c\u6570\u636e\u4e71\u5806&#xff0c;\u76ee\u5f55\u6839\u672c\u6ca1\u6cd5\u8bb0&#xff0c;\u6240\u4ee5\u806a\u660e\u7684\u4f60\u4e00\u4e0b\u5b50\u5c31\u60f3\u5230\u4e86&#xff0c;\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728\u4f7f\u7528\u4e3b\u952e\u7684\u65f6\u5019&#xff0c;mysql\u4f1a\u8fdb\u884c\u6392\u5e8f\u5462&#xff0c;\u539f\u56e0\u5c31\u662f\u5728\u8fd9\u91cc\u54e6&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u53cc\u5411\u94fe\u8868\u8fde\u63a5&#xff1a;\u6bcf\u4e2a\u9875\u7684 \u201c\u5c01\u9762\u201d&#xff08;\u9875\u5934&#xff09;\u90fd\u4f1a\u8bb0\u4e0a\u4e0a\u4e00\u4e2a\u9875\u7684\u9875\u53f7\u548c\u4e0b\u4e00\u4e2a\u9875\u7684\u9875\u53f7&#xff0c;\u5c31\u50cf\u56fe\u4e66\u9986\u8584\u4e66\u7684\u5c01\u9762\u6807\u7740 \u201c\u4e0a\u4e00\u672c\u662f 3 \u6392 4 \u53f7&#xff0c;\u4e0b\u4e00\u672c\u662f 3 \u6392 6 \u53f7\u201d&#xff0c;\u6240\u6709\u9875\u8fde\u8d77\u6765\u5f62\u6210\u4e00\u4e2a\u73af\u5f62\u7684\u94fe\u8868 \u2014\u2014 \u8fd9\u6837\u627e\u6570\u636e\u65f6&#xff0c;\u627e\u5230\u4e00\u4e2a\u9875&#xff0c;\u5c31\u80fd\u987a\u7740\u94fe\u8868\u627e\u5230\u4e0b\u4e00\u4e2a\u3001\u4e0a\u4e00\u4e2a&#xff0c;\u4e0d\u7528\u518d\u56de\u5934\u67e5\u76ee\u5f55&#xff0c;\u5c24\u5176\u9002\u5408 \u201c\u67e5 id&#061;1-100 \u8fd9\u79cd\u8303\u56f4\u6570\u636e\u201d\u3002<\/span><\/li>\n<p><span style=\"color:#a2e043\">\u5230\u8fd9\u91cc&#xff0c;\u4f60\u5148\u8bb0\u4f4f\u4e00\u4e2a\u7ed3\u8bba&#xff1a;MySQL \u91cc\u7684\u6240\u6709\u6570\u636e&#xff0c;\u90fd\u88ab\u62c6\u6210\u4e86\u4e00\u4e2a\u4e2a 16KB \u7684 Data \u9875&#xff0c;\u6309\u4e3b\u952e\u6709\u5e8f\u6392\u597d&#xff0c;\u7528\u53cc\u5411\u94fe\u8868\u8fde\u8d77\u6765&#xff0c;\u6bcf\u4e2a Data \u9875\u6709\u552f\u4e00\u7684\u9875\u53f7&#xff1b;\u800c\u7d22\u5f15&#xff0c;\u5c31\u662f\u7ed9\u8fd9\u4e9b Data \u9875\u5efa\u4e00\u5957 \u201c\u76ee\u5f55\u672c&#xff08;\u76ee\u5f55\u9875&#xff09;\u201d&#xff0c;\u8ba9\u6570\u636e\u5e93\u80fd\u6309\u76ee\u5f55\u627e Data \u9875&#xff0c;\u4e0d\u7528\u7ffb\u904d\u6240\u6709 Data \u9875\u3002<\/span><\/p>\n<h3>\u4e8c\u3001\u6570\u636e\u9875\u7684\u8be6\u7ec6\u8bbe\u8ba1&#xff1a;\u5b58\u5b9e\u9645\u6570\u636e\u7684 \u201c\u8584\u4e66\u201d&#xff0c;\u5185\u90e8\u4e5f\u6709 \u201c\u5c0f\u76ee\u5f55\u201d<\/h3>\n<p>\u54b1\u4eec\u5148\u628a \u201c\u5b58\u6570\u636e\u7684\u8f7d\u4f53 \u2014\u2014 \u6570\u636e\u9875\u201d \u8bb2\u900f&#xff0c;\u56e0\u4e3a\u76ee\u5f55\u9875\u6700\u7ec8\u90fd\u662f\u6307\u5411\u6570\u636e\u9875\u7684&#xff0c;\u6570\u636e\u9875\u600e\u4e48\u8bbe\u8ba1&#xff0c;\u51b3\u5b9a\u4e86\u76ee\u5f55\u9875\u8be5\u600e\u4e48\u5efa\u3002<\/p>\n<p>\u8fd8\u662f\u7528\u7c7b\u6bd4&#xff1a;\u6570\u636e\u9875\u662f16 \u9875\u7684\u8584\u4e66&#xff08;16KB&#xff09;&#xff0c;\u8fd9\u672c\u8584\u4e66\u7684\u5185\u90e8\u6392\u7248\u662f\u56fa\u5b9a\u7684&#xff0c;\u5c31\u50cf\u6240\u6709\u6545\u4e8b\u4e66\u90fd\u6709 \u201c\u5c01\u9762\u2192\u76ee\u5f55\u2192\u6b63\u6587\u2192\u5c01\u5e95\u201d&#xff0c;\u6570\u636e\u9875\u4e5f\u6709\u56fa\u5b9a\u7684\u7ed3\u6784&#xff1a;\u9875\u5934&#xff08;\u5c01\u9762&#xff09;\u2192\u9875\u4f53&#xff08;\u76ee\u5f55 &#043; \u6b63\u6587&#xff09;\u2192\u9875\u5c3e&#xff08;\u5c01\u5e95&#xff09;&#xff0c;\u603b\u5927\u5c0f\u521a\u597d 16KB&#xff0c;\u4e00\u70b9\u4e0d\u591a\u4e00\u70b9\u4e0d\u5c11\u3002<\/p>\n<h4>2.1 \u9875\u5934&#xff1a;\u6570\u636e\u9875\u7684 \u201c\u5c01\u9762\u201d&#xff0c;\u5b58\u57fa\u7840\u4fe1\u606f&#xff0c;\u4e00\u773c\u5c31\u80fd\u770b\u61c2<\/h4>\n<p><span style=\"color:#ff9900\">\u6570\u636e\u9875\u7684\u5f00\u5934\u662f\u9875\u5934&#xff08;File Header&#xff09;&#xff0c;\u5360 38 \u4e2a\u5b57\u8282&#xff08;\u76f8\u5f53\u4e8e\u8584\u4e66\u7684\u5c01\u9762&#xff0c;\u5c31\u51e0\u884c\u5b57&#xff09;&#xff0c;\u91cc\u9762\u53ea\u5b58\u8fd9\u672c \u201c\u8584\u4e66\u201d \u7684\u57fa\u7840\u4fe1\u606f&#xff0c;\u6570\u636e\u5e93\u62ff\u5230\u4e00\u4e2a\u6570\u636e\u9875&#xff0c;\u5148\u770b\u9875\u5934&#xff0c;\u5c31\u77e5\u9053\u8fd9\u672c\u8584\u4e66\u662f\u5e72\u561b\u7684\u3001\u7f16\u53f7\u662f\u591a\u5c11\u3001\u548c\u8c01\u6328\u7740\u3002\u9875\u5934\u91cc\u7684\u6838\u5fc3\u4fe1\u606f\u5c31 4 \u4e2a&#xff0c;\u90fd\u662f\u4e3a\u4e86 \u201c\u5feb\u901f\u5b9a\u4f4d\u3001\u5feb\u901f\u5173\u8054\u201d<\/span>&#xff1a;<\/p>\n<li>\u9875\u53f7&#xff1a;\u8fd9\u672c\u6570\u636e\u9875\u7684\u552f\u4e00\u8eab\u4efd\u8bc1\u53f7&#xff0c;\u6bd4\u5982 100\u3001200&#xff0c;\u76ee\u5f55\u9875\u91cc\u7684\u6307\u5f15\u6700\u7ec8\u90fd\u662f\u6307\u5411\u8fd9\u4e2a\u9875\u53f7&#xff1b;<\/li>\n<li>\u9875\u7c7b\u578b&#xff1a;\u6807\u8bb0\u8fd9\u662f \u201c\u6570\u636e\u9875\u201d&#xff0c;\u4e0d\u662f \u201c\u76ee\u5f55\u9875\u201d&#xff0c;\u6570\u636e\u5e93\u4e00\u770b\u5c31\u77e5\u9053\u8fd9\u9875\u662f\u5b58\u6570\u636e\u7684&#xff1b;<\/li>\n<li>\u4e0a\u4e00\u9875\u53f7 \/ \u4e0b\u4e00\u9875\u53f7&#xff1a;\u5c31\u662f\u53cc\u5411\u94fe\u8868\u7684\u6307\u9488&#xff0c;\u6bd4\u5982\u9875\u53f7 100 \u7684\u6570\u636e\u9875&#xff0c;\u4e0a\u4e00\u9875\u53f7\u662f 99&#xff0c;\u4e0b\u4e00\u9875\u53f7\u662f 101&#xff0c;\u987a\u7740\u8fd9\u4e2a\u5c31\u80fd\u627e\u5230\u6240\u6709\u76f8\u90bb\u7684\u6570\u636e\u9875&#xff1b;<\/li>\n<li>\u8bb0\u5f55\u6570&#xff1a;\u8fd9\u672c\u6570\u636e\u9875\u91cc\u5b58\u4e86\u591a\u5c11\u6761\u5b9e\u9645\u7684\u4e1a\u52a1\u8bb0\u5f55&#xff0c;\u6bd4\u5982 16 \u6761\u300115 \u6761&#xff0c;\u6570\u636e\u5e93\u4e00\u770b\u5c31\u77e5\u9053\u8fd9\u9875\u6709\u6ca1\u6709\u7a7a\u4f4d\u7f6e\u3002<\/li>\n<p><span style=\"color:#a2e043\">\u9664\u6b64\u4e4b\u5916&#xff0c;\u9875\u5934\u91cc\u8fd8\u6709\u4e00\u4e9b\u6821\u9a8c\u4fe1\u606f&#xff0c;\u4e0d\u7528\u7ba1&#xff0c;\u6838\u5fc3\u5c31\u662f\u4e0a\u9762 4 \u4e2a \u2014\u2014 \u8bbe\u8ba1\u9875\u5934\u7684\u552f\u4e00\u76ee\u7684&#xff0c;\u5c31\u662f\u8ba9\u6570\u636e\u5e93\u80fd\u5feb\u901f\u8bc6\u522b\u8fd9\u4e2a\u6570\u636e\u9875\u7684\u57fa\u672c\u4fe1\u606f&#xff0c;\u4e0d\u7528\u8bfb\u6b63\u6587&#xff0c;\u5c31\u80fd\u77e5\u9053\u5b83\u7684\u7f16\u53f7\u3001\u90bb\u5c45\u3001\u5b58\u4e86\u591a\u5c11\u6570\u636e\u3002<\/span><\/p>\n<h4>2.2 \u9875\u4f53&#xff1a;\u6570\u636e\u9875\u7684 \u201c\u6838\u5fc3\u5185\u5bb9\u533a\u201d&#xff0c;\u6709 \u201c\u5c0f\u76ee\u5f55\u201d&#043;\u201c\u6b63\u6587\u201d&#xff0c;\u627e\u6570\u636e\u4e0d\u7528\u9010\u884c\u7ffb<\/h4>\n<p>\u9875\u4f53\u662f\u6570\u636e\u9875\u7684\u6838\u5fc3&#xff0c;\u5360\u4e86\u5dee\u4e0d\u591a 16KB-100 \u5b57\u8282\u7684\u7a7a\u95f4&#xff08;\u8584\u4e66\u7684\u6b63\u6587 &#043; \u5185\u90e8\u5c0f\u76ee\u5f55&#xff09;&#xff0c;\u4e5f\u662f\u6570\u636e\u9875\u8bbe\u8ba1\u6700\u7cbe\u5999\u7684\u5730\u65b9 \u2014\u2014 \u5b83\u88ab\u5206\u6210\u4e86\u4e24\u90e8\u5206&#xff1a;<span style=\"color:#fe2c24\">\u69fd\u4f4d\u76ee\u5f55&#xff08;\u9875\u5185\u5c0f\u76ee\u5f55&#xff09;&#043; \u6570\u636e\u8bb0\u5f55\u533a&#xff08;\u6b63\u6587&#xff09;&#xff0c;\u800c\u4e14\u6570\u636e\u8bb0\u5f55\u533a\u7684\u8bb0\u5f55&#xff0c;\u5fc5\u987b\u6309\u4e3b\u952e\u4ece\u5c0f\u5230\u5927\u6709\u5e8f\u6392\u5217\u3002<\/span><\/p>\n<p><span style=\"color:#ffd900\">\u54b1\u4eec\u5148\u8bb2\u6570\u636e\u8bb0\u5f55\u533a&#xff1a;\u8fd9\u90e8\u5206\u5c31\u662f\u5b58\u5b9e\u9645\u4e1a\u52a1\u6570\u636e\u7684\u5730\u65b9&#xff0c;\u6bd4\u5982\u7528\u6237\u8868\u7684 id&#061;1 \u59d3\u540d &#061; \u5f20\u4e09 \u5e74\u9f84 &#061; 25\u3001id&#061;2 \u59d3\u540d &#061; \u674e\u56db \u5e74\u9f84 &#061; 30&#xff0c;\u4e00\u6761\u6761\u8bb0\u5f55\u6309\u4e3b\u952e id \u7684\u987a\u5e8f\u6392\u597d&#xff0c;\u5c31\u50cf\u8584\u4e66\u91cc\u7684\u6b63\u6587\u6309\u7ae0\u8282\u987a\u5e8f\u6392\u597d&#xff0c;\u7edd\u4e0d\u4e71\u5e8f\u3002\u8fd9\u91cc\u6709\u4e2a\u5173\u952e\u8bbe\u8ba1&#xff1a;1 \u4e2a\u6570\u636e\u9875\u80fd\u5b58\u591a\u5c11\u6761\u8bb0\u5f55&#xff0c;\u53d6\u51b3\u4e8e\u5355\u6761\u8bb0\u5f55\u7684\u5927\u5c0f\u2014\u2014 \u5982\u679c\u5355\u6761\u8bb0\u5f55 1KB&#xff0c;\u90a3 16KB \u7684\u6570\u636e\u9875\u5c31\u80fd\u5b58 16 \u6761&#xff1b;\u5982\u679c\u5355\u6761\u8bb0\u5f55 2KB&#xff0c;\u5c31\u53ea\u80fd\u5b58 8 \u6761&#xff0c;\u53cd\u6b63\u603b\u5927\u5c0f\u4e0d\u80fd\u8d85\u8fc7 16KB\u3002<\/span><\/p>\n<p><span style=\"color:#ffd900\">\u7136\u540e\u662f\u69fd\u4f4d\u76ee\u5f55&#xff08;Slot Directory&#xff09;&#xff1a;\u8fd9\u662f\u6570\u636e\u9875\u7684 \u201c\u7075\u9b42\u8bbe\u8ba1\u201d&#xff0c;\u4e5f\u662f\u4e3a\u4e86\u89e3\u51b3 \u201c\u6570\u636e\u9875\u91cc\u5b58\u4e86 16 \u6761\u8bb0\u5f55&#xff0c;\u627e id&#061;10 \u7684\u8bb0\u5f55&#xff0c;\u96be\u9053\u8981\u9010\u884c\u7ffb 16 \u6761\u5417&#xff1f;\u201d \u7684\u95ee\u9898 \u2014\u2014 \u69fd\u4f4d\u76ee\u5f55\u5c31\u662f\u6570\u636e\u9875\u5185\u90e8\u7684\u5c0f\u76ee\u5f55&#xff0c;\u5c31\u50cf\u8584\u4e66\u91cc\u7684 \u201c\u7ae0\u8282\u76ee\u5f55\u201d&#xff0c;\u6807\u7740 \u201c\u7b2c 1 \u7ae0\u5728\u7b2c 1 \u9875&#xff0c;\u7b2c 10 \u7ae0\u5728\u7b2c 10 \u9875\u201d&#xff0c;\u8ba9\u4f60\u4e0d\u7528\u9010\u9875\u7ffb\u5c31\u80fd\u627e\u5230\u76ee\u6807\u5185\u5bb9\u3002<\/span><\/p>\n<p>\u69fd\u4f4d\u76ee\u5f55\u7684\u8bbe\u8ba1\u7279\u522b\u7b80\u5355&#xff1a;\u5b83\u662f\u4e00\u4e2a\u6709\u5e8f\u7684\u5c0f\u6570\u7ec4&#xff0c;\u6570\u7ec4\u91cc\u7684\u6bcf\u4e2a\u5143\u7d20&#xff0c;\u53ea\u5b58 \u201c\u67d0\u6761\u8bb0\u5f55\u5728\u6570\u636e\u9875\u91cc\u7684\u5177\u4f53\u4f4d\u7f6e&#xff08;\u504f\u79fb\u91cf&#xff09;\u201d\u2014\u2014 \u6bd4\u5982\u6570\u7ec4\u7684\u7b2c 1 \u4e2a\u5143\u7d20&#xff0c;\u5b58 id&#061;1 \u7684\u8bb0\u5f55\u5728\u6570\u636e\u9875\u91cc\u7684\u4f4d\u7f6e&#xff0c;\u7b2c 10 \u4e2a\u5143\u7d20&#xff0c;\u5b58 id&#061;10 \u7684\u8bb0\u5f55\u5728\u6570\u636e\u9875\u91cc\u7684\u4f4d\u7f6e\u3002\u56e0\u4e3a\u6570\u636e\u8bb0\u5f55\u533a\u662f\u6309\u4e3b\u952e\u6709\u5e8f\u7684&#xff0c;\u6240\u4ee5\u69fd\u4f4d\u76ee\u5f55\u4e5f\u662f\u6309\u4e3b\u952e\u6709\u5e8f\u7684&#xff0c;\u627e\u8bb0\u5f55\u65f6&#xff0c;\u6570\u636e\u5e93\u4f1a\u5148\u4e8c\u5206\u67e5\u627e\u69fd\u4f4d\u76ee\u5f55&#xff08;\u6bd4\u5982\u627e id&#061;10&#xff0c;\u5148\u5728\u69fd\u4f4d\u76ee\u5f55\u91cc\u627e\u5230\u7b2c 10 \u4e2a\u5143\u7d20&#xff09;&#xff0c;\u518d\u6839\u636e\u5143\u7d20\u91cc\u7684\u4f4d\u7f6e&#xff0c;\u76f4\u63a5\u8df3\u8f6c\u5230\u76ee\u6807\u8bb0\u5f55&#xff0c;\u4e0d\u7528\u9010\u884c\u7ffb\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;\u6570\u636e\u9875\u91cc\u5b58\u4e86 id&#061;1-16 \u7684 16 \u6761\u8bb0\u5f55&#xff0c;\u8981\u627e id&#061;10 \u7684\u8bb0\u5f55&#xff0c;\u6570\u636e\u5e93\u4e0d\u4f1a\u4ece id&#061;1 \u5f00\u59cb\u6570&#xff0c;\u800c\u662f\u5148\u67e5\u69fd\u4f4d\u76ee\u5f55&#xff0c;\u627e\u5230\u7b2c 10 \u4e2a\u5143\u7d20&#xff0c;\u8fd9\u4e2a\u5143\u7d20\u6807\u7740 \u201cid&#061;10 \u7684\u8bb0\u5f55\u5728\u6570\u636e\u9875\u7684\u7b2c 800 \u5b57\u8282\u4f4d\u7f6e\u201d&#xff0c;\u6570\u636e\u5e93\u76f4\u63a5\u8df3\u5230 800 \u5b57\u8282&#xff0c;\u5c31\u80fd\u62ff\u5230 id&#061;10 \u7684\u8bb0\u5f55&#xff0c;\u4e00\u6b65\u5230\u4f4d\u3002<\/p>\n<p><span style=\"color:#a2e043\">\u8bbe\u8ba1\u69fd\u4f4d\u76ee\u5f55\u7684\u6838\u5fc3\u76ee\u7684&#xff1a;\u628a\u6570\u636e\u9875\u5185\u7684\u67e5\u627e\u6548\u7387&#xff0c;\u4ece \u201c\u9010\u884c\u7ffb\u7684 O (N)\u201d \u63d0\u5347\u5230 \u201c\u4e8c\u5206\u67e5\u627e\u7684 O (logN)\u201d&#xff0c;\u54ea\u6015\u6570\u636e\u9875\u91cc\u5b58\u6ee1\u4e86\u8bb0\u5f55&#xff0c;\u627e\u4e00\u6761\u4e5f\u53ea\u8981\u51e0\u6b65\u3002<\/span><\/p>\n<h4>2.3 \u9875\u5c3e&#xff1a;\u6570\u636e\u9875\u7684 \u201c\u5c01\u5e95\u201d&#xff0c;\u5b58\u6821\u9a8c\u4fe1\u606f&#xff0c;\u4fdd\u8bc1\u6570\u636e\u6ca1\u574f<\/h4>\n<p>\u6570\u636e\u9875\u7684\u6700\u540e\u662f\u9875\u5c3e&#xff08;File Trailer&#xff09;&#xff0c;\u5360 8 \u4e2a\u5b57\u8282&#xff08;\u8584\u4e66\u7684\u5c01\u5e95&#xff09;&#xff0c;\u91cc\u9762\u53ea\u5b58\u4e24\u4e2a\u6821\u9a8c\u4fe1\u606f&#xff1a;\u6821\u9a8c\u548c &#043; LSN&#xff0c;<span style=\"color:#b95514\">\u4f5c\u7528\u5c31\u50cf\u8584\u4e66\u5c01\u5e95\u7684\u9632\u4f2a\u6807&#xff0c;\u4fdd\u8bc1\u8fd9\u672c\u6570\u636e\u9875\u7684\u5185\u5bb9\u5728\u786c\u76d8\u4e0a\u6ca1\u88ab\u635f\u574f\u3001\u6ca1\u88ab\u7be1\u6539\u3002<\/span>\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\u9875\u65f6&#xff0c;\u4f1a\u5148\u7b97\u4e00\u904d\u6570\u636e\u9875\u7684\u6821\u9a8c\u548c&#xff0c;\u548c\u9875\u5c3e\u91cc\u7684\u6821\u9a8c\u548c\u5bf9\u6bd4&#xff0c;\u5982\u679c\u4e0d\u4e00\u6837&#xff0c;\u5c31\u8bf4\u660e\u6570\u636e\u9875\u574f\u4e86&#xff0c;\u76f4\u63a5\u653e\u5f03\u8bfb\u53d6&#xff1b;\u5982\u679c\u4e00\u6837&#xff0c;\u5c31\u8bf4\u660e\u6570\u636e\u662f\u5b8c\u6574\u7684&#xff0c;\u53ef\u4ee5\u6b63\u5e38\u7528\u3002<\/p>\n<p>\u9875\u5c3e\u7684\u8bbe\u8ba1\u5f88\u7b80\u5355&#xff0c;\u6838\u5fc3\u5c31\u662f\u4fdd\u8bc1\u6570\u636e\u9875\u7684\u5b8c\u6574\u6027&#xff0c;\u6ca1\u6709\u5176\u4ed6\u590d\u6742\u7684\u903b\u8f91\u3002<\/p>\n<h4>2.4 \u6570\u636e\u9875\u7684\u6838\u5fc3\u8bbe\u8ba1\u603b\u7ed3&#xff1a;\u6709\u5e8f &#043; \u5185\u90e8\u5c0f\u76ee\u5f55&#xff0c;\u4e3a \u201c\u5efa\u5916\u90e8\u5927\u76ee\u5f55\u201d \u6253\u57fa\u7840<\/h4>\n<p>\u54b1\u4eec\u628a\u6570\u636e\u9875\u7684\u8bbe\u8ba1\u603b\u7ed3\u4e00\u4e0b&#xff0c;\u6838\u5fc3\u5c31\u4e09\u4e2a\u70b9&#xff0c;\u8fd9\u4e09\u4e2a\u70b9\u90fd\u662f\u540e\u7eed\u5efa\u76ee\u5f55\u9875\u7684\u57fa\u7840&#xff1a;<\/p>\n<li><span style=\"color:#ff9900\">\u56fa\u5b9a\u5927\u5c0f 16KB&#xff1a;\u548c\u786c\u76d8\u4ea4\u4e92\u7684\u6700\u5c0f\u5355\u4f4d&#xff0c;\u6570\u636e\u5e93\u53ea\u80fd\u4e00\u9875\u4e00\u9875\u8bfb \/ \u5199&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u4e3b\u952e\u6709\u5e8f\u6392\u5217 &#043; \u53cc\u5411\u94fe\u8868&#xff1a;\u6570\u636e\u9875\u5185\u7684\u8bb0\u5f55\u6309\u4e3b\u952e\u6392&#xff0c;\u6570\u636e\u9875\u4e4b\u95f4\u6309\u4e3b\u952e\u6392&#xff0c;\u8fd8\u7528\u53cc\u5411\u94fe\u8868\u8fde\u8d77\u6765&#xff0c;\u6709\u5e8f\u662f\u5efa\u76ee\u5f55\u7684\u524d\u63d0&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u5185\u7f6e\u69fd\u4f4d\u76ee\u5f55&#xff1a;\u6570\u636e\u9875\u5185\u627e\u8bb0\u5f55\u4e0d\u7528\u9010\u884c\u7ffb&#xff0c;\u4e8c\u5206\u67e5\u627e\u69fd\u4f4d\u76ee\u5f55\u5c31\u80fd\u5b9a\u4f4d&#xff0c;\u4fdd\u8bc1\u9875\u5185\u67e5\u627e\u9ad8\u6548\u3002<\/span><\/li>\n<p>\u5230\u8fd9\u91cc&#xff0c;\u4f60\u53ef\u4ee5\u60f3\u8c61\u4e00\u4e0b&#xff1a;\u4f60\u7684\u6570\u636e\u5e93\u91cc\u6709 100 \u4e07\u6761\u7528\u6237\u8bb0\u5f55&#xff0c;\u6bcf\u6761\u8bb0\u5f55 1KB&#xff0c;\u8fd9\u4e9b\u8bb0\u5f55\u88ab\u5206\u6210\u4e8662500 \u4e2a\u6570\u636e\u9875&#xff08;100 \u4e07 \/ 16&#xff09;&#xff0c;\u6bcf\u4e2a\u6570\u636e\u9875\u5b58 16 \u6761&#xff0c;\u6309 id&#061;1-16\u300117-32\u2026\u2026 \u7684\u987a\u5e8f\u6392\u597d&#xff0c;\u6bcf\u672c\u6570\u636e\u9875\u7684\u5c01\u9762\u90fd\u6807\u4e86\u4e0a\u4e00\u672c\u548c\u4e0b\u4e00\u672c\u7684\u7f16\u53f7&#xff0c;\u5185\u90e8\u8fd8\u6709\u5c0f\u76ee\u5f55 \u2014\u2014 \u5982\u679c\u6ca1\u6709\u7d22\u5f15&#xff0c;\u6570\u636e\u5e93\u627e id&#061;50000 \u7684\u8bb0\u5f55&#xff0c;\u5c31\u8981\u4ece\u7b2c 1 \u4e2a\u6570\u636e\u9875\u5f00\u59cb&#xff0c;\u9010\u9875\u7ffb\u5230\u7b2c 3125 \u4e2a\u6570\u636e\u9875&#xff08;50000\/16&#xff09;&#xff0c;\u7ffb 3000 \u591a\u672c\u8584\u4e66&#xff0c;\u6162\u5f97\u79bb\u8c31&#xff1b;\u800c\u6709\u4e86\u7d22\u5f15&#xff0c;\u5c31\u662f\u7ed9\u8fd9 62500 \u4e2a\u6570\u636e\u9875&#xff0c;\u5efa\u4e00\u5957 \u201c\u76ee\u5f55\u672c&#xff08;\u76ee\u5f55\u9875&#xff09;\u201d&#xff0c;\u8ba9\u6570\u636e\u5e93\u6309\u76ee\u5f55\u672c\u76f4\u63a5\u627e\u5230\u7b2c 3125 \u4e2a\u6570\u636e\u9875&#xff0c;\u4e0d\u7528\u7ffb\u904d\u6240\u6709\u3002<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u54b1\u4eec\u5c31\u8bb2\u8fd9\u5957 \u201c\u76ee\u5f55\u672c&#xff08;\u76ee\u5f55\u9875&#xff09;\u201d \u662f\u600e\u4e48\u8bbe\u8ba1\u7684\u3002<\/p>\n<h3>\u4e09\u3001\u76ee\u5f55\u9875\u7684\u8be6\u7ec6\u8bbe\u8ba1&#xff1a;\u5b58\u6307\u5f15\u7684 \u201c\u5c0f\u672c\u5b50\u201d&#xff0c;\u53ea\u8bb0 \u201c\u6570\u636e\u9875\u7684\u8303\u56f4 &#043; \u9875\u53f7\u201d<\/h3>\n<p><span style=\"color:#fe2c24\">\u76ee\u5f55\u9875\u7684\u8bbe\u8ba1&#xff0c;\u6bd4\u6570\u636e\u9875\u7b80\u5355&#xff0c;\u56e0\u4e3a\u5b83\u4e0d\u7528\u5b58\u590d\u6742\u7684\u4e1a\u52a1\u6570\u636e&#xff0c;\u53ea\u5b58\u6570\u636e\u9875\u7684\u6307\u5f15\u4fe1\u606f\u2014\u2014 \u6838\u5fc3\u8bbe\u8ba1\u903b\u8f91\u662f&#xff1a;\u8f7b\u91cf\u5316\u3001\u6709\u5e8f\u3001\u53ea\u5b58\u5173\u952e\u6307\u5f15&#xff0c;\u76ee\u7684\u662f\u8ba9\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u5c3d\u53ef\u80fd\u591a\u7684\u6307\u5f15\u4fe1\u606f&#xff0c;\u51cf\u5c11\u76ee\u5f55\u7684\u5c42\u7ea7\u3002<\/span><\/p>\n<p>\u8fd8\u662f\u7528\u7c7b\u6bd4&#xff1a;<span style=\"color:#ff9900\">\u76ee\u5f55\u9875\u662f16 \u9875\u7684\u5c0f\u672c\u5b50&#xff08;16KB&#xff09;&#xff0c;\u8fd9\u4e2a\u5c0f\u672c\u5b50\u91cc\u6ca1\u6709\u4efb\u4f55\u6b63\u6587&#xff0c;\u53ea\u6709\u4e00\u884c\u884c\u7684 \u201c\u6307\u5f15\u9879\u201d&#xff0c;\u6bcf\u4e00\u884c\u6307\u5f15\u9879\u90fd\u53ea\u8bb0\u4e09\u4e2a\u4fe1\u606f&#xff1a;\u5bf9\u5e94\u6570\u636e\u9875\u7684\u6700\u5c0f\u4e3b\u952e\u503c &#043; \u6700\u5927\u4e3b\u952e\u503c &#043; \u6570\u636e\u9875\u53f7&#xff0c;\u6bd4\u5982 \u201c1-16&#xff0c;\u9875\u53f7 100\u201d\u201c17-32&#xff0c;\u9875\u53f7 101\u201d\u201c33-48&#xff0c;\u9875\u53f7 102\u201d\u2014\u2014 \u8bf4\u767d\u4e86&#xff0c;\u76ee\u5f55\u9875\u5c31\u662f \u201c\u6570\u636e\u9875\u7684\u6e05\u5355\u201d&#xff0c;\u8bb0\u7740\u6bcf\u672c\u6570\u636e\u9875\u5b58\u4e86\u4ec0\u4e48\u8303\u56f4\u7684\u6570\u636e\u3001\u7f16\u53f7\u662f\u591a\u5c11\u3002<\/span><\/p>\n<p>\u548c\u6570\u636e\u9875\u4e00\u6837&#xff0c;\u76ee\u5f55\u9875\u4e5f\u6709\u56fa\u5b9a\u7684\u7ed3\u6784&#xff1a;\u9875\u5934\u2192\u9875\u4f53\u2192\u9875\u5c3e&#xff0c;\u9875\u5934\u548c\u9875\u5c3e\u7684\u8bbe\u8ba1\u548c\u6570\u636e\u9875\u51e0\u4e4e\u4e00\u6a21\u4e00\u6837&#xff08;\u9875\u5934\u5b58\u9875\u53f7\u3001\u4e0a \/ \u4e0b\u4e00\u9875\u53f7\u3001\u9875\u7c7b\u578b&#xff1b;\u9875\u5c3e\u5b58\u6821\u9a8c\u4fe1\u606f&#xff09;&#xff0c;\u552f\u4e00\u7684\u533a\u522b\u5728\u9875\u4f53\u2014\u2014 \u76ee\u5f55\u9875\u7684\u9875\u4f53\u53ea\u5b58\u76ee\u5f55\u9879\u6570\u7ec4&#xff0c;\u6ca1\u6709\u69fd\u4f4d\u76ee\u5f55&#xff08;\u56e0\u4e3a\u76ee\u5f55\u9879\u672c\u8eab\u5c31\u662f\u6709\u5e8f\u7684&#xff0c;\u76f4\u63a5\u4e8c\u5206\u67e5\u627e\u5c31\u884c&#xff09;\u3002<\/p>\n<p>\u54b1\u4eec\u91cd\u70b9\u8bb2\u76ee\u5f55\u9875\u7684\u9875\u4f53\u548c\u76ee\u5f55\u9879&#xff0c;\u8fd9\u662f\u76ee\u5f55\u9875\u7684\u6838\u5fc3&#xff1a;<\/p>\n<h4>3.1 \u76ee\u5f55\u9879&#xff1a;\u76ee\u5f55\u9875\u7684 \u201c\u6838\u5fc3\u6307\u5f15\u5355\u5143\u201d&#xff0c;\u6781\u7b80\u8bbe\u8ba1&#xff0c;\u53ea\u5b58\u4e09\u4e2a\u5173\u952e\u4fe1\u606f<\/h4>\n<p>\u76ee\u5f55\u9879\u662f\u76ee\u5f55\u9875\u91cc\u7684\u6700\u5c0f\u6307\u5f15\u5355\u5143&#xff0c;\u5c31\u50cf\u76ee\u5f55\u672c\u91cc\u7684\u4e00\u884c\u8bb0\u5f55&#xff0c;\u8bbe\u8ba1\u5f97\u6781\u81f4\u6781\u7b80&#xff0c;\u53ea\u5b58\u4e09\u4e2a\u4fe1\u606f&#xff0c;\u6ca1\u6709\u4efb\u4f55\u5197\u4f59 \u2014\u2014 \u56e0\u4e3a\u8d8a\u7b80\u5355&#xff0c;\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u7684\u76ee\u5f55\u9879\u5c31\u8d8a\u591a&#xff0c;\u76ee\u5f55\u7684\u5c42\u7ea7\u5c31\u8d8a\u5c11&#xff0c;\u627e\u6570\u636e\u5c31\u8d8a\u5feb\u3002\u8fd9\u4e09\u4e2a\u4fe1\u606f\u662f&#xff1a;<\/p>\n<li><span style=\"color:#ff9900\">min_key&#xff1a;\u5f53\u524d\u76ee\u5f55\u9879\u6307\u5411\u7684\u6570\u636e\u9875\u7684\u6700\u5c0f\u4e3b\u952e\u503c&#xff0c;\u6bd4\u5982\u6570\u636e\u9875\u5b58 id&#061;1-16&#xff0c;min_key \u5c31\u662f 1&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">max_key&#xff1a;\u5f53\u524d\u76ee\u5f55\u9879\u6307\u5411\u7684\u6570\u636e\u9875\u7684\u6700\u5927\u4e3b\u952e\u503c&#xff0c;\u6bd4\u5982\u6570\u636e\u9875\u5b58 id&#061;1-16&#xff0c;max_key \u5c31\u662f 16&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">page_no&#xff1a;\u5f53\u524d\u76ee\u5f55\u9879\u6307\u5411\u7684\u6570\u636e\u9875\u7684\u9875\u53f7&#xff0c;\u6bd4\u5982\u9875\u53f7 100\u3001101\u2014\u2014 \u8fd9\u662f\u6700\u6838\u5fc3\u7684\u4fe1\u606f&#xff0c;\u76ee\u5f55\u7684\u6700\u7ec8\u76ee\u7684\u5c31\u662f\u627e\u5230\u8fd9\u4e2a\u9875\u53f7\u3002<\/span><\/li>\n<p><span style=\"color:#ff9900\">\u4e3a\u4ec0\u4e48\u8981\u5b58 min_key \u548c max_key&#xff1f;\u56e0\u4e3a\u6570\u636e\u5e93\u627e\u6570\u636e\u65f6&#xff0c;\u4f1a\u5148\u6839\u636e\u8981\u627e\u7684\u4e3b\u952e\u503c&#xff0c;\u5728\u76ee\u5f55\u9875\u91cc\u627e \u201c\u4e3b\u952e\u503c\u843d\u5728\u54ea\u4e2a min_key \u548c max_key \u4e4b\u95f4\u201d \u7684\u76ee\u5f55\u9879&#xff0c;\u518d\u62ff\u5230\u5bf9\u5e94\u7684 page_no&#xff0c;\u76f4\u63a5\u5b9a\u4f4d\u5230\u6570\u636e\u9875\u3002<\/span><\/p>\n<p>\u6bd4\u5982\u8981\u627e id&#061;20 \u7684\u8bb0\u5f55&#xff0c;\u6570\u636e\u5e93\u4f1a\u5728\u76ee\u5f55\u9875\u91cc\u627e \u201cmin_key\u226420\u2264max_key\u201d \u7684\u76ee\u5f55\u9879&#xff0c;\u627e\u5230 \u201c17-32&#xff0c;\u9875\u53f7 101\u201d \u8fd9\u4e2a\u9879&#xff0c;\u62ff\u5230\u9875\u53f7 101&#xff0c;\u76f4\u63a5\u627e\u5230\u6570\u636e\u9875 101&#xff0c;\u4e0d\u7528\u518d\u770b\u5176\u4ed6\u76ee\u5f55\u9879\u3002<\/p>\n<h4>3.2 \u76ee\u5f55\u9879\u7684\u5927\u5c0f&#xff1a;\u6781\u81f4\u538b\u7f29&#xff0c;\u8ba9\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u4e0a\u5343\u4e2a\u6307\u5f15<\/h4>\n<p>\u76ee\u5f55\u9879\u7684\u8bbe\u8ba1\u6838\u5fc3\u662f \u201c\u538b\u7f29\u201d&#xff0c;\u56e0\u4e3a\u76ee\u5f55\u9879\u8d8a\u5c0f&#xff0c;\u4e00\u4e2a 16KB \u7684\u76ee\u5f55\u9875\u80fd\u5b58\u7684\u76ee\u5f55\u9879\u5c31\u8d8a\u591a\u3002\u54b1\u4eec\u7b97\u4e00\u7b14\u8d26&#xff0c;\u770b\u770b\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u591a\u5c11\u4e2a\u76ee\u5f55\u9879&#xff1a;<\/p>\n<ul>\n<li>\u4e3b\u952e\u5982\u679c\u662fbigint \u7c7b\u578b&#xff08;8 \u4e2a\u5b57\u8282&#xff0c;\u6700\u5e38\u7528\u7684\u4e3b\u952e\u7c7b\u578b&#xff09;&#xff0c;min_key \u548c max_key \u5404\u5360 8 \u5b57\u8282&#xff0c;\u5408\u8ba1 16 \u5b57\u8282&#xff1b;<\/li>\n<li>\u9875\u53f7\u662f6 \u4e2a\u5b57\u8282&#xff08;InnoDB \u7684\u56fa\u5b9a\u8bbe\u8ba1&#xff09;&#xff1b;<\/li>\n<li>\u4e00\u4e2a\u76ee\u5f55\u9879\u7684\u603b\u5927\u5c0f&#xff1a;16&#043;6&#061;22 \u5b57\u8282&#xff08;\u5b9e\u9645\u4f1a\u6709\u4e00\u70b9\u70b9\u5bf9\u9f50&#xff0c;\u7ea6 24 \u5b57\u8282&#xff09;&#xff1b;<\/li>\n<li>\u4e00\u4e2a 16KB \u7684\u76ee\u5f55\u9875&#xff0c;\u6263\u6389\u9875\u5934\u548c\u9875\u5c3e\u7684\u7ea6 100 \u5b57\u8282&#xff0c;\u5269\u4e0b\u7ea6 16284 \u5b57\u8282&#xff1b;<\/li>\n<li>\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u7684\u76ee\u5f55\u9879\u6570\u91cf&#xff1a;16284\/24 \u2248 678 \u4e2a&#xff08;\u5982\u679c\u4e3b\u952e\u662f int \u7c7b\u578b&#xff0c;8 \u5b57\u8282&#xff0c;\u80fd\u5b58\u7ea6 1170 \u4e2a&#xff09;\u3002<\/li>\n<\/ul>\n<p><span style=\"color:#a2e043\">\u8fd9\u662f\u4ec0\u4e48\u6982\u5ff5&#xff1f;\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u7ea6 1000 \u4e2a\u6570\u636e\u9875\u7684\u6307\u5f15\u4fe1\u606f&#xff0c;\u5982\u679c\u4e00\u4e2a\u6570\u636e\u9875\u5b58 16 \u6761\u8bb0\u5f55&#xff0c;\u90a3\u4e00\u4e2a\u76ee\u5f55\u9875\u5c31\u80fd\u6307\u5f1516000 \u6761\u8bb0\u5f55\u2014\u2014 \u627e 16000 \u6761\u8bb0\u5f55\u4ee5\u5185\u7684\u6570\u636e&#xff0c;\u53ea\u9700\u8981\u67e5\u4e00\u4e2a\u76ee\u5f55\u9875&#xff0c;\u5c31\u80fd\u627e\u5230\u5bf9\u5e94\u7684\u9875\u3002<\/span><\/p>\n<h4>3.3 \u76ee\u5f55\u9875\u7684\u6838\u5fc3\u8bbe\u8ba1\u89c4\u5219&#xff1a;\u6709\u5e8f &#043; \u8f7b\u91cf\u5316 &#043; \u552f\u4e00\u6307\u5f15&#xff0c;\u4fdd\u8bc1\u76ee\u5f55\u9ad8\u6548<\/h4>\n<p>\u76ee\u5f55\u9875\u7684\u8bbe\u8ba1\u6709\u4e09\u4e2a\u786c\u6027\u89c4\u5219&#xff0c;\u8fd9\u4e09\u4e2a\u89c4\u5219\u662f\u4fdd\u8bc1\u76ee\u5f55\u80fd\u5feb\u901f\u6307\u5f15\u7684\u5173\u952e&#xff0c;\u7f3a\u4e00\u4e0d\u53ef&#xff1a;<\/p>\n<li>\u76ee\u5f55\u9879\u5fc5\u987b\u6309 min_key \u6709\u5e8f\u6392\u5217&#xff1a;\u6240\u6709\u76ee\u5f55\u9879\u6309 min_key \u4ece\u5c0f\u5230\u5927\u6392&#xff0c;\u6bd4\u5982 \u201c1-16\u201d\u201c17-32\u201d\u201c33-48\u201d\u2026\u2026 \u6709\u5e8f\u662f\u4e8c\u5206\u67e5\u627e\u7684\u524d\u63d0&#xff0c;\u6570\u636e\u5e93\u627e\u76ee\u5f55\u9879\u65f6&#xff0c;\u4e0d\u7528\u9010\u884c\u7ffb&#xff0c;\u76f4\u63a5\u4e8c\u5206\u67e5\u627e&#xff0c;\u4e00\u6b65\u5230\u4f4d&#xff1b;<\/li>\n<li>\u6781\u81f4\u8f7b\u91cf\u5316&#xff0c;\u4e0d\u5b58\u5197\u4f59\u4fe1\u606f&#xff1a;\u53ea\u5b58 min_key\u3001max_key\u3001page_no&#xff0c;\u4e0d\u5b58\u4efb\u4f55\u4e1a\u52a1\u6570\u636e&#xff0c;\u4e0d\u5b58\u4efb\u4f55\u591a\u4f59\u7684\u4fe1\u606f&#xff0c;\u76ee\u7684\u662f\u8ba9\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58\u5c3d\u53ef\u80fd\u591a\u7684\u76ee\u5f55\u9879&#xff0c;\u51cf\u5c11\u76ee\u5f55\u5c42\u7ea7&#xff1b;<\/li>\n<li>\u552f\u4e00\u6307\u5f15&#xff0c;\u65e0\u5197\u4f59&#xff1a;\u4e00\u4e2a\u6570\u636e\u9875&#xff0c;\u53ea\u80fd\u5728\u4e00\u4e2a\u76ee\u5f55\u9879\u91cc\u51fa\u73b0&#xff0c;\u4e00\u4e2a\u76ee\u5f55\u9879&#xff0c;\u53ea\u80fd\u6307\u5411\u4e00\u4e2a\u6570\u636e\u9875\u2014\u2014 \u5c31\u50cf\u56fe\u4e66\u9986\u7684\u4e00\u672c\u8584\u4e66&#xff0c;\u53ea\u80fd\u5728\u4e00\u4e2a\u76ee\u5f55\u672c\u91cc\u6709\u4e00\u6761\u8bb0\u5f55&#xff0c;\u4e0d\u4f1a\u91cd\u590d\u8bb0\u5f55&#xff0c;\u907f\u514d\u76ee\u5f55\u6df7\u4e71\u3002<\/li>\n<h4>3.4 \u5355\u7ea7\u76ee\u5f55\u9875\u7684\u67e5\u8be2\u6d41\u7a0b&#xff1a;\u627e\u6570\u636e &#061; \u67e5\u76ee\u5f55\u9875\u2192\u627e\u6570\u636e\u9875\u2192\u67e5\u6570\u636e\u9875<\/h4>\n<p>\u5230\u8fd9\u91cc&#xff0c;\u54b1\u4eec\u6709\u4e86\u6570\u636e\u9875\u548c\u5355\u7ea7\u76ee\u5f55\u9875&#xff0c;\u53ef\u4ee5\u770b\u4e00\u4e0b\u6700\u7b80\u5355\u7684\u7d22\u5f15\u67e5\u8be2\u6d41\u7a0b\u4e86&#xff0c;\u7528\u4e00\u4e2a\u4f8b\u5b50\u8bb2\u900f&#xff1a;\u5047\u8bbe&#xff1a;<\/p>\n<ul>\n<li>\u4e3b\u952e\u662f int \u7c7b\u578b&#xff0c;\u4e00\u4e2a\u76ee\u5f55\u9875\u80fd\u5b58 1170 \u4e2a\u76ee\u5f55\u9879&#xff0c;\u4e00\u4e2a\u6570\u636e\u9875\u5b58 16 \u6761\u8bb0\u5f55&#xff1b;<\/li>\n<li>\u6709 10000 \u6761\u8bb0\u5f55&#xff0c;\u88ab\u5206\u6210 625 \u4e2a\u6570\u636e\u9875&#xff08;10000\/16&#xff09;&#xff0c;\u7528 1 \u4e2a\u76ee\u5f55\u9875\u5c31\u80fd\u6307\u5f15\u6240\u6709\u6570\u636e\u9875&#xff08;625&lt;1170&#xff09;&#xff1b;<\/li>\n<li>\u8981\u627eid&#061;5000\u7684\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<p>\u67e5\u8be2\u6d41\u7a0b\u5c31\u4e09\u6b65&#xff0c;\u5168\u7a0b\u53ea\u67093 \u6b21\u786c\u76d8\u8bfb\u5199&#xff08;3 \u6b21 IO&#xff09;&#xff1a;<\/p>\n<li><span style=\"color:#ff9900\">\u67e5\u76ee\u5f55\u9875&#xff08;1 \u6b21 IO&#xff09;&#xff1a;\u6570\u636e\u5e93\u5148\u8bfb\u76ee\u5f55\u9875&#xff0c;\u5728\u76ee\u5f55\u9879\u91cc\u4e8c\u5206\u67e5\u627e&#xff0c;\u627e\u5230 \u201cmin_key\u22645000\u2264max_key\u201d \u7684\u76ee\u5f55\u9879&#xff0c;\u62ff\u5230\u5bf9\u5e94\u7684\u6570\u636e\u9875\u53f7&#xff08;\u6bd4\u5982 5000 \u5728 4993-5008 \u8fd9\u4e2a\u8303\u56f4&#xff0c;\u5bf9\u5e94\u7684\u9875\u53f7\u662f 313&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u627e\u6570\u636e\u9875&#xff08;2 \u6b21 IO&#xff09;&#xff1a;\u6570\u636e\u5e93\u6839\u636e\u62ff\u5230\u7684\u9875\u53f7 313&#xff0c;\u76f4\u63a5\u5728\u786c\u76d8\u4e0a\u627e\u5230\u6570\u636e\u9875 313&#xff0c;\u8bfb\u5165\u5185\u5b58&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u67e5\u6570\u636e\u9875&#xff08;3 \u6b21 IO&#xff09;&#xff1a;\u6570\u636e\u5e93\u5728\u6570\u636e\u9875 313 \u91cc&#xff0c;\u4e8c\u5206\u67e5\u627e\u69fd\u4f4d\u76ee\u5f55&#xff0c;\u76f4\u63a5\u5b9a\u4f4d\u5230 id&#061;5000 \u7684\u8bb0\u5f55&#xff0c;\u8bfb\u53d6\u5b8c\u6210\u3002<\/span><\/li>\n<p><span style=\"color:#ff9900\">\u6211\u7684\u5929\u554a&#xff0c;\u8fd9\u5b9e\u5728\u662f\u592a\u65b9\u4fbf\u5566&#xff0c;\u4e0d\u8fc7\u5c4f\u5e55\u524d\u7684\u5404\u4f4d&#xff0c;\u6709\u6ca1\u6709\u60f3\u8d77\u6765\u4e4b\u524dlinux\u4e2d\u6240\u8bb2\u7684\u865a\u62df\u5185\u5b58\u5462&#xff1f;<\/span><\/p>\n<p>\u800c\u5982\u679c\u6ca1\u6709\u76ee\u5f55\u9875&#xff08;\u6ca1\u6709\u7d22\u5f15&#xff09;&#xff0c;\u6570\u636e\u5e93\u9700\u8981\u9010\u9875\u7ffb 625 \u4e2a\u6570\u636e\u9875&#xff08;625 \u6b21 IO&#xff09;&#xff0c;\u624d\u80fd\u627e\u5230 id&#061;5000 \u7684\u8bb0\u5f55 \u2014\u2014 \u8fd9\u5c31\u662f\u7d22\u5f15\u7684\u5a01\u529b&#xff0c;\u628a\u786c\u76d8\u8bfb\u5199\u6b21\u6570\u4ece \u201c\u6210\u5343\u4e0a\u4e07\u6b21\u201d \u964d\u5230 \u201c\u4e2a\u4f4d\u6570\u201d\u3002<\/p>\n<h3>\u56db\u3001\u591a\u7ea7\u76ee\u5f55\u7684\u8bbe\u8ba1&#xff1a;\u5355\u7ea7\u76ee\u5f55\u4e0d\u591f\u7528&#xff0c;\u5c31\u5efa \u201c\u603b\u76ee\u5f55\u2192\u5206\u76ee\u5f55\u2192\u6570\u636e\u9875\u201d<\/h3>\n<p><span style=\"color:#b95514\">\u5355\u7ea7\u76ee\u5f55\u9875\u80fd\u89e3\u51b3 \u201c\u51e0\u4e07\u3001\u51e0\u5341\u4e07\u6761\u8bb0\u5f55\u201d \u7684\u6307\u5f15\u95ee\u9898&#xff0c;\u4f46\u5982\u679c\u6570\u636e\u91cf\u5230\u4e86\u5343\u4e07\u3001\u4ebf\u7ea7&#xff0c;\u5355\u7ea7\u76ee\u5f55\u9875\u5c31\u4e0d\u591f\u7528\u4e86 \u2014\u2014 \u6bd4\u5982\u67092200 \u4e07\u6761\u8bb0\u5f55&#xff0c;\u4e00\u4e2a\u6570\u636e\u9875\u5b58 16 \u6761&#xff0c;\u9700\u8981137.5 \u4e07\u4e2a\u6570\u636e\u9875&#xff0c;\u4e00\u4e2a\u76ee\u5f55\u9875\u6700\u591a\u5b58 1170 \u4e2a\u76ee\u5f55\u9879&#xff0c;\u9700\u89811175 \u4e2a\u76ee\u5f55\u9875\u624d\u80fd\u6307\u5f15\u6240\u6709\u6570\u636e\u9875&#xff08;1375000\/1170\u22481175&#xff09;\u3002<\/span><\/p>\n<p><span style=\"color:#ff9900\">\u8fd9\u65f6\u5019&#xff0c;\u5355\u7ea7\u76ee\u5f55\u9875\u5c31\u53d8\u6210\u4e86 \u201c\u65b0\u7684\u6570\u636e\u9875\u201d&#xff0c;\u9700\u8981\u7ed9\u8fd9\u4e9b\u76ee\u5f55\u9875\u518d\u5efa\u4e00\u5c42\u66f4\u9ad8\u7ea7\u7684\u76ee\u5f55\u9875\u2014\u2014 \u8fd9\u5c31\u662f\u591a\u7ea7\u76ee\u5f55\u7684\u8bbe\u8ba1\u903b\u8f91&#xff0c;\u5c31\u50cf\u56fe\u4e66\u9986\u7684\u4e66\u592a\u591a&#xff0c;\u4e00\u4e2a\u76ee\u5f55\u672c\u8bb0\u4e0d\u4e0b&#xff0c;\u5c31\u5efa\u603b\u76ee\u5f55\u672c\u2192\u5206\u533a\u76ee\u5f55\u672c\u2192\u6b63\u6587\u8584\u4e66\u7684\u5c42\u7ea7&#xff1a;<\/span><\/p>\n<ul>\n<li><span style=\"color:#ff9900\">\u603b\u76ee\u5f55\u672c&#xff1a;\u8bb0\u7740\u6bcf\u4e2a\u5206\u533a\u76ee\u5f55\u672c\u7684\u8303\u56f4\u548c\u4f4d\u7f6e&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u5206\u533a\u76ee\u5f55\u672c&#xff1a;\u8bb0\u7740\u6bcf\u4e2a\u6b63\u6587\u8584\u4e66\u7684\u8303\u56f4\u548c\u4f4d\u7f6e&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u6b63\u6587\u8584\u4e66&#xff1a;\u5b58\u5b9e\u9645\u7684\u4e66\u5185\u5bb9\u3002<\/span><\/li>\n<\/ul>\n<p><span style=\"color:#a2e043\">\u5bf9\u5e94\u5230 MySQL \u7684\u7d22\u5f15\u8bbe\u8ba1&#xff0c;\u5c31\u662f\u9876\u7ea7\u76ee\u5f55\u9875\u2192\u4e8c\u7ea7\u76ee\u5f55\u9875\u2192\u6570\u636e\u9875&#xff0c;\u5982\u679c\u6570\u636e\u91cf\u518d\u5927&#xff08;\u6bd4\u5982\u767e\u4ebf\u7ea7&#xff09;&#xff0c;\u8fd8\u80fd\u52a0\u4e09\u7ea7\u76ee\u5f55\u9875&#xff0c;\u4f46\u5b9e\u9645\u4e1a\u52a1\u4e2d&#xff0c;\u4e09\u7ea7\u76ee\u5f55\u9875\u5df2\u7ecf\u80fd\u8986\u76d6\u6240\u6709\u573a\u666f&#xff0c;MySQL \u7684\u7d22\u5f15\u5c42\u7ea7\u51e0\u4e4e\u4e0d\u4f1a\u8d85\u8fc7 4 \u5c42 \u2014\u2014 \u56e0\u4e3a 4 \u5c42\u76ee\u5f55\u5c31\u80fd\u6307\u5f151170\u00d71170\u00d71170\u00d716\u2248260 \u4ebf\u6761\u8bb0\u5f55&#xff0c;\u8db3\u591f\u7528\u4e86\u3002<\/span><\/p>\n<h4>4.1 \u591a\u7ea7\u76ee\u5f55\u7684\u8bbe\u8ba1\u903b\u8f91&#xff1a;\u76ee\u5f55\u9875\u4e5f\u80fd\u88ab \u201c\u76ee\u5f55\u5316\u201d&#xff0c;\u5c42\u7ea7\u590d\u7528\u540c\u4e00\u5957\u8bbe\u8ba1<\/h4>\n<p>\u591a\u7ea7\u76ee\u5f55\u7684\u8bbe\u8ba1\u903b\u8f91\u7279\u522b\u7b80\u5355&#xff0c;\u56e0\u4e3a\u6240\u6709\u5c42\u7ea7\u7684\u76ee\u5f55\u9875&#xff0c;\u8bbe\u8ba1\u89c4\u5219\u90fd\u662f\u4e00\u6837\u7684\u2014\u2014 \u4e0d\u7ba1\u662f\u9876\u7ea7\u3001\u4e8c\u7ea7\u3001\u4e09\u7ea7&#xff0c;\u76ee\u5f55\u9875\u7684\u7ed3\u6784\u3001\u76ee\u5f55\u9879\u7684\u8bbe\u8ba1\u3001\u6709\u5e8f\u6392\u5217\u7684\u89c4\u5219&#xff0c;\u5168\u90fd\u4e00\u6a21\u4e00\u6837&#xff0c;\u53ea\u662f\u6307\u5f15\u7684\u5bf9\u8c61\u4e0d\u540c&#xff1a;<\/p>\n<ul>\n<li>\u9876\u7ea7\u76ee\u5f55\u9875&#xff1a;\u6307\u5f15\u7684\u662f\u4e8c\u7ea7\u76ee\u5f55\u9875&#xff0c;\u76ee\u5f55\u9879\u91cc\u5b58\u7684\u662f \u201c\u4e8c\u7ea7\u76ee\u5f55\u9875\u7684\u4e3b\u952e\u8303\u56f4 &#043; \u4e8c\u7ea7\u76ee\u5f55\u9875\u7684\u9875\u53f7\u201d&#xff1b;<\/li>\n<li>\u4e8c\u7ea7\u76ee\u5f55\u9875&#xff1a;\u6307\u5f15\u7684\u662f\u6570\u636e\u9875&#xff0c;\u76ee\u5f55\u9879\u91cc\u5b58\u7684\u662f \u201c\u6570\u636e\u9875\u7684\u4e3b\u952e\u8303\u56f4 &#043; \u6570\u636e\u9875\u7684\u9875\u53f7\u201d&#xff1b;<\/li>\n<li>\u5982\u679c\u6709\u4e09\u7ea7\u76ee\u5f55\u9875&#xff1a;\u9876\u7ea7\u6307\u5f15\u4e8c\u7ea7&#xff0c;\u4e8c\u7ea7\u6307\u5f15\u4e09\u7ea7&#xff0c;\u4e09\u7ea7\u6307\u5f15\u6570\u636e\u9875&#xff0c;\u4ee5\u6b64\u7c7b\u63a8\u3002<\/li>\n<\/ul>\n<p><span style=\"color:#a2e043\">\u7b80\u5355\u8bf4&#xff1a;\u9664\u4e86\u6700\u5e95\u5c42\u7684\u76ee\u5f55\u9875\u6307\u5411\u6570\u636e\u9875&#xff0c;\u5176\u4ed6\u6240\u6709\u5c42\u7ea7\u7684\u76ee\u5f55\u9875&#xff0c;\u90fd\u6307\u5411\u4e0b\u4e00\u5c42\u7684\u76ee\u5f55\u9875&#xff0c;\u6240\u6709\u5c42\u7ea7\u7684\u76ee\u5f55\u9875\u90fd\u7528\u540c\u4e00\u5957\u8bbe\u8ba1\u89c4\u5219\u2014\u2014 \u8fd9\u662f MySQL \u7d22\u5f15\u8bbe\u8ba1\u7684\u7cbe\u5999\u4e4b\u5904&#xff0c;\u4e0d\u7528\u4e3a\u4e0d\u540c\u5c42\u7ea7\u8bbe\u8ba1\u4e0d\u540c\u7684\u7ed3\u6784&#xff0c;\u590d\u7528\u5373\u53ef&#xff0c;\u7b80\u5355\u9ad8\u6548\u3002<\/span><\/p>\n<h4>4.2 \u591a\u7ea7\u76ee\u5f55\u7684\u6838\u5fc3\u6570\u636e&#xff1a;3 \u5c42\u76ee\u5f55\u80fd\u6307\u5f15 2200 \u4e07\u6761\u8bb0\u5f55&#xff0c;4 \u5c42\u80fd\u6307\u5f15 260 \u4ebf\u6761<\/h4>\n<p>\u54b1\u4eec\u518d\u7b97\u4e00\u7b14\u8d26&#xff0c;\u76f4\u89c2\u611f\u53d7\u4e00\u4e0b\u591a\u7ea7\u76ee\u5f55\u7684\u5a01\u529b&#xff0c;\u8fd8\u662f\u6309int \u4e3b\u952e\u30011 \u4e2a\u76ee\u5f55\u9875\u5b58 1170 \u4e2a\u76ee\u5f55\u9879\u30011 \u4e2a\u6570\u636e\u9875\u5b58 16 \u6761\u8bb0\u5f55\u6765\u7b97&#xff1a;<\/p>\n<ul>\n<li>1 \u5c42\u76ee\u5f55&#xff08;\u65e0\u76ee\u5f55&#xff0c;\u76f4\u63a5\u6570\u636e\u9875&#xff09;&#xff1a;\u80fd\u5b58 16 \u6761\u8bb0\u5f55&#xff1b;<\/li>\n<li>2 \u5c42\u76ee\u5f55&#xff08;\u9876\u7ea7\u76ee\u5f55\u9875\u2192\u6570\u636e\u9875&#xff09;&#xff1a;1170\u00d716&#061;18720 \u6761&#xff1b;<\/li>\n<li>3 \u5c42\u76ee\u5f55&#xff08;\u9876\u7ea7\u2192\u4e8c\u7ea7\u2192\u6570\u636e\u9875&#xff09;&#xff1a;1170\u00d71170\u00d716&#061;2200 \u4e07\u6761&#xff1b;<\/li>\n<li>4 \u5c42\u76ee\u5f55&#xff08;\u9876\u7ea7\u2192\u4e8c\u7ea7\u2192\u4e09\u7ea7\u2192\u6570\u636e\u9875&#xff09;&#xff1a;1170\u00d71170\u00d71170\u00d716&#061;260 \u4ebf\u6761\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 MySQL \u7684\u7d22\u5f15\u67e5\u8be2&#xff0c;\u4e0d\u7ba1\u6570\u636e\u91cf\u591a\u5927&#xff0c;\u786c\u76d8\u8bfb\u5199\u6b21\u6570&#xff08;IO&#xff09;\u90fd\u53ea\u6709 3-4 \u6b21\u2014\u2014 \u56e0\u4e3a\u7d22\u5f15\u5c42\u7ea7\u6700\u591a 4 \u5c42&#xff0c;\u8bfb\u9876\u7ea7\u76ee\u5f55\u9875&#xff08;1 \u6b21 IO&#xff09;\u2192\u8bfb\u4e8c\u7ea7\u76ee\u5f55\u9875&#xff08;2 \u6b21 IO&#xff09;\u2192\u8bfb\u4e09\u7ea7\u76ee\u5f55\u9875&#xff08;3 \u6b21 IO&#xff09;\u2192\u8bfb\u6570\u636e\u9875&#xff08;4 \u6b21 IO&#xff09;&#xff0c;\u5168\u7a0b\u53ea\u6709 4 \u6b21&#xff0c;\u548c\u6570\u636e\u91cf\u65e0\u5173\u3002<\/p>\n<h4>4.3 \u591a\u7ea7\u76ee\u5f55\u7684\u67e5\u8be2\u6d41\u7a0b&#xff1a;\u4e09\u6b65\u53d8\u56db\u6b65&#xff0c;\u903b\u8f91\u5b8c\u5168\u590d\u7528<\/h4>\n<p>\u591a\u7ea7\u76ee\u5f55\u7684\u67e5\u8be2\u6d41\u7a0b&#xff0c;\u53ea\u662f\u5728\u5355\u7ea7\u76ee\u5f55\u7684\u57fa\u7840\u4e0a&#xff0c;\u591a\u4e86\u4e00\u6b65 \u201c\u67e5\u4e0a\u4e00\u5c42\u76ee\u5f55\u9875\u201d&#xff0c;\u903b\u8f91\u5b8c\u5168\u590d\u7528&#xff0c;\u8fd8\u662f\u75283 \u5c42\u76ee\u5f55\u627e id&#061;150000 \u7684\u8bb0\u5f55\u4e3e\u4f8b&#xff1a;<\/p>\n<li><span style=\"color:#ff9900\">\u8bfb\u9876\u7ea7\u76ee\u5f55\u9875&#xff08;1 \u6b21 IO&#xff09;&#xff1a;\u9876\u7ea7\u76ee\u5f55\u9875\u7684\u76ee\u5f55\u9879\u6307\u5f15\u7684\u662f\u4e8c\u7ea7\u76ee\u5f55\u9875&#xff0c;\u4e8c\u5206\u67e5\u627e\u627e\u5230 id&#061;150000 \u6240\u5728\u7684\u4e8c\u7ea7\u76ee\u5f55\u9875\u53f7&#xff08;\u6bd4\u5982\u4e8c\u7ea7\u76ee\u5f55\u9875 8&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u8bfb\u4e8c\u7ea7\u76ee\u5f55\u9875 8&#xff08;2 \u6b21 IO&#xff09;&#xff1a;\u4e8c\u7ea7\u76ee\u5f55\u9875 8 \u7684\u76ee\u5f55\u9879\u6307\u5f15\u7684\u662f\u6570\u636e\u9875&#xff0c;\u4e8c\u5206\u67e5\u627e\u627e\u5230 id&#061;150000 \u6240\u5728\u7684\u6570\u636e\u9875\u53f7&#xff08;\u6bd4\u5982\u6570\u636e\u9875 9375&#xff09;&#xff1b;<\/span><\/li>\n<li><span style=\"color:#ff9900\">\u8bfb\u6570\u636e\u9875 9375&#xff08;3 \u6b21 IO&#xff09;&#xff1a;\u5728\u6570\u636e\u9875\u91cc\u4e8c\u5206\u67e5\u627e\u69fd\u4f4d\u76ee\u5f55&#xff0c;\u5b9a\u4f4d\u5230 id&#061;150000 \u7684\u8bb0\u5f55&#xff0c;\u8bfb\u53d6\u5b8c\u6210\u3002<\/span><\/li>\n<p>\u5168\u7a0b\u8fd8\u662f 3 \u6b21 IO&#xff0c;\u548c\u5355\u7ea7\u76ee\u5f55\u7684\u67e5\u8be2\u903b\u8f91\u5b8c\u5168\u4e00\u6837&#xff0c;\u53ea\u662f\u591a\u4e86\u4e00\u6b65\u67e5\u9876\u7ea7\u76ee\u5f55\u9875 \u2014\u2014 \u8fd9\u5c31\u662f\u591a\u7ea7\u76ee\u5f55\u7684\u8bbe\u8ba1\u4f18\u52bf&#xff1a;\u5c42\u7ea7\u589e\u52a0&#xff0c;\u4f46\u67e5\u8be2\u903b\u8f91\u4e0d\u53d8&#xff0c;IO \u6b21\u6570\u53ea\u589e\u52a0 1 \u6b21&#xff0c;\u6548\u7387\u59cb\u7ec8\u4fdd\u6301\u6700\u9ad8\u3002<\/p>\n<h4>4.4 \u591a\u7ea7\u76ee\u5f55\u7684\u6838\u5fc3\u8bbe\u8ba1\u603b\u7ed3&#xff1a;\u590d\u7528 &#043; \u5c42\u7ea7\u53ef\u63a7&#xff0c;\u4ebf\u7ea7\u6570\u636e\u4e5f\u80fd 3 \u6b21 IO \u5b9a\u4f4d<\/h4>\n<p>\u591a\u7ea7\u76ee\u5f55\u7684\u8bbe\u8ba1\u603b\u7ed3\u5c31\u4e24\u4e2a\u70b9&#xff0c;\u8fd9\u4e24\u4e2a\u70b9\u8ba9 MySQL \u7684\u7d22\u5f15\u80fd\u652f\u6491\u6d77\u91cf\u6570\u636e&#xff1a;<\/p>\n<li>\u8bbe\u8ba1\u89c4\u5219\u5b8c\u5168\u590d\u7528&#xff1a;\u6240\u6709\u5c42\u7ea7\u7684\u76ee\u5f55\u9875&#xff0c;\u7ed3\u6784\u3001\u76ee\u5f55\u9879\u3001\u6709\u5e8f\u89c4\u5219\u90fd\u4e00\u6837&#xff0c;\u53ea\u662f\u6307\u5f15\u7684\u5bf9\u8c61\u4e0d\u540c&#xff0c;\u4e0d\u7528\u91cd\u65b0\u8bbe\u8ba1&#xff0c;\u7b80\u5355\u9ad8\u6548&#xff1b;<\/li>\n<li>\u5c42\u7ea7\u53ef\u63a7&#xff0c;IO \u6b21\u6570\u56fa\u5b9a&#xff1a;\u4e0d\u7ba1\u6570\u636e\u91cf\u591a\u5927&#xff0c;\u7d22\u5f15\u5c42\u7ea7\u6700\u591a 4 \u5c42&#xff0c;\u786c\u76d8\u8bfb\u5199\u6b21\u6570\u56fa\u5b9a\u5728 3-4 \u6b21&#xff0c;\u4e0d\u4f1a\u56e0\u4e3a\u6570\u636e\u91cf\u589e\u52a0\u800c\u53d8\u6162 \u2014\u2014 \u8fd9\u662f\u7d22\u5f15\u80fd\u652f\u6491\u5343\u4e07\u3001\u4ebf\u7ea7\u6570\u636e\u7684\u6838\u5fc3\u539f\u56e0\u3002<\/li>\n<p>\u5230\u8fd9\u91cc&#xff0c;\u54b1\u4eec\u8bb2\u900f\u4e86\u6570\u636e\u9875\u3001\u76ee\u5f55\u9875\u3001\u591a\u7ea7\u76ee\u5f55&#xff0c;\u8fd9\u662f MySQL \u7d22\u5f15\u8bbe\u8ba1\u7684\u57fa\u7840\u6846\u67b6&#xff0c;\u63a5\u4e0b\u6765\u7684\u805a\u7c07\u7d22\u5f15\u3001\u8f85\u52a9\u7d22\u5f15\u3001\u9875\u5206\u88c2 \/ \u5408\u5e76&#xff0c;\u90fd\u662f\u5728\u8fd9\u4e2a\u57fa\u7840\u6846\u67b6\u4e0a\u7684\u5177\u4f53\u843d\u5730\u548c\u52a8\u6001\u7ef4\u62a4\u3002<\/p>\n<h3>\u4e94\u3001\u805a\u7c07\u7d22\u5f15\u7684\u8bbe\u8ba1&#xff1a;MySQL \u7684 \u201c\u4e3b\u7d22\u5f15\u201d&#xff0c;\u6570\u636e\u9875\u5c31\u662f\u7d22\u5f15&#xff0c;\u7d22\u5f15\u5c31\u662f\u6570\u636e\u9875<\/h3>\n<p>\u805a\u7c07\u7d22\u5f15\u662f InnoDB \u5f15\u64ce\u9ed8\u8ba4\u7684\u3001\u552f\u4e00\u7684\u4e3b\u7d22\u5f15&#xff0c;\u4e5f\u662f\u6700\u6838\u5fc3\u7684\u7d22\u5f15&#xff0c;\u5b83\u7684\u8bbe\u8ba1\u6838\u5fc3\u662f&#xff1a;<span style=\"color:#fe2c24\">\u805a\u7c07\u7d22\u5f15\u7684 \u201c\u6570\u636e\u9875\u201d \u5c31\u662f\u8868\u7684\u5b9e\u9645\u6570\u636e&#xff0c;\u8868\u7684\u5b9e\u9645\u6570\u636e\u5c31\u662f\u805a\u7c07\u7d22\u5f15\u7684 \u201c\u6570\u636e\u9875\u201d&#xff0c;\u805a\u7c07\u7d22\u5f15\u4e0d\u662f \u201c\u9644\u52a0\u5230\u8868\u4e0a\u7684\u4e1c\u897f\u201d&#xff0c;\u800c\u662f\u8868\u7684\u7269\u7406\u5b58\u50a8\u65b9\u5f0f\u3002<\/span><\/p>\n<p>\u7b80\u5355\u8bf4&#xff1a;<span style=\"color:#ff9900\">\u805a\u7c07\u7d22\u5f15\u548c\u8868\u662f\u540c\u4e00\u4e2a\u4e1c\u897f&#xff0c;\u5efa\u8868\u7684\u65f6\u5019&#xff0c;\u805a\u7c07\u7d22\u5f15\u5c31\u5df2\u7ecf\u5efa\u597d\u4e86&#xff0c;\u8868\u7684\u6240\u6709\u6570\u636e&#xff0c;\u90fd\u6309\u805a\u7c07\u7d22\u5f15\u7684\u89c4\u5219\u5b58\u5728\u6570\u636e\u9875\u91cc\u3002<\/span><\/p>\n<p>\u805a\u7c07\u7d22\u5f15\u7684\u8bbe\u8ba1&#xff0c;\u5b8c\u5168\u57fa\u4e8e\u54b1\u4eec\u524d\u9762\u8bb2\u7684 \u201c\u6570\u636e\u9875 &#043; \u591a\u7ea7\u76ee\u5f55\u9875\u201d \u6846\u67b6&#xff0c;\u53ea\u662f\u6709\u51e0\u4e2a\u786c\u6027\u7684\u8bbe\u8ba1\u89c4\u5219&#xff0c;\u8fd9\u4e9b\u89c4\u5219\u51b3\u5b9a\u4e86\u805a\u7c07\u7d22\u5f15\u7684\u9ad8\u6548\u6027\u3002<\/p>\n<h4>5.1 \u805a\u7c07\u7d22\u5f15\u7684 4 \u4e2a\u6838\u5fc3\u8bbe\u8ba1\u89c4\u5219&#xff0c;\u786c\u6027\u8981\u6c42&#xff0c;\u7f3a\u4e00\u4e0d\u53ef<\/h4>\n<p>\u805a\u7c07\u7d22\u5f15\u662f InnoDB \u7684 \u201c\u7075\u9b42\u201d&#xff0c;\u6709 4 \u4e2a\u786c\u6027\u7684\u8bbe\u8ba1\u89c4\u5219&#xff0c;\u6240\u6709 InnoDB \u8868\u90fd\u5fc5\u987b\u9075\u5b88&#xff0c;\u8fd9\u662f\u805a\u7c07\u7d22\u5f15\u9ad8\u6548\u7684\u57fa\u7840&#xff1a;<\/p>\n<h5>\u89c4\u5219 1&#xff1a;\u5fc5\u987b\u4ee5 \u201c\u4e3b\u952e\u201d \u4f5c\u4e3a\u805a\u7c07\u7d22\u5f15\u7684\u5173\u952e\u5b57&#xff0c;\u6570\u636e\u9875\u6309\u4e3b\u952e\u6709\u5e8f\u6392\u5217<\/h5>\n<p>\u805a\u7c07\u7d22\u5f15\u7684\u6240\u6709\u6570\u636e\u9875&#xff0c;\u90fd\u5fc5\u987b\u6309\u4e3b\u952e\u4ece\u5c0f\u5230\u5927\u6709\u5e8f\u6392\u5217&#xff0c;\u76ee\u5f55\u9875\u7684\u6240\u6709\u76ee\u5f55\u9879&#xff0c;\u4e5f\u5fc5\u987b\u6309\u4e3b\u952e\u8303\u56f4\u6709\u5e8f\u6392\u5217 \u2014\u2014 \u4e3b\u952e\u662f\u805a\u7c07\u7d22\u5f15\u7684 \u201c\u552f\u4e00\u5173\u952e\u5b57\u201d&#xff0c;\u6ca1\u6709\u4e3b\u952e&#xff0c;\u5c31\u65e0\u6cd5\u5efa\u805a\u7c07\u7d22\u5f15&#xff0c;\u56e0\u4e3a\u6570\u636e\u9875\u6ca1\u6709\u7edf\u4e00\u7684\u6392\u5e8f\u4f9d\u636e\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 InnoDB \u8868\u5fc5\u987b\u6709\u4e3b\u952e\u2014\u2014 \u4e0d\u662f MySQL \u8981\u6c42\u7684&#xff0c;\u800c\u662f\u805a\u7c07\u7d22\u5f15\u7684\u8bbe\u8ba1\u8981\u6c42&#xff0c;\u6ca1\u6709\u4e3b\u952e&#xff0c;\u6570\u636e\u9875\u5c31\u4e71\u5806&#xff0c;\u76ee\u5f55\u9875\u5c31\u6ca1\u6cd5\u5efa\u3002<\/p>\n<h5>\u89c4\u5219 2&#xff1a;\u805a\u7c07\u7d22\u5f15\u7684\u76ee\u5f55\u9875&#xff0c;\u76f4\u63a5\u6307\u5411\u6570\u636e\u9875&#xff0c;\u6ca1\u6709\u4e2d\u95f4\u5197\u4f59<\/h5>\n<p>\u805a\u7c07\u7d22\u5f15\u7684\u591a\u7ea7\u76ee\u5f55\u9875&#xff0c;\u6700\u7ec8\u90fd\u662f\u76f4\u63a5\u6307\u5411\u5b58\u5b9e\u9645\u6570\u636e\u7684\u6570\u636e\u9875&#xff0c;\u76ee\u5f55\u9879\u91cc\u5b58\u7684\u662f \u201c\u6570\u636e\u9875\u7684\u4e3b\u952e\u8303\u56f4 &#043; \u6570\u636e\u9875\u53f7\u201d&#xff0c;\u6ca1\u6709\u4efb\u4f55\u4e2d\u95f4\u73af\u8282 \u2014\u2014 \u8fd9\u662f\u805a\u7c07\u7d22\u5f15\u67e5\u8be2\u6700\u5feb\u7684\u539f\u56e0&#xff0c;\u56e0\u4e3a\u4ece\u9876\u7ea7\u76ee\u5f55\u9875\u5230\u6570\u636e\u9875&#xff0c;\u53ea\u6709 3-4 \u6b21 IO&#xff0c;\u76f4\u63a5\u62ff\u5230\u5b9e\u9645\u6570\u636e&#xff0c;\u4e0d\u7528\u518d\u505a\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n<h5>\u89c4\u5219 3&#xff1a;\u805a\u7c07\u7d22\u5f15\u662f \u201c\u552f\u4e00\u7684\u201d&#xff0c;\u4e00\u4e2a InnoDB \u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u805a\u7c07\u7d22\u5f15<\/h5>\n<p>\u56e0\u4e3a\u805a\u7c07\u7d22\u5f15\u5c31\u662f\u8868\u7684\u7269\u7406\u5b58\u50a8\u65b9\u5f0f&#xff0c;\u4e00\u4e2a\u8868\u7684\u7269\u7406\u6570\u636e\u53ea\u80fd\u6309\u4e00\u79cd\u987a\u5e8f\u5b58\u5728\u786c\u76d8\u4e0a \u2014\u2014 \u6bd4\u5982\u6309 id \u6392\u5e8f&#xff0c;\u5c31\u4e0d\u80fd\u518d\u6309\u5e74\u9f84\u6392\u5e8f&#xff0c;\u56e0\u4e3a\u6570\u636e\u9875\u7684\u7269\u7406\u4f4d\u7f6e\u662f\u56fa\u5b9a\u7684&#xff0c;\u4e0d\u80fd\u65e2\u5728 id&#061;1-16 \u7684\u4f4d\u7f6e&#xff0c;\u53c8\u5728\u5e74\u9f84 &#061; 25-30 \u7684\u4f4d\u7f6e\u3002\u6240\u4ee5\u4e00\u4e2a InnoDB \u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u805a\u7c07\u7d22\u5f15&#xff0c;\u5c31\u662f\u4ee5\u4e3b\u952e\u4e3a\u5173\u952e\u5b57\u7684\u90a3\u4e2a\u3002<\/p>\n<h5>\u89c4\u5219 4&#xff1a;\u5982\u679c\u8868\u6ca1\u6709\u663e\u5f0f\u5b9a\u4e49\u4e3b\u952e&#xff0c;InnoDB \u4f1a\u81ea\u52a8\u751f\u6210 \u201c\u9690\u85cf\u4e3b\u952e\u201d<\/h5>\n<p><span style=\"color:#b95514\">\u5982\u679c\u6211\u4eec\u5efa\u8868\u65f6\u6ca1\u5199\u4e3b\u952e&#xff08;\u6bd4\u5982CREATE TABLE user (name VARCHAR(10), age INT);&#xff09;&#xff0c;InnoDB \u4e0d\u4f1a\u62a5\u9519&#xff0c;\u800c\u662f\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u9690\u85cf\u7684 6 \u5b57\u8282\u81ea\u589e\u4e3b\u952e&#xff08;row_id&#xff09;&#xff0c;\u4f5c\u4e3a\u805a\u7c07\u7d22\u5f15\u7684\u5173\u952e\u5b57&#xff0c;\u6570\u636e\u9875\u6309\u8fd9\u4e2a\u9690\u85cf\u7684 row_id \u6709\u5e8f\u6392\u5217\u3002\u8fd9\u4e2a\u9690\u85cf\u4e3b\u952e\u5bf9\u7528\u6237\u4e0d\u53ef\u89c1&#xff0c;\u4e5f\u4e0d\u80fd\u67e5\u8be2&#xff0c;\u4f46\u5b83\u7684\u5b58\u5728&#xff0c;\u662f\u4e3a\u4e86\u6ee1\u8db3\u805a\u7c07\u7d22\u5f15\u7684\u8bbe\u8ba1\u8981\u6c42 \u2014\u2014 \u4fdd\u8bc1\u6570\u636e\u9875\u6709\u7edf\u4e00\u7684\u6392\u5e8f\u4f9d\u636e&#xff0c;\u80fd\u5efa\u76ee\u5f55\u9875\u3002<\/span><\/p>\n<h4>5.2 \u805a\u7c07\u7d22\u5f15\u7684\u6838\u5fc3\u4f18\u52bf&#xff1a;\u67e5\u8be2\u6700\u5feb&#xff0c;\u6ca1\u6709\u56de\u8868&#xff0c;\u662f\u6240\u6709\u7d22\u5f15\u7684\u57fa\u7840<\/h4>\n<p>\u805a\u7c07\u7d22\u5f15\u7684\u8bbe\u8ba1&#xff0c;\u51b3\u5b9a\u4e86\u5b83\u662fMySQL \u91cc\u67e5\u8be2\u6700\u5feb\u7684\u7d22\u5f15&#xff0c;\u6838\u5fc3\u4f18\u52bf\u5c31\u4e00\u4e2a&#xff1a;<span style=\"color:#fe2c24\">\u76ee\u5f55\u9875\u76f4\u63a5\u6307\u5411\u6570\u636e\u9875&#xff0c;\u67e5\u8be2\u65f6\u62ff\u5230\u6570\u636e\u9875\u5c31\u80fd\u62ff\u5230\u5b9e\u9645\u6570\u636e&#xff0c;\u6ca1\u6709\u4efb\u4f55\u989d\u5916\u64cd\u4f5c&#xff0c;\u8fd9\u53eb \u201c\u65e0\u56de\u8868\u201d\u3002<\/span><\/p>\n<p>\u800c\u4e14&#xff0c;\u6240\u6709\u5176\u4ed6\u7d22\u5f15&#xff08;\u8f85\u52a9\u7d22\u5f15&#xff09;&#xff0c;\u6700\u7ec8\u90fd\u8981\u4f9d\u8d56\u805a\u7c07\u7d22\u5f15\u2014\u2014 \u8f85\u52a9\u7d22\u5f15\u7684\u8bbe\u8ba1&#xff0c;\u90fd\u662f\u57fa\u4e8e\u805a\u7c07\u7d22\u5f15\u7684\u4e3b\u952e&#xff0c;\u8fd9\u4e00\u70b9\u54b1\u4eec\u540e\u9762\u8bb2\u8f85\u52a9\u7d22\u5f15\u65f6\u4f1a\u8be6\u7ec6\u8bf4\u3002<\/p>\n<h4>5.3 \u805a\u7c07\u7d22\u5f15\u7684\u4e3b\u952e\u8bbe\u8ba1\u5efa\u8bae&#xff1a;\u4f18\u5148\u7528 \u201c\u81ea\u589e\u4e3b\u952e\u201d&#xff0c;\u522b\u7528 uuid<\/h4>\n<p>\u805a\u7c07\u7d22\u5f15\u7684\u4e3b\u952e\u8bbe\u8ba1&#xff0c;\u76f4\u63a5\u5f71\u54cd\u7d22\u5f15\u7684\u6027\u80fd&#xff0c;\u6838\u5fc3\u5efa\u8bae\u662f&#xff1a;\u4f18\u5148\u7528\u81ea\u589e int\/bigint \u4e3b\u952e&#xff0c;\u522b\u7528 uuid\u3001\u968f\u673a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u4e3b\u952e\u2014\u2014 \u539f\u56e0\u5f88\u7b80\u5355&#xff0c;\u5c31\u662f\u4e3a\u4e86\u51cf\u5c11\u6570\u636e\u9875\u7684 \u201c\u9875\u5206\u88c2\u201d&#xff08;\u540e\u9762\u4f1a\u8bb2\u9875\u5206\u88c2&#xff09;\u3002\u81ea\u589e\u4e3b\u952e\u7684\u7279\u70b9\u662f\u6309\u987a\u5e8f\u589e\u957f&#xff0c;\u6bd4\u5982 id&#061;1\u30012\u30013\u30014\u2026\u2026&#xff0c;\u63d2\u5165\u6570\u636e\u65f6&#xff0c;\u53ea\u4f1a\u5f80\u6700\u540e\u4e00\u4e2a\u6570\u636e\u9875\u91cc\u63d2&#xff0c;\u5c31\u7b97\u6700\u540e\u4e00\u4e2a\u6570\u636e\u9875\u6ee1\u4e86&#xff0c;\u4e5f\u53ea\u9700\u8981\u5206\u88c2\u6700\u540e\u4e00\u4e2a\u6570\u636e\u9875&#xff0c;\u6210\u672c\u6781\u4f4e&#xff1b;\u800c uuid \u662f\u968f\u673a\u7684\u5b57\u7b26\u4e32&#xff0c;\u63d2\u5165\u6570\u636e\u65f6&#xff0c;uuid \u53ef\u80fd\u843d\u5728\u4efb\u610f\u6570\u636e\u9875\u7684\u4e2d\u95f4&#xff0c;\u6bd4\u5982\u5f53\u524d\u6570\u636e\u9875\u5b58 uuid&#061;A-F&#xff0c;\u63d2\u5165\u4e00\u4e2a uuid&#061;C \u7684\u8bb0\u5f55&#xff0c;\u5c31\u8981\u628a\u8fd9\u4e2a\u6570\u636e\u9875\u62c6\u6210\u4e24\u4e2a&#xff0c;\u6210\u672c\u6781\u9ad8\u3002<\/p>\n<p>\u8fd9\u662f\u805a\u7c07\u7d22\u5f15\u8bbe\u8ba1\u7684\u4e00\u4e2a\u91cd\u8981\u7ec6\u8282&#xff0c;\u8bb0\u4f4f\u5c31\u884c&#xff1a;\u81ea\u589e\u4e3b\u952e\u662f\u805a\u7c07\u7d22\u5f15\u7684\u6700\u4f18\u9009\u62e9\u3002<\/p>\n<h4>5.4 \u805a\u7c07\u7d22\u5f15\u7684\u603b\u7ed3&#xff1a;\u8868\u5c31\u662f\u7d22\u5f15&#xff0c;\u7d22\u5f15\u5c31\u662f\u8868&#xff0c;\u4e3b\u952e\u662f\u6838\u5fc3<\/h4>\n<p>\u805a\u7c07\u7d22\u5f15\u7684\u8bbe\u8ba1\u53ef\u4ee5\u7528\u4e00\u53e5\u8bdd\u603b\u7ed3&#xff1a;**InnoDB \u7684\u8868&#xff0c;\u5c31\u662f\u4ee5\u4e3b\u952e\u4e3a\u5173\u952e\u5b57\u7684\u805a\u7c07\u7d22\u5f15&#xff0c;\u805a\u7c07\u7d22\u5f15\u7684\u6570\u636e\u9875\u5c31\u662f\u8868\u7684\u7269\u7406\u6570\u636e&#xff0c;\u4e8c\u8005\u5408\u4e8c\u4e3a\u4e00&#xff0c;\u4e3b\u952e\u662f\u805a\u7c07\u7d22\u5f15\u7684\u6838\u5fc3&#xff0c;\u51b3\u5b9a\u4e86\u6570\u636e\u7684\u5b58\u50a8\u987a\u5e8f\u548c\u76ee\u5f55\u7684\u6784\u5efa\u89c4\u5219\u3002<\/p>\n<h3>\u516d\u3001\u8f85\u52a9\u7d22\u5f15\u7684\u8bbe\u8ba1&#xff1a;MySQL \u7684 \u201c\u526f\u7d22\u5f15\u201d&#xff0c;\u76ee\u5f55\u9875\u6307\u5411 \u201c\u4e3b\u952e\u201d&#xff0c;\u9700\u8981\u56de\u8868<\/h3>\n<p>\u9664\u4e86\u805a\u7c07\u7d22\u5f15&#xff0c;\u6211\u4eec\u624b\u52a8\u521b\u5efa\u7684\u6240\u6709\u7d22\u5f15&#xff08;\u6bd4\u5982INDEX idx_age (age)\u3001UNIQUE INDEX idx_name (name)&#xff09;\u90fd\u53eb\u8f85\u52a9\u7d22\u5f15&#xff0c;\u4e5f\u53eb\u4e8c\u7ea7\u7d22\u5f15\u3002\u8f85\u52a9\u7d22\u5f15\u662f \u201c\u9644\u52a0\u5230\u8868\u4e0a\u7684\u7d22\u5f15\u201d&#xff0c;\u4e0d\u662f\u8868\u7684\u7269\u7406\u5b58\u50a8\u65b9\u5f0f&#xff0c;\u5b83\u7684\u8bbe\u8ba1\u6838\u5fc3\u662f&#xff1a;<span style=\"color:#fe2c24\">\u6709\u72ec\u7acb\u7684\u591a\u7ea7\u76ee\u5f55\u9875\u548c\u6570\u636e\u9875&#xff0c;\u4f46\u6570\u636e\u9875\u91cc\u4e0d\u5b58\u5b9e\u9645\u4e1a\u52a1\u6570\u636e&#xff0c;\u53ea\u5b58 \u201c\u8f85\u52a9\u7d22\u5f15\u5173\u952e\u5b57 &#043; \u805a\u7c07\u7d22\u5f15\u4e3b\u952e\u201d&#xff0c;\u67e5\u8be2\u65f6\u9700\u8981\u901a\u8fc7\u4e3b\u952e\u56de\u67e5\u805a\u7c07\u7d22\u5f15&#xff0c;\u624d\u80fd\u62ff\u5230\u5b8c\u6574\u6570\u636e\u3002<\/span><\/p>\n<p><span style=\"color:#a2e043\">\u7b80\u5355\u8bf4&#xff1a;\u8f85\u52a9\u7d22\u5f15\u662f \u201c\u76ee\u5f55\u7684\u76ee\u5f55\u201d&#xff0c;\u5b83\u7684\u76ee\u5f55\u6700\u7ec8\u6307\u5411\u7684\u4e0d\u662f\u5b9e\u9645\u6570\u636e&#xff0c;\u800c\u662f\u805a\u7c07\u7d22\u5f15\u7684\u4e3b\u952e&#xff0c;\u5fc5\u987b\u518d\u901a\u8fc7\u4e3b\u952e\u67e5\u805a\u7c07\u7d22\u5f15&#xff0c;\u624d\u80fd\u62ff\u5230\u5b8c\u6574\u6570\u636e \u2014\u2014 \u8fd9\u4e2a \u201c\u901a\u8fc7\u4e3b\u952e\u67e5\u805a\u7c07\u7d22\u5f15\u201d \u7684\u6b65\u9aa4&#xff0c;\u53eb\u56de\u8868\u3002<\/span><\/p>\n<h4>6.1 \u8f85\u52a9\u7d22\u5f15\u7684\u6838\u5fc3\u8bbe\u8ba1\u89c4\u5219&#xff1a;\u72ec\u7acb\u76ee\u5f55 &#043; \u53ea\u5b58\u4e3b\u952e&#xff0c;\u4f9d\u8d56\u805a\u7c07\u7d22\u5f15<\/h4>\n<p>\u8f85\u52a9\u7d22\u5f15\u7684\u8bbe\u8ba1\u5b8c\u5168\u57fa\u4e8e \u201c\u6570\u636e\u9875 &#043; \u591a\u7ea7\u76ee\u5f55\u9875\u201d \u6846\u67b6&#xff0c;\u4f46\u6709 3 \u4e2a\u6838\u5fc3\u89c4\u5219&#xff0c;\u548c\u805a\u7c07\u7d22\u5f15\u5dee\u5f02\u660e\u663e&#xff1a;<\/p>\n<h5>\u89c4\u5219 1&#xff1a;\u6709\u72ec\u7acb\u7684\u591a\u7ea7\u76ee\u5f55\u9875\u548c\u6570\u636e\u9875&#xff0c;\u4e0e\u805a\u7c07\u7d22\u5f15\u4e92\u4e0d\u5e72\u6270<\/h5>\n<p>\u8f85\u52a9\u7d22\u5f15\u548c\u805a\u7c07\u7d22\u5f15\u662f\u4e24\u5957\u5b8c\u5168\u72ec\u7acb\u7684 \u201c\u76ee\u5f55\u9875 &#043; \u6570\u636e\u9875\u201d \u4f53\u7cfb \u2014\u2014 \u6bd4\u5982 age \u7d22\u5f15\u6709\u81ea\u5df1\u7684\u9876\u7ea7\u76ee\u5f55\u9875\u3001\u4e8c\u7ea7\u76ee\u5f55\u9875\u3001\u6570\u636e\u9875&#xff0c;name \u7d22\u5f15\u4e5f\u6709\u81ea\u5df1\u7684\u4e00\u5957&#xff0c;\u5b83\u4eec\u548c\u805a\u7c07\u7d22\u5f15\u7684\u76ee\u5f55\u9875\u3001\u6570\u636e\u9875\u4e92\u4e0d\u5f71\u54cd&#xff0c;\u589e\u5220\u6539\u6570\u636e\u65f6&#xff0c;\u9700\u8981\u540c\u65f6\u7ef4\u62a4\u805a\u7c07\u7d22\u5f15\u548c\u6240\u6709\u8f85\u52a9\u7d22\u5f15\u7684\u76ee\u5f55\u9875\u3001\u6570\u636e\u9875\u3002<\/p>\n<h5>\u89c4\u5219 2&#xff1a;\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875&#xff0c;\u53ea\u5b58 \u201c\u8f85\u52a9\u5173\u952e\u5b57 &#043; \u4e3b\u952e\u201d&#xff0c;\u4e0d\u5b58\u5b9e\u9645\u4e1a\u52a1\u6570\u636e<\/h5>\n<p>\u8fd9\u662f\u8f85\u52a9\u7d22\u5f15\u548c\u805a\u7c07\u7d22\u5f15\u6700\u6838\u5fc3\u7684\u533a\u522b&#xff1a;\u805a\u7c07\u7d22\u5f15\u7684\u6570\u636e\u9875\u5b58\u5b8c\u6574\u4e1a\u52a1\u6570\u636e&#xff0c;\u800c\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u53ea\u5b58\u4e24\u4e2a\u4e1c\u897f \u2014\u2014\u2460 \u8f85\u52a9\u7d22\u5f15\u5173\u952e\u5b57&#xff08;\u6bd4\u5982 age\u3001name&#xff09;&#xff1b;\u2461 \u805a\u7c07\u7d22\u5f15\u7684\u4e3b\u952e&#xff08;\u6bd4\u5982 id&#xff09;&#xff0c;\u800c\u4e14\u6570\u636e\u9875\u6309 \u201c\u8f85\u52a9\u5173\u952e\u5b57\u201d \u6709\u5e8f\u6392\u5217&#xff0c;\u76ee\u5f55\u9875\u7684\u76ee\u5f55\u9879\u4e5f\u6309 \u201c\u8f85\u52a9\u5173\u952e\u5b57\u8303\u56f4\u201d \u6392\u5217\u3002<\/p>\n<p>\u4e3e\u4f8b&#xff1a;age \u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u91cc&#xff0c;\u5b58\u7684\u662f \u201cage&#061;25&#xff0c;id&#061;100\u201d\u201cage&#061;25&#xff0c;id&#061;101\u201d\u201cage&#061;26&#xff0c;id&#061;102\u201d\u2026\u2026&#xff0c;\u4e0d\u662f \u201cage&#061;25&#xff0c;name &#061; \u5f20\u4e09&#xff0c;\u5730\u5740 &#061; xxx\u201d \u8fd9\u79cd\u5b8c\u6574\u6570\u636e \u2014\u2014 \u8fd9\u6837\u8bbe\u8ba1\u7684\u76ee\u7684\u662f \u201c\u8f7b\u91cf\u5316\u8f85\u52a9\u7d22\u5f15\u201d&#xff0c;\u8ba9\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u3001\u76ee\u5f55\u9875\u80fd\u5b58\u66f4\u591a\u5185\u5bb9&#xff0c;\u51cf\u5c11\u5c42\u7ea7\u3002<\/p>\n<h5>\u89c4\u5219 3&#xff1a;\u8f85\u52a9\u7d22\u5f15\u5fc5\u987b\u4f9d\u8d56\u805a\u7c07\u7d22\u5f15&#xff0c;\u67e5\u8be2\u9700\u56de\u8868&#xff08;\u8986\u76d6\u7d22\u5f15\u9664\u5916&#xff09;<\/h5>\n<p>\u56e0\u4e3a\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u4e0d\u5b58\u5b8c\u6574\u6570\u636e&#xff0c;\u6240\u4ee5\u7528\u8f85\u52a9\u7d22\u5f15\u67e5\u8be2\u65f6&#xff0c;\u5fc5\u987b\u8d70 \u201c\u67e5\u8f85\u52a9\u7d22\u5f15\u2192\u62ff\u4e3b\u952e\u2192\u67e5\u805a\u7c07\u7d22\u5f15\u2192\u62ff\u5b8c\u6574\u6570\u636e\u201d \u7684\u6d41\u7a0b&#xff0c;\u4e5f\u5c31\u662f\u56de\u8868 \u2014\u2014 \u8fd9\u662f\u8f85\u52a9\u7d22\u5f15\u6bd4\u805a\u7c07\u7d22\u5f15\u67e5\u8be2\u6162\u7684\u539f\u56e0&#xff0c;IO \u6b21\u6570\u7ffb\u500d&#xff08;\u805a\u7c07\u7d22\u5f15 3 \u6b21 IO&#xff0c;\u8f85\u52a9\u7d22\u5f15 6 \u6b21 IO&#xff09;\u3002<\/p>\n<h4>6.2 \u8f85\u52a9\u7d22\u5f15\u7684\u67e5\u8be2\u6d41\u7a0b&#xff1a;\u6bd4\u805a\u7c07\u7d22\u5f15\u591a\u4e00\u6b65\u56de\u8868&#xff0c;IO \u6b21\u6570\u7ffb\u500d<\/h4>\n<p>\u54b1\u4eec\u7528 \u201cage \u8f85\u52a9\u7d22\u5f15\u67e5 age&#061;25 \u7684\u5b8c\u6574\u8bb0\u5f55\u201d \u4e3e\u4f8b&#xff0c;\u5047\u8bbe\u662f 3 \u5c42\u76ee\u5f55&#xff0c;\u6d41\u7a0b\u5206 5 \u6b65&#xff0c;\u5171 6 \u6b21 IO&#xff1a;<\/p>\n<li>\u8bfb age \u8f85\u52a9\u7d22\u5f15\u7684\u9876\u7ea7\u76ee\u5f55\u9875&#xff08;1 \u6b21 IO&#xff09;&#xff1a;\u4e8c\u5206\u67e5\u627e\u627e\u5230 age&#061;25 \u6240\u5728\u7684\u4e8c\u7ea7\u76ee\u5f55\u9875\u53f7&#xff1b;<\/li>\n<li>\u8bfb age \u8f85\u52a9\u7d22\u5f15\u7684\u4e8c\u7ea7\u76ee\u5f55\u9875&#xff08;2 \u6b21 IO&#xff09;&#xff1a;\u4e8c\u5206\u67e5\u627e\u627e\u5230 age&#061;25 \u6240\u5728\u7684\u6570\u636e\u9875\u53f7&#xff1b;<\/li>\n<li>\u8bfb age \u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875&#xff08;3 \u6b21 IO&#xff09;&#xff1a;\u62ff\u5230 age&#061;25 \u5bf9\u5e94\u7684\u6240\u6709\u4e3b\u952e id&#xff08;\u6bd4\u5982 100\u3001101\u3001102&#xff09;&#xff1b;<\/li>\n<li>\u8bfb\u805a\u7c07\u7d22\u5f15\u7684\u9876\u7ea7 &#043; \u4e8c\u7ea7\u76ee\u5f55\u9875&#xff08;4-5 \u6b21 IO&#xff09;&#xff1a;\u7528\u62ff\u5230\u7684 id&#061;100&#xff0c;\u67e5\u805a\u7c07\u7d22\u5f15\u7684\u76ee\u5f55\u9875&#xff0c;\u627e\u5230\u5bf9\u5e94\u7684\u6570\u636e\u9875\u53f7&#xff1b;<\/li>\n<li>\u8bfb\u805a\u7c07\u7d22\u5f15\u7684\u6570\u636e\u9875&#xff08;6 \u6b21 IO&#xff09;&#xff1a;\u62ff\u5230 id&#061;100 \u7684\u5b8c\u6574\u4e1a\u52a1\u6570\u636e&#xff0c;\u4f9d\u6b21\u904d\u5386\u6240\u6709 id&#xff0c;\u5b8c\u6210\u67e5\u8be2\u3002<\/li>\n<p>\u5982\u679c\u8981\u67e5\u591a\u6761\u8bb0\u5f55&#xff08;\u6bd4\u5982 age&#061;25 \u6709 10 \u6761&#xff09;&#xff0c;\u56de\u8868\u6b65\u9aa4\u4f1a\u91cd\u590d 10 \u6b21&#xff0c;\u4f46\u56e0\u4e3a\u805a\u7c07\u7d22\u5f15\u7684\u76ee\u5f55\u9875\u3001\u6570\u636e\u9875\u53ef\u80fd\u88ab\u7f13\u5b58&#xff08;\u540e\u9762\u8bb2 Buffer Pool&#xff09;&#xff0c;\u5b9e\u9645 IO \u6b21\u6570\u4f1a\u6bd4 6 \u6b21\u5c11&#xff0c;\u4f46\u603b\u4f53\u8fd8\u662f\u6bd4\u805a\u7c07\u7d22\u5f15\u6162\u3002<\/p>\n<h4>6.3 \u8986\u76d6\u7d22\u5f15&#xff1a;\u8f85\u52a9\u7d22\u5f15\u7684 \u201c\u4f18\u5316\u8bbe\u8ba1\u201d&#xff0c;\u907f\u514d\u56de\u8868&#xff0c;IO \u6b21\u6570\u51cf\u534a<\/h4>\n<p>\u8986\u76d6\u7d22\u5f15\u662f\u8f85\u52a9\u7d22\u5f15\u7684 \u201c\u6700\u4f18\u5f62\u6001\u201d&#xff0c;\u8bbe\u8ba1\u6838\u5fc3\u662f&#xff1a;<span style=\"color:#fe2c24\">\u8ba9\u67e5\u8be2\u9700\u6c42\u521a\u597d\u80fd\u901a\u8fc7\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u6ee1\u8db3&#xff08;\u53ea\u9700\u8981\u8f85\u52a9\u5173\u952e\u5b57 &#043; \u4e3b\u952e&#xff09;&#xff0c;\u4e0d\u7528\u56de\u8868\u67e5\u805a\u7c07\u7d22\u5f15&#xff0c;\u610f\u601d\u5c31\u662f\u8bf4\u628a\u8981\u67e5\u627e\u7684\u5b57\u6bb5\u548c\u7b5b\u9009\u6761\u4ef6\u5b57\u6bb5\u653e\u5728\u540c\u4e00\u4e2a\u8f85\u52a9\u7d22\u5f15\u4e2d&#xff0c;\u662f\u8fd9\u6837\u7684\u54e6<\/span>\u2014\u2014 \u8fd9\u65f6\u5019\u8f85\u52a9\u7d22\u5f15\u7684\u67e5\u8be2 IO \u6b21\u6570&#xff0c;\u548c\u805a\u7c07\u7d22\u5f15\u4e00\u6837&#xff0c;\u90fd\u662f 3 \u6b21\u3002<\/p>\n<p>\u4e3e\u4f8b&#xff1a;<\/p>\n<ul>\n<li>\u67e5\u8be2\u9700\u6c42&#xff1a;SELECT id FROM user WHERE age&#061;25;&#xff08;\u53ea\u67e5\u4e3b\u952e id&#xff0c;\u4e0d\u67e5\u5176\u4ed6\u5b57\u6bb5&#xff09;&#xff1b;<\/li>\n<li>\u8f85\u52a9\u7d22\u5f15\u6570\u636e\u9875&#xff1a;\u5b58\u7684\u662f \u201cage&#043;id\u201d&#xff0c;\u521a\u597d\u6ee1\u8db3\u67e5\u8be2\u9700\u6c42&#xff1b;<\/li>\n<li>\u67e5\u8be2\u6d41\u7a0b&#xff1a;\u8bfb age \u8f85\u52a9\u7d22\u5f15\u7684\u9876\u7ea7\u2192\u4e8c\u7ea7\u2192\u6570\u636e\u9875&#xff08;3 \u6b21 IO&#xff09;&#xff0c;\u76f4\u63a5\u62ff\u5230 id&#xff0c;\u4e0d\u7528\u56de\u8868&#xff1b;<\/li>\n<li>\u8bc6\u522b\u65b9\u5f0f&#xff1a;\u7528 EXPLAIN \u67e5\u8be2\u65f6&#xff0c;Extra \u5217\u4f1a\u663e\u793a \u201cUsing index\u201d&#xff0c;\u8868\u793a\u7528\u5230\u4e86\u8986\u76d6\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<p><span style=\"color:#a2e043\">\u8986\u76d6\u7d22\u5f15\u7684\u8bbe\u8ba1\u6280\u5de7&#xff1a;\u628a\u67e5\u8be2\u9700\u8981\u7684\u5b57\u6bb5&#xff0c;\u90fd\u52a0\u5230\u8f85\u52a9\u7d22\u5f15\u91cc&#xff0c;\u6bd4\u5982\u8981\u67e5SELECT id, name FROM user WHERE age&#061;25;&#xff0c;\u53ef\u4ee5\u521b\u5efaINDEX idx_age_name (age, name)&#xff0c;\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u5b58 \u201cage&#043;name&#043;id\u201d&#xff0c;\u521a\u597d\u8986\u76d6\u67e5\u8be2\u5b57\u6bb5&#xff0c;\u907f\u514d\u56de\u8868\u3002<\/span><\/p>\n<h4>6.4 \u590d\u5408\u8f85\u52a9\u7d22\u5f15&#xff1a;\u591a\u5b57\u6bb5\u7ec4\u5408\u7684\u8f85\u52a9\u7d22\u5f15&#xff0c;\u9075\u5faa \u201c\u6700\u5de6\u5339\u914d\u201d<\/h4>\n<p>\u590d\u5408\u8f85\u52a9\u7d22\u5f15\u662f\u591a\u4e2a\u5b57\u6bb5\u7ec4\u5408\u7684\u8f85\u52a9\u7d22\u5f15&#xff08;\u6bd4\u5982INDEX idx_dept_age (dept, age)&#xff09;&#xff0c;\u5b83\u7684\u8bbe\u8ba1\u6838\u5fc3\u662f&#xff1a;<span style=\"color:#fe2c24\">\u6570\u636e\u9875\u6309 \u201c\u6700\u5de6\u5b57\u6bb5\u4f18\u5148\u201d \u6709\u5e8f\u6392\u5217&#xff0c;\u76ee\u5f55\u9875\u7684\u76ee\u5f55\u9879\u4e5f\u6309\u6700\u5de6\u5b57\u6bb5\u8303\u56f4\u6392\u5217<\/span>\u2014\u2014 \u8fd9\u5c31\u662f \u201c\u6700\u5de6\u5339\u914d\u539f\u5219\u201d \u7684\u5e95\u5c42\u539f\u56e0&#xff0c;\u4e0d\u662f\u8bed\u6cd5\u8981\u6c42&#xff0c;\u662f\u6570\u636e\u9875\u7684\u6392\u5e8f\u89c4\u5219\u51b3\u5b9a\u7684\u3002<\/p>\n<h5>\u590d\u5408\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u6392\u5e8f\u89c4\u5219&#xff1a;<\/h5>\n<p>\u5148\u6309\u7b2c\u4e00\u4e2a\u5b57\u6bb5&#xff08;dept&#xff09;\u6709\u5e8f\u6392\u5217&#xff0c;dept \u76f8\u540c\u7684\u60c5\u51b5\u4e0b&#xff0c;\u518d\u6309\u7b2c\u4e8c\u4e2a\u5b57\u6bb5&#xff08;age&#xff09;\u6709\u5e8f\u6392\u5217&#xff0c;\u6bd4\u5982&#xff1a;\u201cdept&#061;10&#xff0c;age&#061;25&#xff0c;id&#061;100\u201d\u2192\u201cdept&#061;10&#xff0c;age&#061;26&#xff0c;id&#061;101\u201d\u2192\u201cdept&#061;20&#xff0c;age&#061;24&#xff0c;id&#061;102\u201d\u2192\u201cdept&#061;20&#xff0c;age&#061;25&#xff0c;id&#061;103\u201d\u2026\u2026<\/p>\n<h5>\u6700\u5de6\u5339\u914d\u539f\u5219\u7684\u5e95\u5c42\u903b\u8f91&#xff1a;<\/h5>\n<p><span style=\"color:#b95514\">\u56e0\u4e3a\u6570\u636e\u9875\u662f\u6309 \u201c\u6700\u5de6\u5b57\u6bb5\u201d \u6392\u5e8f\u7684&#xff0c;\u6240\u4ee5&#xff1a;<\/span><\/p>\n<ul>\n<li><span style=\"color:#b95514\">\u67e5dept&#061;10 AND age&#061;25&#xff1a;\u80fd\u5339\u914d\u7d22\u5f15&#xff0c;\u5148\u6309 dept \u627e\u8303\u56f4&#xff0c;\u518d\u6309 age \u627e&#xff0c;\u9ad8\u6548&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">\u67e5dept&#061;10&#xff1a;\u80fd\u5339\u914d\u7d22\u5f15&#xff0c;\u76f4\u63a5\u6309 dept \u627e\u8303\u56f4&#xff0c;\u9ad8\u6548&#xff1b;<\/span><\/li>\n<li><span style=\"color:#b95514\">\u67e5age&#061;25&#xff1a;\u4e0d\u80fd\u5339\u914d\u7d22\u5f15&#xff0c;\u56e0\u4e3a\u6570\u636e\u9875\u91cc age \u662f\u6309 dept \u5206\u7ec4\u6392\u5e8f\u7684&#xff0c;\u6574\u4f53\u65e0\u5e8f&#xff08;dept&#061;10\u300120\u300130 \u90fd\u6709 age&#061;25&#xff09;&#xff0c;\u6570\u636e\u5e93\u53ea\u80fd\u5168\u8868\u626b\u63cf\u3002<\/span><\/li>\n<\/ul>\n<p>\u590d\u5408\u8f85\u52a9\u7d22\u5f15\u7684\u8bbe\u8ba1\u5efa\u8bae&#xff1a;\u628a\u67e5\u8be2\u9891\u7387\u9ad8\u3001\u533a\u5206\u5ea6\u9ad8\u7684\u5b57\u6bb5\u653e\u5728\u6700\u5de6\u8fb9&#xff0c;\u6bd4\u5982 dept \u67e5\u8be2\u9891\u7387\u6bd4 age \u9ad8&#xff0c;\u5c31\u628a dept \u653e\u524d\u9762&#xff0c;\u4fdd\u8bc1\u6700\u5de6\u5b57\u6bb5\u80fd\u5339\u914d\u66f4\u591a\u67e5\u8be2\u573a\u666f\u3002<\/p>\n<h4>6.5 \u524d\u7f00\u7d22\u5f15&#xff1a;\u957f\u5b57\u7b26\u4e32\u8f85\u52a9\u7d22\u5f15\u7684 \u201c\u8f7b\u91cf\u5316\u8bbe\u8ba1\u201d<\/h4>\n<p>\u5982\u679c\u8f85\u52a9\u7d22\u5f15\u7684\u5173\u952e\u5b57\u662f\u957f\u5b57\u7b26\u4e32&#xff08;\u6bd4\u5982 name \u5b57\u6bb5&#xff0c;\u957f\u5ea6 50&#xff09;&#xff0c;\u76f4\u63a5\u5efa\u7d22\u5f15\u4f1a\u6709\u95ee\u9898&#xff1a;<\/p>\n<ul>\n<li>\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u91cc&#xff0c;\u6bcf\u4e2a\u5173\u952e\u5b57\u5360 50 \u5b57\u8282&#xff0c;\u80fd\u5b58\u7684\u8bb0\u5f55\u6570\u5927\u5e45\u51cf\u5c11&#xff08;\u6bd4\u5982\u4ece 1000 \u6761\u964d\u5230 200 \u6761&#xff09;&#xff1b;<\/li>\n<li>\u76ee\u5f55\u9875\u7684\u76ee\u5f55\u9879\u4e5f\u53d8\u5927&#xff0c;\u80fd\u5b58\u7684\u6307\u5f15\u6570\u51cf\u5c11&#xff0c;\u76ee\u5f55\u5c42\u7ea7\u589e\u52a0&#xff0c;IO \u6b21\u6570\u53d8\u591a\u3002<\/li>\n<\/ul>\n<p><span style=\"color:#ff9900\">\u524d\u7f00\u7d22\u5f15\u7684\u8bbe\u8ba1\u4f18\u5316&#xff1a;\u53ea\u53d6\u957f\u5b57\u7b26\u4e32\u7684\u524d N \u4e2a\u5b57\u7b26\u4f5c\u4e3a\u8f85\u52a9\u5173\u952e\u5b57&#xff0c;\u6bd4\u5982INDEX idx_name_prefix (name(20))&#xff0c;\u53ea\u5b58 name \u7684\u524d 20 \u4e2a\u5b57\u7b26 &#043; \u4e3b\u952e&#xff0c;\u6838\u5fc3\u662f \u201c\u5728\u4fdd\u8bc1\u533a\u5206\u5ea6\u7684\u524d\u63d0\u4e0b&#xff0c;\u7f29\u5c0f\u5173\u952e\u5b57\u5927\u5c0f\u201d\u3002<\/span><\/p>\n<h5>\u524d\u7f00\u7d22\u5f15\u7684\u8bbe\u8ba1\u8981\u70b9&#xff1a;<\/h5>\n<li>\u4fdd\u8bc1\u533a\u5206\u5ea6&#xff1a;\u524d N \u4e2a\u5b57\u7b26\u8981\u80fd\u533a\u5206 99% \u4ee5\u4e0a\u7684\u8bb0\u5f55&#xff0c;\u6bd4\u5982 name \u7684\u524d 20 \u4e2a\u5b57\u7b26\u51e0\u4e4e\u6ca1\u6709\u91cd\u590d&#xff0c;\u5c31\u9002\u5408\u5efa\u524d\u7f00\u7d22\u5f15&#xff1b;\u5982\u679c\u524d 20 \u4e2a\u5b57\u7b26\u91cd\u590d\u7387\u9ad8&#xff08;\u6bd4\u5982\u90fd\u662f \u201c\u5f20\u4e09 xxx\u201d&#xff09;&#xff0c;\u5c31\u4e0d\u9002\u5408&#xff0c;\u4f1a\u5bfc\u81f4\u7d22\u5f15\u5931\u6548&#xff08;\u67e5\u8be2\u65f6\u8fd8\u662f\u8981\u5168\u8868\u626b\u63cf&#xff09;&#xff1b;<\/li>\n<li>\u4e0d\u80fd\u7528\u4e8e\u6392\u5e8f \/ \u5206\u7ec4&#xff1a;\u5982\u679c\u67e5\u8be2\u9700\u8981ORDER BY name\u6216GROUP BY name&#xff0c;\u524d\u7f00\u7d22\u5f15\u65e0\u6cd5\u6ee1\u8db3&#xff0c;\u56e0\u4e3a\u53ea\u5b58\u4e86\u524d N \u4e2a\u5b57\u7b26&#xff0c;\u65e0\u6cd5\u5b8c\u6574\u6392\u5e8f&#xff1b;<\/li>\n<li>\u8f7b\u91cf\u5316\u6548\u679c\u660e\u663e&#xff1a;name \u4ece 50 \u5b57\u8282\u7f29\u5230 20 \u5b57\u8282&#xff0c;\u8f85\u52a9\u7d22\u5f15\u7684\u6570\u636e\u9875\u3001\u76ee\u5f55\u9875\u80fd\u5b58\u7684\u5185\u5bb9\u7ffb\u500d&#xff0c;\u5c42\u7ea7\u51cf\u5c11&#xff0c;IO \u6548\u7387\u63d0\u5347\u3002<\/li>\n<h4>6.6 \u8f85\u52a9\u7d22\u5f15\u7684\u603b\u7ed3&#xff1a;\u72ec\u7acb\u76ee\u5f55 &#043; \u4f9d\u8d56\u805a\u7c07\u7d22\u5f15&#xff0c;\u8986\u76d6\u7d22\u5f15\u662f\u6700\u4f18\u89e3<\/h4>\n<p>\u8f85\u52a9\u7d22\u5f15\u7684\u8bbe\u8ba1\u53ef\u4ee5\u603b\u7ed3\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\u6709\u72ec\u7acb\u7684\u591a\u7ea7\u76ee\u5f55\u9875\u548c\u6570\u636e\u9875&#xff0c;\u6570\u636e\u9875\u53ea\u5b58 \u201c\u8f85\u52a9\u5173\u952e\u5b57 &#043; \u4e3b\u952e\u201d&#xff0c;\u8f7b\u91cf\u5316\u8bbe\u8ba1&#xff1b;<\/li>\n<li>\u4f9d\u8d56\u805a\u7c07\u7d22\u5f15&#xff0c;\u67e5\u8be2\u9700\u56de\u8868&#xff0c;IO \u6b21\u6570\u6bd4\u805a\u7c07\u7d22\u5f15\u591a\u4e00\u500d&#xff1b;<\/li>\n<li>\u8986\u76d6\u7d22\u5f15\u80fd\u907f\u514d\u56de\u8868&#xff0c;\u662f\u8f85\u52a9\u7d22\u5f15\u7684\u6700\u4f18\u5f62\u6001&#xff1b;<\/li>\n<li>\u590d\u5408\u7d22\u5f15\u9075\u5faa\u6700\u5de6\u5339\u914d&#xff0c;\u524d\u7f00\u7d22\u5f15\u9002\u5408\u957f\u5b57\u7b26\u4e32&#xff0c;\u90fd\u662f\u8f85\u52a9\u7d22\u5f15\u7684\u4f18\u5316\u624b\u6bb5\u3002<\/li>\n<\/ul>\n<h3>\u4e03\u3001\u7d22\u5f15\u7684\u52a8\u6001\u7ef4\u62a4&#xff1a;\u9875\u5206\u88c2\u4e0e\u9875\u5408\u5e76&#xff0c;\u4fdd\u8bc1\u76ee\u5f55\u548c\u6570\u636e\u9875\u7684\u6709\u5e8f\u6027<\/h3>\n<p>\u524d\u9762\u8bb2\u7684\u90fd\u662f \u201c\u9759\u6001\u7d22\u5f15\u201d\u2014\u2014 \u6570\u636e\u4e0d\u53d8\u65f6&#xff0c;\u6570\u636e\u9875\u548c\u76ee\u5f55\u9875\u7684\u7ed3\u6784\u3002\u4f46\u5b9e\u9645\u4e1a\u52a1\u4e2d&#xff0c;\u6570\u636e\u4f1a\u9891\u7e41\u589e\u5220\u6539&#xff0c;\u8fd9\u65f6\u5019\u7d22\u5f15\u9700\u8981\u52a8\u6001\u8c03\u6574&#xff0c;\u6838\u5fc3\u5c31\u662f\u9875\u5206\u88c2&#xff08;\u63d2\u5165\u6570\u636e\u65f6&#xff09;\u548c\u9875\u5408\u5e76&#xff08;\u5220\u9664\u6570\u636e\u65f6&#xff09;&#xff0c;\u76ee\u7684\u662f\u4fdd\u8bc1\u6570\u636e\u9875\u59cb\u7ec8\u6709\u5e8f\u3001\u76ee\u5f55\u9875\u7684\u6307\u5f15\u59cb\u7ec8\u51c6\u786e\u3002<\/p>\n<h4>7.1 \u9875\u5206\u88c2&#xff1a;\u6570\u636e\u9875\u6ee1\u4e86&#xff0c;\u62c6\u6210\u4e24\u4e2a\u9875&#xff0c;\u540c\u6b65\u66f4\u65b0\u76ee\u5f55\u9875<\/h4>\n<p><span style=\"color:#fe2c24\">\u5f53\u5f80\u6570\u636e\u9875\u91cc\u63d2\u5165\u6570\u636e&#xff0c;\u6570\u636e\u9875\u5df2\u7ecf\u5b58\u6ee1&#xff08;16KB \u7528\u5b8c&#xff09;&#xff0c;\u65e0\u6cd5\u518d\u63d2\u5165\u65b0\u8bb0\u5f55\u65f6&#xff0c;\u5c31\u4f1a\u89e6\u53d1\u9875\u5206\u88c2\u2014\u2014 \u628a\u5f53\u524d\u6570\u636e\u9875\u62c6\u6210\u4e24\u4e2a\u65b0\u6570\u636e\u9875&#xff0c;\u91cd\u65b0\u5206\u914d\u8bb0\u5f55&#xff0c;\u518d\u540c\u6b65\u66f4\u65b0\u76ee\u5f55\u9875\u7684\u6307\u5f15&#xff0c;\u907f\u514d\u6570\u636e\u9875\u65e0\u5e8f\u3002<\/span><\/p>\n<h5>\u9875\u5206\u88c2\u7684\u5b8c\u6574\u6d41\u7a0b&#xff08;\u4ee5\u805a\u7c07\u7d22\u5f15\u3001\u81ea\u589e\u4e3b\u952e\u4e3a\u4f8b&#xff09;&#xff1a;<\/h5>\n<p>\u5047\u8bbe&#xff1a;\u6570\u636e\u9875 100 \u5b58 id&#061;1-16&#xff08;\u6ee1\u4e86&#xff09;&#xff0c;\u8981\u63d2\u5165 id&#061;17 \u7684\u8bb0\u5f55&#xff0c;\u89e6\u53d1\u9875\u5206\u88c2&#xff1a;<\/p>\n<li>\u65b0\u5efa\u4e00\u4e2a\u7a7a\u6570\u636e\u9875&#xff08;\u6bd4\u5982\u9875\u53f7 &#061; 300&#xff09;&#xff0c;\u5206\u914d\u552f\u4e00\u9875\u53f7&#xff1b;<\/li>\n<li>\u628a\u539f\u6570\u636e\u9875 100 \u7684\u8bb0\u5f55&#xff0c;\u6309\u4e3b\u952e\u5206\u6210\u4e24\u90e8\u5206&#xff1a;id&#061;1-8 \u7559\u5728\u539f\u9875&#xff0c;id&#061;9-16 \u79fb\u5230\u65b0\u6570\u636e\u9875 300&#xff1b;<\/li>\n<li>\u63d2\u5165\u65b0\u8bb0\u5f55 id&#061;17 \u5230\u65b0\u6570\u636e\u9875 300&#xff08;\u56e0\u4e3a\u662f\u81ea\u589e\u4e3b\u952e&#xff0c;id&#061;17 \u6bd4 id&#061;16 \u5927&#xff0c;\u843d\u5728\u65b0\u9875&#xff09;&#xff1b;<\/li>\n<li>\u66f4\u65b0\u4e24\u4e2a\u6570\u636e\u9875\u7684\u9875\u5934&#xff1a;\u539f\u6570\u636e\u9875 100 \u7684 \u201c\u4e0b\u4e00\u9875\u53f7\u201d&#061;300&#xff0c;\u65b0\u6570\u636e\u9875 300 \u7684 \u201c\u4e0a\u4e00\u9875\u53f7\u201d&#061;100&#xff0c;\u4fdd\u6301\u53cc\u5411\u94fe\u8868\u8fde\u63a5&#xff1b;<\/li>\n<li>\u66f4\u65b0\u76ee\u5f55\u9875&#xff1a;\u627e\u5230\u539f\u6307\u5411\u6570\u636e\u9875 100 \u7684\u76ee\u5f55\u9879&#xff08;\u6bd4\u5982 \u201c1-16&#xff0c;100\u201d&#xff09;&#xff0c;\u5220\u9664\u8be5\u76ee\u5f55\u9879&#xff0c;\u65b0\u589e\u4e24\u4e2a\u76ee\u5f55\u9879 \u201c1-8&#xff0c;100\u201d\u201c9-17&#xff0c;300\u201d&#xff1b;<\/li>\n<li>\u5982\u679c\u76ee\u5f55\u9875\u4e5f\u6ee1\u4e86&#xff08;\u6bd4\u5982\u4e8c\u7ea7\u76ee\u5f55\u9875\u5b58\u4e86 1170 \u4e2a\u76ee\u5f55\u9879&#xff09;&#xff0c;\u5219\u5bf9\u76ee\u5f55\u9875\u6267\u884c\u540c\u6837\u7684\u5206\u88c2\u64cd\u4f5c&#xff0c;\u65b0\u589e\u66f4\u9ad8\u4e00\u7ea7\u7684\u76ee\u5f55\u9875&#xff08;\u9876\u7ea7\u76ee\u5f55\u9875\u51e0\u4e4e\u4e0d\u4f1a\u6ee1&#xff09;\u3002<\/li>\n<h5>\u9875\u5206\u88c2\u7684\u6838\u5fc3\u5f71\u54cd&#xff1a;<\/h5>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u4fdd\u8bc1\u6570\u636e\u9875\u59cb\u7ec8\u6709\u5e8f&#xff0c;\u76ee\u5f55\u9875\u6307\u5f15\u51c6\u786e&#xff0c;\u4e0d\u5f71\u54cd\u67e5\u8be2\u6548\u7387&#xff1b;<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u589e\u52a0 IO \u6210\u672c&#xff08;\u62c6\u9875\u3001\u79fb\u6570\u636e\u3001\u66f4\u65b0\u76ee\u5f55&#xff09;&#xff0c;\u8fd8\u4f1a\u4ea7\u751f \u201c\u9875\u788e\u7247\u201d&#xff08;\u6570\u636e\u9875\u91cc\u6709\u7a7a\u95f2\u7a7a\u95f4&#xff09;&#xff1b;<\/li>\n<li>\u5173\u952e\u5dee\u5f02&#xff1a;\u81ea\u589e\u4e3b\u952e\u53ea\u4f1a\u5728\u6700\u540e\u4e00\u4e2a\u6570\u636e\u9875\u89e6\u53d1\u9875\u5206\u88c2&#xff0c;\u6210\u672c\u4f4e&#xff1b;\u975e\u81ea\u589e\u4e3b\u952e\u53ef\u80fd\u5728\u4efb\u610f\u6570\u636e\u9875\u89e6\u53d1\u5206\u88c2&#xff0c;\u6210\u672c\u6781\u9ad8\u3002<\/li>\n<\/ul>\n<h4>7.2 \u9875\u5408\u5e76&#xff1a;\u6570\u636e\u9875\u7a7a\u95f2\u591a\u4e86&#xff0c;\u5408\u5e76\u6210\u4e00\u4e2a\u9875&#xff0c;\u540c\u6b65\u66f4\u65b0\u76ee\u5f55\u9875<\/h4>\n<p><span style=\"color:#fe2c24\">\u5f53\u6570\u636e\u9875\u91cc\u7684\u8bb0\u5f55\u88ab\u5220\u9664&#xff0c;\u7a7a\u95f2\u7a7a\u95f4\u8fbe\u5230\u9608\u503c&#xff08;InnoDB \u9ed8\u8ba4\u7ea6 50%&#xff09;&#xff0c;\u4e14\u76f8\u90bb\u7684\u6570\u636e\u9875\u4e5f\u6709\u7a7a\u95f2\u7a7a\u95f4\u65f6&#xff0c;\u4f1a\u89e6\u53d1\u9875\u5408\u5e76\u2014\u2014 \u628a\u4e24\u4e2a\u76f8\u90bb\u7684\u6570\u636e\u9875\u5408\u5e76\u6210\u4e00\u4e2a&#xff0c;\u91ca\u653e\u7a7a\u9875&#xff0c;\u51cf\u5c11\u788e\u7247&#xff0c;\u540c\u6b65\u66f4\u65b0\u76ee\u5f55\u9875\u3002<\/span><\/p>\n<h5>\u9875\u5408\u5e76\u7684\u5b8c\u6574\u6d41\u7a0b&#xff1a;<\/h5>\n<p>\u5047\u8bbe&#xff1a;\u6570\u636e\u9875 100&#xff08;id&#061;1-8&#xff0c;\u7a7a\u95f2\u7a7a\u95f4 60%&#xff09;\u548c\u6570\u636e\u9875 300&#xff08;id&#061;9-17&#xff0c;\u7a7a\u95f2\u7a7a\u95f4 55%&#xff09;&#xff0c;\u90fd\u6709\u5927\u91cf\u7a7a\u95f2\u7a7a\u95f4&#xff0c;\u89e6\u53d1\u9875\u5408\u5e76&#xff1a;<\/p>\n<li>\u628a\u6570\u636e\u9875 300 \u7684\u6240\u6709\u6709\u6548\u8bb0\u5f55&#xff08;id&#061;9-17&#xff09;&#xff0c;\u79fb\u5230\u6570\u636e\u9875 100&#xff0c;\u6309\u4e3b\u952e\u6709\u5e8f\u6392\u5217&#xff08;id&#061;1-17&#xff09;&#xff1b;<\/li>\n<li>\u6e05\u7a7a\u6570\u636e\u9875 300&#xff0c;\u6807\u8bb0\u4e3a \u201c\u7a7a\u95f2\u9875\u201d&#xff0c;\u540e\u7eed\u63d2\u5165\u6570\u636e\u65f6\u53ef\u590d\u7528&#xff1b;<\/li>\n<li>\u66f4\u65b0\u6570\u636e\u9875 100 \u7684\u9875\u5934&#xff1a;\u201c\u4e0b\u4e00\u9875\u53f7\u201d&#061; \u539f\u6570\u636e\u9875 300 \u7684\u4e0b\u4e00\u9875\u53f7&#xff0c;\u65ad\u5f00\u548c\u6570\u636e\u9875 300 \u7684\u5173\u8054&#xff1b;<\/li>\n<li>\u66f4\u65b0\u76ee\u5f55\u9875&#xff1a;\u5220\u9664\u6307\u5411\u6570\u636e\u9875 300 \u7684\u76ee\u5f55\u9879&#xff08;\u201c9-17&#xff0c;300\u201d&#xff09;&#xff0c;\u628a\u6307\u5411\u6570\u636e\u9875 100 \u7684\u76ee\u5f55\u9879\u66f4\u65b0\u4e3a \u201c1-17&#xff0c;100\u201d&#xff1b;<\/li>\n<li>\u91ca\u653e\u6570\u636e\u9875 300 \u7684\u7a7a\u95f4&#xff0c;\u5f52\u8fd8\u7ed9\u6570\u636e\u5e93\u3002<\/li>\n<h5>\u9875\u5408\u5e76\u7684\u6838\u5fc3\u5f71\u54cd&#xff1a;<\/h5>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u51cf\u5c11\u9875\u788e\u7247&#xff0c;\u8ba9\u6570\u636e\u9875\u66f4\u7d27\u51d1&#xff0c;\u63d0\u5347\u67e5\u8be2 IO \u6548\u7387&#xff1b;<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u589e\u52a0\u5220\u9664\u6570\u636e\u540e\u7684 IO \u6210\u672c&#xff08;\u79fb\u6570\u636e\u3001\u66f4\u65b0\u76ee\u5f55&#xff09;&#xff0c;\u4f46\u6bd4\u9875\u5206\u88c2\u7684\u6210\u672c\u4f4e&#xff1b;<\/li>\n<li>\u89e6\u53d1\u6761\u4ef6&#xff1a;\u7a7a\u95f2\u7a7a\u95f4\u8fbe\u5230\u9608\u503c &#043; \u76f8\u90bb\u9875\u6709\u7a7a\u95f2&#xff0c;\u4e0d\u662f\u5220\u9664\u4e00\u6761\u8bb0\u5f55\u5c31\u89e6\u53d1&#xff0c;\u907f\u514d\u9891\u7e41\u5408\u5e76\u3002<\/li>\n<\/ul>\n<h4>7.3 \u7d22\u5f15\u788e\u7247&#xff1a;\u9875\u5206\u88c2\u4e0e\u5408\u5e76\u7684 \u201c\u526f\u4f5c\u7528\u201d&#xff0c;\u9700\u8981\u5b9a\u671f\u6e05\u7406<\/h4>\n<p><span style=\"color:#fe2c24\">\u7d22\u5f15\u788e\u7247\u7684\u672c\u8d28\u662f&#xff1a;\u9875\u5206\u88c2 \/ \u5408\u5e76\u540e&#xff0c;\u6570\u636e\u9875\u51fa\u73b0\u5927\u91cf\u7a7a\u95f2\u7a7a\u95f4&#xff0c;\u76ee\u5f55\u9875\u4ecd\u6307\u5411\u8fd9\u4e9b\u4e0d\u7d27\u51d1\u7684\u6570\u636e\u9875&#xff0c;\u5bfc\u81f4\u67e5\u8be2\u65f6\u9700\u8981\u8bfb\u53d6\u66f4\u591a\u7684\u9875&#xff0c;IO \u6548\u7387\u964d\u4f4e\u3002<\/span><\/p>\n<h5>\u7d22\u5f15\u788e\u7247\u7684\u4e24\u79cd\u7c7b\u578b&#xff1a;<\/h5>\n<li>\u5916\u90e8\u788e\u7247&#xff1a;\u6570\u636e\u9875\u4e4b\u95f4\u6709\u5927\u91cf\u7a7a\u95f2\u9875&#xff08;\u6bd4\u5982\u9875\u5206\u88c2\u540e\u4ea7\u751f\u7684\u7a7a\u9875&#xff0c;\u6ca1\u88ab\u53ca\u65f6\u5408\u5e76&#xff09;&#xff0c;\u76ee\u5f55\u9875\u8981\u6307\u5411\u8fd9\u4e9b\u7a7a\u9875&#xff0c;\u67e5\u8be2\u65f6\u4f1a\u8df3\u8fc7&#xff0c;\u4f46\u6d6a\u8d39\u7a7a\u95f4&#xff1b;<\/li>\n<li>\u5185\u90e8\u788e\u7247&#xff1a;\u6570\u636e\u9875\u5185\u90e8\u6709\u5927\u91cf\u7a7a\u95f2\u7a7a\u95f4&#xff08;\u6bd4\u5982\u9875\u5206\u88c2\u540e&#xff0c;\u4e00\u4e2a 16KB \u7684\u6570\u636e\u9875\u53ea\u5b58 8KB \u6570\u636e&#xff09;&#xff0c;\u67e5\u8be2\u65f6\u8fd8\u662f\u8981\u8bfb\u6574\u4e2a 16KB \u7684\u9875&#xff0c;\u6d6a\u8d39 IO\u3002<\/li>\n<h5>\u7d22\u5f15\u788e\u7247\u7684\u6e05\u7406\u65b9\u6cd5&#xff1a;<\/h5>\n<li>\u91cd\u5efa\u7d22\u5f15&#xff08;\u63a8\u8350&#xff09;&#xff1a;ALTER TABLE \u8868\u540d REBUILD INDEX \u7d22\u5f15\u540d;&#xff0c;\u539f\u7406\u662f\u6e05\u7a7a\u6240\u6709\u6570\u636e\u9875\u548c\u76ee\u5f55\u9875&#xff0c;\u91cd\u65b0\u6309\u4e3b\u952e\u6709\u5e8f\u6392\u5217\u6570\u636e&#xff0c;\u751f\u6210\u7d27\u51d1\u7684\u65b0\u6570\u636e\u9875\u548c\u76ee\u5f55\u9875&#xff0c;\u5f7b\u5e95\u6d88\u9664\u788e\u7247&#xff1b;<\/li>\n<li>\u4f18\u5316\u8868&#xff08;\u9002\u5408\u5c0f\u8868&#xff09;&#xff1a;OPTIMIZE TABLE \u8868\u540d;&#xff0c;\u539f\u7406\u548c\u91cd\u5efa\u7d22\u5f15\u7c7b\u4f3c&#xff0c;\u4f1a\u91cd\u5efa\u8868\u548c\u7d22\u5f15&#xff0c;\u6d88\u9664\u788e\u7247&#xff0c;\u4f46\u9501\u8868\u65f6\u95f4\u957f&#xff0c;\u4e0d\u9002\u5408\u5927\u8868&#xff1b;<\/li>\n<li>\u788e\u7247\u7387\u5224\u65ad&#xff1a;\u901a\u8fc7SHOW TABLE STATUS LIKE &#039;\u8868\u540d&#039;;\u67e5\u770bData_free\u5b57\u6bb5&#xff0c;Data_free \u8d8a\u5927&#xff0c;\u788e\u7247\u8d8a\u591a&#xff0c;\u4e00\u822c\u788e\u7247\u7387\u8d85\u8fc7 30% \u5c31\u9700\u8981\u6e05\u7406\u3002<\/li>\n<h4>7.4 \u52a8\u6001\u7ef4\u62a4\u7684\u603b\u7ed3&#xff1a;\u9875\u5206\u88c2\u4fdd\u6709\u5e8f&#xff0c;\u9875\u5408\u5e76\u51cf\u788e\u7247&#xff0c;\u81ea\u589e\u4e3b\u952e\u964d\u6210\u672c<\/h4>\n<p>\u7d22\u5f15\u52a8\u6001\u7ef4\u62a4\u7684\u6838\u5fc3\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u63d2\u5165\u6570\u636e\u89e6\u53d1\u9875\u5206\u88c2&#xff0c;\u4fdd\u8bc1\u6570\u636e\u9875\u59cb\u7ec8\u6709\u5e8f&#xff0c;\u76ee\u5f55\u6307\u5f15\u51c6\u786e&#xff1b;<\/li>\n<li>\u5220\u9664\u6570\u636e\u89e6\u53d1\u9875\u5408\u5e76&#xff0c;\u51cf\u5c11\u788e\u7247&#xff0c;\u63d0\u5347 IO \u6548\u7387&#xff1b;<\/li>\n<li>\u81ea\u589e\u4e3b\u952e\u80fd\u5927\u5e45\u964d\u4f4e\u9875\u5206\u88c2\u7684\u9891\u7387\u548c\u6210\u672c&#xff0c;\u662f\u7d22\u5f15\u52a8\u6001\u7ef4\u62a4\u7684 \u201c\u6700\u4f18\u914d\u5408\u201d\u3002<\/li>\n<\/ul>\n<h3>\u516b\u3001\u7d22\u5f15\u8bbe\u8ba1\u7684\u9690\u5f62\u652f\u6491&#xff1a;Buffer Pool \u7f13\u5b58&#xff0c;\u628a\u78c1\u76d8 IO \u53d8\u6210\u5185\u5b58 IO<\/h3>\n<p><span style=\"color:#fe2c24\">\u524d\u9762\u8bb2\u7684\u6240\u6709\u6d41\u7a0b&#xff0c;\u90fd\u9ed8\u8ba4 \u201c\u6bcf\u6b21\u8bfb\u9875\u90fd\u8981\u8bfb\u786c\u76d8\u201d&#xff0c;\u4f46\u5b9e\u9645 MySQL \u91cc\u6709\u4e00\u4e2a \u201c\u9690\u5f62\u4f18\u5316\u5668\u201d\u2014\u2014Buffer Pool&#xff08;\u7f13\u51b2\u6c60&#xff09;&#xff0c;\u5b83\u662f\u5185\u5b58\u4e2d\u7684\u4e00\u5757\u533a\u57df&#xff0c;\u4e13\u95e8\u7f13\u5b58\u5e38\u7528\u7684\u76ee\u5f55\u9875\u548c\u6570\u636e\u9875&#xff0c;\u628a\u9891\u7e41\u8bbf\u95ee\u7684\u9875\u4ece\u786c\u76d8\u8bfb\u5230\u5185\u5b58&#xff0c;\u540e\u7eed\u67e5\u8be2\u76f4\u63a5\u8bfb\u5185\u5b58&#xff0c;\u4e0d\u7528\u518d\u8bfb\u786c\u76d8&#xff0c;\u628a \u201c\u6162\u78c1\u76d8 IO\u201d \u53d8\u6210 \u201c\u5feb\u5185\u5b58 IO\u201d\u3002<\/span><\/p>\n<h4>8.1 Buffer Pool \u7684\u6838\u5fc3\u8bbe\u8ba1&#xff1a;\u6309\u9875\u7f13\u5b58&#xff0c;\u4f18\u5148\u7f13\u5b58\u76ee\u5f55\u9875<\/h4>\n<p>Buffer Pool \u7684\u8bbe\u8ba1\u5f88\u7b80\u5355&#xff0c;\u6838\u5fc3\u5c31\u662f \u201c\u6309\u9875\u7f13\u5b58\u201d&#xff0c;\u6709\u4e09\u4e2a\u5173\u952e\u8bbe\u8ba1&#xff1a;<\/p>\n<li>\u7f13\u5b58\u5355\u4f4d\u662f \u201c\u9875\u201d&#xff1a;\u4e0d\u7ba1\u662f\u76ee\u5f55\u9875\u8fd8\u662f\u6570\u636e\u9875&#xff0c;\u53ea\u8981\u88ab\u8bfb\u53d6\u8fc7&#xff0c;\u5c31\u4f1a\u7f13\u5b58\u5230 Buffer Pool&#xff0c;\u7f13\u5b58\u7684\u662f\u6574\u4e2a\u9875&#xff08;16KB&#xff09;&#xff0c;\u4e0d\u662f\u5355\u6761\u8bb0\u5f55&#xff1b;<\/li>\n<li>\u7f13\u5b58\u4f18\u5148\u7ea7&#xff1a;\u9876\u7ea7\u76ee\u5f55\u9875 &gt; \u4e8c\u7ea7\u76ee\u5f55\u9875 &gt; \u9ad8\u9891\u6570\u636e\u9875&#xff0c;\u56e0\u4e3a\u76ee\u5f55\u9875\u662f\u6240\u6709\u67e5\u8be2\u7684 \u201c\u5165\u53e3\u201d&#xff0c;\u4f18\u5148\u7f13\u5b58\u76ee\u5f55\u9875&#xff0c;\u80fd\u8ba9\u6240\u6709\u67e5\u8be2\u90fd\u53d7\u76ca&#xff1b;<\/li>\n<li>\u6dd8\u6c70\u89c4\u5219&#xff1a;\u7528 LRU&#xff08;\u6700\u8fd1\u6700\u5c11\u4f7f\u7528&#xff09;\u7b97\u6cd5&#xff0c;\u6dd8\u6c70\u957f\u65f6\u95f4\u4e0d\u88ab\u8bbf\u95ee\u7684\u9875&#xff0c;\u4fdd\u8bc1\u7f13\u5b58\u7a7a\u95f4\u7559\u7ed9\u9ad8\u9891\u8bbf\u95ee\u7684\u9875 \u2014\u2014 \u6bd4\u5982\u4e00\u4e2a\u6570\u636e\u9875\u534a\u5e74\u6ca1\u88ab\u8bbf\u95ee&#xff0c;\u4f1a\u88ab\u6dd8\u6c70&#xff0c;\u817e\u51fa\u7a7a\u95f4\u7ed9\u65b0\u7684\u9ad8\u9891\u9875\u3002<\/li>\n<h4>8.2 Buffer Pool \u5bf9\u7d22\u5f15\u6027\u80fd\u7684\u5f71\u54cd&#xff1a;IO \u6b21\u6570\u5927\u5e45\u964d\u4f4e<\/h4>\n<p>Buffer Pool \u662f\u7d22\u5f15\u6027\u80fd\u7684 \u201c\u9690\u5f62\u63d0\u5347\u5668\u201d&#xff0c;\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;<\/p>\n<ul>\n<li>\u7b2c\u4e00\u6b21\u67e5 id&#061;100 \u7684\u8bb0\u5f55&#xff1a;\u8bfb\u9876\u7ea7\u76ee\u5f55\u9875&#xff08;\u786c\u76d8 IO&#xff09;\u3001\u4e8c\u7ea7\u76ee\u5f55\u9875&#xff08;\u786c\u76d8 IO&#xff09;\u3001\u6570\u636e\u9875&#xff08;\u786c\u76d8 IO&#xff09;&#xff0c;\u5171 3 \u6b21\u786c\u76d8 IO&#xff0c;\u540c\u65f6\u628a\u8fd9\u4e09\u4e2a\u9875\u7f13\u5b58\u5230 Buffer Pool&#xff1b;<\/li>\n<li>\u7b2c\u4e8c\u6b21\u67e5 id&#061;100 \u7684\u8bb0\u5f55&#xff1a;\u76f4\u63a5\u4ece Buffer Pool \u8bfb\u8fd9\u4e09\u4e2a\u9875&#xff0c;0 \u6b21\u786c\u76d8 IO&#xff0c;\u7eaf\u5185\u5b58\u8bfb\u53d6&#xff0c;\u901f\u5ea6\u63d0\u5347 10 \u4e07\u500d\u4ee5\u4e0a&#xff1b;<\/li>\n<li>\u67e5 id&#061;101 \u7684\u8bb0\u5f55&#xff08;\u548c id&#061;100 \u5728\u540c\u4e00\u4e2a\u6570\u636e\u9875&#xff09;&#xff1a;\u6570\u636e\u9875\u3001\u76ee\u5f55\u9875\u90fd\u5728\u7f13\u5b58\u91cc&#xff0c;\u4e5f\u662f 0 \u6b21\u786c\u76d8 IO\u3002<\/li>\n<\/ul>\n<p>\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;Buffer Pool \u7684\u5927\u5c0f\u901a\u5e38\u4f1a\u8c03\u5f97\u5f88\u5927&#xff08;\u6bd4\u5982 8G\u300116G&#xff09;&#xff0c;\u80fd\u7f13\u5b58\u5927\u90e8\u5206\u9ad8\u9891\u8bbf\u95ee\u7684\u76ee\u5f55\u9875\u548c\u6570\u636e\u9875&#xff0c;\u8ba9\u7edd\u5927\u591a\u6570\u67e5\u8be2\u90fd\u4e0d\u7528\u8bfb\u786c\u76d8&#xff0c;\u53ea\u8bfb\u5185\u5b58 \u2014\u2014 \u8fd9\u662f MySQL \u7d22\u5f15\u80fd\u652f\u6491\u9ad8\u5e76\u53d1\u67e5\u8be2\u7684\u6838\u5fc3\u539f\u56e0\u4e4b\u4e00\u3002<\/p>\n<h4>8.3 Buffer Pool \u7684\u603b\u7ed3&#xff1a;\u7f13\u5b58\u9ad8\u9891\u9875&#xff0c;\u628a\u78c1\u76d8 IO \u53d8\u6210\u5185\u5b58 IO&#xff0c;\u63d0\u5347\u5e76\u53d1\u6027\u80fd<\/h4>\n<p>Buffer Pool \u7684\u8bbe\u8ba1\u6838\u5fc3&#xff1a;\u901a\u8fc7\u7f13\u5b58\u9ad8\u9891\u8bbf\u95ee\u7684\u76ee\u5f55\u9875\u548c\u6570\u636e\u9875&#xff0c;\u51cf\u5c11\u786c\u76d8 IO \u6b21\u6570&#xff0c;\u628a\u7d22\u5f15\u67e5\u8be2\u7684\u901f\u5ea6\u4ece \u201c\u6beb\u79d2\u7ea7\u201d \u63d0\u5347\u5230 \u201c\u5fae\u79d2\u7ea7\u201d&#xff0c;\u652f\u6491\u9ad8\u5e76\u53d1\u67e5\u8be2\u3002<\/p>\n<h3>\u4e5d\u3001\u603b\u7ed3&#xff1a;MySQL \u7d22\u5f15\u8bbe\u8ba1\u7684\u6838\u5fc3\u903b\u8f91<\/h3>\n<p>\u628a\u6574\u4e2a\u7d22\u5f15\u8bbe\u8ba1\u7684\u903b\u8f91\u4e32\u8d77\u6765&#xff0c;\u6838\u5fc3\u5c31\u56db\u53e5\u8bdd&#xff0c;\u4e5f\u662f\u54b1\u4eec\u5168\u7a0b\u8bb2\u7684\u91cd\u70b9&#xff1a;<\/p>\n<li>\u7d22\u5f15\u7684\u6700\u5c0f\u5355\u4f4d\u662f 16KB \u7684 \u201c\u9875\u201d&#xff0c;\u5206\u6570\u636e\u9875&#xff08;\u5b58\u4e1a\u52a1\u6570\u636e&#xff0c;\u5185\u7f6e\u5c0f\u76ee\u5f55&#xff09;\u548c\u76ee\u5f55\u9875&#xff08;\u5b58\u6307\u5f15&#xff0c;\u53ea\u8bb0\u8303\u56f4 &#043; \u9875\u53f7&#xff09;&#xff0c;\u6240\u6709\u6570\u636e\u548c\u76ee\u5f55\u90fd\u88c5\u5728\u9875\u91cc&#xff0c;\u786c\u76d8\u4ea4\u4e92\u53ea\u80fd\u4e00\u9875\u4e00\u9875\u6765&#xff1b;<\/li>\n<li>\u7d22\u5f15\u7684\u6838\u5fc3\u662f \u201c\u591a\u7ea7\u76ee\u5f55\u201d&#xff0c;\u901a\u8fc7\u9876\u7ea7\u2192\u4e8c\u7ea7\u2192\u6570\u636e\u9875\u7684\u5c42\u7ea7\u6307\u5f15&#xff0c;\u628a\u67e5\u8be2\u7684\u786c\u76d8 IO \u6b21\u6570\u56fa\u5b9a\u5728 3-4 \u6b21&#xff0c;\u548c\u6570\u636e\u91cf\u65e0\u5173&#xff0c;\u4ebf\u7ea7\u6570\u636e\u4e5f\u80fd\u5feb\u901f\u5b9a\u4f4d&#xff1b;<\/li>\n<li>\u805a\u7c07\u7d22\u5f15\u662f\u8868\u7684\u7269\u7406\u5b58\u50a8\u65b9\u5f0f&#xff0c;\u6570\u636e\u9875 &#061; \u8868\u6570\u636e&#xff0c;\u76ee\u5f55\u9875\u76f4\u63a5\u6307\u5411\u6570\u636e\u9875&#xff0c;\u65e0\u56de\u8868&#xff0c;\u662f\u6700\u5feb\u7684\u7d22\u5f15&#xff0c;\u4e3b\u952e\u662f\u6838\u5fc3&#xff0c;\u4f18\u5148\u7528\u81ea\u589e\u4e3b\u952e&#xff1b;<\/li>\n<li>\u8f85\u52a9\u7d22\u5f15\u662f\u72ec\u7acb\u7684\u591a\u7ea7\u76ee\u5f55&#xff0c;\u6570\u636e\u9875\u53ea\u5b58 \u201c\u8f85\u52a9\u5173\u952e\u5b57 &#043; \u4e3b\u952e\u201d&#xff0c;\u67e5\u8be2\u9700\u56de\u8868&#xff0c;\u8986\u76d6\u7d22\u5f15\u53ef\u907f\u514d\u56de\u8868&#xff0c;\u52a8\u6001\u7ef4\u62a4\u9760\u9875\u5206\u88c2 \/ \u5408\u5e76&#xff0c;Buffer Pool \u7f13\u5b58\u63d0\u5347\u6027\u80fd\u3002<\/li>\n<p>\u6574\u4e2a\u7d22\u5f15\u8bbe\u8ba1\u7684\u6240\u6709\u7ec6\u8282&#xff0c;\u4e0d\u7ba1\u662f\u6570\u636e\u9875\u7684\u69fd\u4f4d\u76ee\u5f55\u3001\u76ee\u5f55\u9875\u7684\u6781\u7b80\u8bbe\u8ba1&#xff0c;\u8fd8\u662f\u9875\u5206\u88c2\u3001\u8986\u76d6\u7d22\u5f15&#xff0c;\u6700\u7ec8\u76ee\u7684\u90fd\u53ea\u6709\u4e00\u4e2a&#xff1a;\u51cf\u5c11\u786c\u76d8 IO \u6b21\u6570&#xff0c;\u8ba9\u6570\u636e\u5e93\u627e\u6570\u636e\u4e0d\u7528\u7ffb\u904d\u786c\u76d8&#xff0c;\u800c\u662f\u6309\u76ee\u5f55\u5feb\u901f\u5b9a\u4f4d&#xff0c;\u628a\u6162\u67e5\u8be2\u53d8\u6210\u5feb\u67e5\u8be2\u3002<\/p>\n<h2>\u4e09\u3001\u7d22\u5f15\u7684\u672c\u8d28&#xff1a;B &#043; \u6811\u7684 \u201c\u76ee\u5f55\u201d \u8bbe\u8ba1<\/h2>\n<p>\u7d22\u5f15\u7684\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u662fB &#043; \u6811&#xff0c;MySQL \u7684\u7d22\u5f15\u8bed\u6cd5\u672c\u8d28\u662f \u201c\u6784\u5efa B &#043; \u6811\u201d\u201c\u7ef4\u62a4 B &#043; \u6811\u201d\u201c\u4f7f\u7528 B &#043; \u6811\u67e5\u8be2\u201d \u7684\u63a5\u53e3\u3002\u6211\u4eec\u5148\u62c6\u89e3 B &#043; \u6811\u7684\u7ed3\u6784&#xff0c;\u518d\u5173\u8054\u8bed\u6cd5\u3002<\/p>\n<h4>3.1 B &#043; \u6811\u7684\u7ed3\u6784<\/h4>\n<h5>3.1.1 B &#043; \u6811\u7684\u56db\u5c42\u7ed3\u6784&#xff08;\u4ece\u6839\u5230\u53f6&#xff09;<\/h5>\n<table>\n<tr><span style=\"color:#ff9900\">B &#043; \u6811\u5c42\u7ea7<\/span><span style=\"color:#ff9900\">\u8282\u70b9\u7c7b\u578b<\/span><span style=\"color:#ff9900\">\u5b58\u50a8\u5185\u5bb9<\/span><span style=\"color:#ff9900\">\u7c7b\u6bd4&#xff08;\u56fe\u4e66\u9986\u4e66\u76ee&#xff09;<\/span><span style=\"color:#ff9900\">MySQL \u5bf9\u5e94 Page \u7c7b\u578b<\/span><span style=\"color:#ff9900\">\u6570\u91cf&#xff08;800 \u4e07\u6570\u636e&#xff09;<\/span><\/tr>\n<tbody>\n<tr>\n<td><span style=\"color:#ff9900\">\u7b2c 1 \u5c42<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u6839\u8282\u70b9<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u5b50\u8282\u70b9\u7684 \u201c\u952e\u503c\u8303\u56f4 &#043; \u6307\u9488\u201d<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u4e66\u76ee\u603b\u76ee\u5f55&#xff08;\u201cA-F \u7c7b\u5728 1 \u697c&#xff0c;G-Z \u7c7b\u5728 2 \u697c\u201d&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7d22\u5f15\u6839\u9875<\/span><\/td>\n<td><span style=\"color:#ff9900\">1 \u4e2a<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ff9900\">\u7b2c 2 \u5c42<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u975e\u53f6\u5b50\u8282\u70b9<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u53f6\u5b50\u8282\u70b9\u7684 \u201c\u952e\u503c\u8303\u56f4 &#043; \u6307\u9488\u201d<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u697c\u5c42\u76ee\u5f55&#xff08;\u201cA \u7c7b\u5728 1 \u697c 1 \u533a&#xff0c;B \u7c7b\u5728 1 \u697c 2 \u533a\u201d&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7d22\u5f15\u4e2d\u95f4\u9875<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7ea6 1000 \u4e2a<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ff9900\">\u7b2c 3 \u5c42<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u53f6\u5b50\u8282\u70b9<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7d22\u5f15\u5b57\u6bb5\u503c &#043; \u6570\u636e Page \u6307\u9488&#xff08;MyISAM&#xff09;\/ \u4e3b\u952e\u503c&#xff08;InnoDB&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u4e66\u67b6\u76ee\u5f55&#xff08;\u201cA001 \u53f7\u4e66\u5728 1 \u697c 1 \u533a 1 \u67b6 1 \u5c42\u201d&#xff09;<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7d22\u5f15\u53f6\u5b50\u9875<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7ea6 8000 \u4e2a<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ff9900\">\u6570\u636e\u5c42<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u6570\u636e\u9875<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u5b8c\u6574\u6570\u636e\u8bb0\u5f55<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u5b9e\u9645\u7684\u4e66\u7c4d\u5185\u5bb9<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u6570\u636e\u9875<\/span><\/td>\n<td><span style=\"color:#ff9900\">\u7ea6 80000 \u4e2a<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>3.1.2 B &#043; \u6811\u7684\u6838\u5fc3\u7279\u6027&#xff08;\u8bed\u6cd5\u5173\u8054&#xff09;<\/h5>\n<li>\u6709\u5e8f\u6027&#xff1a;\u540c\u4e00\u5c42\u8282\u70b9\u7684\u952e\u503c\u6309\u5347\u5e8f\u6392\u5217&#xff08;\u8bed\u6cd5\u4e0a\u4f53\u73b0\u4e3a \u201c\u67e5\u8be2\u7ed3\u679c\u9ed8\u8ba4\u6309\u7d22\u5f15\u5b57\u6bb5\u6392\u5e8f\u201d&#xff09;&#xff1b;\n<p>&#8212; \u8bed\u6cd5\u9a8c\u8bc1&#xff1a;\u4e3b\u952e\u7d22\u5f15\u6709\u5e8f<br \/>\nCREATE TABLE user (id INT PRIMARY KEY, name VARCHAR(16));<br \/>\nINSERT INTO user VALUES(3, &#039;\u5f20\u4e09&#039;), (1, &#039;\u674e\u56db&#039;), (2, &#039;\u738b\u4e94&#039;);<br \/>\nSELECT * FROM user; &#8212; \u7ed3\u679c\u6309id\u5347\u5e8f&#xff1a;1&#xff08;\u674e\u56db&#xff09;\u30012&#xff08;\u738b\u4e94&#xff09;\u30013&#xff08;\u5f20\u4e09&#xff09;<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;B&#043;\u6811\u7684\u53f6\u5b50\u8282\u70b9\u6309id\u6709\u5e8f\u6392\u5217&#xff0c;\u67e5\u8be2\u65f6\u76f4\u63a5\u904d\u5386\u53f6\u5b50\u8282\u70b9&#xff0c;\u65e0\u9700\u6392\u5e8f\u3002<\/p>\n<\/li>\n<li>\u53f6\u5b50\u8282\u70b9\u94fe\u5f0f\u8fde\u63a5&#xff1a;\u6240\u6709\u53f6\u5b50\u8282\u70b9\u901a\u8fc7\u53cc\u5411\u94fe\u8868\u8fde\u63a5&#xff08;\u8bed\u6cd5\u4e0a\u4f53\u73b0\u4e3a \u201c\u8303\u56f4\u67e5\u8be2\u9ad8\u6548\u201d&#xff09;&#xff1b;\n<p>&#8212; \u8bed\u6cd5\u9a8c\u8bc1&#xff1a;\u8303\u56f4\u67e5\u8be2\u9ad8\u6548<br \/>\nSELECT * FROM user WHERE id BETWEEN 1 AND 3; &#8212; \u4ec5\u9700\u904d\u5386\u53f6\u5b50\u8282\u70b9\u94fe\u8868&#xff0c;\u65e0\u9700\u56de\u67e5\u4e0a\u5c42\u8282\u70b9<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u53f6\u5b50\u8282\u70b9\u94fe\u8868\u53ef\u76f4\u63a5\u4eceid&#061;1\u904d\u5386\u5230id&#061;3&#xff0c;\u65e0\u9700\u91cd\u590d\u67e5\u627e\u6839\u8282\u70b9\/\u975e\u53f6\u5b50\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\u975e\u53f6\u5b50\u8282\u70b9\u4e0d\u5b58\u6570\u636e&#xff1a;\u4ec5\u5b58\u952e\u503c\u548c\u6307\u9488&#xff08;\u8bed\u6cd5\u4e0a\u4f53\u73b0\u4e3a \u201c\u7d22\u5f15\u5360\u7528\u7a7a\u95f4\u5c0f\u201d&#xff09;&#xff1b;\n<ul>\n<li>\u5bf9\u6bd4 B \u6811&#xff1a;B \u6811\u7684\u975e\u53f6\u5b50\u8282\u70b9\u5b58\u6570\u636e&#xff0c;\u5bfc\u81f4\u5355\u4e2a\u8282\u70b9\u80fd\u5b58\u7684\u952e\u503c\u5c11\u2192\u6811\u9ad8\u66f4\u9ad8\u2192IO \u6b21\u6570\u66f4\u591a&#xff08;B \u6811\u67e5 800 \u4e07\u6570\u636e\u9700 5 \u6b21 IO&#xff0c;B &#043; \u6811\u4ec5 3 \u6b21&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<h5>3.1.3 \u4e3b\u952e\u7d22\u5f15\u7684 B &#043; \u6811\u6784\u5efa&#xff08;\u8bed\u6cd5 &#043; \u5e95\u5c42\u62c6\u89e3&#xff09;<\/h5>\n<p>CREATE TABLE user (<br \/>\n    id INT PRIMARY KEY, &#8212; \u4e3b\u952e\u5b57\u6bb5&#xff0c;\u81ea\u52a8\u521b\u5efa\u805a\u7c07\u7d22\u5f15<br \/>\n    age INT NOT NULL,<br \/>\n    name VARCHAR(16) NOT NULL<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u6784\u5efa\u8fc7\u7a0b&#xff08;\u9010\u6b65\u62c6\u89e3&#xff09;&#xff1a;<\/p>\n<li>\u521d\u59cb\u5316\u6839\u8282\u70b9&#xff1a;\u521b\u5efa 1 \u4e2a\u7d22\u5f15\u6839\u9875&#xff0c;\u521d\u59cb\u4e3a\u7a7a&#xff1b;<\/li>\n<li>\u63d2\u5165\u7b2c\u4e00\u6761\u6570\u636e&#xff08;id&#061;1&#xff09;&#xff1a;\u5c06 id&#061;1 \u5199\u5165\u6839\u8282\u70b9&#xff08;\u6b64\u65f6\u6839\u8282\u70b9\u4e5f\u662f\u53f6\u5b50\u8282\u70b9&#xff09;&#xff0c;\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u5b8c\u6574\u6570\u636e&#xff08;id&#061;1, age&#061;18, name &#061; \u674e\u56db&#xff09;&#xff1b;<\/li>\n<li>\u63d2\u5165\u7b2c\u4e8c\u6761\u6570\u636e&#xff08;id&#061;3&#xff09;&#xff1a;id&#061;3&gt;1&#xff0c;\u8ffd\u52a0\u5230\u6839\u8282\u70b9&#xff0c;\u6839\u8282\u70b9\u4ecd\u80fd\u5bb9\u7eb3&#xff08;B &#043; \u6811\u8282\u70b9\u9ed8\u8ba4\u53ef\u5b58\u7ea6 1000 \u4e2a\u952e\u503c&#xff09;&#xff1b;<\/li>\n<li>\u63d2\u5165\u7b2c\u4e09\u6761\u6570\u636e&#xff08;id&#061;2&#xff09;&#xff1a;id&#061;2 \u4ecb\u4e8e 1 \u548c 3 \u4e4b\u95f4&#xff0c;\u63d2\u5165\u5230\u4e2d\u95f4\u4f4d\u7f6e&#xff0c;\u4fdd\u6301\u6709\u5e8f&#xff1b;<\/li>\n<li>\u6570\u636e\u91cf\u8fbe\u5230\u8282\u70b9\u4e0a\u9650&#xff1a;\u5f53\u6839\u8282\u70b9\u5b58\u6ee1 1000 \u4e2a\u952e\u503c\u65f6&#xff0c;\u89e6\u53d1 \u201c\u9875\u5206\u88c2\u201d\u2192 \u6839\u8282\u70b9\u5206\u88c2\u4e3a 2 \u4e2a\u53f6\u5b50\u8282\u70b9&#xff0c;\u65b0\u5efa\u6839\u8282\u70b9\u5b58\u50a8 2 \u4e2a\u53f6\u5b50\u8282\u70b9\u7684\u952e\u503c\u8303\u56f4&#xff08;\u5982 \u201c1-500 \u5728\u5de6\u8282\u70b9&#xff0c;501-1000 \u5728\u53f3\u8282\u70b9\u201d&#xff09;&#xff1b;<\/li>\n<li>\u6301\u7eed\u63d2\u5165\u6570\u636e&#xff1a;\u91cd\u590d\u9875\u5206\u88c2\u8fc7\u7a0b&#xff0c;\u6700\u7ec8\u5f62\u6210 3 \u5c42 B &#043; \u6811&#xff08;\u6839\u8282\u70b9\u2192\u975e\u53f6\u5b50\u8282\u70b9\u2192\u53f6\u5b50\u8282\u70b9&#xff09;\u3002<\/li>\n<h4>3.2 \u4e3a\u4ec0\u4e48\u9009\u62e9 B &#043; \u6811&#xff1f;<\/h4>\n<p>\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u56e0\u4e0d\u9002\u5408 MySQL \u7684 IO \u573a\u666f&#xff0c;\u672a\u88ab\u4e3b\u6d41\u5b58\u50a8\u5f15\u64ce\u91c7\u7528&#xff0c;\u5bf9\u5e94\u8bed\u6cd5\u652f\u6301\u60c5\u51b5&#xff1a;<\/p>\n<table>\n<tr>\u6570\u636e\u7ed3\u6784\u8bed\u6cd5\u652f\u6301\u60c5\u51b5\u6838\u5fc3\u7f3a\u9677&#xff08;\u8bed\u6cd5\u65e0\u6cd5\u5f25\u8865&#xff09;\u5e95\u5c42 IO \u5bf9\u6bd4&#xff08;800 \u4e07\u6570\u636e&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u94fe\u8868<\/td>\n<td>\u65e0\u4e13\u95e8\u8bed\u6cd5\u652f\u6301<\/td>\n<td>\u7ebf\u6027\u904d\u5386&#xff0c;\u67e5\u8be2\u6548\u7387 O (n)&#xff0c;\u65e0\u6cd5\u5e94\u5bf9\u6d77\u91cf\u6570\u636e<\/td>\n<td>\u9700 800 \u4e07\u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>\u4e8c\u53c9\u641c\u7d22\u6811<\/td>\n<td>\u65e0\u4e13\u95e8\u8bed\u6cd5\u652f\u6301<\/td>\n<td>\u6613\u9000\u5316&#xff0c;\u6709\u5e8f\u63d2\u5165\u65f6\u9000\u5316\u4e3a\u94fe\u8868&#xff0c;\u8bed\u6cd5\u65e0\u6cd5\u4fdd\u8bc1\u5e73\u8861<\/td>\n<td>\u6700\u574f\u9700 800 \u4e07\u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>AVL \u6811 \/ \u7ea2\u9ed1\u6811<\/td>\n<td>\u65e0\u4e13\u95e8\u8bed\u6cd5\u652f\u6301<\/td>\n<td>\u6811\u9ad8\u8fc7\u9ad8&#xff08;\u4e8c\u53c9\u7ed3\u6784&#xff0c;800 \u4e07\u6570\u636e\u6811\u9ad8\u224823&#xff09;&#xff0c;\u8bed\u6cd5\u65e0\u6cd5\u51cf\u5c11 IO \u6b21\u6570<\/td>\n<td>\u9700 23 \u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>Hash \u8868<\/td>\n<td>MEMORY \u5f15\u64ce\u652f\u6301&#xff08;CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5\u540d) USING HASH&#xff09;<\/td>\n<td>\u4e0d\u652f\u6301\u8303\u56f4\u67e5\u8be2&#xff08;\u5982 WHERE id BETWEEN 1 AND 100&#xff09;&#xff0c;\u8bed\u6cd5\u65e0\u6cd5\u4f18\u5316\u8303\u56f4\u67e5\u8be2\u6548\u7387<\/td>\n<td>\u7b49\u503c\u67e5\u8be2 1 \u6b21 IO&#xff0c;\u8303\u56f4\u67e5\u8be2 800 \u4e07\u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>B \u6811<\/td>\n<td>\u65e0\u4e13\u95e8\u8bed\u6cd5\u652f\u6301&#xff08;InnoDB\/MyISAM \u9ed8\u8ba4 B &#043; \u6811&#xff09;<\/td>\n<td>\u8282\u70b9\u5b58\u50a8\u6570\u636e&#xff0c;\u5355\u4e2a\u8282\u70b9\u952e\u503c\u5c11&#xff08;\u6811\u9ad8\u22484&#xff09;&#xff0c;\u8bed\u6cd5\u65e0\u6cd5\u964d\u4f4e IO \u6b21\u6570<\/td>\n<td>\u9700 4 \u6b21 IO<\/td>\n<\/tr>\n<tr>\n<td>B &#043; \u6811<\/td>\n<td>\u6240\u6709\u5f15\u64ce\u9ed8\u8ba4\u652f\u6301&#xff08;CREATE INDEX \u8bed\u6cd5&#xff09;<\/td>\n<td>\u65e0\u660e\u663e\u7f3a\u9677&#xff0c;\u9002\u914d\u78c1\u76d8 IO \u7279\u6027<\/td>\n<td>\u9700 3 \u6b21 IO<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u8bed\u6cd5\u9a8c\u8bc1&#xff1a;MEMORY \u5f15\u64ce\u7684 Hash \u7d22\u5f15&#xff08;\u8865\u5145\u5931\u6548\u573a\u666f&#xff09;<\/h5>\n<p>CREATE TABLE hash_test (<br \/>\n    id INT,<br \/>\n    name VARCHAR(20),<br \/>\n    INDEX idx_id (id) USING HASH &#8212; \u660e\u786e\u6307\u5b9aHash\u7d22\u5f15<br \/>\n) ENGINE&#061;MEMORY;<\/p>\n<p>INSERT INTO hash_test VALUES(1, &#039;\u5f20\u4e09&#039;), (2, &#039;\u674e\u56db&#039;), (3, &#039;\u738b\u4e94&#039;);<\/p>\n<p>&#8212; \u652f\u6301\u7b49\u503c\u67e5\u8be2&#xff08;Hash\u7d22\u5f15\u9ad8\u6548&#xff09;<br \/>\nEXPLAIN SELECT * FROM hash_test WHERE id&#061;2;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;type&#061;ref&#xff0c;rows&#061;1&#xff08;\u4ec5\u626b\u63cf1\u884c&#xff09;&#xff0c;Extra&#061;Using index&#xff08;\u4f7f\u7528Hash\u7d22\u5f15&#xff09;<\/p>\n<p>&#8212; \u4e0d\u652f\u6301\u8303\u56f4\u67e5\u8be2&#xff08;Hash\u7d22\u5f15\u5931\u6548&#xff09;<br \/>\nEXPLAIN SELECT * FROM hash_test WHERE id BETWEEN 1 AND 3;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;type&#061;ALL&#xff0c;rows&#061;3&#xff08;\u5168\u8868\u626b\u63cf&#xff09;&#xff0c;Extra&#061;&#xff08;\u65e0\u7d22\u5f15\u6807\u8bc6&#xff09;<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;Hash\u7d22\u5f15\u662f\u901a\u8fc7id\u8ba1\u7b97Hash\u503c&#xff08;\u5982id&#061;2\u2192Hash&#061;100&#xff09;&#xff0c;\u65e0\u6cd5\u901a\u8fc7Hash\u503c\u5224\u65ad\u8303\u56f4&#xff0c;\u53ea\u80fd\u5168\u8868\u626b\u63cf\u3002<\/p>\n<h4>3.3 \u6838\u5fc3\u8bed\u6cd5\u603b\u7ed3&#xff08;B &#043; \u6811\u5173\u8054&#xff09;<\/h4>\n<table>\n<tr>\u64cd\u4f5c\u7c7b\u578b\u8bed\u6cd5\u7ed3\u6784\u5e95\u5c42 B &#043; \u6811\u5173\u8054\u6027\u80fd\u6838\u5fc3\u6307\u6807<\/tr>\n<tbody>\n<tr>\n<td>\u521b\u5efa\u805a\u7c07\u7d22\u5f15<\/td>\n<td>CREATE TABLE \u8868\u540d (\u5b57\u6bb5 INT PRIMARY KEY); \u6216 ALTER TABLE \u8868\u540d ADD PRIMARY KEY (\u5b57\u6bb5);<\/td>\n<td>\u4e3b\u952e\u5b57\u6bb5\u4e3a B &#043; \u6811\u952e\u503c&#xff0c;\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u5b8c\u6574\u6570\u636e&#xff1b;\u6811\u9ad8\u22483 \u5c42&#xff0c;\u67e5\u8be2\u9700 3 \u6b21 IO<\/td>\n<td>IO \u6b21\u6570&#xff1a;3 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>\u521b\u5efa\u8f85\u52a9\u7d22\u5f15<\/td>\n<td>CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5); \u6216 ALTER TABLE \u8868\u540d ADD INDEX \u7d22\u5f15\u540d (\u5b57\u6bb5);<\/td>\n<td>\u5b57\u6bb5\u4e3a B &#043; \u6811\u952e\u503c&#xff0c;\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u4e3b\u952e\u503c&#xff1b;\u67e5\u8be2\u9700\u5148\u67e5\u8f85\u52a9\u7d22\u5f15&#xff08;3 \u6b21 IO&#xff09;&#xff0c;\u518d\u67e5\u805a\u7c07\u7d22\u5f15&#xff08;3 \u6b21 IO&#xff09;<\/td>\n<td>IO \u6b21\u6570&#xff1a;6 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>Hash \u7d22\u5f15\u521b\u5efa<\/td>\n<td>CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5) USING HASH;<\/td>\n<td>\u4ec5 MEMORY \u5f15\u64ce\u652f\u6301&#xff0c;B &#043; \u6811\u7ed3\u6784\u66ff\u6362\u4e3a Hash \u8868&#xff1b;\u7b49\u503c\u67e5\u8be2 1 \u6b21 IO&#xff0c;\u8303\u56f4\u67e5\u8be2\u5168\u8868\u626b\u63cf<\/td>\n<td>IO \u6b21\u6570&#xff1a;1 \u6b21&#xff08;\u7b49\u503c&#xff09;\/N \u6b21&#xff08;\u8303\u56f4&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u56db\u3001MySQL \u7d22\u5f15\u7684\u5206\u7c7b\u4e0e\u8bed\u6cd5\u8be6\u89e3<\/h2>\n<p>MySQL \u7d22\u5f15\u6309\u529f\u80fd\u5206\u4e3a\u4e3b\u952e\u7d22\u5f15\u3001\u552f\u4e00\u7d22\u5f15\u3001\u666e\u901a\u7d22\u5f15\u3001\u5168\u6587\u7d22\u5f15&#xff0c;\u6309\u5b58\u50a8\u7ed3\u6784\u5206\u4e3a\u805a\u7c07\u7d22\u5f15\u3001\u975e\u805a\u7c07\u7d22\u5f15\u3002<\/p>\n<h4>4.1 \u4e3b\u952e\u7d22\u5f15&#xff08;Primary Key&#xff09;\u2014\u2014 \u6548\u7387\u6700\u9ad8\u7684\u7d22\u5f15<\/h4>\n<p>\u4e3b\u952e\u7d22\u5f15\u662f MySQL \u81ea\u52a8\u4e3a \u201c\u4e3b\u952e\u5b57\u6bb5\u201d \u521b\u5efa\u7684\u805a\u7c07\u7d22\u5f15&#xff0c;\u8bed\u6cd5\u6838\u5fc3\u662f \u201cPRIMARY KEY\u201d \u7ea6\u675f\u3002<\/p>\n<h5>4.1.1 \u8bed\u6cd5\u7ed3\u6784&#xff08;\u4e09\u79cd\u521b\u5efa\u65b9\u5f0f &#043; \u5e95\u5c42\u7ec6\u8282&#xff09;<\/h5>\n<h6>\u65b9\u5f0f 1&#xff1a;\u521b\u5efa\u8868\u65f6\u76f4\u63a5\u6307\u5b9a\u4e3b\u952e&#xff08;\u6700\u5e38\u7528&#xff09;<\/h6>\n<p>CREATE TABLE user1 (<br \/>\n    id INT(11) NOT NULL PRIMARY KEY, &#8212; \u5b57\u6bb5\u540e\u76f4\u63a5\u52a0PRIMARY KEY<br \/>\n    name VARCHAR(30) NOT NULL<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>INT(11)&#xff1a;\u663e\u793a\u5bbd\u5ea6 11 \u4f4d&#xff08;\u4ec5\u7528\u4e8e\u5c55\u793a&#xff0c;\u5e95\u5c42\u5b58\u50a8 4 \u5b57\u8282&#xff09;&#xff0c;\u4e3b\u952e\u5b57\u6bb5\u5efa\u8bae\u7528 INT&#xff08;\u5360\u7528\u7a7a\u95f4\u5c0f&#xff0c;\u6392\u5e8f\u5feb&#xff09;&#xff1b;<\/li>\n<li>NOT NULL&#xff1a;PRIMARY KEY \u9690\u542b NOT NULL \u7ea6\u675f&#xff08;\u5373\u4f7f\u7701\u7565&#xff0c;MySQL \u4e5f\u4f1a\u81ea\u52a8\u6dfb\u52a0&#xff09;&#xff1b;<\/li>\n<li>\u7d22\u5f15\u540d\u56fa\u5b9a\u4e3a \u201cPRIMARY\u201d&#xff08;\u65e0\u6cd5\u81ea\u5b9a\u4e49&#xff0c;\u53ef\u901a\u8fc7SHOW KEYS FROM user1\u9a8c\u8bc1&#xff09;&#xff1b;<\/li>\n<li>\u805a\u7c07\u7d22\u5f15\u7684\u53f6\u5b50\u8282\u70b9\u5b58\u50a8\u5b8c\u6574\u6570\u636e&#xff0c;\u67e5\u8be2\u65f6\u65e0\u9700\u56de\u8868&#xff08;IO \u6b21\u6570\u6700\u5c11&#xff09;\u3002<\/li>\n<\/ul>\n<h6>\u65b9\u5f0f 2&#xff1a;\u521b\u5efa\u8868\u65f6\u5728\u672b\u5c3e\u6307\u5b9a\u4e3b\u952e&#xff08;\u9002\u5408\u590d\u5408\u4e3b\u952e&#xff09;<\/h6>\n<p>CREATE TABLE user2 (<br \/>\n    id INT(11) NOT NULL,<br \/>\n    dept_id INT(11) NOT NULL,<br \/>\n    name VARCHAR(30) NOT NULL,<br \/>\n    PRIMARY KEY(id, dept_id) &#8212; \u590d\u5408\u4e3b\u952e&#xff1a;id&#043;dept_id\u8054\u5408\u4f5c\u4e3a\u4e3b\u952e<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>\u590d\u5408\u4e3b\u952e\u7684 B &#043; \u6811\u952e\u503c\u662f \u201cid&#043;dept_id\u201d&#xff08;\u62fc\u63a5\u540e\u6392\u5e8f&#xff09;&#xff0c;\u5982 (1,10)\u3001(1,20)\u3001(2,10)&#xff1b;<\/li>\n<li>\u552f\u4e00\u6027\u6821\u9a8c&#xff1a;\u4ec5\u5f53 id \u548c dept_id \u90fd\u76f8\u540c\u65f6&#xff0c;\u624d\u5224\u5b9a\u4e3a\u91cd\u590d&#xff08;\u5982 (1,10) \u548c (1,10) \u91cd\u590d&#xff0c;(1,10) \u548c (1,20) \u4e0d\u91cd\u590d&#xff09;&#xff1b;<\/li>\n<li>\u6392\u5e8f\u89c4\u5219&#xff1a;\u5148\u6309 id \u5347\u5e8f&#xff0c;id \u76f8\u540c\u65f6\u6309 dept_id \u5347\u5e8f&#xff08;\u8bed\u6cd5\u4e0a\u4f53\u73b0\u4e3aSELECT * FROM user2\u7ed3\u679c\u6309\u6b64\u987a\u5e8f&#xff09;\u3002<\/li>\n<\/ul>\n<h6>\u65b9\u5f0f 3&#xff1a;\u521b\u5efa\u8868\u540e\u6dfb\u52a0\u4e3b\u952e&#xff08;\u8868\u5df2\u5b58\u5728\u65f6\u4f7f\u7528&#xff09;<\/h6>\n<p>CREATE TABLE user3 (<br \/>\n    id INT(11) NOT NULL,<br \/>\n    name VARCHAR(30) NOT NULL<br \/>\n);<\/p>\n<p>ALTER TABLE user3 ADD PRIMARY KEY(id);<\/p>\n<p>\u5e95\u5c42\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\u524d\u63d0&#xff1a;\u8868\u4e2d id \u5b57\u6bb5\u5fc5\u987b \u201c\u975e\u7a7a\u4e14\u552f\u4e00\u201d&#xff08;\u5426\u5219\u62a5\u9519&#xff09;&#xff0c;MySQL \u4f1a\u5148\u5168\u8868\u626b\u63cf\u6821\u9a8c&#xff1b;<\/li>\n<li>\u6027\u80fd&#xff1a;\u82e5\u8868\u4e2d\u5df2\u6709\u6d77\u91cf\u6570\u636e&#xff08;\u5982 800 \u4e07&#xff09;&#xff0c;\u6dfb\u52a0\u4e3b\u952e\u8017\u65f6\u7ea6 1 \u5206\u949f&#xff08;\u9700\u6784\u5efa\u805a\u7c07\u7d22\u5f15 B &#043; \u6811&#xff09;&#xff1b;<\/li>\n<li>\u6570\u636e\u91cd\u6392&#xff1a;InnoDB \u4f1a\u6309 id \u5b57\u6bb5\u91cd\u65b0\u6392\u5e8f\u6570\u636e\u9875&#xff08;\u805a\u7c07\u7d22\u5f15\u7684\u7279\u6027&#xff09;&#xff0c;\u53ef\u80fd\u5bfc\u81f4 \u201c\u9875\u5206\u88c2\u201d&#xff0c;\u5efa\u8bae\u521b\u5efa\u8868\u65f6\u76f4\u63a5\u6307\u5b9a\u4e3b\u952e&#xff08;\u907f\u514d\u540e\u671f\u91cd\u6392&#xff09;\u3002<\/li>\n<\/ul>\n<h5>4.1.2 \u4e3b\u952e\u7d22\u5f15\u7684\u6838\u5fc3\u7279\u6027<\/h5>\n<li>\u552f\u4e00\u6027&#xff1a;\u4e3b\u952e\u503c\u5fc5\u987b\u552f\u4e00&#xff0c;\u63d2\u5165\u91cd\u590d\u503c\u62a5\u9519&#xff08;\u5e95\u5c42\u662f B &#043; \u6811\u7684\u952e\u503c\u552f\u4e00\u6027\u6821\u9a8c&#xff09;&#xff1b;\n<p>INSERT INTO user1 VALUES(1, &#039;\u5f20\u4e09&#039;);<br \/>\nINSERT INTO user1 VALUES(1, &#039;\u674e\u56db&#039;); &#8212; \u62a5\u9519&#xff1a;Duplicate entry &#039;1&#039; for key &#039;PRIMARY&#039;<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u63d2\u5165\u65f6\u904d\u5386B&#043;\u6811&#xff0c;\u53d1\u73b0id&#061;1\u5df2\u5b58\u5728&#xff0c;\u89e6\u53d1\u552f\u4e00\u6027\u7ea6\u675f&#xff0c;\u7ec8\u6b62\u63d2\u5165\u3002<\/p>\n<\/li>\n<li>\u975e\u7a7a\u6027&#xff1a;\u4e3b\u952e\u5b57\u6bb5\u4e0d\u5141\u8bb8 NULL&#xff08;\u5e95\u5c42\u662f B &#043; \u6811\u65e0\u6cd5\u5b58\u50a8 NULL \u952e\u503c&#xff0c;NULL \u65e0\u6392\u5e8f\u610f\u4e49&#xff09;&#xff1b;\n<p>INSERT INTO user1 VALUES(NULL, &#039;\u738b\u4e94&#039;); &#8212; \u62a5\u9519&#xff1a;Column &#039;id&#039; cannot be null<\/p>\n<\/li>\n<li>\u4e00\u4e2a\u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u4e3b\u952e&#xff1a;\u91cd\u590d\u521b\u5efa\u4e3b\u952e\u62a5\u9519&#xff08;\u5e95\u5c42\u662f\u805a\u7c07\u7d22\u5f15\u53ea\u80fd\u6709\u4e00\u4e2a&#xff0c;\u6570\u636e\u53ea\u80fd\u6309\u4e00\u79cd\u987a\u5e8f\u5b58\u50a8&#xff09;&#xff1b;\n<p>ALTER TABLE user1 ADD PRIMARY KEY(name); &#8212; \u62a5\u9519&#xff1a;Multiple primary key defined<\/p>\n<\/li>\n<li>\u81ea\u589e\u4e3b\u952e\u4f18\u5316&#xff1a;\n<p>CREATE TABLE user4 (<br \/>\n    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, &#8212; \u81ea\u589e\u4e3b\u952e<br \/>\n    name VARCHAR(30) NOT NULL<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u4f18\u5316\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u81ea\u589e\u4e3b\u952e\u6309\u987a\u5e8f\u63d2\u5165&#xff0c;\u907f\u514d B &#043; \u6811\u7684 \u201c\u9875\u5206\u88c2\u201d&#xff08;\u65e0\u5e8f\u63d2\u5165\u4f1a\u5bfc\u81f4\u9875\u5206\u88c2&#xff0c;\u589e\u52a0 IO&#xff09;&#xff1b;<\/li>\n<li>\u81ea\u589e\u4e3b\u952e\u7684\u4e0b\u4e00\u4e2a\u503c\u5b58\u50a8\u5728 InnoDB \u7684\u7cfb\u7edf\u8868\u4e2d&#xff0c;\u63d2\u5165\u65f6\u76f4\u63a5\u83b7\u53d6&#xff0c;\u65e0\u9700\u8ba1\u7b97&#xff1b;<\/li>\n<li>\u8bed\u6cd5\u4e0a\u53ef\u7701\u7565 id \u5b57\u6bb5\u63d2\u5165&#xff1a;INSERT INTO user4(name) VALUES(&#039;\u5f20\u4e09&#039;)&#xff0c;id \u81ea\u52a8\u4e3a 1\u3002<\/li>\n<\/ul>\n<\/li>\n<h5>4.1.3 \u5e38\u89c1\u9519\u8bef\u4e0e\u89e3\u51b3\u65b9\u6848<\/h5>\n<table>\n<tr>\u9519\u8bef\u4fe1\u606f\u9519\u8bef\u539f\u56e0\u5e95\u5c42\u6eaf\u6e90\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>Duplicate entry &#039;xxx&#039; for key &#039;PRIMARY&#039;<\/td>\n<td>\u63d2\u5165\u91cd\u590d\u7684\u4e3b\u952e\u503c<\/td>\n<td>B &#043; \u6811\u952e\u503c\u552f\u4e00\u6027\u6821\u9a8c\u5931\u8d25<\/td>\n<td>\u786e\u4fdd\u4e3b\u952e\u503c\u552f\u4e00&#xff1b;\u4f7f\u7528\u81ea\u589e\u4e3b\u952e&#xff08;AUTO_INCREMENT&#xff09;&#xff1b;\u5220\u9664\u91cd\u590d\u6570\u636e&#xff1a;DELETE FROM \u8868\u540d WHERE id&#061;xxx;<\/td>\n<\/tr>\n<tr>\n<td>Column &#039;xxx&#039; cannot be null<\/td>\n<td>\u4e3b\u952e\u5b57\u6bb5\u63d2\u5165 NULL \u503c<\/td>\n<td>B &#043; \u6811\u65e0\u6cd5\u5b58\u50a8 NULL \u952e\u503c&#xff08;NULL \u65e0\u6392\u5e8f\u610f\u4e49&#xff09;<\/td>\n<td>\u4e3a\u4e3b\u952e\u5b57\u6bb5\u6dfb\u52a0 NOT NULL \u7ea6\u675f&#xff1b;\u63d2\u5165\u65f6\u4f20\u5165\u975e\u7a7a\u503c&#xff1b;\u82e5\u9700\u7a7a\u503c&#xff0c;\u7528 0 \/ \u7a7a\u5b57\u7b26\u4e32\u66ff\u4ee3<\/td>\n<\/tr>\n<tr>\n<td>Multiple primary key defined<\/td>\n<td>\u91cd\u590d\u521b\u5efa\u4e3b\u952e\u7d22\u5f15<\/td>\n<td>\u805a\u7c07\u7d22\u5f15\u53ea\u80fd\u6709\u4e00\u4e2a&#xff08;\u6570\u636e\u53ea\u80fd\u6309\u4e00\u79cd\u987a\u5e8f\u5b58\u50a8&#xff09;<\/td>\n<td>\u5220\u9664\u5df2\u5b58\u5728\u7684\u4e3b\u952e&#xff1a;ALTER TABLE \u8868\u540d DROP PRIMARY KEY; \u518d\u521b\u5efa\u65b0\u4e3b\u952e<\/td>\n<\/tr>\n<tr>\n<td>Incorrect table definition; there can be only one auto column<\/td>\n<td>\u591a\u4e2a\u5b57\u6bb5\u8bbe\u7f6e AUTO_INCREMENT<\/td>\n<td>\u81ea\u589e\u5c5e\u6027\u4f9d\u8d56\u4e3b\u952e&#xff0c;\u4e00\u4e2a\u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u81ea\u589e\u5e8f\u5217&#xff08;\u5b58\u50a8\u5728\u7cfb\u7edf\u8868\u4e2d&#xff09;<\/td>\n<td>\u4ec5\u4e3a\u4e3b\u952e\u5b57\u6bb5\u8bbe\u7f6e AUTO_INCREMENT&#xff1b;\u82e5\u9700\u591a\u4e2a\u81ea\u589e\u5b57\u6bb5&#xff0c;\u7528\u89e6\u53d1\u5668\u5b9e\u73b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.2 \u552f\u4e00\u7d22\u5f15&#xff08;Unique Index&#xff09;\u2014\u2014 \u4fdd\u8bc1\u5b57\u6bb5\u552f\u4e00\u6027<\/h4>\n<p>\u552f\u4e00\u7d22\u5f15\u7528\u4e8e\u4fdd\u8bc1\u5b57\u6bb5\u503c\u552f\u4e00&#xff08;\u5141\u8bb8 NULL \u503c&#xff0c;\u4e14\u53ef\u591a\u4e2a NULL&#xff09;&#xff0c;\u8bed\u6cd5\u6838\u5fc3\u662f \u201cUNIQUE\u201d \u5173\u952e\u5b57&#xff0c;\u5176\u5b9e\u6211\u4eec\u5728\u4e4b\u524d\u4e5f\u6709\u8bb2\u5230\u8fc7&#xff0c;\u4e0d\u5c31\u662f\u552f\u4e00\u952e\u5417\u3002<\/p>\n<h5>4.2.1 \u8bed\u6cd5\u7ed3\u6784&#xff08;\u4e09\u79cd\u521b\u5efa\u65b9\u5f0f &#043; \u5e95\u5c42\u7ec6\u8282&#xff09;<\/h5>\n<h6>\u65b9\u5f0f 1&#xff1a;\u521b\u5efa\u8868\u65f6\u76f4\u63a5\u6307\u5b9a\u552f\u4e00\u7d22\u5f15<\/h6>\n<p>CREATE TABLE user4 (<br \/>\n    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br \/>\n    phone VARCHAR(11) NOT NULL UNIQUE, &#8212; \u624b\u673a\u53f7&#xff1a;\u975e\u7a7a&#043;\u552f\u4e00<br \/>\n    email VARCHAR(30) UNIQUE &#8212; \u90ae\u7bb1&#xff1a;\u5141\u8bb8NULL&#043;\u552f\u4e00<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>\u552f\u4e00\u7d22\u5f15\u7684 B &#043; \u6811\u7ed3\u6784\u4e0e\u4e3b\u952e\u7d22\u5f15\u7c7b\u4f3c&#xff0c;\u4f46\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 \u201c\u552f\u4e00\u5b57\u6bb5\u503c &#043; \u4e3b\u952e\u503c\u201d&#xff08;\u8f85\u52a9\u7d22\u5f15\u7279\u6027&#xff09;&#xff1b;<\/li>\n<li>phone \u5b57\u6bb5\u975e\u7a7a &#043; \u552f\u4e00&#xff1a;\u529f\u80fd\u63a5\u8fd1\u4e3b\u952e&#xff0c;\u4f46\u4e00\u4e2a\u8868\u53ef\u591a\u4e2a&#xff08;\u5982\u540c\u65f6\u7ed9 phone \u548c email \u52a0\u552f\u4e00\u7d22\u5f15&#xff09;&#xff1b;<\/li>\n<li>email \u5b57\u6bb5\u5141\u8bb8 NULL&#xff1a;NULL \u4e0d\u53c2\u4e0e\u552f\u4e00\u6027\u6821\u9a8c&#xff08;\u591a\u4e2a NULL \u4e0d\u51b2\u7a81&#xff09;&#xff0c;\u5e95\u5c42\u662f B &#043; \u6811\u5c06 NULL \u89c6\u4e3a \u201c\u6700\u5c0f\u952e\u503c\u201d&#xff0c;\u5b58\u50a8\u5728\u53f6\u5b50\u8282\u70b9\u6700\u5de6\u4fa7\u3002<\/li>\n<\/ul>\n<h6>\u65b9\u5f0f 2&#xff1a;\u521b\u5efa\u8868\u65f6\u5728\u672b\u5c3e\u6307\u5b9a\u552f\u4e00\u7d22\u5f15&#xff08;\u590d\u5408\u552f\u4e00\u7d22\u5f15&#xff09;<\/h6>\n<p>CREATE TABLE user5 (<br \/>\n    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br \/>\n    dept_id INT(11) NOT NULL,<br \/>\n    emp_no VARCHAR(20) NOT NULL,<br \/>\n    UNIQUE idx_dept_emp(dept_id, emp_no) &#8212; \u590d\u5408\u552f\u4e00\u7d22\u5f15<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u9a8c\u8bc1&#xff1a;<\/p>\n<p>INSERT INTO user5(dept_id, emp_no) VALUES(1, &#039;001&#039;);<br \/>\nINSERT INTO user5(dept_id, emp_no) VALUES(1, &#039;001&#039;); &#8212; \u62a5\u9519&#xff1a;Duplicate entry &#039;1-001&#039; for key &#039;idx_dept_emp&#039;<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u590d\u5408\u552f\u4e00\u7d22\u5f15\u7684\u952e\u503c\u662f\u201cdept_id&#043;emp_no\u201d&#xff0c;\u62fc\u63a5\u540e(1,001)\u5df2\u5b58\u5728&#xff0c;\u89e6\u53d1\u552f\u4e00\u6027\u6821\u9a8c\u3002<\/p>\n<h6>\u65b9\u5f0f 3&#xff1a;\u521b\u5efa\u8868\u540e\u6dfb\u52a0\u552f\u4e00\u7d22\u5f15&#xff08;\u4e24\u79cd\u8bed\u6cd5\u5bf9\u6bd4&#xff09;<\/h6>\n<p>&#8212; \u8bed\u6cd51&#xff1a;ALTER TABLE&#xff08;\u4fee\u6539\u8868\u7ed3\u6784&#xff09;<br \/>\nCREATE TABLE user6 (<br \/>\n    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br \/>\n    id_card VARCHAR(18)<br \/>\n);<br \/>\nALTER TABLE user6 ADD UNIQUE idx_id_card(id_card);<\/p>\n<p>&#8212; \u8bed\u6cd52&#xff1a;CREATE UNIQUE INDEX&#xff08;\u76f4\u63a5\u521b\u5efa\u7d22\u5f15&#xff09;<br \/>\nCREATE UNIQUE INDEX idx_id_card ON user6(id_card);<\/p>\n<p>\u5e95\u5c42\u533a\u522b&#xff1a;<\/p>\n<ul>\n<li>ALTER TABLE&#xff1a;\u4f1a\u89e6\u53d1\u8868\u9501&#xff08;MyISAM&#xff09;\u6216\u5143\u6570\u636e\u9501&#xff08;InnoDB&#xff09;&#xff0c;\u9501\u8868\u671f\u95f4\u65e0\u6cd5\u5199\u64cd\u4f5c&#xff1b;<\/li>\n<li>CREATE UNIQUE INDEX&#xff1a;InnoDB \u4e2d\u662f \u201c\u5728\u7ebf DDL\u201d&#xff08;MySQL 5.6&#043;&#xff09;&#xff0c;\u9501\u8868\u65f6\u95f4\u6781\u77ed&#xff08;\u4ec5\u4fee\u6539\u5143\u6570\u636e&#xff09;&#xff1b;<\/li>\n<li>\u529f\u80fd\u5b8c\u5168\u4e00\u81f4&#xff0c;\u5efa\u8bae\u4f18\u5148\u7528CREATE UNIQUE INDEX&#xff08;\u51cf\u5c11\u9501\u8868\u65f6\u95f4&#xff09;\u3002<\/li>\n<\/ul>\n<h5>4.2.2 \u552f\u4e00\u7d22\u5f15\u7684\u6838\u5fc3\u7279\u6027<\/h5>\n<table>\n<tr>\u7279\u6027\u552f\u4e00\u7d22\u5f15\u4e3b\u952e\u7d22\u5f15\u5e95\u5c42\u539f\u56e0<\/tr>\n<tbody>\n<tr>\n<td>\u6570\u91cf\u9650\u5236<\/td>\n<td>\u4e00\u4e2a\u8868\u53ef\u591a\u4e2a<\/td>\n<td>\u4e00\u4e2a\u8868\u53ea\u80fd\u4e00\u4e2a<\/td>\n<td>\u552f\u4e00\u7d22\u5f15\u662f\u8f85\u52a9\u7d22\u5f15&#xff08;\u591a\u4e2a\u4e0d\u5f71\u54cd\u6570\u636e\u5b58\u50a8\u987a\u5e8f&#xff09;&#xff1b;\u4e3b\u952e\u7d22\u5f15\u662f\u805a\u7c07\u7d22\u5f15&#xff08;\u6570\u636e\u53ea\u80fd\u6309\u4e00\u79cd\u987a\u5e8f\u5b58\u50a8&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>NULL \u503c\u5141\u8bb8<\/td>\n<td>\u5141\u8bb8&#xff08;\u591a\u4e2a NULL&#xff09;<\/td>\n<td>\u4e0d\u5141\u8bb8<\/td>\n<td>\u552f\u4e00\u7d22\u5f15\u7684 B &#043; \u6811\u5c06 NULL \u89c6\u4e3a \u201c\u6700\u5c0f\u952e\u503c\u201d&#xff1b;\u4e3b\u952e\u7d22\u5f15\u7684 B &#043; \u6811\u65e0\u6cd5\u5b58\u50a8 NULL<\/td>\n<\/tr>\n<tr>\n<td>\u7d22\u5f15\u7c7b\u578b<\/td>\n<td>\u8f85\u52a9\u7d22\u5f15&#xff08;\u975e\u805a\u7c07&#xff09;<\/td>\n<td>\u805a\u7c07\u7d22\u5f15<\/td>\n<td>\u552f\u4e00\u7d22\u5f15\u53f6\u5b50\u8282\u70b9\u5b58\u4e3b\u952e\u503c&#xff1b;\u4e3b\u952e\u7d22\u5f15\u53f6\u5b50\u8282\u70b9\u5b58\u5b8c\u6574\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>\u81ea\u589e\u652f\u6301<\/td>\n<td>\u4e0d\u652f\u6301<\/td>\n<td>\u652f\u6301<\/td>\n<td>\u81ea\u589e\u5c5e\u6027\u4f9d\u8d56\u805a\u7c07\u7d22\u5f15&#xff0c;\u8f85\u52a9\u7d22\u5f15\u65e0\u6570\u636e\u5b58\u50a8\u63a7\u5236\u6743<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>4.2.3 \u5e38\u89c1\u9519\u8bef\u4e0e\u89e3\u51b3\u65b9\u6848<\/h5>\n<table>\n<tr>\u9519\u8bef\u4fe1\u606f\u9519\u8bef\u539f\u56e0\u5e95\u5c42\u6eaf\u6e90\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>Duplicate entry &#039;xxx&#039; for key &#039;xxx&#039;<\/td>\n<td>\u63d2\u5165\u91cd\u590d\u7684\u552f\u4e00\u7d22\u5f15\u503c<\/td>\n<td>\u552f\u4e00\u7d22\u5f15 B &#043; \u6811\u952e\u503c\u552f\u4e00\u6027\u6821\u9a8c\u5931\u8d25<\/td>\n<td>1. \u67e5\u627e\u91cd\u590d\u6570\u636e&#xff1a;SELECT \u5b57\u6bb5&#xff0c;COUNT () FROM \u8868\u540d GROUP BY \u5b57\u6bb5 HAVING COUNT () &gt; 1; 2. \u5220\u9664\u91cd\u590d\u6570\u636e&#xff1a;DELETE FROM \u8868\u540d WHERE id NOT IN (SELECT MIN (id) FROM \u8868\u540d GROUP BY \u5b57\u6bb5); 3. \u91cd\u65b0\u521b\u5efa\u7d22\u5f15<\/td>\n<\/tr>\n<tr>\n<td>Can&#039;t write; duplicate key in table &#039;xxx&#039;<\/td>\n<td>\u521b\u5efa\u552f\u4e00\u7d22\u5f15\u65f6&#xff0c;\u8868\u4e2d\u5df2\u5b58\u5728\u91cd\u590d\u6570\u636e<\/td>\n<td>\u6784\u5efa\u552f\u4e00\u7d22\u5f15 B &#043; \u6811\u65f6&#xff0c;\u53d1\u73b0\u91cd\u590d\u952e\u503c&#xff0c;\u7ec8\u6b62\u6784\u5efa<\/td>\n<td>\u5148\u6e05\u7406\u91cd\u590d\u6570\u636e&#xff0c;\u518d\u521b\u5efa\u7d22\u5f15&#xff1b;\u82e5\u9700\u4fdd\u7559\u91cd\u590d\u6570\u636e&#xff0c;\u6539\u7528\u666e\u901a\u7d22\u5f15<\/td>\n<\/tr>\n<tr>\n<td>Index name &#039;xxx&#039; already exists<\/td>\n<td>\u7d22\u5f15\u540d\u5df2\u5b58\u5728<\/td>\n<td>MySQL \u7684\u7d22\u5f15\u540d\u5728\u8868\u5185\u552f\u4e00&#xff0c;\u91cd\u590d\u521b\u5efa\u4f1a\u89e6\u53d1\u5143\u6570\u636e\u6821\u9a8c\u5931\u8d25<\/td>\n<td>1. \u67e5\u770b\u5df2\u6709\u7d22\u5f15&#xff1a;SHOW KEYS FROM \u8868\u540d&#xff1b;2. \u5220\u9664\u65e7\u7d22\u5f15&#xff1a;DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;3. \u521b\u5efa\u65b0\u7d22\u5f15<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.3 \u666e\u901a\u7d22\u5f15&#xff08;Index&#xff09;\u2014\u2014 \u6700\u5e38\u7528\u7684\u7d22\u5f15<\/h4>\n<p><span style=\"color:#fe2c24\">\u666e\u901a\u7d22\u5f15\u662f\u65e0\u552f\u4e00\u6027\u7ea6\u675f\u7684\u8f85\u52a9\u7d22\u5f15&#xff0c;\u9002\u7528\u4e8e\u9891\u7e41\u4f5c\u4e3a\u67e5\u8be2\u6761\u4ef6\u7684\u5b57\u6bb5&#xff08;\u5982\u59d3\u540d\u3001\u90e8\u95e8\u7f16\u53f7&#xff09;&#xff0c;\u8bed\u6cd5\u6838\u5fc3\u662f \u201cINDEX\u201d \u5173\u952e\u5b57&#xff0c;\u8fd9\u4e2a\u662f\u6211\u4eec\u8981\u5b66\u4e60\u7684\u91cd\u70b9\u6240\u5728\u3002<\/span><\/p>\n<h5>4.3.1 \u8bed\u6cd5\u7ed3\u6784<\/h5>\n<h6>\u65b9\u5f0f 1&#xff1a;\u521b\u5efa\u8868\u65f6\u6307\u5b9a\u666e\u901a\u7d22\u5f15<\/h6>\n<p>CREATE TABLE user8 (<br \/>\n    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br \/>\n    name VARCHAR(20) NOT NULL,<br \/>\n    email VARCHAR(30) NOT NULL,<br \/>\n    age INT(3) NOT NULL,<br \/>\n    INDEX idx_name(name), &#8212; \u5355\u5b57\u6bb5\u666e\u901a\u7d22\u5f15<br \/>\n    INDEX idx_email_age(email, age) &#8212; \u590d\u5408\u666e\u901a\u7d22\u5f15<br \/>\n);<\/p>\n<p>\u5e95\u5c42\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>\u666e\u901a\u7d22\u5f15\u7684 B &#043; \u6811\u65e0\u552f\u4e00\u6027\u6821\u9a8c&#xff0c;\u952e\u503c\u53ef\u91cd\u590d&#xff08;\u5982 name&#061;&#039; \u5f20\u4e09 &#039; \u53ef\u51fa\u73b0\u591a\u6b21&#xff09;&#xff1b;<\/li>\n<li>\u590d\u5408\u7d22\u5f15\u7684\u952e\u503c\u662f \u201cemail&#043;age\u201d&#xff0c;\u6392\u5e8f\u89c4\u5219&#xff1a;\u5148\u6309 email \u5347\u5e8f&#xff0c;email \u76f8\u540c\u65f6\u6309 age \u5347\u5e8f&#xff1b;<\/li>\n<li>\u7d22\u5f15\u540d\u7701\u7565\u65f6&#xff0c;MySQL \u9ed8\u8ba4\u547d\u540d\u89c4\u5219&#xff1a;\u5355\u5b57\u6bb5\u2192\u5b57\u6bb5\u540d&#xff0c;\u590d\u5408\u5b57\u6bb5\u2192\u5b57\u6bb5 1_\u5b57\u6bb5 2&#xff08;\u5982 email_age&#xff09;\u3002<\/li>\n<\/ul>\n<h6>\u65b9\u5f0f 2&#xff1a;\u521b\u5efa\u8868\u540e\u6dfb\u52a0\u666e\u901a\u7d22\u5f15&#xff08;ALTER TABLE&#xff09;<\/h6>\n<p>CREATE TABLE user9 (<br \/>\n    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,<br \/>\n    name VARCHAR(20) NOT NULL,<br \/>\n    email VARCHAR(30) NOT NULL,<br \/>\n    age INT(3) NOT NULL<br \/>\n);<\/p>\n<p>ALTER TABLE user9 ADD INDEX idx_name(name); &#8212; \u5355\u5b57\u6bb5<br \/>\nALTER TABLE user9 ADD INDEX idx_email_age(email, age); &#8212; \u590d\u5408\u5b57\u6bb5<\/p>\n<h6>\u65b9\u5f0f 3&#xff1a;\u521b\u5efa\u8868\u540e\u6dfb\u52a0\u666e\u901a\u7d22\u5f15&#xff08;CREATE INDEX&#xff09;<\/h6>\n<p>\u683c\u5f0f\u5176\u5b9e\u4e5f\u5f88\u7b80\u5355&#xff0c;\u65e0\u975e\u5c31\u662f\u00a0 \u00a0create index \u7d22\u5f15\u540d on \u8868\u540d&#xff08;\u5b57\u6bb5\u540d&#xff09;\u00a0<\/p>\n<p>CREATE INDEX idx_name ON user9(name); &#8212; \u5355\u5b57\u6bb5<br \/>\nCREATE INDEX idx_email_age ON user9(email, age); &#8212; \u590d\u5408\u5b57\u6bb5<\/p>\n<p>\u8bed\u6cd5\u5bf9\u6bd4&#xff1a;<\/p>\n<table>\n<tr>\u8bed\u6cd5\u65b9\u5f0f\u9501\u8868\u60c5\u51b5&#xff08;InnoDB&#xff09;\u9002\u7528\u573a\u666f\u5e95\u5c42\u6548\u7387<\/tr>\n<tbody>\n<tr>\n<td>ALTER TABLE<\/td>\n<td>\u5728\u7ebf DDL&#xff08;\u77ed\u65f6\u95f4\u9501\u8868&#xff09;<\/td>\n<td>\u540c\u65f6\u4fee\u6539\u8868\u7ed3\u6784&#xff08;\u5982\u6dfb\u52a0\u5b57\u6bb5 &#043; \u521b\u5efa\u7d22\u5f15&#xff09;<\/td>\n<td>\u4e00\u6b21\u5143\u6570\u636e\u4fee\u6539&#xff0c;\u6548\u7387\u9ad8<\/td>\n<\/tr>\n<tr>\n<td>CREATE INDEX<\/td>\n<td>\u5728\u7ebf DDL&#xff08;\u51e0\u4e4e\u65e0\u9501&#xff09;<\/td>\n<td>\u4ec5\u521b\u5efa\u7d22\u5f15<\/td>\n<td>\u4e13\u6ce8\u7d22\u5f15\u6784\u5efa&#xff0c;\u9501\u8868\u65f6\u95f4\u66f4\u77ed&#xff0c;\u5efa\u8bae\u4f18\u5148\u4f7f\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>4.3.2 \u590d\u5408\u666e\u901a\u7d22\u5f15\u7684 \u201c\u6700\u5de6\u5339\u914d\u539f\u5219\u201d<\/h5>\n<p>\u590d\u5408\u666e\u901a\u7d22\u5f15\u7684\u67e5\u8be2\u6548\u7387\u53d6\u51b3\u4e8e \u201c\u67e5\u8be2\u6761\u4ef6\u662f\u5426\u5339\u914d\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u201d&#xff0c;\u8fd9\u662f\u666e\u901a\u7d22\u5f15\u8bed\u6cd5\u4e2d\u6700\u91cd\u8981\u7684\u4f18\u5316\u70b9\u3002<\/p>\n<h6>\u8bed\u6cd5\u793a\u4f8b&#xff1a;\u521b\u5efa\u590d\u5408\u7d22\u5f15<\/h6>\n<p>CREATE INDEX idx_name_age ON user8(name, age); &#8212; \u5b57\u6bb5\u987a\u5e8f&#xff1a;name\u5728\u524d&#xff0c;age\u5728\u540e<\/p>\n<h6>\u6700\u5de6\u5339\u914d\u539f\u5219\u7684\u5e95\u5c42\u903b\u8f91&#xff08;\u7528 \u201c\u5b57\u5178\u201d \u7c7b\u6bd4&#xff09;<\/h6>\n<p>\u590d\u5408\u7d22\u5f15idx_name_age\u7684 B &#043; \u6811\u952e\u503c\u662f \u201cname&#043;age\u201d&#xff0c;\u76f8\u5f53\u4e8e \u201c\u5b57\u5178\u5148\u6309\u59d3\u540d\u6392\u5e8f&#xff0c;\u59d3\u540d\u76f8\u540c\u518d\u6309\u5e74\u9f84\u6392\u5e8f\u201d&#xff1a;<\/p>\n<ul>\n<li>\u67e5 \u201cname &#061; \u5f20\u4e09\u201d\u2192 \u76f8\u5f53\u4e8e \u201c\u67e5\u5b57\u5178\u4e2d\u6240\u6709\u59d3\u5f20\u7684\u5b57\u201d&#xff0c;\u80fd\u76f4\u63a5\u5b9a\u4f4d&#xff08;\u7528\u7d22\u5f15&#xff09;&#xff1b;<\/li>\n<li>\u67e5 \u201cname &#061; \u5f20\u4e09 AND age&#061;18\u201d\u2192 \u76f8\u5f53\u4e8e \u201c\u67e5\u5b57\u5178\u4e2d\u59d3\u5f20\u4e14\u9875\u7801\u4e3a 18 \u7684\u5b57\u201d&#xff0c;\u80fd\u7cbe\u51c6\u5b9a\u4f4d&#xff08;\u7528\u7d22\u5f15&#xff09;&#xff1b;<\/li>\n<li>\u67e5 \u201cage&#061;18\u201d\u2192 \u76f8\u5f53\u4e8e \u201c\u67e5\u5b57\u5178\u4e2d\u6240\u6709\u9875\u7801\u4e3a 18 \u7684\u5b57\u201d&#xff0c;\u65e0\u6cd5\u901a\u8fc7\u59d3\u540d\u76ee\u5f55\u5b9a\u4f4d&#xff08;\u4e0d\u7528\u7d22\u5f15&#xff09;\u3002<\/li>\n<\/ul>\n<h6>\u8bed\u6cd5\u9a8c\u8bc1&#xff1a;\u54ea\u4e9b\u67e5\u8be2\u80fd\u7528\u5230\u7d22\u5f15&#xff1f;<\/h6>\n<table>\n<tr>\u67e5\u8be2\u8bed\u53e5\u662f\u5426\u7528\u5230\u7d22\u5f15\u6267\u884c\u8ba1\u5212\u7279\u5f81&#xff08;EXPLAIN&#xff09;\u5e95\u5c42 IO \u6b21\u6570<\/tr>\n<tbody>\n<tr>\n<td>SELECT * FROM user8 WHERE name&#061;&#039; \u5f20\u4e09 &#039;;<\/td>\n<td>\u662f&#xff08;\u5168\u7d22\u5f15&#xff09;<\/td>\n<td>type&#061;ref&#xff0c;key&#061;idx_name_age&#xff0c;rows&#061;10<\/td>\n<td>3 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user8 WHERE name&#061;&#039; \u5f20\u4e09 &#039; AND age&#061;18;<\/td>\n<td>\u662f&#xff08;\u5168\u7d22\u5f15&#xff09;<\/td>\n<td>type&#061;ref&#xff0c;key&#061;idx_name_age&#xff0c;rows&#061;1<\/td>\n<td>3 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user8 WHERE age&#061;18;<\/td>\n<td>\u5426&#xff08;\u5168\u8868\u626b\u63cf&#xff09;<\/td>\n<td>type&#061;ALL&#xff0c;key&#061;NULL&#xff0c;rows&#061;8000000<\/td>\n<td>8000 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user8 WHERE name&#061;&#039; \u5f20\u4e09 &#039; AND age&gt;18;<\/td>\n<td>\u662f&#xff08;\u90e8\u5206\u7d22\u5f15&#xff09;<\/td>\n<td>type&#061;range&#xff0c;key&#061;idx_name_age&#xff0c;rows&#061;5<\/td>\n<td>3 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user8 WHERE name LIKE &#039; \u5f20 %&#039;;<\/td>\n<td>\u662f&#xff08;\u90e8\u5206\u7d22\u5f15&#xff09;<\/td>\n<td>type&#061;range&#xff0c;key&#061;idx_name_age&#xff0c;rows&#061;100<\/td>\n<td>3 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user8 WHERE name LIKE &#039;% \u4e09 &#039;;<\/td>\n<td>\u5426&#xff08;\u5168\u8868\u626b\u63cf&#xff09;<\/td>\n<td>type&#061;ALL&#xff0c;key&#061;NULL&#xff0c;rows&#061;8000000<\/td>\n<td>8000 \u6b21<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h6>\u8bed\u6cd5\u4f18\u5316\u5efa\u8bae<\/h6>\n<li>\u590d\u5408\u7d22\u5f15\u5b57\u6bb5\u987a\u5e8f&#xff1a;\n<ul>\n<li>\u67e5\u8be2\u9891\u7387\u9ad8\u7684\u5b57\u6bb5\u653e\u6700\u5de6&#xff08;\u5982 deptno \u6bd4 gender \u67e5\u8be2\u9891\u7e41&#xff0c;deptno \u653e\u524d&#xff09;&#xff1b;<\/li>\n<li>\u533a\u5206\u5ea6\u9ad8\u7684\u5b57\u6bb5\u653e\u6700\u5de6&#xff08;\u5982 name \u533a\u5206\u5ea6 90%&#xff0c;age \u533a\u5206\u5ea6 10%&#xff0c;name \u653e\u524d&#xff09;&#xff1b;<\/li>\n<li>\u793a\u4f8b&#xff1a;idx_deptno_gender&#xff08;deptno \u5728\u524d&#xff0c;gender \u5728\u540e&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u907f\u514d\u8de8\u5b57\u6bb5\u67e5\u8be2&#xff1a;\n<ul>\n<li>\u4ec5\u67e5 age \u65f6&#xff0c;\u4e0d\u8981\u4f9d\u8d56idx_name_age&#xff0c;\u5355\u72ec\u521b\u5efaidx_age&#xff1a;\n<p>CREATE INDEX idx_age ON user8(age);<br \/>\nSELECT * FROM user8 WHERE age&#061;18; &#8212; IO\u6b21\u6570\u4ece8000\u6b21\u21923\u6b21<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u524d\u7f00\u6a21\u7cca\u67e5\u8be2\u4f18\u5316&#xff1a;\n<ul>\n<li>\u4ec5\u652f\u6301 \u201c% \u5728\u672b\u5c3e\u201d&#xff08;\u5982name LIKE &#039;\u5f20%&#039;&#xff09;&#xff0c;\u907f\u514d \u201c% \u5728\u5f00\u5934\u201d&#xff08;\u5982name LIKE &#039;%\u4e09&#039;&#xff09;&#xff1b;<\/li>\n<li>\u82e5\u9700\u540e\u7f00\u6a21\u7cca\u67e5\u8be2&#xff0c;\u53ef\u53cd\u5411\u5b58\u50a8\u5b57\u6bb5&#xff08;\u5982 name&#061;&#039; \u5f20\u4e09 &#039;\u2192reverse_name&#061;&#039; \u4e09\u5f20 &#039;&#xff09;&#xff0c;\u518d\u521b\u5efa\u7d22\u5f15&#xff1a;\n<p>ALTER TABLE user8 ADD COLUMN reverse_name VARCHAR(20) AFTER name;<br \/>\nUPDATE user8 SET reverse_name &#061; REVERSE(name);<br \/>\nCREATE INDEX idx_reverse_name ON user8(reverse_name);<br \/>\nSELECT * FROM user8 WHERE reverse_name LIKE &#039;\u4e09%&#039;; &#8212; \u7528\u5230\u7d22\u5f15<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h5>4.3.3 \u5e38\u89c1\u9519\u8bef\u4e0e\u89e3\u51b3\u65b9\u6848<\/h5>\n<table>\n<tr>\u9519\u8bef\u4fe1\u606f\u9519\u8bef\u539f\u56e0\u5e95\u5c42\u6eaf\u6e90\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>Index column size too large<\/td>\n<td>\u7d22\u5f15\u5b57\u6bb5\u957f\u5ea6\u8fc7\u5927&#xff08;\u5982 VARCHAR (2000)&#xff09;<\/td>\n<td>\u7d22\u5f15\u9875\u5b58\u50a8\u7684\u952e\u503c\u8fc7\u957f&#xff0c;\u5355\u4e2a Page \u80fd\u5b58\u7684\u952e\u503c\u5c11\u2192\u6811\u9ad8\u589e\u52a0\u2192IO \u6b21\u6570\u589e\u591a<\/td>\n<td>\u524d\u7f00\u7d22\u5f15&#xff1a;CREATE INDEX idx_name ON \u8868\u540d (name (20));&#xff08;\u7d22\u5f15\u524d 20 \u4e2a\u5b57\u7b26&#xff0c;\u51cf\u5c11\u952e\u503c\u957f\u5ea6&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Too many keys specified; max 64 keys allowed<\/td>\n<td>\u8868\u4e2d\u7d22\u5f15\u6570\u91cf\u8d85\u8fc7 64 \u4e2a<\/td>\n<td>MySQL \u9650\u5236\u5355\u8868\u7d22\u5f15\u6570\u226464&#xff08;\u5143\u6570\u636e\u5b58\u50a8\u9650\u5236&#xff09;<\/td>\n<td>\u5220\u9664\u65e0\u7528\u7d22\u5f15&#xff1a;DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;\u5408\u5e76\u590d\u5408\u7d22\u5f15&#xff08;\u5982 idx_name&#043;idx_age\u2192idx_name_age&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Column &#039;xxx&#039; not found<\/td>\n<td>\u521b\u5efa\u7d22\u5f15\u65f6\u5b57\u6bb5\u4e0d\u5b58\u5728<\/td>\n<td>\u5143\u6570\u636e\u6821\u9a8c\u5931\u8d25&#xff08;\u5b57\u6bb5\u540d\u62fc\u5199\u9519\u8bef \/ \u5b57\u6bb5\u5df2\u5220\u9664&#xff09;<\/td>\n<td>1. \u67e5\u770b\u8868\u7ed3\u6784&#xff1a;DESC \u8868\u540d&#xff1b;2. \u4fee\u6b63\u5b57\u6bb5\u540d&#xff1b;3. \u91cd\u65b0\u521b\u5efa\u7d22\u5f15<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.4 \u5168\u6587\u7d22\u5f15&#xff08;Fulltext Index&#xff09;\u2014\u2014 \u5927\u6587\u672c\u5173\u952e\u8bcd\u68c0\u7d22<\/h4>\n<p>\u5168\u6587\u7d22\u5f15\u7528\u4e8e\u5bf9\u5927\u6587\u672c\u5b57\u6bb5&#xff08;\u5982\u6587\u7ae0\u5185\u5bb9\u3001\u8bc4\u8bba&#xff09;\u8fdb\u884c\u5173\u952e\u8bcd\u68c0\u7d22&#xff0c;\u8bed\u6cd5\u6838\u5fc3\u662f \u201cFULLTEXT\u201d \u5173\u952e\u5b57&#xff0c;\u9700\u6ce8\u610f\u5b58\u50a8\u5f15\u64ce\u9650\u5236\u3002<\/p>\n<h5>4.4.1 \u8bed\u6cd5\u7ed3\u6784&#xff08;\u521b\u5efa &#043; \u67e5\u8be2 &#043; \u5e95\u5c42\u7ec6\u8282&#xff09;<\/h5>\n<h6>\u65b9\u5f0f 1&#xff1a;\u521b\u5efa\u8868\u65f6\u6307\u5b9a\u5168\u6587\u7d22\u5f15<\/h6>\n<p>CREATE TABLE articles (<br \/>\n    id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,<br \/>\n    title VARCHAR(200) NOT NULL,<br \/>\n    body TEXT NOT NULL,<br \/>\n    FULLTEXT idx_title_body(title, body) &#8212; \u5168\u6587\u7d22\u5f15<br \/>\n) ENGINE&#061;MyISAM DEFAULT CHARSET&#061;utf8;<\/p>\n<p>\u5e95\u5c42\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>\u652f\u6301\u5b57\u6bb5\u7c7b\u578b&#xff1a;CHAR\u3001VARCHAR\u3001TEXT&#xff08;\u4ec5\u6587\u672c\u7c7b\u578b&#xff09;&#xff0c;INT\/DATE \u7b49\u4e0d\u652f\u6301&#xff1b;<\/li>\n<li>MyISAM vs InnoDB&#xff1a;\n<ul>\n<li>MyISAM&#xff1a;\u652f\u6301\u5168\u6587\u7d22\u5f15&#xff0c;\u652f\u6301\u4e2d\u6587&#xff08;\u9700\u914d\u7f6e\u5206\u8bcd&#xff09;&#xff0c;\u6548\u7387\u9ad8&#xff1b;<\/li>\n<li>InnoDB&#xff08;5.6&#043;&#xff09;&#xff1a;\u652f\u6301\u5168\u6587\u7d22\u5f15&#xff0c;\u4f46\u4e0d\u652f\u6301\u4e2d\u6587\u5206\u8bcd&#xff08;\u9700\u7b2c\u4e09\u65b9\u63d2\u4ef6\u5982 CoreSeek&#xff09;&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u5168\u6587\u7d22\u5f15\u7684\u5e95\u5c42\u7ed3\u6784&#xff1a;\u4e0d\u662f B &#043; \u6811&#xff0c;\u800c\u662f \u201c\u5012\u6392\u7d22\u5f15\u201d&#xff08;\u5173\u952e\u8bcd\u2192\u6587\u6863 ID \u5217\u8868&#xff09;\u3002<\/li>\n<\/ul>\n<h6>\u65b9\u5f0f 2&#xff1a;\u521b\u5efa\u8868\u540e\u6dfb\u52a0\u5168\u6587\u7d22\u5f15<\/h6>\n<p>CREATE TABLE articles2 (<br \/>\n    id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,<br \/>\n    title VARCHAR(200) NOT NULL,<br \/>\n    body TEXT NOT NULL<br \/>\n) ENGINE&#061;MyISAM;<\/p>\n<p>ALTER TABLE articles2 ADD FULLTEXT idx_title_body(title, body);<\/p>\n<h6>\u5168\u6587\u7d22\u5f15\u67e5\u8be2\u8bed\u6cd5&#xff08;\u6838\u5fc3&#xff1a;MATCH () AGAINST ()&#xff09;<\/h6>\n<p>&#8212; \u793a\u4f8b1&#xff1a;\u81ea\u7136\u8bed\u8a00\u6a21\u5f0f&#xff08;\u9ed8\u8ba4&#xff0c;\u65e0\u8fd0\u7b97\u7b26&#xff09;<br \/>\nSELECT * FROM articles WHERE MATCH(title, body) AGAINST(&#039;database&#039;);<br \/>\n&#8212; \u5e95\u5c42&#xff1a;\u8ba1\u7b97\u5173\u952e\u8bcd\u4e0e\u6587\u6863\u7684\u201c\u76f8\u5173\u6027\u5f97\u5206\u201d&#xff0c;\u6309\u5f97\u5206\u6392\u5e8f&#xff08;\u5f97\u5206\u8d8a\u9ad8&#xff0c;\u5339\u914d\u5ea6\u8d8a\u9ad8&#xff09;\u3002<\/p>\n<p>&#8212; \u793a\u4f8b2&#xff1a;\u5e03\u5c14\u6a21\u5f0f&#xff08;\u652f\u6301\u8fd0\u7b97\u7b26&#xff09;<br \/>\nSELECT * FROM articles WHERE MATCH(title, body) AGAINST(&#039;&#043;database -mysql&#039; IN BOOLEAN MODE);<br \/>\n&#8212; \u8fd0\u7b97\u7b26\u89e3\u6790&#xff1a;<br \/>\n&#8212; &#043;database&#xff1a;\u5fc5\u987b\u5305\u542bdatabase&#xff1b;<br \/>\n&#8212; -mysql&#xff1a;\u5fc5\u987b\u6392\u9664mysql&#xff1b;<br \/>\n&#8212; &gt;database&#xff1a;\u63d0\u5347database\u7684\u76f8\u5173\u6027\u5f97\u5206&#xff1b;<br \/>\n&#8212; &lt;mysql&#xff1a;\u964d\u4f4emysql\u7684\u76f8\u5173\u6027\u5f97\u5206&#xff1b;<br \/>\n&#8212; database*&#xff1a;\u5339\u914ddatabase\u3001databases\u7b49\u524d\u7f00\u3002<\/p>\n<h5>4.4.2 \u5168\u6587\u7d22\u5f15\u7684\u6838\u5fc3\u7279\u6027&#xff08;\u8bed\u6cd5 &#043; \u5e95\u5c42\u9650\u5236&#xff09;<\/h5>\n<li>\u5173\u952e\u8bcd\u957f\u5ea6\u9650\u5236&#xff1a;\n<p>&#8212; \u67e5\u770bMyISAM\u5173\u952e\u8bcd\u957f\u5ea6\u9650\u5236<br \/>\nSHOW GLOBAL VARIABLES LIKE &#039;ft_min_word_len&#039;; &#8212; \u9ed8\u8ba44&#xff08;\u5ffd\u7565&lt;4\u7684\u5173\u952e\u8bcd&#xff0c;\u5982a\u3001an&#xff09;<br \/>\n&#8212; \u67e5\u770bInnoDB\u5173\u952e\u8bcd\u957f\u5ea6\u9650\u5236<br \/>\nSHOW GLOBAL VARIABLES LIKE &#039;innodb_ft_min_token_size&#039;; &#8212; \u9ed8\u8ba43<\/p>\n<p>\u4fee\u6539\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>\u7f16\u8f91 my.cnf&#xff1a;ft_min_word_len&#061;2&#xff08;MyISAM&#xff09;\u3001innodb_ft_min_token_size&#061;2&#xff08;InnoDB&#xff09;&#xff1b;<\/li>\n<li>\u91cd\u542f MySQL&#xff1b;<\/li>\n<li>\u91cd\u5efa\u5168\u6587\u7d22\u5f15&#xff08;\u4fee\u6539\u914d\u7f6e\u540e\u9700\u91cd\u65b0\u6784\u5efa&#xff09;&#xff1a;\n<p>ALTER TABLE articles DROP INDEX idx_title_body;<br \/>\nALTER TABLE articles ADD FULLTEXT idx_title_body(title, body);<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u505c\u6b62\u8bcd\u5ffd\u7565&#xff1a;\n<ul>\n<li>MySQL \u5185\u7f6e\u505c\u6b62\u8bcd\u5217\u8868&#xff08;\u5982 the\u3001a\u3001is\u3001\u7684\u3001\u4e86\u7b49\u65e0\u610f\u4e49\u8bcd\u6c47&#xff09;&#xff0c;\u68c0\u7d22\u65f6\u81ea\u52a8\u5ffd\u7565&#xff1b;<\/li>\n<li>\u81ea\u5b9a\u4e49\u505c\u6b62\u8bcd\u5217\u8868&#xff1a;\n<li>\u521b\u5efa\u505c\u6b62\u8bcd\u6587\u4ef6&#xff1a;\/usr\/local\/mysql\/stopwords.txt&#xff08;\u6bcf\u884c\u4e00\u4e2a\u505c\u6b62\u8bcd&#xff09;&#xff1b;<\/li>\n<li>\u7f16\u8f91 my.cnf&#xff1a;ft_stopword_file&#061;\/usr\/local\/mysql\/stopwords.txt&#xff1b;<\/li>\n<li>\u91cd\u542f MySQL&#xff0c;\u91cd\u5efa\u7d22\u5f15\u3002<\/li>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4e2d\u6587\u68c0\u7d22\u4f18\u5316&#xff1a;\n<ul>\n<li>MyISAM&#043;CoreSeek&#xff08;\u4e2d\u6587\u5206\u8bcd\u63d2\u4ef6&#xff09;&#xff1a;\n<li>\u5b89\u88c5 CoreSeek&#xff1b;<\/li>\n<li>\u914d\u7f6e\u5206\u8bcd\u89c4\u5219&#xff1b;<\/li>\n<li>\u4f7f\u7528MATCH() AGAINST()\u67e5\u8be2\u4e2d\u6587\u5173\u952e\u8bcd\u3002<\/li>\n<\/li>\n<\/ul>\n<\/li>\n<h5>4.4.3 \u5b9e\u6218\u5bf9\u6bd4&#xff1a;\u5168\u6587\u7d22\u5f15 vs like \u67e5\u8be2<\/h5>\n<table>\n<tr>\u67e5\u8be2\u65b9\u5f0f\u6570\u636e\u91cf\u8017\u65f6IO \u6b21\u6570CPU \u5360\u7528\u5e95\u5c42\u539f\u56e0<\/tr>\n<tbody>\n<tr>\n<td>\u5168\u6587\u7d22\u5f15<\/td>\n<td>10 \u4e07\u7bc7<\/td>\n<td>0.05 \u79d2<\/td>\n<td>10 \u6b21<\/td>\n<td>5%<\/td>\n<td>\u5012\u6392\u7d22\u5f15\u76f4\u63a5\u5b9a\u4f4d\u5173\u952e\u8bcd\u5bf9\u5e94\u7684\u6587\u6863 ID&#xff0c;\u65e0\u9700\u626b\u63cf\u5168\u6587<\/td>\n<\/tr>\n<tr>\n<td>like \u67e5\u8be2<\/td>\n<td>10 \u4e07\u7bc7<\/td>\n<td>5 \u79d2<\/td>\n<td>1000 \u6b21<\/td>\n<td>80%<\/td>\n<td>\u5168\u8868\u626b\u63cf&#xff0c;\u9010\u884c\u5339\u914d % database%&#xff0c;\u9700\u8bfb\u53d6\u6240\u6709\u6587\u672c\u5185\u5bb9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>4.4.4 \u5e38\u89c1\u9519\u8bef\u4e0e\u89e3\u51b3\u65b9\u6848<\/h5>\n<table>\n<tr>\u9519\u8bef\u4fe1\u606f\u9519\u8bef\u539f\u56e0\u5e95\u5c42\u6eaf\u6e90\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>Fulltext index is not supported on table<\/td>\n<td>\u5b58\u50a8\u5f15\u64ce\u4e0d\u652f\u6301&#xff08;\u5982 InnoDB 5.5 \u53ca\u4ee5\u4e0b&#xff09;<\/td>\n<td>\u5143\u6570\u636e\u6821\u9a8c\u5931\u8d25&#xff08;\u5b58\u50a8\u5f15\u64ce\u4e0d\u517c\u5bb9&#xff09;<\/td>\n<td>1. \u5347\u7ea7 MySQL \u5230 5.6&#043;&#xff1b;2. \u66f4\u6362\u4e3a MyISAM \u5f15\u64ce&#xff1b;3. \u4f7f\u7528\u7b2c\u4e09\u65b9\u5168\u6587\u68c0\u7d22\u5de5\u5177&#xff08;\u5982 Elasticsearch&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Column &#039;xxx&#039; cannot be part of a FULLTEXT index<\/td>\n<td>\u5b57\u6bb5\u7c7b\u578b\u4e0d\u652f\u6301&#xff08;\u5982 INT&#xff09;<\/td>\n<td>\u5168\u6587\u7d22\u5f15\u4ec5\u652f\u6301\u6587\u672c\u7c7b\u578b&#xff0c;INT \u65e0\u5206\u8bcd\u610f\u4e49<\/td>\n<td>\u8f6c\u6362\u5b57\u6bb5\u7c7b\u578b&#xff1a;ALTER TABLE \u8868\u540d MODIFY \u5b57\u6bb5\u540d VARCHAR (20);<\/td>\n<\/tr>\n<tr>\n<td>Can&#039;t find FULLTEXT index matching the column list<\/td>\n<td>MATCH () \u5b57\u6bb5\u4e0e\u7d22\u5f15\u5b57\u6bb5\u4e0d\u4e00\u81f4<\/td>\n<td>\u5012\u6392\u7d22\u5f15\u7684\u5173\u952e\u8bcd\u5217\u8868\u4e0e\u67e5\u8be2\u5b57\u6bb5\u4e0d\u5339\u914d<\/td>\n<td>\u786e\u4fdd MATCH () \u4e2d\u7684\u5b57\u6bb5\u4e0e\u521b\u5efa\u7d22\u5f15\u65f6\u7684\u5b57\u6bb5\u5b8c\u5168\u4e00\u81f4&#xff08;\u5982 MATCH (title, body) \u5bf9\u5e94 idx_title_body&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d\u6587\u68c0\u7d22\u65e0\u7ed3\u679c<\/td>\n<td>\u672a\u914d\u7f6e\u4e2d\u6587\u5206\u8bcd<\/td>\n<td>MySQL \u9ed8\u8ba4\u6309\u7a7a\u683c \/ \u6807\u70b9\u5206\u8bcd&#xff0c;\u4e2d\u6587\u65e0\u5206\u9694\u7b26\u2192\u65e0\u6cd5\u8bc6\u522b\u5173\u952e\u8bcd<\/td>\n<td>\u5b89\u88c5 CoreSeek \u63d2\u4ef6&#xff1b;\u6539\u7528 Elasticsearch&#xff1b;\u624b\u52a8\u6dfb\u52a0\u4e2d\u6587\u5206\u8bcd\u7b26&#xff08;\u5982 \u201c\u6570\u636e\u5e93 \u7d22\u5f15\u201d&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.5 \u7d22\u5f15\u67e5\u8be2\u4e0e\u5220\u9664\u8bed\u6cd5<\/h4>\n<p>\u521b\u5efa\u7d22\u5f15\u540e&#xff0c;\u9700\u638c\u63e1 \u201c\u67e5\u8be2\u7d22\u5f15\u4fe1\u606f\u201d \u548c \u201c\u5220\u9664\u65e0\u7528\u7d22\u5f15\u201d \u7684\u8bed\u6cd5&#xff0c;\u8fd9\u662f\u7d22\u5f15\u7ef4\u62a4\u7684\u5173\u952e\u3002<\/p>\n<h5>4.5.1 \u67e5\u8be2\u7d22\u5f15\u4fe1\u606f<\/h5>\n<h6>\u8bed\u6cd5 1&#xff1a;SHOW KEYS FROM \u8868\u540d \\\\G;<\/h6>\n<p>SHOW KEYS FROM user8 \\\\G;<\/p>\n<p>\u6838\u5fc3\u5b57\u6bb5\u89e3\u8bfb&#xff08;\u5e95\u5c42\u610f\u4e49&#xff09;&#xff1a;<\/p>\n<table>\n<tr>\u5b57\u6bb5\u540d\u793a\u4f8b\u503c\u5e95\u5c42\u610f\u4e49<\/tr>\n<tbody>\n<tr>\n<td>Table<\/td>\n<td>user8<\/td>\n<td>\u7d22\u5f15\u6240\u5c5e\u8868\u540d<\/td>\n<\/tr>\n<tr>\n<td>Non_unique<\/td>\n<td>1<\/td>\n<td>0 &#061; \u552f\u4e00\u7d22\u5f15&#xff08;\u4e3b\u952e \/ \u552f\u4e00\u7d22\u5f15&#xff09;&#xff0c;1 &#061; \u975e\u552f\u4e00\u7d22\u5f15&#xff08;\u666e\u901a \/ \u5168\u6587\u7d22\u5f15&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Key_name<\/td>\n<td>idx_name_age<\/td>\n<td>\u7d22\u5f15\u540d&#xff08;\u4e3b\u952e\u7d22\u5f15\u56fa\u5b9a\u4e3a PRIMARY&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Seq_in_index<\/td>\n<td>1<\/td>\n<td>\u5b57\u6bb5\u5728\u590d\u5408\u7d22\u5f15\u4e2d\u7684\u4f4d\u7f6e&#xff08;1 &#061; \u7b2c\u4e00\u4e2a\u5b57\u6bb5&#xff0c;2 &#061; \u7b2c\u4e8c\u4e2a\u5b57\u6bb5&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Column_name<\/td>\n<td>name<\/td>\n<td>\u7d22\u5f15\u5bf9\u5e94\u7684\u5b57\u6bb5\u540d<\/td>\n<\/tr>\n<tr>\n<td>Collation<\/td>\n<td>A<\/td>\n<td>\u6392\u5e8f\u65b9\u5f0f&#xff08;A &#061; \u5347\u5e8f&#xff0c;NULL &#061; \u65e0\u6392\u5e8f&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Cardinality<\/td>\n<td>8000000<\/td>\n<td>\u7d22\u5f15\u57fa\u6570&#xff08;\u4f30\u7b97\u7684\u552f\u4e00\u503c\u6570\u91cf&#xff09;&#xff0c;\u57fa\u6570\u2248\u6570\u636e\u91cf\u2192\u7d22\u5f15\u6548\u7387\u9ad8&#xff0c;\u57fa\u6570\u5c0f\u2192\u7d22\u5f15\u6548\u7387\u4f4e<\/td>\n<\/tr>\n<tr>\n<td>Sub_part<\/td>\n<td>NULL<\/td>\n<td>\u524d\u7f00\u7d22\u5f15\u7684\u957f\u5ea6&#xff08;\u5982 name (20)\u219220&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Packed<\/td>\n<td>NULL<\/td>\n<td>\u662f\u5426\u538b\u7f29\u7d22\u5f15\u952e\u503c&#xff08;NULL &#061; \u672a\u538b\u7f29&#xff0c;COMPRESSED &#061; \u538b\u7f29&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Null<\/td>\n<td><\/td>\n<td>\u5b57\u6bb5\u662f\u5426\u5141\u8bb8 NULL&#xff08;\u7a7a &#061; \u4e0d\u5141\u8bb8&#xff0c;YES &#061; \u5141\u8bb8&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Index_type<\/td>\n<td>BTREE<\/td>\n<td>\u7d22\u5f15\u7c7b\u578b&#xff08;BTREE&#061;B &#043; \u6811&#xff0c;HASH &#061; \u54c8\u5e0c&#xff0c;FULLTEXT &#061; \u5168\u6587\u7d22\u5f15&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Comment<\/td>\n<td><\/td>\n<td>\u7d22\u5f15\u6ce8\u91ca&#xff08;\u53ef\u901a\u8fc7 COMMENT \u6dfb\u52a0&#xff1a;CREATE INDEX idx_name ON \u8868\u540d (name) COMMENT &#039; \u59d3\u540d\u7d22\u5f15 &#039;;&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h6>\u8bed\u6cd5 2&#xff1a;SHOW INDEX FROM \u8868\u540d&#xff1b;&#xff08;\u4e0e SHOW KEYS \u7b49\u4ef7&#xff09;<\/h6>\n<p>SHOW INDEX FROM user8; &#8212; \u6a2a\u5411\u663e\u793a&#xff0c;\u9002\u5408\u6279\u91cf\u67e5\u770b\u591a\u4e2a\u7d22\u5f15<\/p>\n<h6>\u8bed\u6cd5 3&#xff1a;DESC \u8868\u540d&#xff1b;&#xff08;\u6700\u7b80\u7565&#xff09;<\/h6>\n<p>DESC user8;<\/p>\n<p>Key \u5217\u89e3\u8bfb&#xff1a;<\/p>\n<ul>\n<li>PRI&#xff1a;\u4e3b\u952e\u7d22\u5f15&#xff1b;<\/li>\n<li>UNI&#xff1a;\u552f\u4e00\u7d22\u5f15&#xff1b;<\/li>\n<li>MUL&#xff1a;\u666e\u901a \/ \u5168\u6587\u7d22\u5f15&#xff08;\u975e\u552f\u4e00&#xff09;&#xff1b;<\/li>\n<li>\u7a7a&#xff1a;\u65e0\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<h5>4.5.2 \u5220\u9664\u7d22\u5f15\u8bed\u6cd5<\/h5>\n<h6>\u8bed\u6cd5 1&#xff1a;\u5220\u9664\u4e3b\u952e\u7d22\u5f15<\/h6>\n<p>ALTER TABLE user3 DROP PRIMARY KEY;<\/p>\n<p>\u5e95\u5c42\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\u4e3b\u952e\u7d22\u5f15\u5220\u9664\u540e&#xff0c;InnoDB \u4f1a\u521b\u5efa\u9690\u85cf\u7684rowid\u5b57\u6bb5\u4f5c\u4e3a\u805a\u7c07\u7d22\u5f15&#xff08;rowid\u662f 6 \u5b57\u8282\u81ea\u589e\u6574\u6570&#xff09;&#xff1b;<\/li>\n<li>\u82e5\u4e3b\u952e\u5b57\u6bb5\u6709AUTO_INCREMENT&#xff0c;\u9700\u5148\u53d6\u6d88\u81ea\u589e&#xff1a;\n<p>ALTER TABLE user4 MODIFY id INT(11) NOT NULL; &#8212; \u53d6\u6d88\u81ea\u589e<br \/>\nALTER TABLE user4 DROP PRIMARY KEY; &#8212; \u5220\u9664\u4e3b\u952e<\/p>\n<\/li>\n<li>\u4e3b\u952e\u5220\u9664\u540e&#xff0c;\u6570\u636e\u4f1a\u6309rowid\u91cd\u65b0\u6392\u5e8f&#xff08;\u89e6\u53d1\u9875\u5206\u88c2&#xff0c;\u8017\u65f6\u8f83\u957f&#xff09;\u3002<\/li>\n<\/ul>\n<h6>\u8bed\u6cd5 2&#xff1a;\u5220\u9664\u552f\u4e00\u7d22\u5f15 \/ \u666e\u901a\u7d22\u5f15 \/ \u5168\u6587\u7d22\u5f15<\/h6>\n<p>\u683c\u5f0f\u4e5f\u6bd4\u8f83\u7b80\u5355&#xff0c;\u6211\u4e2a\u4eba\u662f\u6bd4\u8f83\u63a8\u8350\u4f7f\u7528drop index \u7d22\u5f15\u6539\u540d\u5b57 on \u8868\u540d;<\/p>\n<p>&#8212; \u8bed\u6cd51&#xff1a;ALTER TABLE<br \/>\nALTER TABLE user6 DROP INDEX idx_id_card;<\/p>\n<p>&#8212; \u8bed\u6cd52&#xff1a;DROP INDEX&#xff08;\u63a8\u8350&#xff09;<br \/>\nDROP INDEX idx_name ON user8;<\/p>\n<p>\u5e95\u5c42\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\u5220\u9664\u7d22\u5f15\u4f1a\u91ca\u653e\u7d22\u5f15\u9875\u7684\u5b58\u50a8\u7a7a\u95f4&#xff08;\u53ef\u901a\u8fc7SHOW TABLE STATUS LIKE &#039;user8&#039;\u67e5\u770b\u6570\u636e \/ \u7d22\u5f15\u5927\u5c0f&#xff09;&#xff1b;<\/li>\n<li>\u5728\u7ebf DDL \u5220\u9664\u7d22\u5f15&#xff1a;InnoDB 5.6 &#043; \u652f\u6301 \u201c\u5728\u7ebf\u5220\u9664\u201d&#xff0c;\u9501\u8868\u65f6\u95f4\u6781\u77ed&#xff08;\u4ec5\u4fee\u6539\u5143\u6570\u636e&#xff09;&#xff1b;<\/li>\n<li>\u590d\u5408\u7d22\u5f15\u5220\u9664&#xff1a;\u53ea\u9700\u6307\u5b9a\u7d22\u5f15\u540d&#xff0c;\u65e0\u9700\u6307\u5b9a\u5b57\u6bb5&#xff08;\u5982DROP INDEX idx_email_age ON user8&#xff09;\u3002<\/li>\n<\/ul>\n<h5>4.5.3 \u5e38\u89c1\u9519\u8bef\u4e0e\u89e3\u51b3\u65b9\u6848<\/h5>\n<table>\n<tr>\u9519\u8bef\u4fe1\u606f\u9519\u8bef\u539f\u56e0\u5e95\u5c42\u6eaf\u6e90\u89e3\u51b3\u65b9\u6848<\/tr>\n<tbody>\n<tr>\n<td>Can&#039;t drop index &#039;PRIMARY&#039;: needed in a foreign key constraint<\/td>\n<td>\u4e3b\u952e\u88ab\u5916\u952e\u5f15\u7528<\/td>\n<td>\u5916\u952e\u7ea6\u675f\u4f9d\u8d56\u4e3b\u952e&#xff0c;\u5220\u9664\u4e3b\u952e\u4f1a\u5bfc\u81f4\u5916\u952e\u5931\u6548<\/td>\n<td>1. \u67e5\u770b\u5916\u952e&#xff1a;SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME&#061;&#039; \u8868\u540d &#039;; 2. \u5220\u9664\u5916\u952e&#xff1a;ALTER TABLE \u5b50\u8868\u540d DROP FOREIGN KEY \u5916\u952e\u540d&#xff1b;3. \u5220\u9664\u4e3b\u952e<\/td>\n<\/tr>\n<tr>\n<td>Unknown key name &#039;xxx&#039;<\/td>\n<td>\u7d22\u5f15\u540d\u4e0d\u5b58\u5728<\/td>\n<td>\u5143\u6570\u636e\u4e2d\u65e0\u8be5\u7d22\u5f15\u540d&#xff08;\u62fc\u5199\u9519\u8bef \/ \u5df2\u5220\u9664&#xff09;<\/td>\n<td>1. \u67e5\u770b\u6240\u6709\u7d22\u5f15&#xff1a;SHOW KEYS FROM \u8868\u540d&#xff1b;2. \u4fee\u6b63\u7d22\u5f15\u540d&#xff1b;3. \u91cd\u65b0\u5220\u9664<\/td>\n<\/tr>\n<tr>\n<td>Error on rename of &#039;.\/dbname\/table.frm&#039; to &#039;.\/dbname\/#sql2-xxx.frm&#039;<\/td>\n<td>\u8868\u88ab\u9501\u5b9a<\/td>\n<td>\u5176\u4ed6\u4f1a\u8bdd\u6301\u6709\u8868\u7684\u5199\u9501 \/ \u5143\u6570\u636e\u9501&#xff0c;\u65e0\u6cd5\u4fee\u6539\u8868\u7ed3\u6784<\/td>\n<td>1. \u67e5\u770b\u9501&#xff1a;SHOW PROCESSLIST; 2. \u6740\u6b7b\u9501\u5b9a\u8fdb\u7a0b&#xff1a;KILL \u8fdb\u7a0b ID; 3. \u91cd\u65b0\u5220\u9664\u7d22\u5f15<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e94\u3001\u805a\u7c07\u7d22\u5f15\u4e0e\u975e\u805a\u7c07\u7d22\u5f15<\/h2>\n<p>\u805a\u7c07\u7d22\u5f15\u548c\u975e\u805a\u7c07\u7d22\u5f15\u7684\u6838\u5fc3\u533a\u522b\u662f \u201c\u7d22\u5f15\u4e0e\u6570\u636e\u7684\u5b58\u50a8\u4f4d\u7f6e\u5173\u7cfb\u201d&#xff0c;\u8bed\u6cd5\u4e0a\u901a\u8fc7 \u201c\u5b58\u50a8\u5f15\u64ce\u201d \u548c \u201c\u7d22\u5f15\u7c7b\u578b\u201d \u51b3\u5b9a\u3002<\/p>\n<h4>5.1 \u805a\u7c07\u7d22\u5f15&#xff08;InnoDB \u4e3b\u952e\u7d22\u5f15&#xff09;\u2014\u2014 \u6570\u636e\u5373\u7d22\u5f15<\/h4>\n<h5>5.1.1 \u8bed\u6cd5\u5173\u8054&#xff1a;InnoDB \u8868\u7684\u4e3b\u952e\u7d22\u5f15<\/h5>\n<p>CREATE TABLE itest (<br \/>\n    id INT PRIMARY KEY,<br \/>\n    name VARCHAR(11) NOT NULL<br \/>\n) ENGINE&#061;InnoDB;<\/p>\n<p>\u5e95\u5c42\u5b58\u50a8\u7ed3\u6784&#xff08;\u53ef\u89c6\u5316\u62c6\u89e3&#xff09;&#xff1a;<\/p>\n<li>\u7269\u7406\u6587\u4ef6&#xff1a;\u4ec5itest.ibd&#xff08;InnoDB \u8868\u7a7a\u95f4\u6587\u4ef6&#xff09;&#xff0c;\u5305\u542b \u201c\u805a\u7c07\u7d22\u5f15 B &#043; \u6811\u201d \u548c \u201c\u8f85\u52a9\u7d22\u5f15 B &#043; \u6811\u201d&#xff1b;<\/li>\n<li>\u805a\u7c07\u7d22\u5f15 B &#043; \u6811&#xff1a;\n<ul>\n<li>\u6839\u8282\u70b9 \/ \u975e\u53f6\u5b50\u8282\u70b9&#xff1a;\u5b58\u50a8 \u201c\u4e3b\u952e\u503c &#043; \u5b50\u8282\u70b9\u6307\u9488\u201d&#xff1b;<\/li>\n<li>\u53f6\u5b50\u8282\u70b9&#xff1a;\u5b58\u50a8\u5b8c\u6574\u6570\u636e\u884c&#xff08;id&#043;name&#xff09;&#xff0c;\u4e14\u6309\u4e3b\u952e\u6709\u5e8f\u6392\u5217&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u6570\u636e\u9875\u4e0e\u7d22\u5f15\u9875&#xff1a;\u805a\u7c07\u7d22\u5f15\u7684\u53f6\u5b50\u8282\u70b9\u5c31\u662f\u6570\u636e\u9875&#xff0c;\u65e0\u9700\u5355\u72ec\u5b58\u50a8\u6570\u636e\u3002<\/li>\n<h5>5.1.2 \u805a\u7c07\u7d22\u5f15\u7684\u67e5\u8be2\u6d41\u7a0b&#xff08;\u7528 \u201c\u6587\u4ef6\u67dc\u201d \u7c7b\u6bd4&#xff09;<\/h5>\n<p>SELECT * FROM itest WHERE id&#061;1;<\/p>\n<p>\u67e5\u8be2\u6d41\u7a0b&#xff1a;<\/p>\n<li>\u904d\u5386\u805a\u7c07\u7d22\u5f15 B &#043; \u6811&#xff0c;\u4ece\u6839\u8282\u70b9\u2192\u975e\u53f6\u5b50\u8282\u70b9\u2192\u53f6\u5b50\u8282\u70b9&#xff08;3 \u6b21 IO&#xff09;&#xff1b;<\/li>\n<li>\u53f6\u5b50\u8282\u70b9\u5c31\u662f\u6570\u636e\u9875&#xff0c;\u76f4\u63a5\u8bfb\u53d6\u5b8c\u6574\u6570\u636e&#xff08;\u65e0\u9700\u56de\u8868&#xff09;&#xff1b;<\/li>\n<li>\u8fd4\u56de\u7ed3\u679c&#xff08;\u603b IO \u6b21\u6570&#xff1a;3 \u6b21&#xff09;\u3002<\/li>\n<h4>5.2 \u975e\u805a\u7c07\u7d22\u5f15&#xff08;MyISAM \u6240\u6709\u7d22\u5f15 &#043; InnoDB \u8f85\u52a9\u7d22\u5f15&#xff09;<\/h4>\n<h5>5.2.1 \u8bed\u6cd5\u5173\u8054&#xff1a;MyISAM \u8868\u7684\u7d22\u5f15<\/h5>\n<p>CREATE TABLE mtest (<br \/>\n    id INT PRIMARY KEY,<br \/>\n    name VARCHAR(11) NOT NULL<br \/>\n) ENGINE&#061;MyISAM;<\/p>\n<p>\u5e95\u5c42\u5b58\u50a8\u7ed3\u6784&#xff1a;<\/p>\n<li>\u7269\u7406\u6587\u4ef6&#xff1a;\n<ul>\n<li>mtest.frm&#xff1a;\u8868\u7ed3\u6784\u6587\u4ef6&#xff08;\u5143\u6570\u636e&#xff09;&#xff1b;<\/li>\n<li>mtest.MYD&#xff1a;\u6570\u636e\u6587\u4ef6&#xff08;\u5b58\u50a8\u65e0\u5e8f\u7684\u5b8c\u6574\u6570\u636e&#xff09;&#xff1b;<\/li>\n<li>mtest.MYI&#xff1a;\u7d22\u5f15\u6587\u4ef6&#xff08;\u5b58\u50a8\u6240\u6709\u7d22\u5f15\u7684 B &#043; \u6811&#xff09;&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u4e3b\u952e\u7d22\u5f15 B &#043; \u6811&#xff08;\u975e\u805a\u7c07&#xff09;&#xff1a;\n<ul>\n<li>\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 \u201c\u4e3b\u952e\u503c &#043; \u6570\u636e\u6587\u4ef6\u4e2d\u7684\u7269\u7406\u5730\u5740\u201d&#xff08;\u5982 id&#061;1\u2192\u5730\u5740 0x123456&#xff09;&#xff1b;<\/li>\n<li>\u67e5\u8be2\u65f6\u9700\u5148\u67e5\u7d22\u5f15&#xff08;3 \u6b21 IO&#xff09;&#xff0c;\u518d\u6839\u636e\u5730\u5740\u8bfb\u6570\u636e\u6587\u4ef6&#xff08;1 \u6b21 IO&#xff09;&#xff0c;\u603b IO \u6b21\u6570&#xff1a;4 \u6b21\u3002<\/li>\n<\/ul>\n<\/li>\n<h5>5.2.2 \u8bed\u6cd5\u5173\u8054&#xff1a;InnoDB \u7684\u8f85\u52a9\u7d22\u5f15&#xff08;\u975e\u805a\u7c07&#xff09;<\/h5>\n<p>CREATE INDEX idx_name ON itest(name); &#8212; \u666e\u901a\u7d22\u5f15&#xff08;\u8f85\u52a9\u7d22\u5f15&#xff09;<\/p>\n<p>\u5e95\u5c42\u7ed3\u6784 &#043; \u67e5\u8be2\u6d41\u7a0b&#xff1a;<\/p>\n<li>\u8f85\u52a9\u7d22\u5f15 B &#043; \u6811&#xff1a;\n<ul>\n<li>\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 \u201cname \u503c &#043; \u4e3b\u952e id\u201d&#xff08;\u5982 name&#061;&#039; \u5f20\u4e09 &#039;\u2192id&#061;1&#xff09;&#xff1b;<\/li>\n<li>\u975e\u53f6\u5b50\u8282\u70b9\u5b58\u50a8 \u201cname \u503c &#043; \u5b50\u8282\u70b9\u6307\u9488\u201d&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u67e5\u8be2\u6d41\u7a0b&#xff08;\u56de\u8868&#xff09;&#xff1a;\n<p>SELECT * FROM itest WHERE name&#061;&#039;\u5f20\u4e09&#039;;<\/p>\n<ul>\n<li>\u6b65\u9aa4 1&#xff1a;\u904d\u5386\u8f85\u52a9\u7d22\u5f15 B &#043; \u6811&#xff0c;\u627e\u5230 name&#061;&#039; \u5f20\u4e09 &#039; \u5bf9\u5e94\u7684\u4e3b\u952e id&#061;1&#xff08;3 \u6b21 IO&#xff09;&#xff1b;<\/li>\n<li>\u6b65\u9aa4 2&#xff1a;\u904d\u5386\u805a\u7c07\u7d22\u5f15 B &#043; \u6811&#xff0c;\u627e\u5230 id&#061;1 \u5bf9\u5e94\u7684\u5b8c\u6574\u6570\u636e&#xff08;3 \u6b21 IO&#xff09;&#xff1b;<\/li>\n<li>\u603b IO \u6b21\u6570&#xff1a;6 \u6b21&#xff08;\u6bd4\u805a\u7c07\u7d22\u5f15\u591a 3 \u6b21&#xff09;&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>\u6267\u884c\u8ba1\u5212\u9a8c\u8bc1&#xff1a;\n<p>EXPLAIN SELECT * FROM itest WHERE name&#061;&#039;\u5f20\u4e09&#039;;<br \/>\n&#8212; Extra\u5217&#xff1a;Using index condition&#xff08;\u8868\u793a\u89e6\u53d1\u56de\u8868&#xff09;<\/p>\n<\/li>\n<h4>5.3 \u6838\u5fc3\u533a\u522b<\/h4>\n<table>\n<tr><span style=\"color:#ffd900\">\u5bf9\u6bd4\u7ef4\u5ea6<\/span><span style=\"color:#ffd900\">\u805a\u7c07\u7d22\u5f15&#xff08;InnoDB \u4e3b\u952e\u7d22\u5f15&#xff09;<\/span><span style=\"color:#ffd900\">\u975e\u805a\u7c07\u7d22\u5f15&#xff08;MyISAM \u6240\u6709\u7d22\u5f15 &#043; InnoDB \u8f85\u52a9\u7d22\u5f15&#xff09;<\/span><\/tr>\n<tbody>\n<tr>\n<td><span style=\"color:#ffd900\">\u8bed\u6cd5\u89e6\u53d1<\/span><\/td>\n<td><span style=\"color:#ffd900\">InnoDB \u8868 &#043; PRIMARY KEY \u7ea6\u675f<\/span><\/td>\n<td><span style=\"color:#ffd900\">MyISAM \u8868 &#043; \u4efb\u4f55\u7d22\u5f15\u7c7b\u578b&#xff1b;InnoDB \u8868 &#043; \u975e\u4e3b\u952e\u7d22\u5f15<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ffd900\">\u5b58\u50a8\u6587\u4ef6<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u7d22\u5f15\u548c\u6570\u636e\u5728\u540c\u4e00\u6587\u4ef6&#xff08;.ibd&#xff09;<\/span><\/td>\n<td><span style=\"color:#ffd900\">MyISAM&#xff1a;.MYI&#043;.MYD&#xff1b;InnoDB \u8f85\u52a9\u7d22\u5f15&#xff1a;.ibd \u4e2d\u72ec\u7acb B &#043; \u6811<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ffd900\">\u53f6\u5b50\u8282\u70b9\u5b58\u50a8<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u5b8c\u6574\u6570\u636e\u8bb0\u5f55<\/span><\/td>\n<td><span style=\"color:#ffd900\">MyISAM&#xff1a;\u6570\u636e\u7269\u7406\u5730\u5740&#xff1b;InnoDB \u8f85\u52a9\u7d22\u5f15&#xff1a;\u4e3b\u952e\u503c<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ffd900\">\u67e5\u8be2 IO \u6b21\u6570<\/span><\/td>\n<td><span style=\"color:#ffd900\">3 \u6b21&#xff08;\u65e0\u9700\u56de\u8868&#xff09;<\/span><\/td>\n<td><span style=\"color:#ffd900\">MyISAM&#xff1a;4 \u6b21&#xff1b;InnoDB \u8f85\u52a9\u7d22\u5f15&#xff1a;6 \u6b21&#xff08;\u9700\u56de\u8868&#xff09;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ffd900\">\u6570\u636e\u6709\u5e8f\u6027<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u6570\u636e\u6309\u4e3b\u952e\u6709\u5e8f\u5b58\u50a8<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u6570\u636e\u65e0\u5e8f\u5b58\u50a8&#xff0c;\u7d22\u5f15\u6709\u5e8f<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ffd900\">\u9875\u5206\u88c2\u5f71\u54cd<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u6570\u636e\u9875\u5206\u88c2&#xff0c;\u5f71\u54cd\u6027\u80fd<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u7d22\u5f15\u9875\u5206\u88c2&#xff0c;\u4e0d\u5f71\u54cd\u6570\u636e\u9875<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"color:#ffd900\">\u8bed\u6cd5\u9650\u5236<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u4e00\u4e2a\u8868\u53ea\u80fd\u6709\u4e00\u4e2a<\/span><\/td>\n<td><span style=\"color:#ffd900\">\u4e00\u4e2a\u8868\u53ef\u4ee5\u6709\u591a\u4e2a<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5.4 \u8bed\u6cd5\u4f18\u5316&#xff1a;\u51cf\u5c11\u56de\u8868<\/h4>\n<p>\u56de\u8868\u662f InnoDB \u8f85\u52a9\u7d22\u5f15\u7684\u6027\u80fd\u74f6\u9888&#xff0c;\u53ef\u901a\u8fc7 \u201c\u8986\u76d6\u7d22\u5f15\u201d \u907f\u514d&#xff1a;<\/p>\n<p>&#8212; \u9700\u6c42&#xff1a;\u67e5\u8be2name&#061;&#039;\u5f20\u4e09&#039;\u7684id\u548cname&#xff08;\u65e0\u9700\u5176\u4ed6\u5b57\u6bb5&#xff09;<br \/>\n&#8212; \u6b65\u9aa41&#xff1a;\u521b\u5efa\u8986\u76d6\u7d22\u5f15&#xff08;\u5305\u542b\u67e5\u8be2\u6240\u9700\u7684\u6240\u6709\u5b57\u6bb5&#xff09;<br \/>\nCREATE INDEX idx_name_cover ON itest(name, id);<br \/>\n&#8212; \u6b65\u9aa42&#xff1a;\u67e5\u8be2&#xff08;\u4ec5\u9700\u626b\u63cf\u7d22\u5f15&#xff0c;\u65e0\u9700\u56de\u8868&#xff09;<br \/>\nSELECT id, name FROM itest WHERE name&#061;&#039;\u5f20\u4e09&#039;;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;Extra&#061;Using index&#xff08;\u8986\u76d6\u7d22\u5f15&#xff0c;\u65e0\u56de\u8868&#xff09;<br \/>\n&#8212; \u5e95\u5c42IO\u6b21\u6570&#xff1a;3\u6b21&#xff08;\u4e0e\u805a\u7c07\u7d22\u5f15\u76f8\u540c&#xff09;<\/p>\n<h2>\u516d\u3001\u7d22\u5f15\u521b\u5efa\u539f\u5219\u4e0e\u8bed\u6cd5\u4f18\u5316<\/h2>\n<p>\u638c\u63e1\u7d22\u5f15\u8bed\u6cd5\u540e&#xff0c;\u9700\u9075\u5faa \u201c\u5408\u7406\u521b\u5efa\u3001\u907f\u514d\u6ee5\u7528\u201d \u7684\u539f\u5219&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u5199\u64cd\u4f5c\u6548\u7387\u4e0b\u964d\u3002<\/p>\n<h4>6.1 \u7d22\u5f15\u521b\u5efa\u539f\u5219<\/h4>\n<h5>\u539f\u5219 1&#xff1a;\u9891\u7e41\u4f5c\u4e3a\u67e5\u8be2\u6761\u4ef6\u7684\u5b57\u6bb5 \u2014\u2014 \u521b\u5efa\u7d22\u5f15<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;\u5458\u5de5\u8868\u9891\u7e41\u6309deptno\u67e5\u8be2<br \/>\nALTER TABLE EMP ADD INDEX idx_deptno(deptno);<br \/>\n&#8212; \u5e95\u5c42\u9a8c\u8bc1&#xff1a;<br \/>\nEXPLAIN SELECT * FROM EMP WHERE deptno&#061;10;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;type&#061;ref&#xff0c;key&#061;idx_deptno&#xff0c;rows&#061;1000&#xff08;IO\u6b21\u6570\u4ece8000\u6b21\u21923\u6b21&#xff09;<\/p>\n<h5>\u539f\u5219 2&#xff1a;\u552f\u4e00\u6027\u592a\u5dee\u7684\u5b57\u6bb5 \u2014\u2014 \u4e0d\u9002\u5408\u5355\u72ec\u521b\u5efa\u7d22\u5f15<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;gender\u5b57\u6bb5&#xff08;\u4ec5\u7537\/\u5973&#xff0c;\u552f\u4e00\u6027\u5dee&#xff09;<br \/>\n&#8212; \u4e0d\u63a8\u8350&#xff1a;\u5355\u72ec\u521b\u5efa\u7d22\u5f15&#xff08;\u7d22\u5f15\u57fa\u6570\u5c0f&#xff0c;IO\u6536\u76ca&lt;\u5f00\u9500&#xff09;<br \/>\nALTER TABLE EMP ADD INDEX idx_gender(gender); &#8212; \u7d22\u5f15\u57fa\u6570&#061;2&#xff0c;\u67e5\u8be2\u4ecd\u9700\u626b\u63cf50%\u6570\u636e<\/p>\n<p>&#8212; \u63a8\u8350&#xff1a;\u590d\u5408\u7d22\u5f15\u540e\u7f00<br \/>\nALTER TABLE EMP ADD INDEX idx_deptno_gender(deptno, gender);<br \/>\n&#8212; \u5e95\u5c42\u9a8c\u8bc1&#xff1a;<br \/>\nEXPLAIN SELECT * FROM EMP WHERE deptno&#061;10 AND gender&#061;&#039;\u7537&#039;;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;type&#061;ref&#xff0c;key&#061;idx_deptno_gender&#xff0c;rows&#061;500&#xff08;IO\u6b21\u6570&#061;3\u6b21&#xff09;<\/p>\n<h5>\u539f\u5219 3&#xff1a;\u66f4\u65b0\u9891\u7e41\u7684\u5b57\u6bb5 \u2014\u2014 \u4e0d\u9002\u5408\u521b\u5efa\u7d22<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;sal\u5b57\u6bb5&#xff08;\u9891\u7e41\u8c03\u85aa&#xff09;<br \/>\n&#8212; \u4e0d\u63a8\u8350&#xff1a;\u521b\u5efa\u7d22\u5f15&#xff08;\u66f4\u65b0\u65f6\u9700\u7ef4\u62a4B&#043;\u6811&#xff0c;\u589e\u52a0IO&#xff09;<br \/>\nALTER TABLE EMP ADD INDEX idx_sal(sal);<br \/>\n&#8212; \u5e95\u5c42\u4ee3\u4ef7&#xff1a;<br \/>\n&#8212; 1. \u66f4\u65b0sal\u65f6&#xff0c;\u9700\u4fee\u6539\u6570\u636e\u9875&#043;\u7d22\u5f15\u9875&#xff08;2\u6b21IO&#xff09;&#xff1b;<br \/>\n&#8212; 2. \u82e5sal\u5728\u590d\u5408\u7d22\u5f15\u4e2d&#xff0c;\u9700\u4fee\u6539\u6240\u6709\u5305\u542bsal\u7684\u7d22\u5f15\u9875&#xff08;\u591a\u6b21IO&#xff09;\u3002<\/p>\n<p>&#8212; \u66ff\u4ee3\u65b9\u6848&#xff1a;<br \/>\n&#8212; 1. \u65e0\u7d22\u5f15&#xff0c;\u67e5\u8be2\u65f6\u7528\u5206\u533a\u8868&#xff08;\u6309sal\u8303\u56f4\u5206\u533a&#xff09;&#xff1b;<br \/>\n&#8212; 2. \u79bb\u7ebf\u66f4\u65b0\u7d22\u5f15&#xff08;\u4f4e\u5cf0\u671f\u521b\u5efa&#xff0c;\u9ad8\u5cf0\u671f\u5220\u9664&#xff09;\u3002<\/p>\n<h5>\u539f\u5219 4&#xff1a;\u4e0d\u4f1a\u51fa\u73b0\u5728 WHERE \u5b50\u53e5\u7684\u5b57\u6bb5 \u2014\u2014 \u4e0d\u521b\u5efa\u7d22\u5f15<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;remark\u5b57\u6bb5&#xff08;\u4ec5\u5c55\u793a&#xff0c;\u4e0d\u67e5\u8be2&#xff09;<br \/>\n&#8212; \u4e0d\u63a8\u8350&#xff1a;\u521b\u5efa\u7d22\u5f15&#xff08;\u6d6a\u8d39\u5b58\u50a8\u7a7a\u95f4&#xff0c;\u65e0\u67e5\u8be2\u6536\u76ca&#xff09;<br \/>\nALTER TABLE EMP ADD INDEX idx_remark(remark);<br \/>\n&#8212; \u5e95\u5c42\u4ee3\u4ef7&#xff1a;<br \/>\n&#8212; 1. \u7d22\u5f15\u5360\u7528\u5b58\u50a8\u7a7a\u95f4&#xff08;remark\u5b57\u6bb5VARCHAR(200)&#xff0c;\u7d22\u5f15\u9875\u5360\u7528\u5927&#xff09;&#xff1b;<br \/>\n&#8212; 2. \u63d2\u5165\/\u66f4\u65b0remark\u65f6&#xff0c;\u9700\u7ef4\u62a4\u7d22\u5f15&#xff08;\u589e\u52a0IO&#xff09;\u3002<\/p>\n<h5>\u539f\u5219 5&#xff1a;\u590d\u5408\u7d22\u5f15\u5b57\u6bb5\u987a\u5e8f \u2014\u2014\u201c\u67e5\u8be2\u9891\u7e41\u7684\u5728\u524d&#xff0c;\u533a\u5206\u5ea6\u9ad8\u7684\u5728\u524d\u201d<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;\u9891\u7e41\u67e5\u8be2deptno&#043;name&#xff08;deptno\u67e5\u8be2\u9891\u738780%&#xff0c;name\u533a\u5206\u5ea690%&#xff09;<br \/>\n&#8212; \u63a8\u8350&#xff1a;idx_deptno_name&#xff08;deptno\u5728\u524d&#xff0c;name\u5728\u540e&#xff09;<br \/>\nCREATE INDEX idx_deptno_name ON EMP(deptno, name);<br \/>\n&#8212; \u5e95\u5c42\u9a8c\u8bc1&#xff1a;<br \/>\nEXPLAIN SELECT * FROM EMP WHERE deptno&#061;10; &#8212; \u7528\u5230\u7d22\u5f15&#xff08;\u6700\u5de6\u5339\u914d&#xff09;<br \/>\nEXPLAIN SELECT * FROM EMP WHERE deptno&#061;10 AND name&#061;&#039;\u5f20\u4e09&#039;; &#8212; \u7528\u5230\u7d22\u5f15&#xff08;\u5168\u5339\u914d&#xff09;<\/p>\n<p>&#8212; \u4e0d\u63a8\u8350&#xff1a;idx_name_deptno&#xff08;name\u5728\u524d&#xff0c;deptno\u5728\u540e&#xff09;<br \/>\nCREATE INDEX idx_name_deptno ON EMP(name, deptno);<br \/>\n&#8212; \u5e95\u5c42\u9a8c\u8bc1&#xff1a;<br \/>\nEXPLAIN SELECT * FROM EMP WHERE deptno&#061;10; &#8212; \u672a\u7528\u5230\u7d22\u5f15&#xff08;\u8fdd\u53cd\u6700\u5de6\u5339\u914d&#xff09;<\/p>\n<h4>6.2 \u7d22\u5f15\u8bed\u6cd5\u4f18\u5316\u6280\u5de7<\/h4>\n<h5>\u6280\u5de7 1&#xff1a;\u524d\u7f00\u7d22\u5f15 \u2014\u2014 \u4f18\u5316\u957f\u5b57\u7b26\u4e32\u5b57\u6bb5<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;email\u5b57\u6bb5&#xff08;VARCHAR(50)&#xff0c;\u524d20\u4e2a\u5b57\u7b26\u5df2\u80fd\u533a\u520699%\u7684\u503c&#xff09;<br \/>\nCREATE INDEX idx_email_prefix ON user(email(20));<br \/>\n&#8212; \u5e95\u5c42\u4f18\u5316&#xff1a;<br \/>\n&#8212; 1. \u7d22\u5f15\u952e\u503c\u957f\u5ea6\u4ece50\u5b57\u8282\u219220\u5b57\u8282&#xff0c;\u5355\u4e2aPage\u80fd\u5b58\u7684\u952e\u503c\u6570\u4ece200\u2192500&#xff1b;<br \/>\n&#8212; 2. B&#043;\u6811\u9ad8\u5ea6\u4ece4\u5c42\u21923\u5c42&#xff0c;IO\u6b21\u6570\u4ece4\u6b21\u21923\u6b21&#xff1b;<br \/>\n&#8212; 3. \u5b58\u50a8\u7a7a\u95f4\u4ece100MB\u219240MB&#xff0c;\u51cf\u5c1160%\u3002<\/p>\n<p>&#8212; \u9a8c\u8bc1\u524d\u7f00\u7d22\u5f15\u6709\u6548\u6027&#xff1a;<br \/>\nSELECT COUNT(DISTINCT email) \/ COUNT(*) AS full_distinct,<br \/>\n       COUNT(DISTINCT LEFT(email,20)) \/ COUNT(*) AS prefix_distinct<br \/>\nFROM user;<br \/>\n&#8212; \u82e5prefix_distinct\u2248full_distinct&#xff08;\u5982&gt;99%&#xff09;&#xff0c;\u5219\u524d\u7f00\u7d22\u5f15\u6709\u6548\u3002<\/p>\n<h5>\u6280\u5de7 2&#xff1a;\u8986\u76d6\u7d22\u5f15 \u2014\u2014 \u907f\u514d\u56de\u8868\u67e5\u8be2<\/h5>\n<p>&#8212; \u573a\u666f&#xff1a;\u67e5\u8be2deptno&#061;10\u7684\u5458\u5de5\u59d3\u540d\u548c\u90e8\u95e8\u7f16\u53f7<br \/>\n&#8212; \u6b65\u9aa41&#xff1a;\u521b\u5efa\u8986\u76d6\u7d22\u5f15&#xff08;\u5305\u542bdeptno&#043;name&#xff09;<br \/>\nCREATE INDEX idx_deptno_name ON EMP(deptno, name);<br \/>\n&#8212; \u6b65\u9aa42&#xff1a;\u67e5\u8be2&#xff08;\u4ec5\u626b\u63cf\u7d22\u5f15&#xff0c;\u65e0\u9700\u56de\u8868&#xff09;<br \/>\nSELECT name, deptno FROM EMP WHERE deptno&#061;10;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;Extra&#061;Using index&#xff08;\u8986\u76d6\u7d22\u5f15&#xff09;<br \/>\n&#8212; \u5e95\u5c42IO\u6b21\u6570&#xff1a;3\u6b21&#xff08;vs \u56de\u8868\u76846\u6b21&#xff09;\u3002<\/p>\n<h5>\u6280\u5de7 3&#xff1a;\u907f\u514d\u7d22\u5f15\u5931\u6548\u7684\u8bed\u6cd5\u5199\u6cd5<\/h5>\n<table>\n<tr>\u9519\u8bef\u8bed\u6cd5\u5199\u6cd5\u5e95\u5c42\u539f\u56e0&#xff08;\u7d22\u5f15\u5931\u6548&#xff09;\u6b63\u786e\u8bed\u6cd5\u5199\u6cd5\u5e95\u5c42\u4f18\u5316&#xff08;IO \u6b21\u6570&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>SELECT * FROM user WHERE YEAR(birthday)&#061;1990;<\/td>\n<td>\u7d22\u5f15\u5b57\u6bb5\u505a\u51fd\u6570\u64cd\u4f5c&#xff0c;\u7834\u574f B &#043; \u6811\u6709\u5e8f\u6027<\/td>\n<td>SELECT * FROM user WHERE birthday BETWEEN &#039;1990-01-01&#039; AND &#039;1990-12-31&#039;;<\/td>\n<td>8000 \u6b21\u21923 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user WHERE deptno!&#061;10;<\/td>\n<td>\u4e0d\u7b49\u4e8e\u64cd\u4f5c\u65e0\u6cd5\u5229\u7528 B &#043; \u6811\u7684\u8303\u56f4\u67e5\u627e<\/td>\n<td>SELECT * FROM user WHERE deptno&lt;10 UNION ALL SELECT * FROM user WHERE deptno&gt;10;<\/td>\n<td>8000 \u6b21\u21926 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user WHERE name LIKE &#039;% \u4e09 &#039;;<\/td>\n<td>\u540e\u7f00\u6a21\u7cca\u5339\u914d&#xff0c;\u65e0\u6cd5\u5229\u7528 B &#043; \u6811\u7684\u524d\u7f00\u6392\u5e8f<\/td>\n<td>\u53cd\u5411\u5b58\u50a8 &#043; \u524d\u7f00\u7d22\u5f15&#xff1a;SELECT * FROM user WHERE reverse_name LIKE &#039; \u4e09 %&#039;;<\/td>\n<td>8000 \u6b21\u21923 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user WHERE name&#061;123;<\/td>\n<td>\u5b57\u7b26\u4e32\u5b57\u6bb5\u4e0e\u6570\u5b57\u6bd4\u8f83&#xff0c;\u89e6\u53d1\u7c7b\u578b\u8f6c\u6362<\/td>\n<td>SELECT * FROM user WHERE name&#061;&#039;123&#039;;<\/td>\n<td>8000 \u6b21\u21923 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>SELECT * FROM user WHERE deptno IN (10,20,30);<\/td>\n<td>IN \u64cd\u4f5c\u5728\u6570\u636e\u91cf\u5927\u65f6\u5931\u6548&#xff08;MySQL \u4f18\u5316\u5668\u9009\u62e9\u5168\u8868\u626b\u63cf&#xff09;<\/td>\n<td>\u62c6\u5206\u591a\u4e2a OR&#xff1a;SELECT * FROM user WHERE dept<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u6280\u5de7 4&#xff1a;\u4f7f\u7528 FORCE INDEX \u5f3a\u5236\u8d70\u7d22\u5f15&#xff08;\u4f18\u5316\u5668\u8bef\u5224\u65f6&#xff09;<\/h5>\n<p>MySQL \u7684\u67e5\u8be2\u4f18\u5316\u5668\u4f1a\u6839\u636e \u201c\u7d22\u5f15\u57fa\u6570\u3001\u6570\u636e\u91cf\u3001IO \u6210\u672c\u201d \u81ea\u52a8\u9009\u62e9\u662f\u5426\u8d70\u7d22\u5f15&#xff0c;\u4f46\u90e8\u5206\u573a\u666f\u4e0b\u4f18\u5316\u5668\u4f1a\u8bef\u5224&#xff08;\u5982\u5c0f\u8868\u5168\u8868\u626b\u63cf\u66f4\u5feb&#xff0c;\u4f46\u5927\u8868\u4ecd\u9009\u62e9\u5168\u8868\u626b\u63cf&#xff09;&#xff0c;\u6b64\u65f6\u53ef\u901a\u8fc7FORCE INDEX\u5f3a\u5236\u8d70\u7d22\u5f15\u3002<\/p>\n<p>&#8212; \u573a\u666f&#xff1a;EMP\u8868800\u4e07\u6570\u636e&#xff0c;deptno&#061;10\u7684\u8bb0\u5f55\u670910\u4e07\u6761&#xff0c;\u4f18\u5316\u5668\u8bef\u5224\u4e3a\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u9519\u8bef\u6267\u884c\u8ba1\u5212&#xff1a;type&#061;ALL&#xff0c;key&#061;NULL&#xff08;\u5168\u8868\u626b\u63cf&#xff0c;8000\u6b21IO&#xff09;<br \/>\nEXPLAIN SELECT * FROM EMP WHERE deptno&#061;10;<\/p>\n<p>&#8212; \u6b63\u786e\u8bed\u6cd5&#xff1a;FORCE INDEX\u5f3a\u5236\u8d70idx_deptno\u7d22\u5f15<br \/>\nEXPLAIN SELECT * FROM EMP FORCE INDEX (idx_deptno) WHERE deptno&#061;10;<br \/>\n&#8212; \u6267\u884c\u8ba1\u5212&#xff1a;type&#061;ref&#xff0c;key&#061;idx_deptno&#xff08;3\u6b21IO&#xff09;<br \/>\n&#8212; \u5e95\u5c42\u539f\u7406&#xff1a;\u5f3a\u5236\u4f18\u5316\u5668\u4f7f\u7528\u6307\u5b9a\u7d22\u5f15&#xff0c;\u8df3\u8fc7\u6210\u672c\u8ba1\u7b97&#xff0c;\u76f4\u63a5\u901a\u8fc7B&#043;\u6811\u5b9a\u4f4d\u6570\u636e<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\u4ec5\u5728\u4f18\u5316\u5668\u660e\u786e\u8bef\u5224\u65f6\u4f7f\u7528&#xff0c;\u4e0d\u8981\u6ee5\u7528&#xff08;\u4f18\u5316\u5668\u5927\u90e8\u5206\u573a\u666f\u4e0b\u7684\u9009\u62e9\u662f\u6700\u4f18\u7684&#xff09;&#xff1b;<\/li>\n<li>\u82e5\u9891\u7e41\u9700\u8981 FORCE INDEX&#xff0c;\u8bf4\u660e\u7d22\u5f15\u57fa\u6570\u7edf\u8ba1\u5931\u6548&#xff0c;\u9700\u66f4\u65b0\u7edf\u8ba1\u4fe1\u606f&#xff1a;\n<p>sql<\/p>\n<p>ANALYZE TABLE EMP; &#8212; \u66f4\u65b0\u8868\u7684\u7d22\u5f15\u57fa\u6570\u7edf\u8ba1&#xff0c;\u8ba9\u4f18\u5316\u5668\u91cd\u65b0\u8ba1\u7b97\u6210\u672c<\/p>\n<\/li>\n<\/ul>\n<h5>\u6280\u5de7 5&#xff1a;\u6279\u91cf\u64cd\u4f5c\u4f18\u5316&#xff08;\u51cf\u5c11\u7d22\u5f15\u7ef4\u62a4 IO&#xff09;<\/h5>\n<p>\u6279\u91cf\u63d2\u5165 \/ \u66f4\u65b0 \/ \u5220\u9664\u6570\u636e\u65f6&#xff0c;\u9891\u7e41\u7684\u7d22\u5f15\u7ef4\u62a4\u4f1a\u5bfc\u81f4\u5927\u91cf IO&#xff08;\u6bcf\u6b21\u64cd\u4f5c\u90fd\u8981\u8c03\u6574 B &#043; \u6811&#xff09;&#xff0c;\u53ef\u901a\u8fc7\u4e34\u65f6\u5220\u9664\u7d22\u5f15\u2192\u6279\u91cf\u64cd\u4f5c\u2192\u91cd\u5efa\u7d22\u5f15\u4f18\u5316\u3002<\/p>\n<p>&#8212; \u573a\u666f&#xff1a;\u6279\u91cf\u63d2\u5165100\u4e07\u6761\u5458\u5de5\u6570\u636e\u5230EMP\u8868&#xff0c;\u8868\u4e2d\u5df2\u6709idx_deptno\/idx_ename\u7b495\u4e2a\u7d22\u5f15<br \/>\n&#8212; \u6b65\u9aa41&#xff1a;\u4e34\u65f6\u5220\u9664\u6240\u6709\u975e\u4e3b\u952e\u7d22\u5f15&#xff08;\u4e3b\u952e\u7d22\u5f15\u65e0\u6cd5\u5220\u9664&#xff0c;\u805a\u7c07\u7d22\u5f15\u7279\u6027&#xff09;<br \/>\nDROP INDEX idx_deptno ON EMP;<br \/>\nDROP INDEX idx_ename ON EMP;<br \/>\n&#8212; \u6b65\u9aa42&#xff1a;\u6279\u91cf\u63d2\u5165\u6570\u636e&#xff08;\u65e0\u7d22\u5f15\u7ef4\u62a4&#xff0c;IO\u6b21\u6570\u51cf\u5c1190%&#xff09;<br \/>\nCALL insert_emp(9000001, 1000000);<br \/>\n&#8212; \u6b65\u9aa43&#xff1a;\u91cd\u5efa\u7d22\u5f15&#xff08;\u4e00\u6b21\u6027\u6784\u5efaB&#043;\u6811&#xff0c;\u6bd4\u9010\u6761\u7ef4\u62a4\u6548\u7387\u9ad810\u500d&#xff09;<br \/>\nCREATE INDEX idx_deptno ON EMP(deptno);<br \/>\nCREATE INDEX idx_ename ON EMP(ename);<\/p>\n<p>\u5e95\u5c42\u4f18\u5316\u903b\u8f91&#xff1a;<\/p>\n<ul>\n<li>\u9010\u6761\u63d2\u5165\u5e26\u7d22\u5f15\u7684\u8868&#xff1a;\u6bcf\u6b21\u63d2\u5165\u9700\u8c03\u6574 B &#043; \u6811 &#043; \u9875\u5206\u88c2&#xff0c;100 \u4e07\u6b21\u63d2\u5165\u5bf9\u5e94 100 \u4e07\u6b21\u7d22\u5f15\u7ef4\u62a4&#xff1b;<\/li>\n<li>\u5148\u5220\u540e\u5efa\u7d22\u5f15&#xff1a;\u91cd\u5efa\u7d22\u5f15\u65f6\u4e00\u6b21\u6027\u904d\u5386\u6570\u636e &#043; \u6392\u5e8f &#043; \u6784\u5efa B &#043; \u6811&#xff0c;\u4ec5 1 \u6b21\u7d22\u5f15\u7ef4\u62a4&#xff0c;\u5927\u5e45\u51cf\u5c11 IO\u3002<\/li>\n<\/ul>\n<h5>\u6280\u5de7 6&#xff1a;NULL \u503c\u5904\u7406\u4f18\u5316&#xff08;\u907f\u514d\u7d22\u5f15\u5931\u6548&#xff09;<\/h5>\n<p>\u7d22\u5f15\u5b57\u6bb5\u5141\u8bb8 NULL \u65f6&#xff0c;MySQL \u4f1a\u5c06 NULL \u89c6\u4e3a\u6700\u5c0f\u952e\u503c\u5b58\u50a8\u5728 B &#043; \u6811\u6700\u5de6\u4fa7&#xff0c;\u4f46\u90e8\u5206\u67e5\u8be2\u6761\u4ef6\u4f1a\u56e0 NULL \u503c\u5bfc\u81f4\u7d22\u5f15\u5931\u6548&#xff0c;\u9700\u7edf\u4e00\u5904\u7406\u3002<\/p>\n<p>&#8212; \u573a\u666f&#xff1a;user\u8868\u7684email\u5b57\u6bb5\u5141\u8bb8NULL&#xff0c;\u521b\u5efa\u4e86idx_email\u7d22\u5f15&#xff0c;\u67e5\u8be2\u975e\u7a7aemail\u65f6\u7d22\u5f15\u5931\u6548<br \/>\n&#8212; \u9519\u8bef\u5199\u6cd5&#xff1a;SELECT * FROM user WHERE email IS NOT NULL;&#xff08;\u90e8\u5206MySQL\u7248\u672c\u4f1a\u5168\u8868\u626b\u63cf&#xff09;<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;IS NOT NULL\u7684\u8303\u56f4\u67e5\u8be2\u5728NULL\u503c\u8f83\u591a\u65f6&#xff0c;\u4f18\u5316\u5668\u5224\u5b9a\u6210\u672c\u8fc7\u9ad8<\/p>\n<p>&#8212; \u4f18\u5316\u65b9\u68481&#xff1a;\u5b57\u6bb5\u9ed8\u8ba4\u503c\u66ff\u4ee3NULL&#xff08;\u63a8\u8350&#xff0c;\u4ece\u6e90\u5934\u907f\u514d&#xff09;<br \/>\nALTER TABLE user MODIFY email VARCHAR(50) NOT NULL DEFAULT &#039;&#039;; &#8212; \u7a7a\u5b57\u7b26\u4e32\u66ff\u4ee3NULL<br \/>\nCREATE INDEX idx_email ON user(email);<br \/>\nSELECT * FROM user WHERE email!&#061;&#039;&#039;; &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<p>&#8212; \u4f18\u5316\u65b9\u68482&#xff1a;\u4f7f\u7528\u51fd\u6570\u8fc7\u6ee4&#xff08;\u4ec5\u517c\u5bb9&#xff09;<br \/>\nSELECT * FROM user WHERE IFNULL(email, &#039;&#039;)!&#061;&#039;&#039;; &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h2>\u4e03\u3001\u7d22\u5f15\u5931\u6548\u7684\u907f\u5751\u6307\u5357<\/h2>\n<h4>7.1 \u8bed\u6cd5\u5199\u6cd5\u7c7b\u5931\u6548&#xff08;\u5360\u6bd4 80%&#xff0c;\u6700\u6613\u907f\u514d&#xff09;<\/h4>\n<h5>\u573a\u666f 1&#xff1a;\u7d22\u5f15\u5b57\u6bb5\u505a\u51fd\u6570 \/ \u8fd0\u7b97\u64cd\u4f5c<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_sal ON EMP(sal);<br \/>\nSELECT * FROM EMP WHERE sal*1.1 &gt; 5000; &#8212; \u7d22\u5f15\u5931\u6548&#xff0c;\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u5bf9sal\u505a\u4e58\u6cd5\u8fd0\u7b97&#xff0c;\u7834\u574f\u4e86B&#043;\u6811\u7684\u952e\u503c\u6709\u5e8f\u6027&#xff0c;MySQL\u65e0\u6cd5\u901a\u8fc7\u7d22\u5f15\u5b9a\u4f4d<br \/>\n&#8212; \u89e3\u51b3\u65b9\u6848&#xff1a;\u5c06\u8fd0\u7b97\u79fb\u5230\u6761\u4ef6\u53f3\u4fa7&#xff08;\u4e0d\u4fee\u6539\u7d22\u5f15\u5b57\u6bb5&#xff09;<br \/>\nSELECT * FROM EMP WHERE sal &gt; 5000\/1.1; &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h5>\u573a\u666f 2&#xff1a;\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_ename ON EMP(ename); &#8212; ename\u662fVARCHAR\u7c7b\u578b<br \/>\nSELECT * FROM EMP WHERE ename&#061;123; &#8212; \u7d22\u5f15\u5931\u6548&#xff0c;\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u6570\u5b57123\u4e0e\u5b57\u7b26\u4e32ename\u505a\u6bd4\u8f83&#xff0c;MySQL\u81ea\u52a8\u6267\u884cCAST(ename AS INT)&#xff0c;\u5bf9\u7d22\u5f15\u5b57\u6bb5\u505a\u8f6c\u6362<br \/>\n&#8212; \u89e3\u51b3\u65b9\u6848&#xff1a;\u4fdd\u6301\u7c7b\u578b\u4e00\u81f4&#xff0c;\u4f20\u5165\u5b57\u7b26\u4e32\u6761\u4ef6<br \/>\nSELECT * FROM EMP WHERE ename&#061;&#039;123&#039;; &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h5>\u573a\u666f 3&#xff1a;\u6a21\u7cca\u67e5\u8be2 % \u5728\u5f00\u5934<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_ename ON EMP(ename);<br \/>\nSELECT * FROM EMP WHERE ename LIKE &#039;%\u5f20&#039;; &#8212; \u7d22\u5f15\u5931\u6548&#xff0c;\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;%\u5728\u5f00\u5934\u8868\u793a\u201c\u4efb\u610f\u524d\u7f00&#043;\u5f20\u201d&#xff0c;\u65e0\u6cd5\u5339\u914dB&#043;\u6811\u7684\u524d\u7f00\u6709\u5e8f\u952e\u503c&#xff0c;\u65e0\u6cd5\u5b9a\u4f4d\u8282\u70b9<br \/>\n&#8212; \u89e3\u51b3\u65b9\u6848&#xff1a;\u53cd\u5411\u5b58\u50a8\u5b57\u6bb5&#043;\u524d\u7f00\u7d22\u5f15&#xff08;\u8be6\u89c16.2\u6280\u5de73&#xff09;<br \/>\nALTER TABLE EMP ADD reverse_ename VARCHAR(6) AFTER ename;<br \/>\nUPDATE EMP SET reverse_ename &#061; REVERSE(ename);<br \/>\nCREATE INDEX idx_rev_ename ON EMP(reverse_ename);<br \/>\nSELECT * FROM EMP WHERE reverse_ename LIKE &#039;\u5f20%&#039;; &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h5>\u573a\u666f 4&#xff1a;AND\/OR \u6df7\u5408\u4f7f\u7528\u65e0\u4f18\u5148\u7ea7<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_deptno_age ON EMP(deptno, age);<br \/>\nSELECT * FROM EMP WHERE deptno&#061;10 OR age&gt;20; &#8212; \u7d22\u5f15\u5931\u6548&#xff0c;\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;OR\u4e24\u4fa7\u7684\u6761\u4ef6&#xff0c;age&gt;20\u65e0\u6cd5\u5339\u914d\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00&#xff0c;\u4f18\u5316\u5668\u76f4\u63a5\u653e\u5f03\u7d22\u5f15<br \/>\n&#8212; \u89e3\u51b3\u65b9\u68481&#xff1a;\u52a0\u62ec\u53f7\u62c6\u5206&#xff0c;\u4fdd\u8bc1\u4e00\u4fa7\u5339\u914d\u7d22\u5f15<br \/>\nSELECT * FROM EMP WHERE (deptno&#061;10 OR age&gt;20) AND deptno IS NOT NULL; &#8212; \u7528\u5230\u7d22\u5f15<br \/>\n&#8212; \u89e3\u51b3\u65b9\u68482&#xff1a;\u62c6\u5206\u67e5\u8be2&#xff0c;UNION ALL\u5408\u5e76\u7ed3\u679c<br \/>\nSELECT * FROM EMP WHERE deptno&#061;10 UNION ALL SELECT * FROM EMP WHERE age&gt;20 AND deptno!&#061;10;<\/p>\n<h5>\u573a\u666f 5&#xff1a;\u4f7f\u7528 NOT IN\/NOT EXISTS&#xff08;\u5927\u6570\u636e\u91cf&#xff09;<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_deptno ON EMP(deptno);<br \/>\nSELECT * FROM EMP WHERE deptno NOT IN (10,20,30); &#8212; \u6570\u636e\u91cf\u5927\u65f6\u7d22\u5f15\u5931\u6548<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;NOT IN\u7684\u8303\u56f4\u8fc7\u5927\u65f6&#xff0c;MySQL\u4f18\u5316\u5668\u5224\u5b9a\u5168\u8868\u626b\u63cf\u7684IO\u6210\u672c\u66f4\u4f4e<br \/>\n&#8212; \u89e3\u51b3\u65b9\u6848&#xff1a;\u7528LEFT JOIN\u66ff\u4ee3NOT IN<br \/>\nSELECT e.* FROM EMP e LEFT JOIN (SELECT 10 AS deptno UNION ALL SELECT 20 UNION ALL SELECT 30) t ON e.deptno&#061;t.deptno WHERE t.deptno IS NULL;<\/p>\n<h4>7.2 \u7d22\u5f15\u8bbe\u8ba1\u7c7b\u5931\u6548<\/h4>\n<h5>\u573a\u666f 1&#xff1a;\u590d\u5408\u7d22\u5f15\u8fdd\u53cd\u6700\u5de6\u5339\u914d\u539f\u5219<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_name_age_deptno ON EMP(name, age, deptno);<br \/>\nSELECT * FROM EMP WHERE age&#061;18; &#8212; \u7d22\u5f15\u5931\u6548&#xff0c;\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u590d\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u662fname&#xff0c;\u67e5\u8be2\u6761\u4ef6\u672a\u5305\u542bname&#xff0c;\u65e0\u6cd5\u5339\u914d\u7d22\u5f15\u8282\u70b9<br \/>\n&#8212; \u89e3\u51b3\u65b9\u68481&#xff1a;\u8c03\u6574\u67e5\u8be2\u6761\u4ef6&#xff0c;\u5305\u542b\u6700\u5de6\u524d\u7f00name<br \/>\nSELECT * FROM EMP WHERE name&#061;&#039;\u5f20\u4e09&#039; AND age&#061;18; &#8212; \u7528\u5230\u7d22\u5f15<br \/>\n&#8212; \u89e3\u51b3\u65b9\u68482&#xff1a;\u5355\u72ec\u4e3aage\u521b\u5efa\u7d22\u5f15<br \/>\nCREATE INDEX idx_age ON EMP(age); &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h5>\u573a\u666f 2&#xff1a;\u7d22\u5f15\u5b57\u6bb5\u552f\u4e00\u6027\u592a\u5dee<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_gender ON EMP(gender); &#8212; gender\u53ea\u6709\u7537\/\u5973&#xff0c;\u57fa\u6570&#061;2<br \/>\nSELECT * FROM EMP WHERE gender&#061;&#039;\u7537&#039;; &#8212; \u7d22\u5f15\u5931\u6548&#xff0c;\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u7d22\u5f15\u57fa\u6570\u592a\u5c0f&#xff0c;\u626b\u63cf\u7d22\u5f15\u7684IO\u6210\u672c&#xff08;3\u6b21&#xff09;\u4e0e\u626b\u63cf\u5168\u8868\u7684IO\u6210\u672c&#xff08;5\u6b21&#xff09;\u63a5\u8fd1&#xff0c;\u4f18\u5316\u5668\u9009\u62e9\u5168\u8868\u626b\u63cf<br \/>\n&#8212; \u89e3\u51b3\u65b9\u6848&#xff1a;\u5c06\u8be5\u5b57\u6bb5\u4f5c\u4e3a\u590d\u5408\u7d22\u5f15\u7684\u540e\u7f00&#xff0c;\u4e0d\u5355\u72ec\u521b\u5efa<br \/>\nCREATE INDEX idx_deptno_gender ON EMP(deptno, gender);<br \/>\nSELECT * FROM EMP WHERE deptno&#061;10 AND gender&#061;&#039;\u7537&#039;; &#8212; \u7528\u5230\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h5>\u573a\u666f 3&#xff1a;\u8fc7\u5ea6\u7d22\u5f15\u5bfc\u81f4\u4f18\u5316\u5668\u9009\u62e9\u56f0\u96be<\/h5>\n<p>&#8212; \u590d\u73b0\u8bed\u6cd5<br \/>\nCREATE INDEX idx_deptno ON EMP(deptno);<br \/>\nCREATE INDEX idx_age ON EMP(age);<br \/>\nCREATE INDEX idx_deptno_age ON EMP(deptno, age);<br \/>\nCREATE INDEX idx_age_deptno ON EMP(age, deptno);<br \/>\nSELECT * FROM EMP WHERE deptno&#061;10 AND age&gt;20; &#8212; \u4f18\u5316\u5668\u8bef\u5224&#xff0c;\u9009\u62e9\u5355\u5b57\u6bb5\u7d22\u5f15<br \/>\n&#8212; \u5e95\u5c42\u539f\u56e0&#xff1a;\u8868\u4e2d\u7d22\u5f15\u8fc7\u591a&#xff0c;\u4f18\u5316\u5668\u7684\u6210\u672c\u8ba1\u7b97\u8017\u65f6\u8fc7\u957f&#xff0c;\u6700\u7ec8\u9009\u62e9\u4f4e\u6548\u7684\u5355\u5b57\u6bb5\u7d22\u5f15<br \/>\n&#8212; \u89e3\u51b3\u65b9\u6848&#xff1a;\u5220\u9664\u65e0\u7528\u7d22\u5f15&#xff0c;\u4ec5\u4fdd\u7559\u6700\u4f18\u7684\u590d\u5408\u7d22\u5f15<br \/>\nDROP INDEX idx_deptno ON EMP;<br \/>\nDROP INDEX idx_age ON EMP;<br \/>\nDROP INDEX idx_age_deptno ON EMP;<br \/>\n&#8212; \u4ec5\u4fdd\u7559idx_deptno_age&#xff0c;\u4f18\u5316\u5668\u76f4\u63a5\u9009\u62e9\u8be5\u7d22\u5f15&#xff0c;3\u6b21IO<\/p>\n<h2>\u516b\u3001\u7d22\u5f15\u5b9e\u6218&#xff1a;\u4f01\u4e1a\u7ea7\u573a\u666f\u843d\u5730<\/h2>\n<h4>8.1 \u573a\u666f 1&#xff1a;\u7535\u5546\u8ba2\u5355\u8868<\/h4>\n<h5>\u4e1a\u52a1\u7279\u6027<\/h5>\n<ul>\n<li>\u8868\u540d&#xff1a;order_info&#xff0c;\u6570\u636e\u91cf&#xff1a;5000 \u4e07\u6761&#xff1b;<\/li>\n<li>\u9ad8\u9891\u67e5\u8be2\u6761\u4ef6&#xff1a;order_id&#xff08;\u7b49\u503c&#xff09;\u3001user_id&#xff08;\u7b49\u503c&#xff09;\u3001create_time&#xff08;\u8303\u56f4&#xff09;\u3001pay_status&#xff08;\u7b49\u503c&#xff09;&#xff1b;<\/li>\n<li>\u9ad8\u9891\u66f4\u65b0\u5b57\u6bb5&#xff1a;pay_status&#xff08;\u652f\u4ed8\u72b6\u6001&#xff09;\u3001update_time&#xff08;\u66f4\u65b0\u65f6\u95f4&#xff09;&#xff1b;<\/li>\n<li>\u6838\u5fc3\u67e5\u8be2&#xff1a;\n<li>\u6839\u636e\u8ba2\u5355\u53f7\u67e5\u8be2\u8ba2\u5355\u8be6\u60c5&#xff1a;SELECT * FROM order_info WHERE order_id&#061;&#039;O20240101001&#039;;<\/li>\n<li>\u6839\u636e\u7528\u6237 ID \u67e5\u8be2\u8fd1 3 \u4e2a\u6708\u8ba2\u5355&#xff1a;SELECT * FROM order_info WHERE user_id&#061;1001 AND create_time &gt;&#061; &#039;2024-01-01&#039;;<\/li>\n<li>\u6839\u636e\u652f\u4ed8\u72b6\u6001\u67e5\u8be2\u672a\u652f\u4ed8\u8ba2\u5355&#xff1a;SELECT * FROM order_info WHERE pay_status&#061;0;<\/li>\n<\/li>\n<\/ul>\n<h5>\u7d22\u5f15\u8bbe\u8ba1\u65b9\u6848&#xff08;\u8bed\u6cd5 &#043; \u5e95\u5c42&#xff09;<\/h5>\n<li>\u4e3b\u952e\u7d22\u5f15&#xff1a;order_id&#xff08;\u5b57\u7b26\u4e32\u7c7b\u578b&#xff0c;\u4e1a\u52a1\u552f\u4e00\u6807\u8bc6&#xff09;&#xff0c;\u805a\u7c07\u7d22\u5f15&#xff0c;\u4fdd\u8bc1\u8ba2\u5355\u53f7\u67e5\u8be2\u9ad8\u6548&#xff1b;\n<p>CREATE TABLE order_info (<br \/>\n    order_id VARCHAR(32) NOT NULL PRIMARY KEY, &#8212; \u4e3b\u952e\u7d22\u5f15&#xff08;\u805a\u7c07&#xff09;<br \/>\n    user_id BIGINT NOT NULL,<br \/>\n    goods_id BIGINT NOT NULL,<br \/>\n    amount DECIMAL(10,2) NOT NULL,<br \/>\n    pay_status TINYINT NOT NULL DEFAULT 0, &#8212; 0-\u672a\u652f\u4ed8&#xff0c;1-\u5df2\u652f\u4ed8&#xff0c;2-\u9000\u6b3e<br \/>\n    create_time DATETIME NOT NULL,<br \/>\n    update_time DATETIME NOT NULL,<br \/>\n    INDEX idx_user_create (user_id, create_time), &#8212; \u590d\u5408\u7d22\u5f15&#xff1a;\u7528\u6237ID&#043;\u521b\u5efa\u65f6\u95f4<br \/>\n    INDEX idx_pay_create (pay_status, create_time) &#8212; \u590d\u5408\u7d22\u5f15&#xff1a;\u652f\u4ed8\u72b6\u6001&#043;\u521b\u5efa\u65f6\u95f4<br \/>\n) ENGINE&#061;InnoDB DEFAULT CHARSET&#061;utf8;<\/p>\n<\/li>\n<li>\u590d\u5408\u7d22\u5f15idx_user_create&#xff1a;user_id&#xff08;\u7b49\u503c&#xff09;\u5728\u524d&#xff0c;create_time&#xff08;\u8303\u56f4&#xff09;\u5728\u540e&#xff0c;\u5339\u914d \u201c\u7528\u6237\u67e5\u8fd1 3 \u4e2a\u6708\u8ba2\u5355\u201d \u7684\u67e5\u8be2&#xff0c;\u7b26\u5408\u6700\u5de6\u5339\u914d&#xff1b;<\/li>\n<li>\u590d\u5408\u7d22\u5f15idx_pay_create&#xff1a;pay_status&#xff08;\u7b49\u503c&#xff09;\u5728\u524d&#xff0c;create_time&#xff08;\u8303\u56f4&#xff09;\u5728\u540e&#xff0c;\u5339\u914d \u201c\u672a\u652f\u4ed8\u8ba2\u5355\u67e5\u8be2\u201d&#xff0c;\u907f\u514d\u5355\u72ec\u521b\u5efapay_status\u4f4e\u57fa\u6570\u7d22\u5f15\u3002<\/li>\n<h5>\u6027\u80fd\u4f18\u5316\u70b9<\/h5>\n<ul>\n<li>\u907f\u514d\u66f4\u65b0\u7d22\u5f15\u5b57\u6bb5&#xff1a;pay_status\u4f5c\u4e3a\u590d\u5408\u7d22\u5f15\u7684\u524d\u7f00&#xff0c;\u4f46\u66f4\u65b0\u9891\u7387\u4f4e&#xff08;\u4ec5\u652f\u4ed8\u65f6\u4fee\u6539&#xff09;&#xff0c;\u7d22\u5f15\u7ef4\u62a4 IO \u53ef\u63a5\u53d7&#xff1b;<\/li>\n<li>\u8986\u76d6\u7d22\u5f15\u4f18\u5316&#xff1a;\u67e5\u8be2\u8ba2\u5355\u5217\u8868\u65f6&#xff0c;\u4ec5\u8fd4\u56de\u6838\u5fc3\u5b57\u6bb5&#xff0c;\u521b\u5efa\u8986\u76d6\u7d22\u5f15\u907f\u514d\u56de\u8868&#xff1b;\n<p>&#8212; \u9700\u6c42&#xff1a;\u67e5\u8be2\u7528\u62371001\u7684\u8ba2\u5355\u53f7\u3001\u5546\u54c1ID\u3001\u91d1\u989d&#xff08;\u65e0\u9700\u5168\u5b57\u6bb5&#xff09;<br \/>\nCREATE INDEX idx_user_cover ON order_info(user_id, create_time, order_id, goods_id, amount); &#8212; \u8986\u76d6\u7d22\u5f15<br \/>\nSELECT order_id, goods_id, amount FROM order_info WHERE user_id&#061;1001 AND create_time &gt;&#061; &#039;2024-01-01&#039;;<br \/>\n&#8212; Extra&#061;Using index&#xff0c;\u65e0\u56de\u8868&#xff0c;IO\u6b21\u65703\u6b21<\/p>\n<\/li>\n<li>\u5206\u533a\u8868\u7ed3\u5408\u7d22\u5f15&#xff1a;\u6309create_time\u505a\u8303\u56f4\u5206\u533a&#xff0c;\u51cf\u5c11\u5355\u8868\u6570\u636e\u91cf&#xff0c;\u7d22\u5f15\u4ec5\u5728\u5206\u533a\u5185\u751f\u6548&#xff1b;\n<p>&#8212; \u521b\u5efa\u6309\u6708\u4efd\u5206\u533a\u7684\u8ba2\u5355\u8868<br \/>\nCREATE TABLE order_info (<br \/>\n    &#8212; \u5b57\u6bb5\u540c\u524d<br \/>\n) ENGINE&#061;InnoDB DEFAULT CHARSET&#061;utf8<br \/>\nPARTITION BY RANGE (TO_DAYS(create_time)) (<br \/>\n    PARTITION p202401 VALUES LESS THAN (TO_DAYS(&#039;2024-02-01&#039;)),<br \/>\n    PARTITION p202402 VALUES LESS THAN (TO_DAYS(&#039;2024-03-01&#039;)),<br \/>\n    PARTITION p202403 VALUES LESS THAN (TO_DAYS(&#039;2024-04-01&#039;))<br \/>\n);<br \/>\n&#8212; \u67e5\u8be22024-01\u7684\u8ba2\u5355&#xff0c;\u4ec5\u626b\u63cfp202401\u5206\u533a&#xff0c;\u6570\u636e\u91cf\u51cf\u5c11\u4e3a1\/12<\/p>\n<\/li>\n<\/ul>\n<h4>8.2 \u573a\u666f 2&#xff1a;\u7528\u6237\u4fe1\u606f\u8868<\/h4>\n<h5>\u4e1a\u52a1\u7279\u6027<\/h5>\n<ul>\n<li>\u8868\u540d&#xff1a;user_info&#xff0c;\u6570\u636e\u91cf&#xff1a;1000 \u4e07\u6761&#xff1b;<\/li>\n<li>\u9ad8\u9891\u67e5\u8be2\u6761\u4ef6&#xff1a;user_id&#xff08;\u7b49\u503c&#xff09;\u3001phone&#xff08;\u7b49\u503c&#xff09;\u3001nickname&#xff08;\u6a21\u7cca&#xff09;&#xff1b;<\/li>\n<li>\u4f4e\u9891\u66f4\u65b0&#xff1a;\u4ec5\u7528\u6237\u4fee\u6539\u8d44\u6599\u65f6\u66f4\u65b0&#xff0c;\u65e0\u6279\u91cf\u64cd\u4f5c&#xff1b;<\/li>\n<li>\u6838\u5fc3\u67e5\u8be2&#xff1a;\n<li>\u6839\u636e\u7528\u6237 ID \u67e5\u8be2\u7528\u6237\u4fe1\u606f&#xff1a;SELECT * FROM user_info WHERE user_id&#061;1001;<\/li>\n<li>\u6839\u636e\u624b\u673a\u53f7\u67e5\u8be2\u7528\u6237&#xff1a;SELECT * FROM user_info WHERE phone&#061;&#039;13800138000&#039;;<\/li>\n<li>\u6839\u636e\u6635\u79f0\u6a21\u7cca\u67e5\u8be2&#xff1a;SELECT * FROM user_info WHERE nickname LIKE &#039;\u5f20%&#039;;<\/li>\n<\/li>\n<\/ul>\n<h5>\u7d22\u5f15\u8bbe\u8ba1\u65b9\u6848<\/h5>\n<p>CREATE TABLE user_info (<br \/>\n    user_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, &#8212; \u81ea\u589e\u4e3b\u952e&#xff08;\u805a\u7c07\u7d22\u5f15&#xff09;<br \/>\n    phone VARCHAR(11) NOT NULL UNIQUE, &#8212; \u552f\u4e00\u7d22\u5f15&#xff0c;\u624b\u673a\u53f7\u552f\u4e00<br \/>\n    nickname VARCHAR(30) NOT NULL,<br \/>\n    age TINYINT,<br \/>\n    gender TINYINT,<br \/>\n    address VARCHAR(100),<br \/>\n    create_time DATETIME NOT NULL,<br \/>\n    INDEX idx_nickname (nickname(20)) &#8212; \u524d\u7f00\u7d22\u5f15&#xff1a;\u6635\u79f0\u524d20\u4e2a\u5b57\u7b26&#xff0c;\u51cf\u5c11\u7d22\u5f15\u5927\u5c0f<br \/>\n) ENGINE&#061;InnoDB DEFAULT CHARSET&#061;utf8;<\/p>\n<li>\u81ea\u589e\u4e3b\u952euser_id&#xff1a;\u805a\u7c07\u7d22\u5f15&#xff0c;\u4fdd\u8bc1\u7528\u6237 ID \u67e5\u8be2\u9ad8\u6548&#xff0c;\u6709\u5e8f\u63d2\u5165\u65e0\u9875\u5206\u88c2&#xff1b;<\/li>\n<li>\u552f\u4e00\u7d22\u5f15phone&#xff1a;\u624b\u673a\u53f7\u552f\u4e00&#xff0c;\u7b49\u503c\u67e5\u8be2\u9ad8\u6548&#xff0c;\u7b26\u5408\u4e1a\u52a1\u552f\u4e00\u6027\u8981\u6c42&#xff1b;<\/li>\n<li>\u524d\u7f00\u7d22\u5f15idx_nickname(20)&#xff1a;\u6635\u79f0\u662f\u957f\u5b57\u7b26\u4e32&#xff0c;\u524d 20 \u4e2a\u5b57\u7b26\u5df2\u80fd\u533a\u5206 99% \u7684\u7528\u6237&#xff0c;\u51cf\u5c11\u7d22\u5f15\u5b58\u50a8\u7a7a\u95f4\u548c IO\u3002<\/li>\n<h5>\u6027\u80fd\u4f18\u5316\u70b9<\/h5>\n<ul>\n<li>\u552f\u4e00\u7d22\u5f15\u66ff\u4ee3\u4e3b\u952e&#xff1a;\u82e5\u4e1a\u52a1\u4e2d\u7528\u624b\u673a\u53f7\u4f5c\u4e3a\u552f\u4e00\u6807\u8bc6&#xff0c;\u53ef\u5c06phone\u8bbe\u4e3a\u4e3b\u952e&#xff0c;\u4f46\u5efa\u8bae\u7528\u81ea\u589e\u4e3b\u952e&#xff08;INT \u6bd4 VARCHAR \u5b58\u50a8\u6548\u7387\u9ad8&#xff09;&#xff1b;<\/li>\n<li>\u6635\u79f0\u6a21\u7cca\u67e5\u8be2\u4f18\u5316&#xff1a;\u4ec5\u652f\u6301%\u5728\u672b\u5c3e&#xff0c;\u82e5\u9700\u5168\u6a21\u7cca\u67e5\u8be2&#xff0c;\u7ed3\u5408 Elasticsearch \u505a\u5168\u6587\u68c0\u7d22&#xff0c;\u4e0d\u4f9d\u8d56 MySQL \u7d22\u5f15&#xff1b;<\/li>\n<li>\u654f\u611f\u5b57\u6bb5\u9694\u79bb&#xff1a;\u5c06\u7528\u6237\u5bc6\u7801\u3001\u8eab\u4efd\u8bc1\u53f7\u7b49\u654f\u611f\u5b57\u6bb5\u62c6\u5206\u5230user_secure\u8868&#xff0c;\u4ec5\u521b\u5efa\u5fc5\u8981\u7d22\u5f15&#xff0c;\u51cf\u5c11\u654f\u611f\u6570\u636e\u6cc4\u9732\u98ce\u9669\u3002<\/li>\n<\/ul>\n<h4>8.3 \u573a\u666f 3&#xff1a;\u7cfb\u7edf\u65e5\u5fd7\u8868<\/h4>\n<h5>\u4e1a\u52a1\u7279\u6027<\/h5>\n<ul>\n<li>\u8868\u540d&#xff1a;sys_log&#xff0c;\u6570\u636e\u91cf&#xff1a;1 \u4ebf\u6761 &#043;&#xff08;\u65e5\u589e 100 \u4e07\u6761&#xff09;&#xff1b;<\/li>\n<li>\u9ad8\u9891\u64cd\u4f5c&#xff1a;\u63d2\u5165\u65e5\u5fd7&#xff08;99%&#xff09;&#xff0c;\u67e5\u8be2\u65e5\u5fd7&#xff08;1%&#xff09;&#xff1b;<\/li>\n<li>\u67e5\u8be2\u6761\u4ef6&#xff1a;create_time&#xff08;\u8303\u56f4&#xff09;\u3001log_type&#xff08;\u7b49\u503c&#xff09;\u3001user_id&#xff08;\u7b49\u503c&#xff09;&#xff1b;<\/li>\n<li>\u6838\u5fc3\u67e5\u8be2&#xff1a;\u6839\u636e\u65f6\u95f4\u8303\u56f4 &#043; \u65e5\u5fd7\u7c7b\u578b\u67e5\u8be2\u65e5\u5fd7&#xff1a;SELECT * FROM sys_log WHERE log_type&#061;1 AND create_time BETWEEN &#039;2024-01-01&#039; AND &#039;2024-01-02&#039;;<\/li>\n<\/ul>\n<h5>\u7d22\u5f15\u8bbe\u8ba1\u65b9\u6848&#xff08;\u8bed\u6cd5 &#043; \u5e95\u5c42&#xff09;<\/h5>\n<p>CREATE TABLE sys_log (<br \/>\n    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, &#8212; \u81ea\u589e\u4e3b\u952e<br \/>\n    log_type TINYINT NOT NULL, &#8212; 1-\u64cd\u4f5c\u65e5\u5fd7&#xff0c;2-\u9519\u8bef\u65e5\u5fd7&#xff0c;3-\u8bbf\u95ee\u65e5\u5fd7<br \/>\n    user_id BIGINT,<br \/>\n    content TEXT NOT NULL,<br \/>\n    create_time DATETIME NOT NULL,<br \/>\n    INDEX idx_type_create (log_type, create_time) &#8212; \u590d\u5408\u7d22\u5f15&#xff1a;\u65e5\u5fd7\u7c7b\u578b&#043;\u521b\u5efa\u65f6\u95f4<br \/>\n) ENGINE&#061;InnoDB DEFAULT CHARSET&#061;utf8<br \/>\nPARTITION BY RANGE (TO_DAYS(create_time)) (<br \/>\n    PARTITION p202401 VALUES LESS THAN (TO_DAYS(&#039;2024-02-01&#039;)),<br \/>\n    PARTITION p202402 VALUES LESS THAN (TO_DAYS(&#039;2024-03-01&#039;)),<br \/>\n    &#8212; \u6309\u6708\u5206\u533a&#xff0c;\u4fdd\u75596\u4e2a\u6708\u6570\u636e&#xff0c;\u8fc7\u671f\u5206\u533a\u76f4\u63a5\u5220\u9664<br \/>\n);<\/p>\n<li>\u4ec5\u521b\u5efa 1 \u4e2a\u590d\u5408\u7d22\u5f15idx_type_create&#xff1a;\u5339\u914d\u552f\u4e00\u7684\u67e5\u8be2\u6761\u4ef6&#xff0c;\u907f\u514d\u8fc7\u591a\u7d22\u5f15\u5bfc\u81f4\u63d2\u5165\u6548\u7387\u4e0b\u964d&#xff1b;<\/li>\n<li>\u6309\u65f6\u95f4\u5206\u533a&#xff1a;\u9ad8\u9891\u63d2\u5165\u7684\u65e5\u5fd7\u8868&#xff0c;\u5206\u533a\u8868\u53ef\u5927\u5e45\u63d0\u5347\u63d2\u5165\u6548\u7387&#xff08;\u6bcf\u4e2a\u5206\u533a\u72ec\u7acb B &#043; \u6811&#xff09;&#xff0c;\u4e14\u8fc7\u671f\u6570\u636e\u53ef\u76f4\u63a5\u5220\u9664\u5206\u533a&#xff08;\u6bd4 DELETE \u9ad8\u6548 100 \u500d&#xff09;&#xff1b;<\/li>\n<li>\u81ea\u589e\u4e3b\u952e&#xff1a;\u4fdd\u8bc1\u63d2\u5165\u6709\u5e8f&#xff0c;\u65e0\u9875\u5206\u88c2&#xff0c;\u63d2\u5165\u6548\u7387\u6700\u5927\u5316\u3002<\/li>\n<h5>\u6027\u80fd\u4f18\u5316\u70b9<\/h5>\n<ul>\n<li>\u7981\u6b62\u521b\u5efa\u591a\u4f59\u7d22\u5f15&#xff1a;\u65e5\u5fd7\u8868\u63d2\u5165\u9891\u7387\u6781\u9ad8&#xff0c;\u6bcf\u589e\u52a0 1 \u4e2a\u7d22\u5f15&#xff0c;\u63d2\u5165\u6548\u7387\u4e0b\u964d 20%&#xff0c;\u4ec5\u4fdd\u7559\u5fc5\u8981\u7684\u67e5\u8be2\u7d22\u5f15&#xff1b;<\/li>\n<li>\u5b9a\u671f\u6e05\u7406\u8fc7\u671f\u6570\u636e&#xff1a;\u901a\u8fc7ALTER TABLE sys_log DROP PARTITION p202310;\u76f4\u63a5\u5220\u9664\u8fc7\u671f\u5206\u533a&#xff0c;\u65e0\u9700\u9010\u6761 DELETE&#xff1b;<\/li>\n<li>\u4f7f\u7528\u6279\u91cf\u63d2\u5165&#xff1a;\u65e5\u5fd7\u63d2\u5165\u7528INSERT INTO sys_log VALUES(&#8230;), (&#8230;), (&#8230;);&#xff0c;\u51cf\u5c11 IO \u6b21\u6570&#xff0c;\u63d0\u5347\u63d2\u5165\u6548\u7387\u3002<\/li>\n<\/ul>\n<h2>\u4e5d\u3001\u7d22\u5f15\u6027\u80fd\u76d1\u63a7\u4e0e\u8c03\u4f18<\/h2>\n<h4>9.1 \u7d22\u5f15\u4f7f\u7528\u60c5\u51b5\u76d1\u63a7&#xff08;\u8bed\u6cd5 &#043; \u89e3\u8bfb&#xff09;<\/h4>\n<p>MySQL \u63d0\u4f9b\u4e86sys\u5e93\u548cinformation_schema\u5e93&#xff0c;\u53ef\u901a\u8fc7 SQL \u8bed\u6cd5\u67e5\u8be2\u7d22\u5f15\u7684\u4f7f\u7528\u6b21\u6570\u3001\u672a\u4f7f\u7528\u7d22\u5f15\u3001\u5931\u6548\u7d22\u5f15&#xff0c;\u7cbe\u51c6\u5b9a\u4f4d\u65e0\u7528\u7d22\u5f15\u3002<\/p>\n<h5>9.1.1 \u67e5\u8be2\u8868\u7684\u7d22\u5f15\u4f7f\u7528\u6b21\u6570<\/h5>\n<p>&#8212; \u8bed\u6cd5&#xff1a;\u67e5\u8be2\u6307\u5b9a\u8868\u7684\u6240\u6709\u7d22\u5f15\u4f7f\u7528\u60c5\u51b5&#xff08;\u9700\u5f00\u542fperformance_schema&#xff09;<br \/>\nSELECT<br \/>\n    INDEX_NAME, &#8212; \u7d22\u5f15\u540d<br \/>\n    COUNT_USAGE &#8212; \u4f7f\u7528\u6b21\u6570<br \/>\nFROM sys.schema_unused_indexes<br \/>\nWHERE TABLE_SCHEMA&#061;&#039;your_db&#039; AND TABLE_NAME&#061;&#039;EMP&#039;;<br \/>\n&#8212; \u89e3\u8bfb&#xff1a;<br \/>\n&#8212; COUNT_USAGE&#061;0 \u2192 \u7d22\u5f15\u4ece\u672a\u4f7f\u7528&#xff0c;\u53ef\u5220\u9664&#xff1b;<br \/>\n&#8212; COUNT_USAGE&lt;100 \u2192 \u7d22\u5f15\u4f7f\u7528\u9891\u7387\u6781\u4f4e&#xff0c;\u8bc4\u4f30\u540e\u53ef\u5220\u9664&#xff1b;<br \/>\n&#8212; \u5f00\u542fperformance_schema&#xff1a;SET GLOBAL performance_schema &#061; ON;&#xff08;\u9700\u91cd\u542fMySQL&#xff09;<\/p>\n<h5>9.1.2 \u67e5\u8be2\u6570\u636e\u5e93\u4e2d\u6240\u6709\u672a\u4f7f\u7528\u7684\u7d22\u5f15<\/h5>\n<p>&#8212; \u8bed\u6cd5&#xff1a;\u67e5\u8be2\u6574\u4e2a\u6570\u636e\u5e93\u7684\u672a\u4f7f\u7528\u7d22\u5f15<br \/>\nSELECT<br \/>\n    TABLE_SCHEMA AS \u6570\u636e\u5e93\u540d,<br \/>\n    TABLE_NAME AS \u8868\u540d,<br \/>\n    INDEX_NAME AS \u672a\u4f7f\u7528\u7d22\u5f15\u540d<br \/>\nFROM sys.schema_unused_indexes;<br \/>\n&#8212; \u5b9e\u6218\u5efa\u8bae&#xff1a;\u5c06\u672a\u4f7f\u7528\u7d22\u5f15\u6574\u7406\u540e&#xff0c;\u5728\u4f4e\u5cf0\u671f\u9010\u4e00\u5220\u9664&#xff08;\u5148\u5907\u4efd&#xff0c;\u518d\u5220\u9664&#xff09;<\/p>\n<h5>9.1.3 \u67e5\u8be2\u7d22\u5f15\u7684\u5177\u4f53\u4f7f\u7528\u7edf\u8ba1<\/h5>\n<p>&#8212; \u8bed\u6cd5&#xff1a;\u67e5\u8be2\u7d22\u5f15\u7684\u626b\u63cf\u6b21\u6570\u3001\u66f4\u65b0\u6b21\u6570\u7b49\u8be6\u7ec6\u7edf\u8ba1<br \/>\nSELECT<br \/>\n    TABLE_NAME,<br \/>\n    INDEX_NAME,<br \/>\n    SCANS AS \u7d22\u5f15\u626b\u63cf\u6b21\u6570,<br \/>\n    UPDATES AS \u7d22\u5f15\u66f4\u65b0\u6b21\u6570<br \/>\nFROM information_schema.INDEX_STATISTICS<br \/>\nWHERE TABLE_SCHEMA&#061;&#039;your_db&#039;;<br \/>\n&#8212; \u89e3\u8bfb&#xff1a;<br \/>\n&#8212; \u626b\u63cf\u6b21\u6570\/\u66f4\u65b0\u6b21\u6570\u6bd4\u503c\u8d8a\u9ad8 \u2192 \u7d22\u5f15\u6027\u4ef7\u6bd4\u8d8a\u9ad8&#xff1b;<br \/>\n&#8212; \u626b\u63cf\u6b21\u6570&#061;0 \u2192 \u7d22\u5f15\u672a\u4f7f\u7528&#xff0c;\u53ef\u5220\u9664&#xff1b;<br \/>\n&#8212; \u66f4\u65b0\u6b21\u6570\u8fdc\u5927\u4e8e\u626b\u63cf\u6b21\u6570 \u2192 \u7d22\u5f15\u7ef4\u62a4\u6210\u672c\u8fc7\u9ad8&#xff0c;\u8bc4\u4f30\u540e\u53ef\u5220\u9664\u3002<\/p>\n<h4>9.2 \u7d22\u5f15\u788e\u7247\u6e05\u7406&#xff08;\u8bed\u6cd5 &#043; \u5e95\u5c42&#xff09;<\/h4>\n<p>InnoDB \u7684\u7d22\u5f15\u5728\u9891\u7e41\u63d2\u5165 \/ \u5220\u9664 \/ \u66f4\u65b0\u540e&#xff0c;\u4f1a\u4ea7\u751f\u7d22\u5f15\u788e\u7247&#xff08;B &#043; \u6811\u4e2d\u7684\u7a7a\u8282\u70b9\u3001\u4e0d\u8fde\u7eed\u7684\u9875&#xff09;&#xff0c;\u5bfc\u81f4\u7d22\u5f15\u9875\u6570\u91cf\u589e\u52a0&#xff0c;IO \u6b21\u6570\u4e0a\u5347&#xff0c;\u67e5\u8be2\u6548\u7387\u4e0b\u964d\u3002\u9700\u5b9a\u671f\u6e05\u7406\u788e\u7247&#xff0c;\u4f18\u5316\u7d22\u5f15\u7ed3\u6784\u3002<\/p>\n<h5>9.2.1 \u67e5\u770b\u7d22\u5f15\u788e\u7247\u7387<\/h5>\n<p>&#8212; \u8bed\u6cd5&#xff1a;\u67e5\u8be2\u6307\u5b9a\u8868\u7684\u788e\u7247\u7387&#xff08;InnoDB&#xff09;<br \/>\nSELECT<br \/>\n    TABLE_NAME,<br \/>\n    DATA_FREE AS \u7a7a\u95f2\u7a7a\u95f4(\u5b57\u8282),<br \/>\n    (DATA_FREE\/(DATA_LENGTH&#043;INDEX_LENGTH))*100 AS \u788e\u7247\u7387(%)<br \/>\nFROM information_schema.TABLES<br \/>\nWHERE TABLE_SCHEMA&#061;&#039;your_db&#039; AND TABLE_NAME&#061;&#039;EMP&#039;;<br \/>\n&#8212; \u89e3\u8bfb&#xff1a;<br \/>\n&#8212; \u788e\u7247\u7387&lt;5% \u2192 \u65e0\u9700\u6e05\u7406&#xff1b;<br \/>\n&#8212; 5%\u2264\u788e\u7247\u7387\u226430% \u2192 \u6267\u884cOPTIMIZE TABLE&#xff1b;<br \/>\n&#8212; \u788e\u7247\u7387&gt;30% \u2192 \u5148\u5220\u9664\u7d22\u5f15&#xff0c;\u518d\u91cd\u5efa\u7d22\u5f15&#xff08;\u6548\u7387\u66f4\u9ad8&#xff09;\u3002<\/p>\n<h5>9.2.2 \u6e05\u7406\u7d22\u5f15\u788e\u7247&#xff08;\u8bed\u6cd5 &#043; \u5e95\u5c42&#xff09;<\/h5>\n<h6>\u65b9\u5f0f 1&#xff1a;OPTIMIZE TABLE&#xff08;\u9002\u5408\u788e\u7247\u7387 5%-30%&#xff09;<\/h6>\n<p>&#8212; \u8bed\u6cd5&#xff1a;\u6e05\u7406\u8868\u7684\u7d22\u5f15\u788e\u7247&#xff08;InnoDB\/MyISAM&#xff09;<br \/>\nOPTIMIZE TABLE your_db.EMP;<br \/>\n&#8212; \u5e95\u5c42\u539f\u7406&#xff1a;<br \/>\n&#8212; 1. InnoDB&#xff1a;\u91cd\u5efa\u8868\u7684\u805a\u7c07\u7d22\u5f15\u548c\u8f85\u52a9\u7d22\u5f15&#xff0c;\u91cd\u65b0\u6392\u5e8f\u6570\u636e\u9875\u548c\u7d22\u5f15\u9875&#xff0c;\u91ca\u653e\u7a7a\u95f2\u7a7a\u95f4&#xff1b;<br \/>\n&#8212; 2. MyISAM&#xff1a;\u6574\u7406\u6570\u636e\u6587\u4ef6\u548c\u7d22\u5f15\u6587\u4ef6&#xff0c;\u51cf\u5c11\u788e\u7247&#xff1b;<br \/>\n&#8212; \u6ce8\u610f\u4e8b\u9879&#xff1a;\u6267\u884c\u65f6\u4f1a\u9501\u8868&#xff08;InnoDB 5.6&#043;\u4e3a\u5728\u7ebfDDL&#xff0c;\u9501\u8868\u65f6\u95f4\u77ed&#xff09;&#xff0c;\u9700\u5728\u4f4e\u5cf0\u671f\u6267\u884c\u3002<\/p>\n<h6>\u65b9\u5f0f 2&#xff1a;\u5220\u9664\u91cd\u5efa\u7d22\u5f15&#xff08;\u9002\u5408\u788e\u7247\u7387 &gt; 30%&#xff09;<\/h6>\n<p>&#8212; \u8bed\u6cd5&#xff1a;\u5148\u5220\u9664\u7d22\u5f15&#xff0c;\u518d\u91cd\u5efa\u7d22\u5f15&#xff08;\u6548\u7387\u6bd4OPTIMIZE TABLE\u9ad850%&#xff09;<br \/>\n&#8212; 1. \u5220\u9664\u7d22\u5f15<br \/>\nDROP INDEX idx_deptno ON EMP;<br \/>\nDROP INDEX idx_ename ON EMP;<br \/>\n&#8212; 2. \u91cd\u5efa\u7d22\u5f15<br \/>\nCREATE INDEX idx_deptno ON EMP(deptno);<br \/>\nCREATE INDEX idx_ename ON EMP(ename);<br \/>\n&#8212; \u5e95\u5c42\u539f\u7406&#xff1a;\u4e00\u6b21\u6027\u91cd\u5efaB&#043;\u6811&#xff0c;\u907f\u514d\u9010\u9875\u6574\u7406\u788e\u7247&#xff0c;\u76f4\u63a5\u751f\u6210\u65e0\u788e\u7247\u7684\u7d22\u5f15\u7ed3\u6784&#xff0c;\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<h4><\/h4>\n<h2>\u5341\u3001\u7ec8\u6781\u603b\u7ed3&#xff1a;MySQL \u7d22\u5f15\u6838\u5fc3\u77e5\u8bc6\u56fe\u8c31<\/h2>\n<h4>10.1 \u7d22\u5f15\u5e95\u5c42\u539f\u7406\u6838\u5fc3<\/h4>\n<p><span style=\"color:#fe2c24\">\u7d22\u5f15\u7684\u672c\u8d28\u662f\u57fa\u4e8e B &#043; \u6811\u7684\u78c1\u76d8\u6570\u636e\u76ee\u5f55&#xff0c;\u901a\u8fc7\u7a7a\u95f4\u6362\u65f6\u95f4&#xff0c;\u5c06\u5168\u8868\u626b\u63cf\u7684 N \u6b21 IO \u51cf\u5c11\u4e3a B &#043; \u6811\u9ad8\u5ea6\u7684 3-4 \u6b21 IO&#xff0c;\u6838\u5fc3\u8bbe\u8ba1\u76ee\u6807\u662f\u51cf\u5c11\u78c1\u76d8 IO \u6b21\u6570&#xff08;\u6570\u636e\u5e93\u6027\u80fd\u7684\u6838\u5fc3\u74f6\u9888\u662f\u78c1\u76d8 IO&#xff09;\u3002<\/span><\/p>\n<h4>10.2 \u7d22\u5f15\u8bed\u6cd5\u6838\u5fc3\u56fe\u8c31<\/h4>\n<table>\n<tr>\u7d22\u5f15\u7c7b\u578b\u6838\u5fc3\u521b\u5efa\u8bed\u6cd5\u6838\u5fc3\u67e5\u8be2\u8bed\u6cd5\u6838\u5fc3\u5220\u9664\u8bed\u6cd5\u9002\u7528\u573a\u666f\u6838\u5fc3\u6ce8\u610f\u4e8b\u9879<\/tr>\n<tbody>\n<tr>\n<td>\u4e3b\u952e\u7d22\u5f15<\/td>\n<td>CREATE TABLE \u8868\u540d (\u5b57\u6bb5 PRIMARY KEY);ALTER TABLE \u8868\u540d ADD PRIMARY KEY (\u5b57\u6bb5);<\/td>\n<td>SELECT * FROM \u8868\u540d WHERE \u4e3b\u952e\u5b57\u6bb5 &#061; \u503c&#xff1b;<\/td>\n<td>ALTER TABLE \u8868\u540d DROP PRIMARY KEY;<\/td>\n<td>\u552f\u4e00\u6807\u8bc6\u8bb0\u5f55&#xff08;\u5982 user_id&#xff09;<\/td>\n<td>\u552f\u4e00\u3001\u975e\u7a7a&#xff1b;\u4e00\u4e2a\u8868\u4ec5 1 \u4e2a&#xff1b;InnoDB \u805a\u7c07\u7d22\u5f15<\/td>\n<\/tr>\n<tr>\n<td>\u552f\u4e00\u7d22\u5f15<\/td>\n<td>CREATE UNIQUE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5);ALTER TABLE \u8868\u540d ADD UNIQUE (\u5b57\u6bb5);<\/td>\n<td>SELECT * FROM \u8868\u540d WHERE \u552f\u4e00\u5b57\u6bb5 &#061; \u503c&#xff1b;<\/td>\n<td>DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;<\/td>\n<td>\u552f\u4e00\u5b57\u6bb5&#xff08;\u5982 phone\/email&#xff09;<\/td>\n<td>\u5141\u8bb8 NULL&#xff1b;\u4e00\u4e2a\u8868\u53ef\u591a\u4e2a&#xff1b;\u8f85\u52a9\u7d22\u5f15<\/td>\n<\/tr>\n<tr>\n<td>\u666e\u901a\u7d22\u5f15<\/td>\n<td>CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5 \/ \u590d\u5408\u5b57\u6bb5);ALTER TABLE \u8868\u540d ADD INDEX (\u5b57\u6bb5);<\/td>\n<td>SELECT * FROM \u8868\u540d WHERE \u7d22\u5f15\u5b57\u6bb5 &#061; \u503c \/ \u8303\u56f4&#xff1b;<\/td>\n<td>DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;<\/td>\n<td>\u9ad8\u9891\u67e5\u8be2\u5b57\u6bb5&#xff08;\u5982 deptno\/age&#xff09;<\/td>\n<td>\u590d\u5408\u7d22\u5f15\u9075\u5faa\u6700\u5de6\u5339\u914d&#xff1b;\u4e0d\u5355\u72ec\u521b\u5efa\u4f4e\u57fa\u6570\u7d22\u5f15<\/td>\n<\/tr>\n<tr>\n<td>\u524d\u7f00\u7d22\u5f15<\/td>\n<td>CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5 (\u524d\u7f00\u957f\u5ea6));<\/td>\n<td>SELECT * FROM \u8868\u540d WHERE \u5b57\u6bb5 LIKE &#039; \u524d\u7f00 %&#039;;<\/td>\n<td>DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;<\/td>\n<td>\u957f\u5b57\u7b26\u4e32\u5b57\u6bb5&#xff08;\u5982 nickname\/email&#xff09;<\/td>\n<td>\u524d\u7f00\u957f\u5ea6\u9700\u4fdd\u8bc1\u533a\u5206\u5ea6 &gt; 99%&#xff1b;\u51cf\u5c11\u7d22\u5f15\u5927\u5c0f<\/td>\n<\/tr>\n<tr>\n<td>\u8986\u76d6\u7d22\u5f15<\/td>\n<td>CREATE INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u67e5\u8be2\u6761\u4ef6\u5b57\u6bb5&#xff0c;\u67e5\u8be2\u7ed3\u679c\u5b57\u6bb5);<\/td>\n<td>SELECT \u67e5\u8be2\u7ed3\u679c\u5b57\u6bb5 FROM \u8868\u540d WHERE \u67e5\u8be2\u6761\u4ef6\u5b57\u6bb5 &#061; \u503c&#xff1b;<\/td>\n<td>DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;<\/td>\n<td>\u9ad8\u9891\u67e5\u8be2\u4e14\u65e0\u9700\u5168\u5b57\u6bb5<\/td>\n<td>\u5305\u542b\u6240\u6709\u67e5\u8be2\u6240\u9700\u5b57\u6bb5&#xff1b;\u907f\u514d\u56de\u8868&#xff1b;IO \u6b21\u6570\u6700\u5c11<\/td>\n<\/tr>\n<tr>\n<td>\u5168\u6587\u7d22\u5f15<\/td>\n<td>CREATE FULLTEXT INDEX \u7d22\u5f15\u540d ON \u8868\u540d (\u5b57\u6bb5) ENGINE&#061;MyISAM;<\/td>\n<td>SELECT * FROM \u8868\u540d WHERE MATCH (\u5b57\u6bb5) AGAINST (&#039; \u5173\u952e\u8bcd &#039;);<\/td>\n<td>DROP INDEX \u7d22\u5f15\u540d ON \u8868\u540d&#xff1b;<\/td>\n<td>\u5927\u6587\u672c\u5173\u952e\u8bcd\u68c0\u7d22&#xff08;\u5982\u6587\u7ae0 \/ \u8bc4\u8bba&#xff09;<\/td>\n<td>\u4ec5\u652f\u6301\u6587\u672c\u7c7b\u578b&#xff1b;MyISAM \u4f18\u5148&#xff1b;\u4e2d\u6587\u9700\u5206\u8bcd\u63d2\u4ef6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>10.3 \u7d22\u5f15\u8bbe\u8ba1\u9ec4\u91d1\u539f\u5219<\/h4>\n<li>\u9ad8\u9891\u67e5\u8be2\u5b57\u6bb5\u5efa\u7d22\u5f15&#xff0c;\u9ad8\u9891\u66f4\u65b0\u5b57\u6bb5\u4e0d\u5efa\u7d22\u5f15&#xff1b;<\/li>\n<li>\u590d\u5408\u7d22\u5f15\u9075\u5faa \u201c\u6700\u5de6\u5339\u914d\u201d&#xff0c;\u5b57\u6bb5\u987a\u5e8f\u6309 \u201c\u67e5\u8be2\u9891\u7387\u9ad8\u2192\u533a\u5206\u5ea6\u9ad8\u201d \u6392\u5217&#xff1b;<\/li>\n<li>\u4f4e\u57fa\u6570\u5b57\u6bb5\u4e0d\u5355\u72ec\u5efa\u7d22\u5f15&#xff0c;\u4f5c\u4e3a\u590d\u5408\u7d22\u5f15\u7684\u540e\u7f00&#xff1b;<\/li>\n<li>\u957f\u5b57\u7b26\u4e32\u5b57\u6bb5\u5efa\u524d\u7f00\u7d22\u5f15&#xff0c;\u4fdd\u8bc1\u533a\u5206\u5ea6\u7684\u540c\u65f6\u51cf\u5c11\u7d22\u5f15\u5927\u5c0f&#xff1b;<\/li>\n<li>\u67e5\u8be2\u6240\u9700\u5b57\u6bb5\u5efa\u8986\u76d6\u7d22\u5f15&#xff0c;\u907f\u514d\u56de\u8868\u67e5\u8be2&#xff1b;<\/li>\n<li>\u907f\u514d\u8fc7\u5ea6\u7d22\u5f15&#xff0c;\u5355\u8868\u7d22\u5f15\u6570\u63a7\u5236\u5728 5 \u4e2a\u4ee5\u5185&#xff1b;<\/li>\n<li>\u81ea\u589e\u4e3b\u952e\u4fdd\u8bc1\u6709\u5e8f\u63d2\u5165&#xff0c;\u51cf\u5c11 B &#043; \u6811\u9875\u5206\u88c2&#xff1b;<\/li>\n<li>NULL \u503c\u5b57\u6bb5\u7528\u9ed8\u8ba4\u503c\u66ff\u4ee3&#xff0c;\u907f\u514d\u7d22\u5f15\u5931\u6548\u3002<\/li>\n<h2>\u7ed3\u8bed<\/h2>\n<p>\u6572\u5b8c\u6700\u540e\u4e00\u884c\u7d22\u5f15\u8c03\u4f18\u7684 SQL \u8bed\u53e5&#xff0c;\u56de\u5934\u518d\u770b\u6211\u4eec\u4ece\u65e0\u7d22\u5f15\u65f6 800 \u4e07\u6761\u6570\u636e\u67e5\u8be2\u8017\u65f6 4.93 \u79d2\u7684\u75db\u70b9\u51fa\u53d1&#xff0c;\u8d70\u8fc7\u7684\u8fd9\u4e00\u8def&#xff0c;\u4ece\u78c1\u76d8 IO \u7684\u5e95\u5c42\u672c\u8d28\u5230 Page \u4e0e\u76ee\u5f55\u7684\u8bbe\u8ba1\u7ec6\u8282&#xff0c;\u4ece B &#043; \u6811\u7684\u7ed3\u6784\u539f\u7406\u5230\u805a\u7c07\u3001\u975e\u805a\u7c07\u7d22\u5f15\u7684\u8bed\u6cd5\u62c6\u89e3&#xff0c;\u4ece\u7d22\u5f15\u5931\u6548\u7684\u907f\u5751\u6307\u5357\u5230\u7535\u5546\u8ba2\u5355\u3001\u7528\u6237\u4fe1\u606f\u3001\u7cfb\u7edf\u65e5\u5fd7\u4e09\u5927\u4f01\u4e1a\u7ea7\u573a\u666f\u7684\u843d\u5730\u8bbe\u8ba1&#xff0c;\u518d\u5230\u7d22\u5f15\u7684\u6027\u80fd\u76d1\u63a7\u4e0e\u788e\u7247\u6e05\u7406&#xff0c;\u6211\u4eec\u7ec8\u4e8e\u628a MySQL \u7d22\u5f15\u4ece \u201c\u8868\u5c42\u7684\u521b\u5efa\u8bed\u53e5\u201d \u6316\u5230\u4e86 \u201c\u5e95\u5c42\u7684\u8bbe\u8ba1\u903b\u8f91\u201d&#xff0c;\u4e5f\u7ec8\u4e8e\u660e\u767d&#xff0c;\u7d22\u5f15\u4ece\u6765\u90fd\u4e0d\u662f\u4e00\u53e5\u7b80\u5355\u7684CREATE INDEX\u5c31\u80fd\u9a7e\u9a6d\u7684\u6280\u80fd&#xff0c;\u800c\u662f\u878d\u5408\u4e86\u78c1\u76d8\u5b58\u50a8\u3001\u6570\u636e\u7ed3\u6784\u3001\u4e1a\u52a1\u573a\u666f\u3001\u6027\u80fd\u8c03\u4f18\u7684\u7efc\u5408\u80fd\u529b\u3002<\/p>\n<p>\u5f88\u591a\u5f00\u53d1\u8005\u5728\u63a5\u89e6\u7d22\u5f15\u65f6&#xff0c;\u90fd\u4f1a\u9677\u5165\u4e00\u4e2a\u8bef\u533a&#xff1a;\u4ee5\u4e3a\u8bb0\u4f4f \u201c\u521b\u5efa\u7d22\u5f15\u7684\u8bed\u6cd5\u201d\u201c\u7d22\u5f15\u5931\u6548\u7684\u53e3\u8bc0\u201d \u5c31\u591f\u4e86&#xff0c;\u53ef\u5b9e\u9645\u5de5\u4f5c\u4e2d&#xff0c;\u4f9d\u7136\u4f1a\u9047\u5230 \u201c\u5efa\u4e86\u7d22\u5f15\u67e5\u5f97\u66f4\u6162\u201d\u201c\u590d\u5408\u7d22\u5f15\u600e\u4e48\u6392\u5b57\u6bb5\u90fd\u4e0d\u5bf9\u201d\u201c\u6d77\u91cf\u6570\u636e\u4e0b\u7d22\u5f15\u7ef4\u62a4\u62d6\u57ae\u5199\u6027\u80fd\u201d \u7684\u95ee\u9898\u3002\u7a76\u5176\u6839\u672c&#xff0c;\u662f\u56e0\u4e3a\u53ea\u770b\u5230\u4e86\u7d22\u5f15\u7684 \u201c\u5f62\u201d&#xff0c;\u5374\u6ca1\u7406\u89e3\u7d22\u5f15\u7684 \u201c\u795e\u201d\u2014\u2014 \u6211\u4eec\u5728\u6587\u4e2d\u53cd\u590d\u5f3a\u8c03&#xff0c;\u6570\u636e\u5e93\u6027\u80fd\u7684\u6838\u5fc3\u74f6\u9888\u662f\u78c1\u76d8 IO&#xff0c;\u800c\u7d22\u5f15\u7684\u6240\u6709\u8bbe\u8ba1\u3001\u6240\u6709\u8bed\u6cd5\u3001\u6240\u6709\u4f18\u5316&#xff0c;\u6700\u7ec8\u7684\u76ee\u6807\u53ea\u6709\u4e00\u4e2a&#xff1a;\u51cf\u5c11\u78c1\u76d8 IO \u7684\u6b21\u6570\u3002\u4ece Page \u7684 16KB \u56fa\u5b9a\u5927\u5c0f\u8bbe\u8ba1&#xff0c;\u5230\u76ee\u5f55\u9875\u7684\u591a\u7ea7\u6307\u5f15&#xff0c;\u4ece B &#043; \u6811\u7684 3 \u5c42\u7ed3\u6784\u63a7\u5236 IO \u6b21\u6570\u5728 3-4 \u6b21&#xff0c;\u5230\u8986\u76d6\u7d22\u5f15\u907f\u514d\u56de\u8868\u51cf\u5c11\u4e00\u534a IO&#xff0c;\u4ece\u81ea\u589e\u4e3b\u952e\u51cf\u5c11\u9875\u5206\u88c2\u964d\u4f4e IO \u6210\u672c&#xff0c;\u518d\u5230\u5206\u533a\u8868\u7ed3\u5408\u7d22\u5f15\u51cf\u5c11\u626b\u63cf\u7684\u6570\u636e\u91cf&#xff0c;\u6240\u6709\u7684\u7ec6\u8282\u90fd\u5728\u4e3a\u8fd9\u4e2a\u6838\u5fc3\u76ee\u6807\u670d\u52a1\u3002\u7406\u89e3\u4e86\u8fd9\u4e00\u70b9&#xff0c;\u5c31\u6293\u4f4f\u4e86\u7d22\u5f15\u7684\u6839\u672c&#xff0c;\u90a3\u4e9b\u770b\u4f3c\u96f6\u6563\u7684\u8bed\u6cd5\u89c4\u5219\u3001\u4f18\u5316\u6280\u5de7&#xff0c;\u90fd\u4f1a\u53d8\u6210\u6709\u8ff9\u53ef\u5faa\u7684\u903b\u8f91\u63a8\u5bfc&#xff0c;\u800c\u4e0d\u662f\u6b7b\u8bb0\u786c\u80cc\u7684\u6761\u6761\u6846\u6846\u3002\u6bd4\u5982&#xff0c;\u4e3a\u4ec0\u4e48\u590d\u5408\u7d22\u5f15\u8981\u9075\u5faa\u6700\u5de6\u5339\u914d&#xff1f;\u56e0\u4e3a B &#043; \u6811\u7684\u952e\u503c\u662f\u6309\u6700\u5de6\u5b57\u6bb5\u6709\u5e8f\u6392\u5217\u7684&#xff0c;\u6253\u7834\u8fd9\u4e2a\u987a\u5e8f\u5c31\u65e0\u6cd5\u901a\u8fc7\u76ee\u5f55\u5feb\u901f\u5b9a\u4f4d&#xff0c;\u53ea\u80fd\u5168\u8868\u626b\u63cf\u589e\u52a0 IO&#xff1b;\u4e3a\u4ec0\u4e48\u4f4e\u57fa\u6570\u5b57\u6bb5\u4e0d\u80fd\u5355\u72ec\u5efa\u7d22\u5f15&#xff1f;\u56e0\u4e3a\u626b\u63cf\u7d22\u5f15\u7684 IO \u6210\u672c\u548c\u5168\u8868\u626b\u63cf\u76f8\u5dee\u65e0\u51e0&#xff0c;\u5efa\u7d22\u5f15\u53cd\u800c\u4f1a\u589e\u52a0\u7ef4\u62a4\u7684 IO \u5f00\u9500&#xff1b;\u4e3a\u4ec0\u4e48 uuid \u4e0d\u80fd\u4f5c\u4e3a\u4e3b\u952e&#xff1f;\u56e0\u4e3a\u65e0\u5e8f\u63d2\u5165\u4f1a\u5f15\u53d1\u9891\u7e41\u7684\u9875\u5206\u88c2&#xff0c;\u6bcf\u6b21\u5206\u88c2\u90fd\u8981\u505a\u6570\u636e\u79fb\u52a8\u3001\u76ee\u5f55\u66f4\u65b0&#xff0c;\u5e26\u6765\u5927\u91cf\u7684 IO \u64cd\u4f5c\u3002\u5f53\u6211\u4eec\u628a\u8fd9\u4e9b\u95ee\u9898\u7684\u7b54\u6848\u56de\u5f52\u5230 \u201c\u51cf\u5c11 IO\u201d \u8fd9\u4e2a\u6838\u5fc3&#xff0c;\u6240\u6709\u7684\u56f0\u60d1\u90fd\u4f1a\u8fce\u5203\u800c\u89e3\u3002<\/p>\n<p>\u5f53\u7136&#xff0c;\u7d22\u5f15\u7684\u5b66\u4e60&#xff0c;\u4ece\u6765\u90fd\u4e0d\u662f \u201c\u7eb8\u4e0a\u8c08\u5175\u201d&#xff0c;\u800c\u662f \u201c\u77e5\u884c\u5408\u4e00\u201d\u3002\u6587\u4e2d\u6211\u4eec\u8bbe\u8ba1\u4e86 800 \u4e07\u6761\u6570\u636e\u7684\u5b9e\u6218\u6d4b\u8bd5&#xff0c;\u62c6\u89e3\u4e86\u7535\u5546\u3001\u7528\u6237\u3001\u65e5\u5fd7\u4e09\u5927\u4f01\u4e1a\u7ea7\u6838\u5fc3\u573a\u666f\u7684\u7d22\u5f15\u65b9\u6848&#xff0c;\u8fd9\u4e9b\u573a\u666f\u90fd\u662f\u5f00\u53d1\u8005\u65e5\u5e38\u5de5\u4f5c\u4e2d\u4e00\u5b9a\u4f1a\u9047\u5230\u7684&#xff1a;\u9ad8\u9891\u67e5\u8be2\u4e0e\u9ad8\u9891\u66f4\u65b0\u5e76\u5b58\u7684\u8ba2\u5355\u8868&#xff0c;\u9700\u8981\u5e73\u8861\u67e5\u8be2\u6548\u7387\u548c\u7d22\u5f15\u7ef4\u62a4\u6210\u672c&#xff1b;\u957f\u5b57\u7b26\u4e32\u3001\u6a21\u7cca\u67e5\u8be2\u5c45\u591a\u7684\u7528\u6237\u8868&#xff0c;\u9700\u8981\u7528\u524d\u7f00\u7d22\u5f15\u3001\u552f\u4e00\u7d22\u5f15\u517c\u987e\u6548\u7387\u548c\u4e1a\u52a1\u552f\u4e00\u6027&#xff1b;\u9ad8\u9891\u63d2\u5165\u3001\u4f4e\u9891\u67e5\u8be2\u7684\u65e5\u5fd7\u8868&#xff0c;\u9700\u8981 \u201c\u5c11\u7d22\u5f15 &#043; \u5206\u533a\u8868\u201d \u6700\u5927\u5316\u63d2\u5165\u6027\u80fd\u3002\u8fd9\u4e9b\u5b9e\u6218\u65b9\u6848\u544a\u8bc9\u6211\u4eec&#xff0c;\u6ca1\u6709 \u201c\u4e07\u80fd\u7684\u7d22\u5f15\u8bbe\u8ba1\u201d&#xff0c;\u53ea\u6709 \u201c\u9002\u5408\u4e1a\u52a1\u7684\u7d22\u5f15\u8bbe\u8ba1\u201d\u3002\u7d22\u5f15\u7684\u521b\u5efa\u4e0d\u662f\u8d8a\u591a\u8d8a\u597d&#xff0c;\u5355\u8868 5 \u4e2a\u7d22\u5f15\u7684\u4e0a\u9650\u4e0d\u4ec5\u662f MySQL \u7684\u7269\u7406\u9650\u5236&#xff0c;\u66f4\u662f\u4e1a\u52a1\u7684\u903b\u8f91\u9650\u5236 \u2014\u2014 \u6bcf\u591a\u4e00\u4e2a\u7d22\u5f15&#xff0c;\u63d2\u5165\u3001\u66f4\u65b0\u3001\u5220\u9664\u64cd\u4f5c\u5c31\u8981\u591a\u7ef4\u62a4\u4e00\u68f5 B &#043; \u6811&#xff0c;\u5e26\u6765\u989d\u5916\u7684 IO \u5f00\u9500&#xff1b;\u7d22\u5f15\u7684\u8bbe\u8ba1\u4e5f\u4e0d\u80fd\u8131\u79bb\u4e1a\u52a1&#xff0c;\u8131\u79bb\u4e86\u67e5\u8be2\u9891\u7387\u3001\u66f4\u65b0\u9891\u7387\u3001\u6570\u636e\u91cf\u7684\u7d22\u5f15&#xff0c;\u518d\u5b8c\u7f8e\u7684\u8bed\u6cd5\u4e5f\u53ea\u662f\u7a7a\u4e2d\u697c\u9601\u3002\u6bd4\u5982&#xff0c;\u8ba2\u5355\u8868\u7684idx_user_create\u590d\u5408\u7d22\u5f15&#xff0c;\u662f\u56e0\u4e3a\u4e1a\u52a1\u4e2d\u9ad8\u9891\u6309 \u201c\u7528\u6237 ID &#043; \u65f6\u95f4\u8303\u56f4\u201d \u67e5\u8be2&#xff1b;\u65e5\u5fd7\u8868\u53ea\u5efa\u4e00\u4e2aidx_type_create\u7d22\u5f15&#xff0c;\u662f\u56e0\u4e3a\u4e1a\u52a1\u4e2d\u53ea\u6709 \u201c\u65e5\u5fd7\u7c7b\u578b &#043; \u65f6\u95f4\u8303\u56f4\u201d \u8fd9\u4e00\u79cd\u67e5\u8be2\u65b9\u5f0f&#xff1b;\u7528\u6237\u8868\u7684\u6635\u79f0\u7528\u524d\u7f00\u7d22\u5f15&#xff0c;\u662f\u56e0\u4e3a\u4e1a\u52a1\u4e2d\u53ea\u6709\u524d\u7f00\u6a21\u7cca\u67e5\u8be2\u7684\u9700\u6c42\u3002\u6240\u6709\u7684\u7d22\u5f15\u8bbe\u8ba1&#xff0c;\u90fd\u8981\u4ece\u4e1a\u52a1\u51fa\u53d1&#xff0c;\u5148\u68b3\u7406\u6e05\u695a \u201c\u54ea\u4e9b\u5b57\u6bb5\u662f\u9ad8\u9891\u67e5\u8be2\u6761\u4ef6\u201d\u201c\u54ea\u4e9b\u5b57\u6bb5\u662f\u9ad8\u9891\u66f4\u65b0\u5b57\u6bb5\u201d\u201c\u67e5\u8be2\u7684\u65b9\u5f0f\u662f\u7b49\u503c\u8fd8\u662f\u8303\u56f4\u201d\u201c\u6570\u636e\u91cf\u6709\u591a\u5927\u3001\u589e\u957f\u901f\u5ea6\u6709\u591a\u5feb\u201d&#xff0c;\u518d\u7ed3\u5408\u7d22\u5f15\u7684\u5e95\u5c42\u539f\u7406\u505a\u8bbe\u8ba1&#xff0c;\u8fd9\u6837\u7684\u7d22\u5f15&#xff0c;\u624d\u662f\u80fd\u771f\u6b63\u63d0\u5347\u6027\u80fd\u7684\u6709\u6548\u7d22\u5f15\u3002<\/p>\n<p>\u800c\u7d22\u5f15\u7684\u80fd\u529b&#xff0c;\u4e5f\u4e0d\u4ec5\u662f \u201c\u8bbe\u8ba1\u548c\u521b\u5efa\u201d&#xff0c;\u8fd8\u6709 \u201c\u6301\u7eed\u7684\u76d1\u63a7\u4e0e\u7ef4\u62a4\u201d\u3002\u5f88\u591a\u5f00\u53d1\u8005\u5efa\u5b8c\u7d22\u5f15\u5c31\u7f6e\u4e4b\u4e0d\u7406&#xff0c;\u5374\u4e0d\u77e5\u9053\u968f\u7740\u6570\u636e\u7684\u589e\u5220\u6539&#xff0c;\u7d22\u5f15\u4f1a\u4ea7\u751f\u788e\u7247&#xff0c;\u4f1a\u51fa\u73b0 \u201c\u672a\u4f7f\u7528\u7684\u7d22\u5f15\u201d\u201c\u7ef4\u62a4\u6210\u672c\u8fdc\u5927\u4e8e\u67e5\u8be2\u6536\u76ca\u7684\u7d22\u5f15\u201d&#xff0c;\u8fd9\u4e9b \u201c\u50f5\u5c38\u7d22\u5f15\u201d \u4f1a\u6162\u6162\u62d6\u57ae\u6570\u636e\u5e93\u7684\u6027\u80fd\u3002\u6587\u4e2d\u6211\u4eec\u4ecb\u7ecd\u4e86\u7528sys\u5e93\u3001information_schema\u5e93\u76d1\u63a7\u7d22\u5f15\u4f7f\u7528\u60c5\u51b5\u7684\u65b9\u6cd5&#xff0c;\u6559\u5927\u5bb6\u5982\u4f55\u8bc6\u522b\u672a\u4f7f\u7528\u7684\u7d22\u5f15\u3001\u5982\u4f55\u8ba1\u7b97\u7d22\u5f15\u7684\u788e\u7247\u7387\u3001\u5982\u4f55\u7528OPTIMIZE TABLE\u6216\u5220\u9664\u91cd\u5efa\u7684\u65b9\u5f0f\u6e05\u7406\u788e\u7247&#xff0c;\u8fd9\u4e9b\u90fd\u662f\u65e5\u5e38\u5de5\u4f5c\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u6280\u80fd\u3002\u7d22\u5f15\u5c31\u50cf\u6570\u636e\u5e93\u7684 \u201c\u7cbe\u5bc6\u4eea\u5668\u201d&#xff0c;\u9700\u8981\u5b9a\u671f\u7684 \u201c\u4f53\u68c0\u201d \u548c \u201c\u4fdd\u517b\u201d&#xff0c;\u53ea\u6709\u53ca\u65f6\u6e05\u7406\u65e0\u7528\u7d22\u5f15\u3001\u4f18\u5316\u788e\u7247\u7d22\u5f15\u3001\u66f4\u65b0\u7edf\u8ba1\u4fe1\u606f&#xff0c;\u624d\u80fd\u8ba9\u7d22\u5f15\u59cb\u7ec8\u4fdd\u6301\u9ad8\u6548\u7684\u72b6\u6001\u3002\u4ece\u521b\u5efa\u5230\u4f7f\u7528&#xff0c;\u4ece\u76d1\u63a7\u5230\u4f18\u5316&#xff0c;\u5f62\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u95ed\u73af&#xff0c;\u624d\u662f\u771f\u6b63\u7684\u7d22\u5f15\u8c03\u4f18\u80fd\u529b\u3002<\/p>\n<p>\u5b66\u4e60\u7d22\u5f15\u7684\u8fc7\u7a0b&#xff0c;\u53ef\u80fd\u4f1a\u6709\u4e9b\u67af\u71e5&#xff1a;\u90a3\u4e9b Page\u3001\u76ee\u5f55\u9875\u3001B &#043; \u6811\u7684\u7ec6\u8282&#xff0c;\u90a3\u4e9b IO \u6b21\u6570\u7684\u8ba1\u7b97&#xff0c;\u90a3\u4e9b\u8bed\u6cd5\u80cc\u540e\u7684\u5e95\u5c42\u903b\u8f91&#xff0c;\u9700\u8981\u6211\u4eec\u6c89\u4e0b\u5fc3\u6765\u4e00\u70b9\u70b9\u7422\u78e8\u3002\u4f46\u5f53\u4f60\u771f\u6b63\u7406\u89e3\u4e86\u8fd9\u4e9b\u7ec6\u8282&#xff0c;\u5f53\u4f60\u5728\u5de5\u4f5c\u4e2d\u7528\u6587\u4e2d\u7684\u65b9\u6cd5\u89e3\u51b3\u4e86\u6162\u67e5\u8be2\u95ee\u9898&#xff0c;\u5f53\u4f60\u770b\u5230\u81ea\u5df1\u8bbe\u8ba1\u7684\u7d22\u5f15\u8ba9 800 \u4e07\u6761\u6570\u636e\u7684\u67e5\u8be2\u4ece 4.93 \u79d2\u964d\u5230 0.01 \u79d2&#xff0c;\u5f53\u4f60\u5728\u6d77\u91cf\u6570\u636e\u4e0b\u901a\u8fc7\u5206\u533a\u8868 &#043; \u590d\u5408\u7d22\u5f15\u5e73\u8861\u4e86\u67e5\u8be2\u548c\u5199\u6027\u80fd&#xff0c;\u4f60\u4f1a\u53d1\u73b0&#xff0c;\u8fd9\u4efd\u67af\u71e5\u7684\u80cc\u540e&#xff0c;\u662f\u6280\u672f\u5e26\u6765\u7684\u5b9e\u5b9e\u5728\u5728\u7684\u6210\u5c31\u611f\u3002\u800c\u8fd9\u4efd\u5bf9\u5e95\u5c42\u539f\u7406\u7684\u63a2\u7d22\u7cbe\u795e&#xff0c;\u66f4\u662f\u4f5c\u4e3a\u5f00\u53d1\u8005\u6700\u73cd\u8d35\u7684\u54c1\u8d28\u3002\u5728\u6570\u636e\u5e93\u7684\u4e16\u754c\u91cc&#xff0c;\u6027\u80fd\u4f18\u5316\u7684\u9053\u8def\u6ca1\u6709\u5c3d\u5934&#xff0c;\u7d22\u5f15\u53ea\u662f\u5176\u4e2d\u7684\u91cd\u8981\u4e00\u73af&#xff0c;\u4f46\u5b66\u4f1a\u4e86\u7528 \u201c\u5e95\u5c42\u539f\u7406\u201d \u63a8\u5bfc \u201c\u5b9e\u9645\u5e94\u7528\u201d&#xff0c;\u7528 \u201c\u4e1a\u52a1\u573a\u666f\u201d \u6307\u5bfc \u201c\u6280\u672f\u8bbe\u8ba1\u201d&#xff0c;\u8fd9\u4efd\u601d\u7ef4\u65b9\u5f0f&#xff0c;\u4f1a\u8ba9\u6211\u4eec\u5728\u540e\u7eed\u5b66\u4e60 InnoDB \u5b58\u50a8\u5f15\u64ce\u3001\u4e8b\u52a1\u3001\u9501\u3001\u5206\u5e93\u5206\u8868\u65f6&#xff0c;\u90fd\u80fd\u4e8b\u534a\u529f\u500d\u3002<\/p>\n<p>\u4f5c\u4e3a\u5f00\u53d1\u8005&#xff0c;\u6211\u4eec\u6bcf\u5929\u90fd\u5728\u548c\u6570\u636e\u6253\u4ea4\u9053&#xff0c;\u800c\u9ad8\u6548\u7684\u67e5\u8be2&#xff0c;\u662f\u7cfb\u7edf\u6027\u80fd\u7684\u57fa\u7840\u3002MySQL \u7d22\u5f15&#xff0c;\u4f5c\u4e3a\u63d0\u5347\u67e5\u8be2\u6027\u80fd\u7684\u6838\u5fc3\u624b\u6bb5&#xff0c;\u662f\u6bcf\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u8005\u90fd\u5fc5\u987b\u638c\u63e1\u7684\u786c\u672c\u9886\u3002\u4ece\u53ea\u4f1a\u5199SELECT *\u7684\u65b0\u624b&#xff0c;\u5230\u80fd\u8bbe\u8ba1\u9ad8\u6548\u7d22\u5f15\u7684\u5de5\u7a0b\u5e08&#xff0c;\u518d\u5230\u80fd\u7ed3\u5408\u4e1a\u52a1\u505a\u6027\u80fd\u8c03\u4f18\u7684\u67b6\u6784\u5e08&#xff0c;\u8fd9\u4e2d\u95f4\u7684\u5dee\u8ddd&#xff0c;\u4e0d\u5728\u4e8e\u8bb0\u4f4f\u4e86\u591a\u5c11\u8bed\u6cd5&#xff0c;\u800c\u5728\u4e8e\u5bf9\u5e95\u5c42\u539f\u7406\u7684\u7406\u89e3&#xff0c;\u5728\u4e8e\u5bf9\u4e1a\u52a1\u573a\u666f\u7684\u628a\u63e1&#xff0c;\u5728\u4e8e\u77e5\u884c\u5408\u4e00\u7684\u5b9e\u8df5\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0&#xff0c;\u80fd\u6210\u4e3a\u4f60 MySQL \u7d22\u5f15\u5b66\u4e60\u8def\u4e0a\u7684\u4e00\u4e2a\u53f0\u9636&#xff0c;\u8ba9\u4f60\u4e0d\u4ec5\u5b66\u4f1a \u201c\u600e\u4e48\u5efa\u7d22\u5f15\u201d&#xff0c;\u66f4\u61c2\u5f97 \u201c\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5efa\u201d\u201c\u600e\u4e48\u5efa\u624d\u66f4\u597d\u201d\u3002\u4e5f\u5e0c\u671b\u4f60\u80fd\u628a\u6587\u4e2d\u7684\u77e5\u8bc6\u843d\u5730\u5230\u5b9e\u9645\u5de5\u4f5c\u4e2d&#xff0c;\u4ece\u5206\u6790\u4e00\u6761\u6162\u67e5\u8be2\u65e5\u5fd7\u5f00\u59cb&#xff0c;\u4ece\u8bbe\u8ba1\u4e00\u5f20\u8868\u7684\u7d22\u5f15\u5f00\u59cb&#xff0c;\u4ece\u76d1\u63a7\u4e00\u6b21\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u51b5\u5f00\u59cb&#xff0c;\u4e00\u70b9\u70b9\u79ef\u7d2f&#xff0c;\u4e00\u70b9\u70b9\u5b9e\u8df5\u3002\u5f53\u4f60\u80fd\u4ece\u5bb9\u5e94\u5bf9\u5404\u79cd\u4e1a\u52a1\u573a\u666f\u7684\u7d22\u5f15\u8bbe\u8ba1&#xff0c;\u80fd\u5feb\u901f\u5b9a\u4f4d\u5e76\u89e3\u51b3\u7d22\u5f15\u5931\u6548\u95ee\u9898&#xff0c;\u80fd\u5728\u6d77\u91cf\u6570\u636e\u4e0b\u4fdd\u6301\u6570\u636e\u5e93\u7684\u9ad8\u6548\u6027\u80fd\u65f6&#xff0c;\u4f60\u4f1a\u53d1\u73b0&#xff0c;\u81ea\u5df1\u5df2\u7ecf\u5728\u6570\u636e\u5e93\u6027\u80fd\u4f18\u5316\u7684\u9053\u8def\u4e0a&#xff0c;\u8fc8\u51fa\u4e86\u575a\u5b9e\u7684\u4e00\u6b65\u3002<\/p>\n<p>\u6280\u672f\u7684\u9053\u8def&#xff0c;\u9053\u963b\u4e14\u957f&#xff0c;\u884c\u5219\u5c06\u81f3\u3002\u7d22\u5f15\u7684\u5b66\u4e60\u544a\u4e00\u6bb5\u843d&#xff0c;\u4f46\u6570\u636e\u5e93\u7684\u63a2\u7d22\u6c38\u65e0\u6b62\u5883\u3002\u613f\u4f60\u4fdd\u6301\u5bf9\u6280\u672f\u7684\u70ed\u7231&#xff0c;\u4fdd\u6301\u5bf9\u5e95\u5c42\u539f\u7406\u7684\u597d\u5947&#xff0c;\u5728\u6570\u636e\u7684\u4e16\u754c\u91cc&#xff0c;\u4e0d\u65ad\u63a2\u7d22&#xff0c;\u4e0d\u65ad\u6210\u957f&#xff0c;\u8ba9\u81ea\u5df1\u7684\u6280\u672f\u80fd\u529b&#xff0c;\u6210\u4e3a\u652f\u6491\u4e1a\u52a1\u53d1\u5c55\u7684\u575a\u5b9e\u529b\u91cf\u3002\u4e5f\u613f\u4f60\u7684\u6bcf\u4e00\u6b21\u67e5\u8be2&#xff0c;\u90fd\u80fd\u56e0\u5408\u7406\u7684\u7d22\u5f15\u800c\u9ad8\u6548&#xff0c;\u4f60\u7684\u6bcf\u4e00\u4e2a\u7cfb\u7edf&#xff0c;\u90fd\u80fd\u56e0\u4f18\u79c0\u7684\u8bbe\u8ba1\u800c\u7a33\u5b9a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f00\u7bc7\u4ecb\u7ecd&#xff1a;hello \u5927\u5bb6&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&#xff0c;\u6700\u91cd\u8981\u7684\u5c31\u662f\u67e5\u8be2\u6570\u636e\u4e86&#xff0c;\u800c\u67e5\u8be2\u6570\u636e\u6700\u91cd\u8981\u7684\u53c8\u662f\u901f\u5ea6&#xff0c;\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f\u6548\u7387&#xff0c;\u800c\u5f53\u6570\u636e\u5e93\u4e2d\u6709\u5927\u91cf\u6570\u636e\u7684\u65f6\u5019&#xff0c;\u8bf6&#xff0c;\u4e0d\u53ef\u907f\u514d\u7684\u662f&#xff0c;\u6211\u4eec\u67e5\u8be2\u6307\u5b9a\u6570\u636e\u7684\u901f\u5ea6\u80af\u5b9a\u4e5f\u4f1a\u53d8\u6162&#xff0c;\u672c\u8d28\u8fd8\u662f\u56e0\u4e3a\u7b49\u5f85\u7cfb\u7edf\u4ece\u78c1\u76d8\u3001\u786c\u76d8\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u95f4\u6d88\u8017&#xff0c;\u8fd9\u4e00\u70b9\u6211\u4eec\u5728IO\u90a3\u91cc\u4e5f\u6709\u8bb2\u5230\u8fc7&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&amp;#xf<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7274,114,100,4581,176],"topic":[],"class_list":["post-104619","post","type-post","status-publish","format-standard","hentry","category-server","tag-7274","tag-mysql","tag-100","tag-4581","tag-176"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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.wsisp.com\/helps\/104619.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5f00\u7bc7\u4ecb\u7ecd&#xff1a;hello \u5927\u5bb6&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&#xff0c;\u6700\u91cd\u8981\u7684\u5c31\u662f\u67e5\u8be2\u6570\u636e\u4e86&#xff0c;\u800c\u67e5\u8be2\u6570\u636e\u6700\u91cd\u8981\u7684\u53c8\u662f\u901f\u5ea6&#xff0c;\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f\u6548\u7387&#xff0c;\u800c\u5f53\u6570\u636e\u5e93\u4e2d\u6709\u5927\u91cf\u6570\u636e\u7684\u65f6\u5019&#xff0c;\u8bf6&#xff0c;\u4e0d\u53ef\u907f\u514d\u7684\u662f&#xff0c;\u6211\u4eec\u67e5\u8be2\u6307\u5b9a\u6570\u636e\u7684\u901f\u5ea6\u80af\u5b9a\u4e5f\u4f1a\u53d8\u6162&#xff0c;\u672c\u8d28\u8fd8\u662f\u56e0\u4e3a\u7b49\u5f85\u7cfb\u7edf\u4ece\u78c1\u76d8\u3001\u786c\u76d8\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u95f4\u6d88\u8017&#xff0c;\u8fd9\u4e00\u70b9\u6211\u4eec\u5728IO\u90a3\u91cc\u4e5f\u6709\u8bb2\u5230\u8fc7&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&amp;#xf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/104619.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-12T12:41:53+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"49 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/104619.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/104619.html\",\"name\":\"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-12T12:41:53+00:00\",\"dateModified\":\"2026-09-12T12:41:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/104619.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/104619.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/104619.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/104619.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5f00\u7bc7\u4ecb\u7ecd&#xff1a;hello \u5927\u5bb6&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&#xff0c;\u6700\u91cd\u8981\u7684\u5c31\u662f\u67e5\u8be2\u6570\u636e\u4e86&#xff0c;\u800c\u67e5\u8be2\u6570\u636e\u6700\u91cd\u8981\u7684\u53c8\u662f\u901f\u5ea6&#xff0c;\u6362\u53e5\u8bdd\u8bf4\u5c31\u662f\u6548\u7387&#xff0c;\u800c\u5f53\u6570\u636e\u5e93\u4e2d\u6709\u5927\u91cf\u6570\u636e\u7684\u65f6\u5019&#xff0c;\u8bf6&#xff0c;\u4e0d\u53ef\u907f\u514d\u7684\u662f&#xff0c;\u6211\u4eec\u67e5\u8be2\u6307\u5b9a\u6570\u636e\u7684\u901f\u5ea6\u80af\u5b9a\u4e5f\u4f1a\u53d8\u6162&#xff0c;\u672c\u8d28\u8fd8\u662f\u56e0\u4e3a\u7b49\u5f85\u7cfb\u7edf\u4ece\u78c1\u76d8\u3001\u786c\u76d8\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u95f4\u6d88\u8017&#xff0c;\u8fd9\u4e00\u70b9\u6211\u4eec\u5728IO\u90a3\u91cc\u4e5f\u6709\u8bb2\u5230\u8fc7&#xff0c;\u90a3\u4e48\u5bf9\u4e8e\u6570\u636e\u5e93\u800c\u8a00&amp;#xf","og_url":"https:\/\/www.wsisp.com\/helps\/104619.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-12T12:41:53+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"49 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/104619.html","url":"https:\/\/www.wsisp.com\/helps\/104619.html","name":"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-12T12:41:53+00:00","dateModified":"2026-09-12T12:41:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/104619.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/104619.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/104619.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5bf9\u4e8eMySQL\uff1a\u7d22\u5f15\u7684\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/104619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=104619"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/104619\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=104619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=104619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=104619"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=104619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}