{"id":5404,"date":"2020-07-30T00:25:03","date_gmt":"2020-07-29T16:25:03","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5404"},"modified":"2020-07-30T00:25:03","modified_gmt":"2020-07-29T16:25:03","slug":"mysql-innodb-%e9%80%8f%e6%98%8e%e9%a1%b5%e5%8e%8b%e7%bc%a9page-compression","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5404","title":{"rendered":"MySQL InnoDB \u900f\u660e\u9875\u538b\u7f29(Page Compression)"},"content":{"rendered":"<div>\n<div>\n<div>\nMySQL InnoDB\u652f\u6301\u6570\u636e\u538b\u7f29\uff0c\u6709\u4e24\u79cd\u6570\u636e\u538b\u7f29\u65b9\u5f0f\uff0c\u7b2c\u4e00\u79cd\u4e3a\u8868\u538b\u7f29\uff0c\u901a\u5e38\u4e5f\u79f0\u4e4b\u4e3a\u884c\u683c\u5f0f\u538b\u7f29\uff0c\u53e6\u5916\u4e00\u79cd\u662f\u9875\u538b\u7f29(Page Compression)\uff0c\u53c8\u53eb\u505a\u900f\u660e\u9875\u538b\u7f29(Transparent Page Compression)\uff0c\u662f\u4e00\u79cd\u9875\u9762\u7ea7\u522b\u7684\u6570\u636e\u538b\u7f29\uff0c\u9875\u538b\u7f29\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u53ca\u6587\u4ef6\u7cfb\u7edf\u6709\u4e00\u5b9a\u7684\u8981\u6c42\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u9875\u538b\u7f29\u7684\u539f\u7406\u53ca\u4f7f\u7528\u65b9\u6cd5\u3002<br \/>\n\u9875\u538b\u7f29\u53ea\u652f\u6301InnoDB\u72ec\u7acb\u8868\u7a7a\u95f4\uff1afile-per-table<br \/>\n\u9875\u538b\u7f29\u9700\u8981\u64cd\u4f5c\u7cfb\u7edf\u5177\u6709\u7a00\u758f\u6587\u4ef6(sparse file)\u6216\u8005\u6587\u4ef6\u6253\u5b54\u6280\u672f(hole punching)\u7684\u652f\u6301\uff0c\u76ee\u524d\u652f\u6301\u8fd9\u79cd\u529f\u80fd\u7684\u4e3b\u6d41\u64cd\u4f5c\u7cfb\u7edf\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>Windows NTFS<\/li>\n<li>RHEL 7 \u5185\u6838 3.10.0-123 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n<li>Ubuntu 14.0.4 LTS \u5185\u6838 3.13 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n<li>Ubuntu 12.0.4 LTS \u5185\u6838 3.2 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n<li>Debian\u00a07 \u5185\u6838 3.2 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n<\/ul>\n<h4>1. \u9875\u538b\u7f29\u8bed\u6cd5<\/h4>\n<p>\u5728create table\u6216\u8005alter table\u65f6\uff0c\u52a0\u4e0a COMPRESSION\u00a0 \u5b50\u53e5\uff0c\u652f\u6301\u7684\u538b\u7f29\u7b97\u6cd5\u4e3b\u8981\u6709Zlib\u00a0\u548c\u00a0LZ4\u3002<br \/>\n\u5f00\u542f\u9875\u538b\u7f29\uff1a<br \/>\nCREATE TABLE t1 (c1 INT) COMPRESSION=\\&#8221;zlib\\&#8221;;<br \/>\nALTER TABLE t1 COMPRESSION=\\&#8221;zlib\\&#8221;;<br \/>\nOPTIMIZE TABLE t1;<br \/>\n\u7981\u7528\u9875\u538b\u7f29\uff1a<br \/>\nALTER TABLE t1 COMPRESSION=\\&#8221;None\\&#8221;;<br \/>\nOPTIMIZE TABLE t1;<\/p>\n<h4>2. \u9875\u538b\u7f29\u539f\u7406<\/h4>\n<p>\u5f53\u4e00\u4e2a\u9875\u88ab\u5199\u5165\u78c1\u76d8\u65f6\uff0cInnoDB\u4f7f\u7528\u6307\u5b9a\u7684\u538b\u7f29\u7b97\u6cd5\u5bf9\u8be5\u9875\u8fdb\u884c\u538b\u7f29\uff0c\u7136\u540e\u5c06\u538b\u7f29\u540e\u7684\u6570\u636e\u5199\u5165\u78c1\u76d8\uff0c\u6b64\u65f6\u6253\u5b54\u673a\u5236\u4f1a\u5c06\u538b\u7f29\u540e\u7684\u9875\u5c3e\u7a7a\u95f2\u5757\u8fdb\u884c\u91ca\u653e\uff0c\u4ee5\u51cf\u5c11\u78c1\u76d8\u7a7a\u95f4\u5360\u7528\u3002\u5982\u679c\u538b\u7f29\u5931\u8d25\uff0c\u5219\u6309\u7167\u539f\u6837\u5199\u5165\u6570\u636e\u3002<br \/>\n\u5728Linux\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6587\u4ef6\u7cfb\u7edf\u5757\u5927\u5c0f\u662f\u6253\u5b54\u7684\u5355\u4f4d\u5c3a\u5bf8\uff0c\u56e0\u6b64\uff0c\u9875\u538b\u7f29\u540e\u7684\u6570\u636e\u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8eInnoDB\u9875\u5927\u5c0f\u51cf\u53bb\u6587\u4ef6\u7cfb\u7edf\u5757\u5927\u5c0f\u7684\u503c\uff0c\u624d\u80fd\u4f7f\u9875\u538b\u7f29\u751f\u6548\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0cInnoDB\u9875\u5927\u5c0f16K\uff0c\u6587\u4ef6\u7cfb\u7edf\u5757\u5927\u5c0f4K\uff0c\u9875\u6570\u636e\u5fc5\u987b\u88ab\u538b\u7f29\u5230\u5c0f\u4e8e\u7b49\u4e8e12K\uff0c\u624d\u80fd\u4f7f\u7528\u6253\u5b54\u673a\u5236\uff0c\u51cf\u5c11\u78c1\u76d8\u7a7a\u95f4\u5360\u7528\u3002<br \/>\n\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u7a00\u758f\u6587\u4ef6\u57fa\u4e8eNTFS\u6587\u4ef6\u7cfb\u7edf\u538b\u7f29\u529f\u80fd\u5b9e\u73b0\uff0c\u6253\u5b54\u5355\u4f4d\u5c3a\u5bf8\u4e3aNTFS\u538b\u7f29\u5355\u5143\u5c3a\u5bf8\uff0c\u8fd9\u4e2a\u5c3a\u5bf8\u662fNTFS\u7c07\u5927\u5c0f\u768416\u500d\u3002NTFS\u7c07\u5927\u5c0f\u4e0e\u538b\u7f29\u5355\u5143\u5927\u5c0f\u5bf9\u5e94\u5173\u7cfb\u5982\u4e0b\u8868\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>NTFS\u7c07\u5927\u5c0f<\/th>\n<th>NTFS\u538b\u7f29\u5355\u5143\u5927\u5c0f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>512Bytes<\/td>\n<td>8KB<\/td>\n<\/tr>\n<tr>\n<td>1KB<\/td>\n<td>16KB<\/td>\n<\/tr>\n<tr>\n<td>2KB<\/td>\n<td>32KB<\/td>\n<\/tr>\n<tr>\n<td>4KB<\/td>\n<td>64KB<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u540c\u6837\u7684\uff0c\u53ea\u6709\u5f53\u538b\u7f29\u540e\u7684\u6570\u636e\u5c0f\u4e8e\u7b49\u4e8eInnoDB\u9875\u5927\u5c0f\u51cf\u53bb\u538b\u7f29\u5355\u5143\u7684\u5927\u5c0f\u65f6\uff0c\u624d\u80fd\u4f7f\u9875\u538b\u7f29\u751f\u6548\u3002\u9ed8\u8ba4\u7684NTFS\u7c07\u5927\u5c0f4KB\uff0c\u538b\u7f29\u5355\u5143\u5927\u5c0f64KB\uff0c\u8fd9\u5c31\u610f\u5473\u7740NTFS\u9ed8\u8ba4\u914d\u7f6e\u4e0b\uff0c\u65e0\u6cd5\u4f7f\u7528\u9875\u538b\u7f29\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8981\u60f3\u9875\u538b\u7f29\u5728NTFS\u6587\u4ef6\u7cfb\u7edf\u4e0a\u751f\u6548\uff0c\u9700\u8981\u8bbe\u7f6eNTFS\u7c07\u5927\u5c0f\u4e3a512Bytes\uff0c\u6b64\u65f6\u538b\u7f29\u5355\u5143\u5927\u5c0f\u4e3a8KB\uff0c\u8bbe\u7f6eInnoDB\u9875\u5927\u5c0f\u4e3a\u9ed8\u8ba4\u768416KB\uff0c\u6216\u8005\u66f4\u5927\u768432KB\u300164KB\uff0c\u624d\u80fd\u4f7f\u9875\u538b\u7f29\u751f\u6548\u3002<\/p>\n<h4>3. \u9875\u538b\u7f29\u7684\u5143\u6570\u636e<\/h4>\n<p>\u7cfb\u7edf\u8868 INNODB_SYS_TABLESPACES \u5b58\u50a8\u4e86\u9875\u538b\u7f29\u76f8\u5173\u7684\u5143\u6570\u636e\uff0c\u5176\u4e3b\u8981\u5b57\u6bb5\u542b\u4e49\u5982\u4e0b\uff1a<br \/>\nINFORMATION_SCHEMA.INNODB_SYS_TABLESPACES<\/p>\n<ol>\n<li>FS_BLOCK_SIZE\uff1a\u6587\u4ef6\u7cfb\u7edf\u5757\u5c3a\u5bf8\uff0c\u6253\u5b54\u5355\u5143\u7684\u5927\u5c0f\u3002<\/li>\n<li>FILE_SIZE\uff1a\u8868\u793a\u672a\u538b\u7f29\u6587\u4ef6\u7684\u5c3a\u5bf8\u3002<\/li>\n<li>ALLOCATED_SIZE\uff1a\u5728\u78c1\u76d8\u4e0a\u5206\u914d\u7684\u6587\u4ef6\u7684\u5b9e\u9645\u5c3a\u5bf8\u3002<\/li>\n<\/ol>\n<p>\u4f7f\u7528\u9875\u538b\u7f29\u529f\u80fd\u540e\uff0cls\u547d\u4ee4\u663e\u793a\u7684\u5927\u5c0f\u662f\u672a\u538b\u7f29\u7684\u5927\u5c0f\uff0c\u800c\u5b9e\u9645\u7684\u5927\u5c0f\u4f7f\u7528du\u547d\u4ee4\u67e5\u770b\u3002<\/p>\n<ul>\n<li>ls -l\u00a0tablespace_name.ibd\uff0c\u663e\u793aFILE_SIZE\u5927\u5c0f<\/li>\n<li>du &#8211;block-size=1\u00a0tablespace_name.ibd\uff0c\u663e\u793aALLOCATED_SIZE\u5927\u5c0f<\/li>\n<\/ul>\n<h4>4. \u9875\u538b\u7f29\u7684\u9650\u5236\u548c\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879<\/h4>\n<ol>\n<li>\u5982\u679c\u6587\u4ef6\u7cfb\u7edf\u5757\u5927\u5c0f\u6216\u8005\u538b\u7f29\u5355\u5143\u5927\u5c0f\u4e58\u4ee52\u5927\u4e8einnodb\u9875\u5927\u5c0f\u65f6\uff0c\u9875\u538b\u7f29\u5c06\u81ea\u52a8\u5931\u6548\u3002<\/li>\n<li>\u5171\u4eab\u8868\u7a7a\u95f4\uff08\u7cfb\u7edf\u8868\u7a7a\u95f4\uff0c\u4e34\u65f6\u8868\u7a7a\u95f4\uff0c\u901a\u7528\u8868\u7a7a\u95f4\uff09\u4e2d\u7684\u8868\u4e0d\u652f\u6301\u9875\u538b\u7f29\u3002<\/li>\n<li>undo log \u548c redo log \u8868\u7a7a\u95f4\u4e0d\u652f\u6301\u9875\u538b\u7f29\u3002<\/li>\n<li>\u7a7a\u95f4\u7d22\u5f15 R-tree \u9875 \u4e0d\u652f\u6301\u9875\u538b\u7f29\u3002<\/li>\n<li>\u884c\u683c\u5f0f\u538b\u7f29\u8fc7\u7684\u8868(ROW_FORMAT=COMPRESSED)\uff0c\u4e0d\u652f\u6301\u9875\u538b\u7f29\u3002<\/li>\n<li>\u5728InnoDB\u5d29\u6e83\u6062\u590d\u8fc7\u7a0b\u4e2d\uff0c\u66f4\u65b0\u7684\u9875\u9762\u5c06\u4ee5\u672a\u538b\u7f29\u7684\u5f62\u5f0f\u5199\u51fa\u3002<\/li>\n<li>\u5728\u4e00\u4e2a\u4e0d\u652f\u6301\u538b\u7f29\u7b97\u6cd5\u7684\u670d\u52a1\u5668\u4e0a\u52a0\u8f7d\u9875\u538b\u7f29\u540e\u7684\u8868\u7a7a\u95f4\uff0c\u4f1a\u5bfc\u81f4I\/O\u9519\u8bef\u3002<\/li>\n<li>\u4f7f\u7528\u4e00\u4e2a\u8f83\u5927\u7684innodb\u9875\u5927\u5c0f\uff0c\u6bd4\u598264KB\uff0c\u6587\u4ef6\u7cfb\u7edf\u5757\u5927\u5c0f4KB\uff0c\u8fd9\u6837\u7684\u914d\u7f6e\u80fd\u591f\u63d0\u9ad8\u538b\u7f29\u6548\u679c\uff0c\u4f46\u662f\u540c\u65f6\u4e5f\u4f1a\u5bfc\u81f4\u5199\u653e\u5927\uff0c\u9700\u8981\u66f4\u5927\u7684buffer pool\uff0c\u589e\u52a0I\/O\u6d88\u8017\u3002<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL InnoDB\u652f\u6301\u6570\u636e\u538b\u7f29\uff0c\u6709\u4e24\u79cd\u6570\u636e\u538b\u7f29\u65b9\u5f0f\uff0c\u7b2c\u4e00\u79cd\u4e3a\u8868\u538b\u7f29\uff0c\u901a\u5e38\u4e5f\u79f0\u4e4b\u4e3a\u884c\u683c\u5f0f\u538b\u7f29\uff0c\u53e6\u5916\u4e00\u79cd\u662f\u9875 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5404\"> <span class=\"screen-reader-text\">MySQL InnoDB \u900f\u660e\u9875\u538b\u7f29(Page Compression)<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL InnoDB\u652f\u6301\u6570\u636e\u538b\u7f29\uff0c\u6709\u4e24\u79cd\u6570\u636e\u538b\u7f29\u65b9\u5f0f\uff0c\u7b2c\u4e00\u79cd\u4e3a\u8868\u538b\u7f29\uff0c\u901a\u5e38\u4e5f\u79f0\u4e4b\u4e3a\u884c\u683c\u5f0f\u538b\u7f29\uff0c\u53e6\u5916\u4e00\u79cd\u662f\u9875&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5404"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5404"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5404\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5404"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}