{"id":28108,"date":"2024-11-24T15:14:38","date_gmt":"2024-11-24T07:14:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28108\/"},"modified":"2024-11-24T15:14:38","modified_gmt":"2024-11-24T07:14:38","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28108\/","title":{"rendered":"\u4f7f\u7528 explain \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173139876487743.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 expln \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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528 expln \u5982\u4f55\u5224\u65ad\u4e8c\u7ea7\u7d22\u5f15\u4f7f\u7528\u540e\u662f\u5426\u56de\u8868\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 expln \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 where created_at &gt;= [&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-28108","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28108","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=28108"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28108\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}