{"id":11455,"date":"2025-06-12T10:55:17","date_gmt":"2025-06-12T02:55:17","guid":{"rendered":"https:\/\/egonlin.com\/?p=11455"},"modified":"2025-06-12T16:28:40","modified_gmt":"2025-06-12T08:28:40","slug":"%e6%b5%8b%e8%af%95%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=11455","title":{"rendered":"\u6d4b\u8bd5\u7d22\u5f15"},"content":{"rendered":"<p><strong>\u4e00 \u51c6\u5907<\/strong><\/p>\n<div class=\"cnblogs_code\">\n<div id=\"cnblogs_code_open_7eeb389f-5b83-47d6-b74f-868bd32eead9\" class=\"cnblogs_code_hide\">\n<pre>#1. \u51c6\u5907\u8868\r\ncreate table s1(\r\nid int,\r\nname varchar(20),\r\ngender char(6),\r\nemail varchar(50)\r\n);\r\n\r\n#2. \u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b9e\u73b0\u6279\u91cf\u63d2\u5165\u8bb0\u5f55\r\ndelimiter $$ #\u58f0\u660e\u5b58\u50a8\u8fc7\u7a0b\u7684\u7ed3\u675f\u7b26\u53f7\u4e3a$$\r\ncreate procedure auto_insert1()\r\nBEGIN\r\n    declare i int default 1;\r\n    while(i&lt;3000000)do\r\n        insert into s1 values(i,'egon','male',concat('egon',i,'@oldboy'));\r\n        set i=i+1;\r\n        select concat('egon',i,'_ok');\r\n    end while;\r\nEND$$ #$$\u7ed3\u675f\r\ndelimiter ;\r\n\r\n#3. \u67e5\u770b\u5b58\u50a8\u8fc7\u7a0b\r\nshow create procedure auto_insert1\\G \r\n\r\n#4. \u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\r\ncall auto_insert1()<\/pre>\n<\/div>\n<\/div>\n<p><strong>\u4e8c \u5728\u6ca1\u6709\u7d22\u5f15\u7684\u524d\u63d0\u4e0b\u6d4b\u8bd5\u67e5\u8be2\u901f\u5ea6<\/strong><\/p>\n<div class=\"cnblogs_code\">\n<pre>#\u65e0\u7d22\u5f15\uff1amysql\u6839\u672c\u5c31\u4e0d\u77e5\u9053\u5230\u5e95\u662f\u5426\u5b58\u5728id\u7b49\u4e8e333333333\u7684\u8bb0\u5f55\uff0c\u53ea\u80fd\u628a\u6570\u636e\u8868\u4ece\u5934\u5230\u5c3e\u626b\u63cf\u4e00\u904d\uff0c\u6b64\u65f6\u6709\u591a\u5c11\u4e2a\u78c1\u76d8\u5757\u5c31\u9700\u8981\u8fdb\u884c\u591a\u5c11IO\u64cd\u4f5c\uff0c\u6240\u4ee5\u67e5\u8be2\u901f\u5ea6\u5f88\u6162\r\nmysql&gt; select * from s1 where id=333333333;\r\nEmpty set (0.33 sec)<\/pre>\n<\/div>\n<p><strong>\u4e09 \u5728\u8868\u4e2d\u5df2\u7ecf\u5b58\u5728\u5927\u91cf\u6570\u636e\u7684\u524d\u63d0\u4e0b\uff0c\u4e3a\u67d0\u4e2a\u5b57\u6bb5\u6bb5\u5efa\u7acb\u7d22\u5f15\uff0c\u5efa\u7acb\u901f\u5ea6\u4f1a\u5f88\u6162<\/strong><\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2025\/06\/1036857-20170913163337125-480382090.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" class=\"alignnone size-full wp-image-11456\" data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2025\/06\/1036857-20170913163337125-480382090.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" width=\"369\" height=\"64\" \/><\/div><\/p>\n<p><strong>\u56db \u5728\u7d22\u5f15\u5efa\u7acb\u5b8c\u6bd5\u540e\uff0c\u4ee5\u8be5\u5b57\u6bb5\u4e3a\u67e5\u8be2\u6761\u4ef6\u65f6\uff0c\u67e5\u8be2\u901f\u5ea6\u63d0\u5347\u660e\u663e<\/strong><\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2025\/06\/1036857-20170913171928047-457783306.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" class=\"alignnone size-full wp-image-11457\" data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2025\/06\/1036857-20170913171928047-457783306.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" width=\"471\" height=\"48\" \/><\/div><\/p>\n<p><strong>PS\uff1a<\/strong><\/p>\n<p><strong>1. mysql\u5148\u53bb\u7d22\u5f15\u8868\u91cc\u6839\u636eb+\u6811\u7684\u641c\u7d22\u539f\u7406\u5f88\u5feb\u641c\u7d22\u5230id\u7b49\u4e8e333333333\u7684\u8bb0\u5f55\u4e0d\u5b58\u5728\uff0cIO\u5927\u5927\u964d\u4f4e\uff0c\u56e0\u800c\u901f\u5ea6\u660e\u663e\u63d0\u5347<\/strong><\/p>\n<p><strong>2. \u6211\u4eec\u53ef\u4ee5\u53bbmysql\u7684data\u76ee\u5f55\u4e0b\u627e\u5230\u8be5\u8868\uff0c\u53ef\u4ee5\u770b\u5230\u5360\u7528\u7684\u786c\u76d8\u7a7a\u95f4\u591a\u4e86<\/strong><\/p>\n<p><strong>3. \u9700\u8981\u6ce8\u610f\uff0c\u5982\u4e0b\u56fe<\/strong><\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2025\/06\/1036857-20170913163702469-1581818233.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" class=\"alignnone size-full wp-image-11459\" data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2025\/06\/1036857-20170913163702469-1581818233.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" width=\"491\" height=\"53\" \/><\/div><\/p>\n<p><strong>\u4e94 \u603b\u7ed3<\/strong><\/p>\n<div class=\"cnblogs_code\">\n<pre>#1. \u4e00\u5b9a\u662f\u4e3a\u641c\u7d22\u6761\u4ef6\u7684\u5b57\u6bb5\u521b\u5efa\u7d22\u5f15\uff0c\u6bd4\u5982select * from s1 where id = 333;\u5c31\u9700\u8981\u4e3aid\u52a0\u4e0a\u7d22\u5f15\r\n\r\n#2. \u5728\u8868\u4e2d\u5df2\u7ecf\u6709\u5927\u91cf\u6570\u636e\u7684\u60c5\u51b5\u4e0b\uff0c\u5efa\u7d22\u5f15\u4f1a\u5f88\u6162\uff0c\u4e14\u5360\u7528\u786c\u76d8\u7a7a\u95f4\uff0c\u5efa\u5b8c\u540e\u67e5\u8be2\u901f\u5ea6\u52a0\u5feb\r\n\u6bd4\u5982create index idx on s1(id);\u4f1a\u626b\u63cf\u8868\u4e2d\u6240\u6709\u7684\u6570\u636e\uff0c\u7136\u540e\u4ee5id\u4e3a\u6570\u636e\u9879\uff0c\u521b\u5efa\u7d22\u5f15\u7ed3\u6784\uff0c\u5b58\u653e\u4e8e\u786c\u76d8\u7684\u8868\u4e2d\u3002\r\n\u5efa\u5b8c\u4ee5\u540e\uff0c\u518d\u67e5\u8be2\u5c31\u4f1a\u5f88\u5feb\u4e86\u3002\r\n\r\n#3. \u9700\u8981\u6ce8\u610f\u7684\u662f\uff1ainnodb\u8868\u7684\u7d22\u5f15\u4f1a\u5b58\u653e\u4e8es1.ibd\u6587\u4ef6\u4e2d\uff0c\u800cmyisam\u8868\u7684\u7d22\u5f15\u5219\u4f1a\u6709\u5355\u72ec\u7684\u7d22\u5f15\u6587\u4ef6table1.MYI\r\n\r\nMySAM\u7d22\u5f15\u6587\u4ef6\u548c\u6570\u636e\u6587\u4ef6\u662f\u5206\u79bb\u7684\uff0c\u7d22\u5f15\u6587\u4ef6\u4ec5\u4fdd\u5b58\u6570\u636e\u8bb0\u5f55\u7684\u5730\u5740\u3002\u800c\u5728innodb\u4e2d\uff0c\u8868\u6570\u636e\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u6309\u7167B+Tree\uff08BTree\u5373Balance True\uff09\u7ec4\u7ec7\u7684\u4e00\u4e2a\u7d22\u5f15\u7ed3\u6784\uff0c\u8fd9\u68f5\u6811\u7684\u53f6\u8282\u70b9data\u57df\u4fdd\u5b58\u4e86\u5b8c\u6574\u7684\u6570\u636e\u8bb0\u5f55\u3002\u8fd9\u4e2a\u7d22\u5f15\u7684key\u662f\u6570\u636e\u8868\u7684\u4e3b\u952e\uff0c\u56e0\u6b64innodb\u8868\u6570\u636e\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u4e3b\u7d22\u5f15\u3002\r\n\u56e0\u4e3ainndob\u7684\u6570\u636e\u6587\u4ef6\u8981\u6309\u7167\u4e3b\u952e\u805a\u96c6\uff0c\u6240\u4ee5innodb\u8981\u6c42\u8868\u5fc5\u987b\u8981\u6709\u4e3b\u952e\uff08Myisam\u53ef\u4ee5\u6ca1\u6709\uff09\uff0c\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u5b9a\u4e49\uff0c\u5219mysql\u7cfb\u7edf<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00 \u51c6\u5907 #1. \u51c6\u5907\u8868 create table s1( id int, name varchar(20), [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/11455"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11455"}],"version-history":[{"count":2,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/11455\/revisions"}],"predecessor-version":[{"id":11460,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/11455\/revisions\/11460"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}