{"id":200742,"date":"2025-05-06T14:12:01","date_gmt":"2025-05-06T06:12:01","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200742\/"},"modified":"2025-05-06T14:12:01","modified_gmt":"2025-05-06T06:12:01","slug":"mysql-%e5%88%a0%e9%99%a4%e6%95%b0%e6%8d%ae%e6%97%b6%e4%bd%95%e6%97%b6%e4%bc%9a%e8%b5%b0%e8%81%94%e5%90%88%e7%b4%a2%e5%bc%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200742\/","title":{"rendered":"MySQL \u5220\u9664\u6570\u636e\u65f6\u4f55\u65f6\u4f1a\u8d70\u8054\u5408\u7d22\u5f15\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MySQL \u5220\u9664\u6570\u636e\u65f6\u4f55\u65f6\u4f1a\u8d70\u8054\u5408\u7d22\u5f15\uff1f<\/h1>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241113\/1731470616673425183bcb1.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>mysql \u5220\u9664\u6570\u636e\u65f6\u8d70\u7d22\u5f15\u7684\u6761\u4ef6<\/strong><\/p>\n<p>\u5728\u4e00\u4e2a\u7528\u6237\u8868\u4e2d\u6709\u5b57\u6bb5 id\u3001name\u3001age\u3001sex\u3001work \u548c city\uff0c\u8054\u5408\u7d22\u5f15\u4e3a (sex, city)\u3002\u73b0\u5728\u8981\u5220\u9664 sex=\u7537\u3001city=\u5317\u4eac \u7684\u6570\u636e\uff0c\u4f1a\u4e0d\u4f1a\u4f7f\u7528\u8054\u5408\u7d22\u5f15\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u5728 mysql \u4e2d\uff0c\u5f53\u6d89\u53ca\u7684\u6570\u636e\u91cf\u8d85\u8fc7 20% \u65f6\uff0c\u4e0d\u4f1a\u4f7f\u7528\u7d22\u5f15\u3002\u56e0\u6b64\uff0c\u5982\u679c\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u91cf\u8d85\u8fc7\u8868\u603b\u6570\u636e\u91cf\u7684 20%\uff0c\u5219\u4e0d\u4f1a\u8d70\u7d22\u5f15\u3002<\/p>\n<p><strong>\u5b9e\u8df5\u9a8c\u8bc1\uff1a<\/strong><\/p>\n<ul>\n<li>\u8868\u603b\u6570\u636e\u91cf\uff1a1602 \u6761<\/li>\n<li>\n<p>\u7b26\u5408\u6761\u4ef6\uff08sex, city\uff09\u6761\u6570\uff1a<\/p>\n<ul>\n<li>\u5973\uff0c\u5e7f\u5dde\uff1a604 \u6761<\/li>\n<li>\u5973\uff0c\u60e0\u5dde\uff1a6 \u6761<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u6267\u884c\u5220\u9664\u8bed\u53e5\u7684 explain \u7ed3\u679c\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u5973\uff0c\u5e7f\u5dde\uff1a\u7b26\u5408\u6761\u4ef6\u6570\u636e\u91cf\u8d85\u8fc7 20%\uff0c<\/strong>\u4e0d\u4f1a\u4f7f\u7528\u7d22\u5f15\u3002<\/p>\n<pre>explain delete from  test_del_idx where sex=\"\u5973\" and city = \"\u5e7f\u5dde\";<\/pre>\n<p>\u8fd4\u56de\u7ed3\u679c\uff1a<\/p>\n<\/li>\n<\/ul>\n<pre>+----+-------------+--------------+------------+------+---------------+------+---------+------+------+----------+-------------+\n| id | select_type | table        | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | extra       |\n+----+-------------+--------------+------------+------+---------------+------+---------+------+------+----------+-------------+\n|  1 | delete      | test_del_idx | null       | all  | idx_sex_city  | null | null    | null | 1602 |   100.00 | using where |\n+----+-------------+--------------+------------+------+---------------+------+---------+------+------+----------+-------------+<\/pre>\n<ul>\n<li>\n<p><strong>\u5973\uff0c\u60e0\u5dde\uff1a\u7b26\u5408\u6761\u4ef6\u6570\u636e\u91cf\u5c11\u4e8e 20%\uff0c<\/strong>\u4f1a\u4f7f\u7528\u7d22\u5f15\u3002<\/p>\n<pre>explain delete from  test_del_idx where sex=\"\u5973\" and city = \"\u60e0\u5dde\";<\/pre>\n<\/li>\n<\/ul>\n<p>\u8fd4\u56de\u7ed3\u679c\uff1a<\/p>\n<pre>+----+-------------+--------------+------------+-------+---------------+--------------+---------+-------------+------+----------+-------------+\n| id | select_type | table        | partitions | type  | possible_keys | key          | key_len | ref         | rows | filtered | Extra       |\n+----+-------------+--------------+------------+-------+---------------+--------------+---------+-------------+------+----------+-------------+\n|  1 | DELETE      | test_del_idx | NULL       | range | idx_sex_city  | idx_sex_city | 773     | const,const |    6 |   100.00 | Using where |\n+----+-------------+--------------+------------+-------+---------------+--------------+---------+-------------+------+----------+-------------+<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300aMySQL \u5220\u9664\u6570\u636e\u65f6\u4f55\u65f6\u4f1a\u8d70\u8054\u5408\u7d22\u5f15\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u5220\u9664\u6570\u636e\u65f6\u4f55\u65f6\u4f1a\u8d70\u8054&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200742","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200742"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200742\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}