{"id":1345,"date":"2022-07-22T10:16:54","date_gmt":"2022-07-22T02:16:54","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1345"},"modified":"2022-07-22T10:16:54","modified_gmt":"2022-07-22T02:16:54","slug":"mysql%e7%b4%a2%e5%bc%95%e5%ba%95%e5%b1%82b%e6%a0%91%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/07\/22\/mysql%e7%b4%a2%e5%bc%95%e5%ba%95%e5%b1%82b%e6%a0%91%e5%ae%9e%e7%8e%b0\/","title":{"rendered":"MySQL\u7d22\u5f15\u5e95\u5c42B+\u6811\u5b9e\u73b0"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u4e00\u3001B \u6811<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u00a01\u3001B Tree\u4ecb\u7ecd<\/h2>\n\n\n\n<p>B\u6811\u7684\u641c\u7d22\uff0c\u4ece\u6839\u7ed3\u70b9\u5f00\u59cb\uff0c\u5bf9\u7ed3\u70b9\u5185\u7684\u5173\u952e\u5b57\uff08\u6709\u5e8f\uff09\u5e8f\u5217\u8fdb\u884c\u4e8c\u5206\u67e5\u627e\uff0c\u5982\u679c\u547d\u4e2d\u5219\u7ed3\u675f\uff0c\u5426\u5219\u8fdb\u5165\u67e5\u8be2\u5173\u952e\u5b57\u6240\u5c5e\u8303\u56f4\u7684\u513f\u5b50\u7ed3\u70b9\uff1b\u91cd\u590d\uff0c\u76f4\u5230\u6240\u5bf9\u5e94\u7684\u513f\u5b50\u6307\u9488\u4e3a\u7a7a\uff0c\u6216\u5df2\u7ecf\u662f\u53f6\u5b50\u7ed3\u70b9\uff1b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9a\u4e49<\/h3>\n\n\n\n<p>BTree\u662f\u4e00\u79cd\u591a\u8def\u641c\u7d22\u6811\uff08\u5e76\u4e0d\u662f\u4e8c\u53c9\u7684\uff09\uff1a<\/p>\n\n\n\n<p>1.\u5b9a\u4e49\u4efb\u610f\u975e\u53f6\u5b50\u7ed3\u70b9\u6700\u591a\u53ea\u6709M\u4e2a\u513f\u5b50\uff1b\u4e14M>2\uff1b<br>2.\u6839\u7ed3\u70b9\u7684\u513f\u5b50\u6570\u4e3a[2, M]\uff1b<br>3.\u9664\u6839\u7ed3\u70b9\u4ee5\u5916\u7684\u975e\u53f6\u5b50\u7ed3\u70b9\u7684\u513f\u5b50\u6570\u4e3a[M\/2, M]\uff1b<br>4.\u6bcf\u4e2a\u7ed3\u70b9\u5b58\u653e\u81f3\u5c11M\/2-1\uff08\u53d6\u4e0a\u6574\uff09\u548c\u81f3\u591aM-1\u4e2a\u5173\u952e\u5b57\uff1b\uff08\u81f3\u5c112\u4e2a\u5173\u952e\u5b57\uff09<br>5.\u975e\u53f6\u5b50\u7ed3\u70b9\u7684\u5173\u952e\u5b57\u4e2a\u6570=\u6307\u5411\u513f\u5b50\u7684\u6307\u9488\u4e2a\u6570-1\uff1b<br>6.\u975e\u53f6\u5b50\u7ed3\u70b9\u7684\u5173\u952e\u5b57\uff1aK[1], K[2], \u2026, K[M-1]\uff1b\u4e14K[i] &lt; K[i+1]\uff1b<br>7.\u975e\u53f6\u5b50\u7ed3\u70b9\u7684\u6307\u9488\uff1aP[1], P[2], \u2026, P[M]\uff1b\u5176\u4e2dP[1]\u6307\u5411\u5173\u952e\u5b57\u5c0f\u4e8eK[1]\u7684\u5b50\u6811\uff0cP[M]\u6307\u5411\u5173\u952e\u5b57\u5927\u4e8eK[M-1]\u7684\u5b50\u6811\uff0c\u5176\u5b83P[i]\u6307\u5411\u5173\u952e\u5b57\u5c5e\u4e8e(K[i-1], K[i])\u7684\u5b50\u6811\uff1b<br>8.\u6240\u6709\u53f6\u5b50\u7ed3\u70b9\u4f4d\u4e8e\u540c\u4e00\u5c42\uff1b<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2022\/07\/Snipaste_2022-07-22_10-22-07-1.png\" alt=\"\" class=\"wp-image-1354\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u6027<\/h3>\n\n\n\n<p>B\u6811\u7684\u7279\u6027\uff1a<\/p>\n\n\n\n<p>1.\u5173\u952e\u5b57\u96c6\u5408\u5206\u5e03\u5728\u6574\u9897\u6811\u4e2d\uff1b<br>2.\u4efb\u4f55\u4e00\u4e2a\u5173\u952e\u5b57\u51fa\u73b0\u4e14\u53ea\u51fa\u73b0\u5728\u4e00\u4e2a\u7ed3\u70b9\u4e2d\uff1b<br>3.\u641c\u7d22\u6709\u53ef\u80fd\u5728\u975e\u53f6\u5b50\u7ed3\u70b9\u7ed3\u675f\uff1b<br>4.\u5176\u641c\u7d22\u6027\u80fd\u7b49\u4ef7\u4e8e\u5728\u5173\u952e\u5b57\u5168\u96c6\u5185\u505a\u4e00\u6b21\u4e8c\u5206\u67e5\u627e\uff1b<br>5.\u81ea\u52a8\u5c42\u6b21\u63a7\u5236\uff1b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001B+Tree\u4ecb\u7ecd<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9a\u4e49<\/h3>\n\n\n\n<p>B+\u6811\u662fB-\u6811\u7684\u53d8\u4f53\uff0c\u4e5f\u662f\u4e00\u79cd\u591a\u8def\u641c\u7d22\u6811\uff1a<\/p>\n\n\n\n<p>1.\u5176\u5b9a\u4e49\u57fa\u672c\u4e0eB-\u6811\u540c\uff0c\u9664\u4e86\uff1a<br>2.\u975e\u53f6\u5b50\u7ed3\u70b9\u7684\u5b50\u6811\u6307\u9488\u4e0e\u5173\u952e\u5b57\u4e2a\u6570\u76f8\u540c\uff1b<br>3.\u975e\u53f6\u5b50\u7ed3\u70b9\u7684\u5b50\u6811\u6307\u9488P[i]\uff0c\u6307\u5411\u5173\u952e\u5b57\u503c\u5c5e\u4e8e[K[i], K[i+1])\u7684\u5b50\u6811\uff08B-\u6811\u662f\u5f00\u533a\u95f4\uff09\uff1b<br>5.\u4e3a\u6240\u6709\u53f6\u5b50\u7ed3\u70b9\u589e\u52a0\u4e00\u4e2a\u94fe\u6307\u9488\uff1b<br>6.\u6240\u6709\u5173\u952e\u5b57\u90fd\u5728\u53f6\u5b50\u7ed3\u70b9\u51fa\u73b0\uff1b<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2022\/07\/Snipaste_2022-07-22_10-25-02.png\" alt=\"\" class=\"wp-image-1360\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u6027<\/h3>\n\n\n\n<p>B+\u7684\u7279\u6027\uff1a<br><br>1.\u6240\u6709\u5173\u952e\u5b57\u90fd\u51fa\u73b0\u5728\u53f6\u5b50\u7ed3\u70b9\u7684\u94fe\u8868\u4e2d\uff08\u7a20\u5bc6\u7d22\u5f15\uff09\uff0c\u4e14\u94fe\u8868\u4e2d\u7684\u5173\u952e\u5b57\u6070\u597d\u662f\u6709\u5e8f\u7684\uff1b<br>2.\u4e0d\u53ef\u80fd\u5728\u975e\u53f6\u5b50\u7ed3\u70b9\u547d\u4e2d\uff1b<br>3.\u975e\u53f6\u5b50\u7ed3\u70b9\u76f8\u5f53\u4e8e\u662f\u53f6\u5b50\u7ed3\u70b9\u7684\u7d22\u5f15\uff08\u7a00\u758f\u7d22\u5f15\uff09\uff0c\u53f6\u5b50\u7ed3\u70b9\u76f8\u5f53\u4e8e\u662f\u5b58\u50a8\uff08\u5173\u952e\u5b57\uff09\u6570\u636e\u7684\u6570\u636e\u5c42\uff1b<br>4.\u66f4\u9002\u5408\u6587\u4ef6\u7d22\u5f15\u7cfb\u7edf\uff1b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001B\u6811\u4e0eB+\u6811\u533a\u522b<\/h2>\n\n\n\n<p>\u8fd9\u90fd\u662f\u7531\u4e8eB+\u6811\u548cB\u5177\u6709\u8fd9\u4e0d\u540c\u7684\u5b58\u50a8\u7ed3\u6784\u6240\u9020\u6210\u7684\u533a\u522b\uff0c\u4ee5\u4e00\u4e2am\u9636\u6811\u4e3a\u4f8b\u3002<\/p>\n\n\n\n<p><strong>\u5173\u952e\u5b57\u7684\u6570\u91cf\u4e0d\u540c<\/strong>\uff1bB+\u6811\u4e2d\u5206\u652f\u7ed3\u70b9\u6709m\u4e2a\u5173\u952e\u5b57\uff0c\u5176\u53f6\u5b50\u7ed3\u70b9\u4e5f\u6709m\u4e2a\uff0c\u5176\u5173\u952e\u5b57\u53ea\u662f\u8d77\u5230\u4e86\u4e00\u4e2a\u7d22\u5f15\u7684\u4f5c\u7528\uff0c\u4f46\u662fB\u6811\u867d\u7136\u4e5f\u6709m\u4e2a\u5b50\u7ed3\u70b9\uff0c\u4f46\u662f\u5176\u53ea\u62e5\u6709m-1\u4e2a\u5173\u952e\u5b57\u3002<\/p>\n\n\n\n<p><strong>\u5b58\u50a8\u7684\u4f4d\u7f6e\u4e0d\u540c<\/strong>\uff1bB+\u6811\u4e2d\u7684\u6570\u636e\u90fd\u5b58\u50a8\u5728\u53f6\u5b50\u7ed3\u70b9\u4e0a\uff0c\u4e5f\u5c31\u662f\u5176\u6240\u6709\u53f6\u5b50\u7ed3\u70b9\u7684\u6570\u636e\u7ec4\u5408\u8d77\u6765\u5c31\u662f\u5b8c\u6574\u7684\u6570\u636e\uff0c\u4f46\u662fB\u6811\u7684\u6570\u636e\u5b58\u50a8\u5728\u6bcf\u4e00\u4e2a\u7ed3\u70b9\u4e2d\uff0c\u5e76\u4e0d\u4ec5\u4ec5\u5b58\u50a8\u5728\u53f6\u5b50\u7ed3\u70b9\u4e0a\u3002<\/p>\n\n\n\n<p><strong>\u5206\u652f\u7ed3\u70b9\u7684\u6784\u9020\u4e0d\u540c<\/strong>\uff1bB+\u6811\u7684\u5206\u652f\u7ed3\u70b9\u4ec5\u4ec5\u5b58\u50a8\u7740\u5173\u952e\u5b57\u4fe1\u606f\u548c\u513f\u5b50\u7684\u6307\u9488\uff08\u8fd9\u91cc\u7684\u6307\u9488\u6307\u7684\u662f\u78c1\u76d8\u5757\u7684\u504f\u79fb\u91cf\uff09\uff0c\u4e5f\u5c31\u662f\u8bf4\u5185\u90e8\u7ed3\u70b9\u4ec5\u4ec5\u5305\u542b\u7740\u7d22\u5f15\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><strong>\u67e5\u8be2\u4e0d\u540c<\/strong>\uff1bB\u6811\u5728\u627e\u5230\u5177\u4f53\u7684\u6570\u503c\u4ee5\u540e\uff0c\u5219\u7ed3\u675f\uff0c\u800cB+\u6811\u5219\u9700\u8981\u901a\u8fc7\u7d22\u5f15\u627e\u5230\u53f6\u5b50\u7ed3\u70b9\u4e2d\u7684\u6570\u636e\u624d\u7ed3\u675f\uff0c\u4e5f\u5c31\u662f\u8bf4B+\u6811\u7684\u641c\u7d22\u8fc7\u7a0b\u4e2d\u8d70\u4e86\u4e00\u6761\u4ece\u6839\u7ed3\u70b9\u5230\u53f6\u5b50\u7ed3\u70b9\u7684\u8def\u5f84<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e8c\u3001\u7d22\u5f15\u5e95\u5c42\u5b9e\u73b0<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">1\u3001MyISAM \u7d22\u5f15\u5b9e\u73b0<\/h2>\n\n\n\n<p>MyISAM \u5f15\u64ce\u4f7f\u7528 B+Tree \u4f5c\u4e3a\u7d22\u5f15\u7ed3\u6784,\u53f6\u8282\u70b9\u7684 data \u57df\u5b58\u653e\u7684\u662f\u6570\u636e\u8bb0\u5f55<br>\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<p>\u4e3b\u7d22\u5f15\u4e0e\u8f85\u52a9\u7d22\u5f15\u7684\u533a\u522b\uff08\u5bf9\u67d0\u5217\u5efa\u7acb\u7d22\u5f15\uff09\uff1a<\/p>\n\n\n\n<p>\u5728\u7ed3\u6784\u4e0a\u6ca1\u6709\u4efb\u4f55\u533a\u522b,\u53ea\u662f\u4e3b\u7d22\u5f15\u8981\u6c42 key \u662f\u552f\u4e00\u7684,\u800c\u8f85\u52a9\u7d22\u5f15\u7684 key \u53ef\u4ee5\u91cd\u590d<\/p>\n\n\n\n<p>\u4e3b\u7d22\u5f15\uff08\u805a\u96c6\u7d22\u5f15\uff09\u4e5f\u5c31\u662f\u8868\u7684\u4e3b\u952e\uff0c\u662f\u5efa\u8868\u65f6\u6307\u5b9a\u7684\uff0c\u5e76\u4e14\u662f\u552f\u4e00\u7684<\/p>\n\n\n\n<p>\u8f85\u52a9\u7d22\u5f15\uff08\u975e\u805a\u96c6\u7d22\u5f15\uff09\u662f\u5bf9\u8868\u6709\u5176\u4ed6\u9700\u8981\u53ef\u4ee5\u6dfb\u52a0\u521b\u5efa\u7684<\/p>\n\n\n\n<p>\u4e0b\u56fe\u662f MyISAM \u7d22\u5f15\u7684\u539f\u7406\u56fe\uff1a<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2022\/07\/Snipaste_2022-07-22_10-26-31.png\" alt=\"\" class=\"wp-image-1363\"\/><\/figure>\n\n\n\n<p><strong>\u7d22\u5f15\u8fc7\u7a0b\uff1a<\/strong><\/p>\n\n\n\n<p>MyISAM \u4e2d\u7d22\u5f15\u68c0\u7d22\u7684\u7b97\u6cd5\u4e3a\u9996\u5148\u6309\u7167 B+Tree \u641c\u7d22\u7b97\u6cd5\u641c\u7d22\u7d22\u5f15,\u5982\u679c\u6307\u5b9a\u7684 Key \u5b58\u5728,\u5219\u53d6\u51fa\u5176data \u57df\u7684\u503c,\u7136\u540e\u4ee5 data \u57df\u7684\u503c\u4e3a\u5730\u5740,\u8bfb\u53d6\u76f8\u5e94\u6570\u636e\u8bb0\u5f55\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001 InnoDB\u7d22\u5f15\u5b9e\u73b0<\/h2>\n\n\n\n<p>1\u3001InnoDB \u7684\u6570\u636e\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u7d22\u5f15\u6587\u4ef6\u3002\u4ece\u4e0a\u6587\u77e5\u9053,MyISAM \u7d22\u5f15\u6587\u4ef6\u548c\u6570\u636e\u6587\u4ef6\u662f\u5206\u79bb\u7684,\u7d22\u5f15\u6587\u4ef6\u4ec5\u4fdd\u5b58\u6570\u636e\u8bb0\u5f55\u7684\u5730\u5740\u3002<\/p>\n\n\n\n<p>\u800c\u5728InnoDB \u4e2d,\u8868\u6570\u636e\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u6309 B+Tree \u7ec4\u7ec7\u7684\u4e00\u4e2a\u7d22\u5f15\u7ed3\u6784,<strong>\u8fd9\u68f5\u6811\u7684\u53f6\u70b9data \u57df\u4fdd\u5b58\u4e86\u5b8c\u6574\u7684\u6570\u636e\u8bb0\u5f55<\/strong>\u3002\u8fd9\u4e2a\u7d22\u5f15\u7684 key \u662f\u6570\u636e\u8868\u7684\u4e3b\u952e,\u56e0\u6b64 InnoDB \u8868\u6570\u636e\u6587\u4ef6\u672c\u8eab\u5c31\u662f\u4e3b\u7d22\u5f15\u3002<\/p>\n\n\n\n<p><strong>InnoDB \u8981\u6c42\u8868\u5fc5\u987b\u6709\u4e3b\u952e<\/strong>(MyISAM \u53ef\u4ee5\u6ca1\u6709),\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u6307\u5b9a,\u5219 MySQL\u7cfb\u7edf\u4f1a\u81ea\u52a8\u9009\u62e9\u4e00\u4e2a\u53ef\u4ee5\u552f\u4e00\u6807\u8bc6\u6570\u636e\u8bb0\u5f55\u7684\u5217\u4f5c\u4e3a\u4e3b\u952e,\u5982\u679c\u4e0d\u5b58\u5728\u8fd9\u79cd\u5217,\u5219MySQL \u81ea\u52a8\u4e3a InnoDB \u8868\u751f\u6210\u4e00\u4e2a\u9690\u542b\u5b57\u6bb5\u4f5c\u4e3a\u4e3b\u952e,\u7c7b\u578b\u4e3a\u957f\u6574\u5f62<\/p>\n\n\n\n<p>2\u3001\u7b2c\u4e8c\u4e2a\u4e0e MyISAM \u7d22\u5f15\u7684\u4e0d\u540c\u662f InnoDB \u7684\u8f85\u52a9\u7d22\u5f15 data \u57df\u5b58\u50a8\u76f8\u5e94\u8bb0\u5f55\u4e3b\u952e\u7684\u503c\u800c\u4e0d\u662f\u5730\u5740\u3002\u6362\u53e5\u8bdd\u8bf4,InnoDB \u7684\u6240\u6709\u8f85\u52a9\u7d22\u5f15\u90fd\u5f15\u7528\u4e3b\u952e\u4f5c\u4e3a data \u57df\u3002<\/p>\n\n\n\n<p>\u8f85\u52a9\u7d22\u5f15\u641c\u7d22\u9700\u8981\u68c0\u7d22\u4e24\u904d\u7d22\u5f15:\u9996\u5148\u68c0\u7d22\u8f85\u52a9\u7d22\u5f15\u83b7\u5f97\u4e3b\u952e,\u7136\u540e\u7528\u4e3b\u952e\u5230\u4e3b\u7d22\u5f15\u4e2d\u68c0\u7d22\u83b7\u5f97\u8bb0\u5f55\u3002<\/p>\n\n\n\n<p>3\u3001\u4e3b\u952e\u8fc7\u957f\u5bfc\u81f4\uff1a<\/p>\n\n\n\n<p>\u56e0\u4e3a\u6240\u6709\u8f85\u52a9\u7d22\u5f15\u90fd\u5f15\u7528\u4e3b\u7d22\u5f15,\u8fc7\u957f\u7684\u4e3b\u7d22\u5f15\u4f1a\u4ee4\u8f85\u52a9\u7d22\u5f15\u53d8\u5f97\u8fc7\u5927\u3002<\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2022\/07\/Snipaste_2022-07-22_10-27-40.png\" alt=\"\" class=\"wp-image-1366\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001B \u6811 \u00a01\u3001B Tree\u4ecb&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1368,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1345","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1345"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1345\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}