{"id":31758,"date":"2023-05-26T11:13:51","date_gmt":"2023-05-26T03:13:51","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=31758"},"modified":"2023-07-31T00:11:00","modified_gmt":"2023-07-30T16:11:00","slug":"select-%e6%95%88%e7%8e%87%e4%bd%8e%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/31758.html","title":{"rendered":"SELECT * \u6548\u7387\u4f4e\u7684\u539f\u56e0\u662f\u4ec0\u4e48"},"content":{"rendered":"<blockquote class=\"wp-block-quote\">\n<p>SELECT * \u6548\u7387\u4f4e\u7684\u539f\u56e0\u662f\uff1a1. \u4e0d\u9700\u8981\u7684\u5217\u4f1a\u589e\u52a0\u6570\u636e\u4f20\u8f93\u65f6\u95f4\u548c\u7f51\u7edc\u5f00\u9500\uff1b2. \u5bf9\u4e8e\u65e0\u7528\u7684\u5927\u5b57\u6bb5\uff0c\u5982 varchar\u3001blob\u3001text\uff0c\u4f1a\u589e\u52a0 io \u64cd\u4f5c\uff1b3. \u5931\u53bbMySQL\u4f18\u5316\u5668\u201c\u8986\u76d6\u7d22\u5f15\u201d\u7b56\u7565\u4f18\u5316\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<\/blockquote>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" alt=\"\" class=\"wp-image-31759\" decoding=\"async\" height=\"421\" sizes=\"(max-width: 680px) 100vw, 680px\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/\u6dfb\u52a0\u6807\u9898-16-13.png?x-oss-process=image\/auto-orient,1\/format,webp\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/\u6dfb\u52a0\u6807\u9898-16-13.png?x-oss-process=image\/auto-orient,1\/format,webp 680w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/05\/\u6dfb\u52a0\u6807\u9898-16-13-300x186.png 300w\" width=\"680\"\/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001SELECT * \u6548\u7387\u4f4e\u7684\u539f\u56e0<\/strong><\/h2>\n<p><strong>1. <\/strong><strong>\u4e0d\u9700\u8981\u7684\u5217\u4f1a\u589e\u52a0\u6570\u636e\u4f20\u8f93\u65f6\u95f4\u548c\u7f51\u7edc\u5f00\u9500<\/strong><\/p>\n<ol start=\"1\" type=\"1\">\n<li>\u7528\u201cSELECT * \u201d\u6570\u636e\u5e93\u9700\u8981\u89e3\u6790\u66f4\u591a\u7684\u5bf9\u8c61\u3001\u5b57\u6bb5\u3001\u6743\u9650\u3001\u5c5e\u6027\u7b49\u76f8\u5173\u5185\u5bb9\uff0c\u5728 SQL \u8bed\u53e5\u590d\u6742\uff0c\u786c\u89e3\u6790\u8f83\u591a\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u5bf9\u6570\u636e\u5e93\u9020\u6210\u6c89\u91cd\u7684\u8d1f\u62c5\u3002<\/li>\n<li>\u589e\u5927\u7f51\u7edc\u5f00\u9500\uff1b* \u6709\u65f6\u4f1a\u8bef\u5e26\u4e0a\u5982log\u3001IconMD5\u4e4b\u7c7b\u7684\u65e0\u7528\u4e14\u5927\u6587\u672c\u5b57\u6bb5\uff0c\u6570\u636e\u4f20\u8f93size\u4f1a\u51e0\u4f55\u589e\u6da8\u3002\u5982\u679cDB\u548c\u5e94\u7528\u7a0b\u5e8f\u4e0d\u5728\u540c\u4e00\u53f0\u673a\u5668\uff0c\u8fd9\u79cd\u5f00\u9500\u975e\u5e38\u660e\u663e<\/li>\n<li>\u5373\u4f7f mysql \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u662f\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\uff0c\u4f7f\u7528\u7684\u534f\u8bae\u8fd8\u662f tcp\uff0c\u901a\u4fe1\u4e5f\u662f\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u3002<\/li>\n<\/ol>\n<p><strong>2. <\/strong><strong>\u5bf9\u4e8e\u65e0\u7528\u7684\u5927\u5b57\u6bb5\uff0c\u5982 varchar\u3001blob\u3001text\uff0c\u4f1a\u589e\u52a0 io \u64cd\u4f5c<\/strong><\/p>\n<p>\u51c6\u786e\u6765\u8bf4\uff0c\u957f\u5ea6\u8d85\u8fc7 728 \u5b57\u8282\u7684\u65f6\u5019\uff0c\u4f1a\u5148\u628a\u8d85\u51fa\u7684\u6570\u636e\u5e8f\u5217\u5316\u5230\u53e6\u5916\u4e00\u4e2a\u5730\u65b9\uff0c\u56e0\u6b64\u8bfb\u53d6\u8fd9\u6761\u8bb0\u5f55\u4f1a\u589e\u52a0\u4e00\u6b21 io \u64cd\u4f5c\u3002\uff08MySQL InnoDB\uff09<\/p>\n<p><strong>3. <\/strong><strong>\u5931\u53bbMySQL\u4f18\u5316\u5668\u201c\u8986\u76d6\u7d22\u5f15\u201d\u7b56\u7565\u4f18\u5316\u7684\u53ef\u80fd\u6027<\/strong><\/p>\n<p>SELECT * \u675c\u7edd\u4e86\u8986\u76d6\u7d22\u5f15\u7684\u53ef\u80fd\u6027\uff0c\u800c\u57fa\u4e8eMySQL\u4f18\u5316\u5668\u7684\u201c\u8986\u76d6\u7d22\u5f15\u201d\u7b56\u7565\u53c8\u662f\u901f\u5ea6\u6781\u5feb\uff0c\u6548\u7387\u6781\u9ad8\uff0c\u4e1a\u754c\u6781\u4e3a\u63a8\u8350\u7684\u67e5\u8be2\u4f18\u5316\u65b9\u5f0f\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6709\u4e00\u4e2a\u8868\u4e3at(a,b,c,d,e,f)\uff0c\u5176\u4e2d\uff0ca\u4e3a\u4e3b\u952e\uff0cb\u5217\u6709\u7d22\u5f15\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u5728\u78c1\u76d8\u4e0a\u6709\u4e24\u68f5 B+ \u6811\uff0c\u5373\u805a\u96c6\u7d22\u5f15\u548c\u8f85\u52a9\u7d22\u5f15\uff08\u5305\u62ec\u5355\u5217\u7d22\u5f15\u3001\u8054\u5408\u7d22\u5f15\uff09\uff0c\u5206\u522b\u4fdd\u5b58(a,b,c,d,e,f)\u548c(a,b)\uff0c\u5982\u679c\u67e5\u8be2\u6761\u4ef6\u4e2dwhere\u6761\u4ef6\u53ef\u4ee5\u901a\u8fc7b\u5217\u7684\u7d22\u5f15\u8fc7\u6ee4\u6389\u4e00\u90e8\u5206\u8bb0\u5f55\uff0c\u67e5\u8be2\u5c31\u4f1a\u5148\u8d70\u8f85\u52a9\u7d22\u5f15\uff0c\u5982\u679c\u7528\u6237\u53ea\u9700\u8981a\u5217\u548cb\u5217\u7684\u6570\u636e\uff0c\u76f4\u63a5\u901a\u8fc7\u8f85\u52a9\u7d22\u5f15\u5c31\u53ef\u4ee5\u77e5\u9053\u7528\u6237\u67e5\u8be2\u7684\u6570\u636e\u3002<\/p>\n<p>\u5982\u679c\u7528\u6237\u4f7f\u7528select *\uff0c\u83b7\u53d6\u4e86\u4e0d\u9700\u8981\u7684\u6570\u636e\uff0c\u5219\u9996\u5148\u901a\u8fc7\u8f85\u52a9\u7d22\u5f15\u8fc7\u6ee4\u6570\u636e\uff0c\u7136\u540e\u518d\u901a\u8fc7\u805a\u96c6\u7d22\u5f15\u83b7\u53d6\u6240\u6709\u7684\u5217\uff0c\u8fd9\u5c31\u591a\u4e86\u4e00\u6b21b+\u6811\u67e5\u8be2\uff0c\u901f\u5ea6\u5fc5\u7136\u4f1a\u6162\u5f88\u591a\u3002<\/p>\n<p><strong>\u5ef6\u4f38\u9605\u8bfb\uff1a<\/strong><\/p>\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u8054\u5408\u7d22\u5f15 (a,b,c)<\/strong><\/h2>\n<p>\u8054\u5408\u7d22\u5f15 (a,b,c) \u5b9e\u9645\u5efa\u7acb\u4e86 (a)\u3001(a,b)\u3001(a,b,c) \u4e09\u4e2a\u7d22\u5f15\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u7ec4\u5408\u7d22\u5f15\u60f3\u6210\u4e66\u7684\u4e00\u7ea7\u76ee\u5f55\u3001\u4e8c\u7ea7\u76ee\u5f55\u3001\u4e09\u7ea7\u76ee\u5f55\uff0c\u5982index(a,b,c)\uff0c\u76f8\u5f53\u4e8ea\u662f\u4e00\u7ea7\u76ee\u5f55\uff0cb\u662f\u4e00\u7ea7\u76ee\u5f55\u4e0b\u7684\u4e8c\u7ea7\u76ee\u5f55\uff0cc\u662f\u4e8c\u7ea7\u76ee\u5f55\u4e0b\u7684\u4e09\u7ea7\u76ee\u5f55\u3002\u8981\u4f7f\u7528\u67d0\u4e00\u76ee\u5f55\uff0c\u5fc5\u987b\u5148\u4f7f\u7528\u5176\u4e0a\u7ea7\u76ee\u5f55\uff0c\u4e00\u7ea7\u76ee\u5f55\u9664\u5916\u3002<\/p>\n<p><strong>\u8054\u5408\u7d22\u5f15\u7684\u4f18\u52bf<\/strong><\/p>\n<p><strong>1<\/strong><strong>\uff09 \u51cf\u5c11\u5f00\u9500<\/strong><\/p>\n<p>\u5efa\u4e00\u4e2a\u8054\u5408\u7d22\u5f15 (a,b,c) \uff0c\u5b9e\u9645\u76f8\u5f53\u4e8e\u5efa\u4e86 (a)\u3001(a,b)\u3001(a,b,c) \u4e09\u4e2a\u7d22\u5f15\u3002\u6bcf\u591a\u4e00\u4e2a\u7d22\u5f15\uff0c\u90fd\u4f1a\u589e\u52a0\u5199\u64cd\u4f5c\u7684\u5f00\u9500\u548c\u78c1\u76d8\u7a7a\u95f4\u7684\u5f00\u9500\u3002\u5bf9\u4e8e\u5927\u91cf\u6570\u636e\u7684\u8868\uff0c\u4f7f\u7528\u8054\u5408\u7d22\u5f15\u4f1a\u5927\u5927\u7684\u51cf\u5c11\u5f00\u9500\uff01<\/p>\n<p><strong>2<\/strong><strong>\uff09\u8986\u76d6\u7d22\u5f15<\/strong><\/p>\n<p>\u5bf9\u8054\u5408\u7d22\u5f15 (a,b,c)\uff0c\u5982\u679c\u6709\u5982\u4e0b sql \u7684\uff0c<\/p>\n<ul>\n<li>\u00a0<\/li>\n<\/ul>\n<p>SELECT a,b,c from table where a=\u2019xx\u2019 and b = \u2018xx\u2019;<\/p>\n<p>\u90a3\u4e48 MySQL \u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u904d\u5386\u7d22\u5f15\u53d6\u5f97\u6570\u636e\uff0c\u800c\u65e0\u9700\u56de\u8868\uff0c\u8fd9\u51cf\u5c11\u4e86\u5f88\u591a\u7684\u968f\u673a io \u64cd\u4f5c\u3002\u51cf\u5c11 io \u64cd\u4f5c\uff0c\u7279\u522b\u662f\u968f\u673a io \u5176\u5b9e\u662f DBA \u4e3b\u8981\u7684\u4f18\u5316\u7b56\u7565\u3002\u6240\u4ee5\uff0c\u5728\u771f\u6b63\u7684\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u8986\u76d6\u7d22\u5f15\u662f\u4e3b\u8981\u7684\u63d0\u5347\u6027\u80fd\u7684\u4f18\u5316\u624b\u6bb5\u4e4b\u4e00\u3002<\/p>\n<p><strong>3<\/strong><strong>\uff09\u6548\u7387\u9ad8<\/strong><\/p>\n<p>\u7d22\u5f15\u5217\u591a\uff0c\u901a\u8fc7\u8054\u5408\u7d22\u5f15\u7b5b\u9009\u51fa\u7684\u6570\u636e\u8d8a\u5c11\u3002\u6bd4\u5982\u6709 1000W \u6761\u6570\u636e\u7684\u8868\uff0c\u6709\u5982\u4e0bSQL:<\/p>\n<ul>\n<li>\u00a0<\/li>\n<\/ul>\n<p>select col1,col2,col3 from table where col1=1 and col2=2 and col3=3;<\/p>\n<p>\u590d\u5236<\/p>\n<p>\u5047\u8bbe\uff1a\u5047\u8bbe\u6bcf\u4e2a\u6761\u4ef6\u53ef\u4ee5\u7b5b\u9009\u51fa 10% \u7684\u6570\u636e\u3002<\/p>\n<ul>\n<li>A. \u5982\u679c\u53ea\u6709\u5355\u5217\u7d22\u5f15\uff0c\u90a3\u4e48\u901a\u8fc7\u8be5\u7d22\u5f15\u80fd\u7b5b\u9009\u51fa 1000W10%=100w \u6761\u6570\u636e\uff0c\u7136\u540e\u518d\u56de\u8868\u4ece 100w \u6761\u6570\u636e\u4e2d\u627e\u5230\u7b26\u5408 col2=2 and col3= 3 \u7684\u6570\u636e\uff0c\u7136\u540e\u518d\u6392\u5e8f\uff0c\u518d\u5206\u9875\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff08\u9012\u5f52\uff09\uff1b<\/li>\n<li>B. \u5982\u679c\u662f\uff08col1,col2,col3\uff09\u8054\u5408\u7d22\u5f15\uff0c\u901a\u8fc7\u4e09\u5217\u7d22\u5f15\u7b5b\u9009\u51fa 1000w10% 10% *10%=1w\uff0c\u6548\u7387\u63d0\u5347\u53ef\u60f3\u800c\u77e5\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"SELECT * \u6548\u7387\u4f4e\u7684\u539f\u56e0\u662f\uff1a1. \u4e0d\u9700\u8981\u7684\u5217\u4f1a\u589e\u52a0\u6570\u636e\u4f20\u8f93\u65f6\u95f4\u548c\u7f51\u7edc\u5f00\u9500\uff1b2. \u5bf9\u4e8e\u65e0\u7528\u7684\u5927\u5b57\u6bb5\uff0c\u5982 v [&hellip;]","protected":false},"author":1,"featured_media":31759,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/31758"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=31758"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/31758\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/31759"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=31758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=31758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=31758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}