{"id":45594,"date":"2024-12-01T14:52:50","date_gmt":"2024-12-01T06:52:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/45594\/"},"modified":"2024-12-01T14:52:50","modified_gmt":"2024-12-01T06:52:50","slug":"%e4%bd%bf%e7%94%a8-explain-%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e4%ba%8c%e7%ba%a7%e7%b4%a2%e5%bc%95%e4%bd%bf%e7%94%a8%e5%90%8e%e6%98%af%e5%90%a6%e5%9b%9e%e8%a1%a8%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/45594\/","title":{"rendered":"\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f<\/h1>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241113\/173146686467341670e4c97.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 explain \u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\uff0c\u662f\u5426\u5b58\u5728\u56de\u8868\u64cd\u4f5c\uff1f<\/strong><\/p>\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u67e5\u8be2 sql\uff1a<\/p>\n<pre>select\n    track_source_id,\n    date_format(created_at, '%y-%m-%d') as day,\n    count(*) as total_count,\n    sum(case when len_parse_result_list = 0 then 1 else 0 end) as len_parse_result_list_zero_count,\n    sum(case when len_parse_result_list is null then 1 else 0 end) as len_parse_result_list_null_count,\n    sum(case when len_parse_result_list &gt; 0 then 1 else 0 end) as len_parse_result_list_gte_zero_count\nfrom\n    keywordtask\nwhere\n    created_at &gt;= now() - interval 30 day\ngroup by\n    track_source_id,\n    day\norder by\n    track_source_id,\n    day;<\/pre>\n<p>\u5176 explain \u8f93\u51fa\uff1a<\/p>\n<pre>| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |\n| --- | ----------- | ----- | ---------- | ---- | ------------- | --- | ------ | --- | ---- | -------- | ----- |\n| 1   | SIMPLE      | keywordtask | NULL      | index | idx_created_at,idx_track_source_id_created_at_len_parse_result_list | idx_track_source_id_created_at_len_parse_result_list | 14 | NULL | 134324154 | 50.0 | Using where; Using index; Using temporary; Using filesort |<\/pre>\n<p><strong>\u662f\u5426\u56de\u8868\u5224\u65ad\uff1a<\/strong><\/p>\n<p>\u901a\u8fc7\u8bfb\u53d6 extra \u5217\uff0c\u53ef\u4ee5\u5224\u65ad\u67e5\u8be2\u662f\u5426\u56de\u8868\uff1a<\/p>\n<ul>\n<li><strong>using index<\/strong> \u8868\u793a\u7d22\u5f15\u8986\u76d6\uff0c\u4e0d\u9700\u8981\u56de\u8868\u3002<\/li>\n<li><strong>using index condition<\/strong> \u8868\u793a\u7d22\u5f15\u67e5\u627e\uff0c\u4e0d\u9700\u8981\u56de\u8868\u8fc7\u6ee4\u3002<\/li>\n<li><strong>using index &amp; using where<\/strong> \u8868\u793a\u7d22\u5f15\u67e5\u627e\uff0c\u4f46\u9700\u8981\u56de\u8868\u8fc7\u6ee4\u3002<\/li>\n<li><strong>using where<\/strong> \u8868\u793a\u56de\u8868\u67e5\u8be2\u6570\u636e\u3002<\/li>\n<li><strong>\u4e3b\u952e\u67e5\u8be2<\/strong> \u4e0d\u56de\u8868\uff0c\u4f46 extra \u5217\u65e0\u6cd5\u53cd\u6620\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u67e5\u8be2\uff0cextra \u5217\u4e3a <strong>using where; using index; using temporary; using filesort<\/strong>\uff0c\u8868\u660e\u67e5\u8be2\u4f7f\u7528\u4e86\u7d22\u5f15 (idx_track_source_id_created_at_len_parse_result_list)\uff0c\u4f46\u9700\u8981\u56de\u8868\u8fc7\u6ee4\u6761\u4ef6 created_at &gt;= now() &#8211; interval 30 day\u3002\u56e0\u6b64\uff0c\u8be5\u67e5\u8be2\u4f1a\u53d1\u751f\u56de\u8868\u64cd\u4f5c\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6570\u636e\u5e93\u77e5\u8bc6\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f \u5982\u4f55\u4f7f\u7528 explain \u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\uff0c\u662f\u5426\u5b58\u5728\u56de\u8868\u64cd\u4f5c\uff1f \u5bf9\u4e8e\u7ed9\u5b9a\u7684\u67e5\u8be2 sql\uff1a select track_source_id, date_format(created_at, &#8216;%y-%m-%d&#8217;) as day, count(*) as total_count, sum(case when len_parse_result_list = 0 then 1 else 0 end) as len_parse_result_list_zero_count, sum(case when len_parse_result_list is null then 1 else 0 end) as len_parse_result_list_null_count, sum(case when len_parse_result_list &gt; 0 then 1 else 0 end) as len_parse_result_list_gte_zero_count from keywordtask [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-45594","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/45594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=45594"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/45594\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=45594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=45594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=45594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}