{"id":81268,"date":"2023-10-20T21:44:05","date_gmt":"2023-10-20T13:44:05","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=81268"},"modified":"2023-10-20T21:44:05","modified_gmt":"2023-10-20T13:44:05","slug":"mysql-high-performance-table","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-high-performance-table.html","title":{"rendered":"\u5982\u4f55\u8bbe\u8ba1\u51faMySQL\u9ad8\u6027\u80fd\u8868"},"content":{"rendered":"

\u826f\u597d\u7684\u903b\u8f91\u8bbe\u8ba1\u548c\u7269\u7406\u8bbe\u8ba1\u662f\u9ad8\u6027\u80fd\u7684\u57fa\u77f3\uff0c \u5e94\u8be5\u6839\u636e\u7cfb\u7edf\u5c06\u8981\u6267\u884c\u7684\u67e5\u8be2\u8bed\u53e5\u6765\u8bbe\u8ba1schema, \u8fd9\u5f80\u5f80\u9700\u8981\u6743\u8861\u5404\u79cd\u56e0\u7d20\u3002<\/p>\n

\"\"<\/p>\n

\u4e00\u3001\u9009\u62e9\u4f18\u5316\u7684\u6570\u636e\u7c7b\u578b<\/strong><\/div>\n

MySQL\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u975e\u5e38\u591a\uff0c \u9009\u62e9\u6b63\u786e\u7684\u6570\u636e\u7c7b\u578b\u5bf9\u4e8e\u83b7\u5f97\u9ad8\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002<\/p>\n

\u66f4\u5c0f\u7684\u901a\u5e38\u66f4\u597d<\/strong><\/p>\n

\u66f4\u5c0f\u7684\u6570\u636e\u7c7b\u578b\u901a\u5e38\u66f4\u5feb\uff0c \u56e0\u4e3a\u5b83\u4eec\u5360\u7528\u66f4\u5c11\u7684\u78c1\u76d8\u3001 \u5185\u5b58\u548cCPU\u7f13\u5b58\uff0c \u5e76\u4e14\u5904\u7406\u65f6\u9700\u8981\u7684CPU\u5468\u671f\u4e5f\u66f4\u5c11\u3002<\/p>\n

\u7b80\u5355\u5c31\u597d<\/strong><\/p>\n

\u7b80\u5355\u6570\u636e\u7c7b\u578b\u7684\u64cd\u4f5c\u901a\u5e38\u9700\u8981\u66f4\u5c11\u7684CPU\u5468\u671f\u3002 \u4f8b\u5982\uff0c \u6574\u578b\u6bd4\u5b57\u7b26\u64cd\u4f5c\u4ee3\u4ef7\u66f4\u4f4e\uff0c \u56e0\u4e3a\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\uff08\u6392\u5e8f\u89c4\u5219 \uff09\u4f7f\u5b57\u7b26\u6bd4\u8f83\u6bd4\u6574\u578b\u6bd4\u8f83\u66f4\u590d\u6742\u3002<\/p>\n

\u5c3d\u91cf\u907f\u514dNULL<\/strong><\/p>\n

\u5982\u679c\u67e5\u8be2\u4e2d\u5305\u542b\u53ef\u4e3aNULL \u7684\u5217\uff0c \u5bf9MySQL\u6765\u8bf4\u66f4\u96be\u4f18\u5316\uff0c \u56e0\u4e3a\u53ef\u4e3aNULL \u7684\u5217\u4f7f\u5f97\u7d22\u5f15\u3001 \u7d22\u5f15\u7edf\u8ba1\u548c\u503c\u6bd4\u8f83\u90fd\u66f4\u590d\u6742\u3002 \u53ef\u4e3aNULL\u7684\u5217\u4f1a\u4f7f\u7528\u66f4\u591a\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c \u5728MySQL\u91cc\u4e5f\u9700\u8981\u7279\u6b8a\u5904\u7406\u3002 \u5f53\u53ef\u4e3aNULL\u7684\u5217\u88ab\u7d22\u5f15\u65f6\uff0c \u6bcf\u4e2a\u7d22\u5f15\u8bb0\u5f55\u9700\u8981\u4e00\u4e2a\u989d\u5916\u7684\u5b57\u8282\uff0c \u5728MyISAM\u91cc\u751a\u81f3\u8fd8\u53ef\u80fd\u5bfc\u81f4\u56fa\u5b9a\u5927\u5c0f\u7684\u7d22\u5f15\uff08\u4f8b\u5982\u53ea\u6709\u4e00\u4e2a\u6574\u6570\u5217\u7684\u7d22\u5f15\uff09\u53d8\u6210\u53ef\u53d8\u5927\u5c0f\u7684\u7d22\u5f15\u3002<\/p>\n

\u5f53\u7136\u4e5f\u6709\u4f8b\u5916\uff0c \u4f8b\u5982InnoDB \u4f7f\u7528\u5355\u72ec\u7684\u4f4d (bit) \u5b58\u50a8NULL\u503c\uff0c \u6240\u4ee5\u5bf9\u4e8e\u7a00\u758f\u6570\u636e\u6709\u5f88\u597d\u7684\u7a7a\u95f4\u6548\u7387\u3002<\/p>\n

1.\u6574\u6570\u7c7b\u578b<\/strong><\/p>\n

\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u6570\u5b57\uff1a\u6574\u6570 (whole number) \u548c\u5b9e\u6570 (real number) \u3002 \u5982\u679c\u5b58\u50a8\u6574\u6570\uff0c \u53ef\u4ee5\u4f7f\u7528\u8fd9\u51e0\u79cd\u6574\u6570\u7c7b\u578b\uff1aTINYINT, SMALLINT, MEDIUMINT, INT, BIGINT\u3002\u5206\u522b\u4f7f\u75288,16, 24, 32, 64\u4f4d\u5b58\u50a8\u7a7a\u95f4\u3002<\/p>\n

\u6574\u6570\u7c7b\u578b\u6709\u53ef\u9009\u7684 **UNSIGNED ** \u5c5e\u6027\uff0c\u8868\u793a\u4e0d\u5141\u8bb8\u8d1f\u503c\uff0c\u8fd9\u5927\u81f4\u53ef\u4ee5\u4f7f\u6b63\u6570\u7684\u4e0a\u9650\u63d0\u9ad8\u4e00\u500d\u3002 \u4f8b\u5982 TINYINT. UNSIGNED \u53ef\u4ee5\u5b58\u50a8\u7684\u8303\u56f4\u662f 0 - 255, \u800c TINYINT \u7684\u5b58\u50a8\u8303\u56f4\u662f -128 -127 \u3002<\/p>\n

\u6709\u7b26\u53f7\u548c\u65e0\u7b26\u53f7\u7c7b\u578b\u4f7f\u7528\u76f8\u540c\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u5e76\u5177\u6709\u76f8\u540c\u7684\u6027\u80fd \uff0c \u56e0\u6b64\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u7c7b\u578b\u3002<\/p>\n

\u4f60\u7684\u9009\u62e9\u51b3\u5b9a MySQL \u662f\u600e\u4e48\u5728\u5185\u5b58\u548c\u78c1\u76d8\u4e2d\u4fdd\u5b58\u6570\u636e\u7684\u3002 \u7136\u800c\uff0c \u6574\u6570\u8ba1\u7b97\u4e00\u822c\u4f7f\u752864 \u4f4d\u7684 BIGINT \u6574\u6570\uff0c \u5373\u4f7f\u5728 32 \u4f4d\u73af\u5883\u4e5f\u662f\u5982\u6b64\u3002\uff08 \u4e00\u4e9b\u805a\u5408\u51fd\u6570\u662f\u4f8b\u5916\uff0c \u5b83\u4eec\u4f7f\u7528DECIMAL \u6216 DOUBLE \u8fdb\u884c\u8ba1\u7b97\uff09\u3002<\/p>\n

MySQL \u53ef\u4ee5\u4e3a\u6574\u6570\u7c7b\u578b\u6307\u5b9a\u5bbd\u5ea6\uff0c \u4f8b\u5982 INT(11), \u5bf9\u5927\u591a\u6570\u5e94\u7528\u8fd9\u662f\u6ca1\u6709\u610f\u4e49\u7684\uff1a\u5b83\u4e0d\u4f1a\u9650\u5236\u503c\u7684\u5408\u6cd5\u8303\u56f4\uff0c\u53ea\u662f\u89c4\u5b9a\u4e86MySQL \u7684\u4e00\u4e9b\u4ea4\u4e92\u5de5\u5177\uff08\u4f8b\u5982 MySQL \u547d\u4ee4\u884c\u5ba2\u6237\u7aef\uff09\u7528\u6765\u663e\u793a\u5b57\u7b26\u7684\u4e2a\u6570\u3002 \u5bf9\u4e8e\u5b58\u50a8\u548c\u8ba1\u7b97\u6765\u8bf4\uff0c INT(1) \u548c INT(20) \u662f\u76f8\u540c\u7684\u3002<\/p>\n

2.\u5b9e\u6570\u7c7b\u578b<\/strong><\/p>\n

\u5b9e\u6570\u662f\u5e26\u6709\u5c0f\u6570\u90e8\u5206\u7684\u6570\u5b57\u3002 \u7136\u800c\uff0c \u5b83\u4eec\u4e0d\u53ea\u662f\u4e3a\u4e86\u5b58\u50a8\u5c0f\u6570\u90e8\u5206\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528DECIMAL \u5b58\u50a8\u6bd4 BIGINT \u8fd8\u5927\u7684\u6574\u6570\u3002<\/p>\n

FLOAT\u548cDOUBLE\u7c7b\u578b\u652f\u6301\u4f7f\u7528\u6807\u51c6\u7684\u6d6e\u70b9\u8fd0\u7b97\u8fdb\u884c\u8fd1\u4f3c\u8ba1\u7b97\u3002<\/p>\n

DECIMAL\u7c7b\u578b\u7528\u4e8e\u5b58\u50a8\u7cbe\u786e\u7684\u5c0f\u6570\u3002<\/p>\n

\u6d6e\u70b9\u548cDECIMAL\u7c7b\u578b\u90fd\u53ef\u4ee5\u6307\u5b9a\u7cbe\u5ea6\u3002 \u5bf9\u4e8eDECIMAL\u5217\uff0c \u53ef\u4ee5\u6307\u5b9a\u5c0f\u6570\u70b9\u524d\u540e\u6240\u5141\u8bb8\u7684\u6700\u5927\u4f4d\u6570\u3002\u8fd9\u4f1a\u5f71\u54cd\u5217\u7684\u7a7a\u95f4\u6d88\u8017\u3002<\/p>\n

\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6307\u5b9a\u6d6e\u70b9\u5217\u6240\u9700\u8981\u7684\u7cbe\u5ea6\uff0c \u8fd9\u4f1a\u4f7f\u5f97MySQL\u9009\u62e9\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6216\u8005\u5728\u5b58\u50a8\u65f6\u5bf9\u503c\u8fdb\u884c\u53d6\u820d\u3002 \u8fd9\u4e9b\u7cbe\u5ea6\u5b9a\u4e49\u662f\u975e\u6807\u51c6\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u5efa\u8bae\u53ea\u6307\u5b9a\u6570\u636e\u7c7b\u578b\uff0c\u4e0d\u6307\u5b9a\u7cbe\u5ea6\u3002<\/p>\n

\u6d6e\u70b9\u7c7b\u578b\u5728\u5b58\u50a8\u540c\u6837\u8303\u56f4\u7684\u503c\u65f6\uff0c \u901a\u5e38\u6bd4DECIMAL\u4f7f\u7528\u66f4\u5c11\u7684\u7a7a\u95f4\u3002FLOAT\u4f7f\u75284\u4e2a\u5b57\u8282\u5b58\u50a8\u3002DOUBLE\u5360\u75288\u4e2a\u5b57\u8282\uff0c\u76f8\u6bd4FLOAT\u6709\u66f4\u9ad8\u7684\u7cbe\u5ea6\u548c\u66f4\u5927\u7684\u8303\u56f4\u3002\u548c\u6574\u6570\u7c7b\u578b\u4e00\u6837\uff0c \u80fd\u9009\u62e9\u7684\u53ea\u662f\u5b58\u50a8\u7c7b\u578b\uff1b MySQL\u4f7f\u7528DOUBLE\u4f5c\u4e3a\u5185\u90e8\u6d6e\u70b9\u8ba1\u7b97\u7684\u7c7b\u578b\u3002<\/p>\n

\u56e0\u4e3a\u9700\u8981\u989d\u5916\u7684\u7a7a\u95f4\u548c\u8ba1\u7b97\u5f00\u9500\uff0c\u6240\u4ee5\u5e94\u8be5\u5c3d\u91cf\u53ea\u5728\u5bf9\u5c0f\u6570\u8fdb\u884c\u7cbe\u786e\u8ba1\u7b97\u65f6\u624d\u4f7f\u7528DECIMAL\u3002\u4f46\u5728\u6570\u636e\u6700\u6bd4\u8f83\u5927\u7684\u65f6\u5019\uff0c \u53ef\u4ee5\u8003\u8651\u4f7f\u7528BIGINT\u4ee3\u66ffDECIMAL, \u5c06\u9700\u8981\u5b58\u50a8\u7684\u8d27\u5e01\u5355\u4f4d\u6839\u636e\u5c0f\u6570\u7684\u4f4d\u6570\u4e58\u4ee5\u76f8\u5e94\u7684\u500d\u6570\u5373\u53ef\u3002<\/p>\n

3.\u5b57\u7b26\u4e32\u7c7b\u578b<\/strong><\/p>\n

VARCHAR<\/strong><\/p>\n