{"id":542,"date":"2008-10-24T00:00:00","date_gmt":"2008-10-23T16:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=542"},"modified":"2011-03-19T13:44:44","modified_gmt":"2011-03-19T05:44:44","slug":"%e5%88%a9%e7%94%a8%e4%b8%b4%e6%97%b6%e8%a1%a8%ef%bc%8c%e5%8a%a0%e5%bf%ab%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e7%9a%84%e6%89%a7%e8%a1%8c%e9%80%9f%e5%ba%a6%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=542","title":{"rendered":"\u5229\u7528\u4e34\u65f6\u8868\uff0c\u52a0\u5feb\u5b58\u50a8\u8fc7\u7a0b\u7684\u6267\u884c\u901f\u5ea6\u3002"},"content":{"rendered":"<p><P>\u5229\u7528\u4e34\u65f6\u8868\uff0c\u52a0\u5feb\u5b58\u50a8\u8fc7\u7a0b\u7684\u6267\u884c\u901f\u5ea6\u3002<\/P><br \/>\n<P>\u80cc\u666f\uff1a<BR>\u3000\u3000\u4e00\u4e2a\u535a\u5ba2\u7f51\u7ad9\u8bbf\u95ee\u6d41\u91cf\u8868\uff0c\u6bcf\u5929\u6709\u5927\u7ea6\uff11\uff10\uff10\u4e07\u6761\u6570\u636e\u63d2\u5165\uff0c\u8bb0\u5f55\u6bcf\u4e2a\u535a\u5ba2\u53ca\u7f51\u7ad9\u7684\u8bbf\u95ee\u60c5\u51b5\u3002\u8868\u7ed3\u6784\uff1a<BR>mysql&gt; show fields from blog_track;<BR>+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+<BR>| Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Null | Key | Default | Extra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+<BR>| track_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | int(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | NO&nbsp;&nbsp; | PRI | NULL&nbsp;&nbsp;&nbsp; | auto_increment | <BR>| track_ip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | char(15)&nbsp;&nbsp;&nbsp;&nbsp; | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>| track_date&nbsp;&nbsp;&nbsp;&nbsp; | datetime&nbsp;&nbsp;&nbsp;&nbsp; | NO&nbsp;&nbsp; | MUL |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>| track_page&nbsp;&nbsp;&nbsp;&nbsp; | varchar(256) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>| track_refferer | varchar(500) | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>| member_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | int(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | NO&nbsp;&nbsp; | MUL | 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>| visiter_id&nbsp;&nbsp;&nbsp;&nbsp; | int(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | NO&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>| track_type&nbsp;&nbsp;&nbsp;&nbsp; | tinyint(4)&nbsp;&nbsp; | NO&nbsp;&nbsp; | MUL | 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | <BR>+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+<\/P><br \/>\n<P><BR>\u6bcf\u9694\uff12\u5c0f\u65f6\u5c31\u4f1a\u5229\u7528\u5b58\u50a8\u8fc7\u7a0b\u5bf9\u8fd9\u4e2a\u8868\u8fdb\u884c\u7edf\u8ba1\uff0c\u5305\u62ec\u7edf\u8ba1\u5f53\u5929\u7684\uff29\uff30\u53ca\uff30\uff36\u3002<\/P><br \/>\n<P>CREATE <A href=\"mailto:DEFINER=`root`@`%\">DEFINER=`root`@`%<\/A>` PROCEDURE `prc_anaylise_track`()<BR>BEGIN<\/P><br \/>\n<P>declare time_now datetime;<BR>DROP TABLE IF EXISTS tmp_tables;<BR>CREATE TEMPORARY TABLE tmp_tables (<BR>blog_id int NOT NULL,<BR>count int NOT NULL,<BR>ip char(15) null<BR>) engine = HEAP;<BR>set time_now = now();<BR>insert into tmp_tables(count,blog_id,ip) select count(*) as count,member_id as blog_id,track_ip as ip&nbsp; from blog_track where track_type=0 and track_date&gt;=date_format(now(),&#8217;%Y-%m-%d 00:00:00&#8242;) and member_id&gt;0 group by track_ip,member_id;<BR>update blog_info set blog_info.today_ip = (select count(*) as count from tmp_tables where blog_info.member_id=tmp_tables.blog_id);<BR>delete from tmp_tables;<BR>select concat(&#8216;count today ip count need time : &#8216;,(unix_timestamp(now()) &#8211; unix_timestamp(time_now))) as neetTime;<BR>END<\/P><br \/>\n<P>\u4f7f\u7528\u4e86\u4e00\u4e2a\u4e34\u65f6\u8868\u4fdd\u5b58\u7edf\u8ba1\u7ed3\u679c\uff0c\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\uff11\uff15\u79d2\u3002<\/P><br \/>\n<P><BR>\u4e0b\u9762\u662f\u4f7f\u7528\u4e86\u4e24\u4e2a\u4e34\u65f6\u8868\u7684\u4ee3\u7801\uff1a<\/P><br \/>\n<P>CREATE <A href=\"mailto:DEFINER=`root`@`%\">DEFINER=`root`@`%<\/A>` PROCEDURE `prc_anaylise_user`()<BR>BEGIN<\/P><br \/>\n<P>declare time_now datetime;<BR>DROP TABLE IF EXISTS tmp_tables_full;<BR>CREATE TEMPORARY TABLE tmp_tables_full (<BR>blog_id int not null,<BR>count int not null default 0,<BR>ip char(15) null,<BR>index blog_id(blog_id)<BR>)engine = HEAP;<\/P><br \/>\n<P>DROP TABLE IF EXISTS tmp_tables;<BR>CREATE TEMPORARY TABLE tmp_tables (<BR>blog_id int NOT NULL,<BR>count int NOT NULL,<BR>ip char(15) null,<BR>index blog_id(blog_id)<BR>) engine = HEAP;<\/P><br \/>\n<P>set time_now = now();<BR>insert into tmp_tables_full(blog_id,ip) select member_id,track_ip&nbsp; from blog_track where track_type=0 and track_date&gt;=date_format(now(),&#8217;%Y-%m-%d 00:00:00&#8242;) and member_id&gt;0;<BR>insert into tmp_tables(count,blog_id,ip) select count(*) as count,blog_id,ip&nbsp; from tmp_tables_full group by blog_id,ip;<BR>update blog_info set blog_info.today_ip = (select count(*) as count from tmp_tables where blog_info.member_id=tmp_tables.blog_id);<BR>delete from tmp_tables_full;<BR>delete from tmp_tables;<BR>select concat(&#8216;count today ip count need time : &#8216;,(unix_timestamp(now()) &#8211; unix_timestamp(time_now))) as neetTime;<BR>END<\/P><br \/>\n<P>\u7b2c\u4e00\u4e2a\u4e34\u65f6\u8868\u5b58\u653e\u4eca\u5929\u7684\u8bbf\u95ee\u8bb0\u5f55\uff0c\u7b2c\u4e00\u4e2a\u4e34\u65f6\u8868\u5b58\u653e\u7edf\u8ba1\u7ed3\u679c\u3002\u8fd9\u6837\u505a\u7684\u76ee\u7684\u662f\u907f\u514d\u7edf\u8ba1\u65f6\u95f4\u8fc7\u957f\uff0c\u9501\u8868\u65f6\u95f4\u8fc7\u957f\uff0c\u5bfc\u81f4\u7f51\u7ad9\u8bbf\u95ee\u4e0d\u6b63\u5e38\u3002\u6267\u884c\u65f6\u95f4\u4e3a2\u79d2\u3002<\/P><br \/>\n<P><BR>\u8fdb\u4e00\u6b65\u4f18\u5316\uff1a<BR>\u5b9a\u4e49\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cf\uff0c<BR>declare p_updatetime datetime;<BR>\u5efa\u7acb\u4e00\u4e2atmpupdatetable\u8868\uff0c\u4fdd\u5b58\u4e0a\u4e00\u6b21\u6267\u884c\u7684\u65f6\u95f4\uff1b<BR>select updatetime into p_updatetime from tmpupdatetable;<BR>\u628a\u6700\u540e\u6267\u884c\u7684\u65f6\u95f4\u56de\u5230where\u6761\u4ef6\u91cc\uff1a<BR>insert into tmp_tables_full(blog_id,ip) select member_id,track_ip&nbsp; from blog_track where track_type=0 and track_date&gt;=date_format(now(),&#8217;%Y-%m-%d 00:00:00&#8242;)&nbsp; and track_date&gt;=p_updatetime and member_id&gt;0;<BR>\u66f4\u65b0\u6570\u636e\u65f6\u7684\u4ee3\u7801\uff1a<BR>update blog_info set blog_info.today_ip =blog_info.today_ip+ (select count(*) as count from tmp_tables where blog_info.member_id=tmp_tables.blog_id);<\/P><br \/>\n<P><BR>\u7ecf\u8fc7\u6837\u7684\u4fee\u6539\uff0c\u6267\u884c\u65f6\u95f4\u53d8\u4e86120ms\u5de6\u53f3\u3002\u5df2\u7ecf\u7b26\u5408\u8981\u6c42\u4e86\uff0c\u5982\u679c\u6ca1\u6709\u8fbe\u5230\u8fd9\u4e2a\u6548\u679c\u7684\u8bdd\uff0c\u8bf7\u68c0\u67e5\u4e00\u4e2ablog_track\u8868\u7684\u7d22\u5f15\u3002<\/P><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528\u4e34\u65f6\u8868\uff0c\u52a0\u5feb\u5b58\u50a8\u8fc7\u7a0b\u7684\u6267\u884c\u901f\u5ea6\u3002 \u80cc\u666f\uff1a\u3000\u3000\u4e00\u4e2a\u535a\u5ba2\u7f51\u7ad9\u8bbf\u95ee\u6d41\u91cf\u8868\uff0c\u6bcf\u5929\u6709\u5927\u7ea6\uff11\uff10\uff10\u4e07\u6761\u6570\u636e\u63d2\u5165\uff0c\u8bb0\u5f55\u6bcf\u4e2a\u535a\u5ba2\u53ca\u7f51\u7ad9\u7684\u8bbf\u95ee\u60c5\u51b5\u3002\u8868\u7ed3\u6784\uff1amysql&gt; show fields from blog_track;+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+| Field&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Null | Key | Default | Extra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |+&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;-+| track_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | int(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | NO&nbsp;&nbsp; | PRI | NULL&nbsp;&nbsp;&nbsp; | auto_increment | | track_ip&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | char(15)&nbsp;&nbsp;&nbsp;&nbsp; | YES&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp; | NULL&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | | track_date&nbsp;&nbsp;&nbsp;&nbsp; | datetime&nbsp;&nbsp;&nbsp;&nbsp; | NO&nbsp;&nbsp; | MUL |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | | track_page&nbsp;&nbsp;&nbsp;&nbsp; | &hellip; <a href=\"https:\/\/www.strongd.net\/?p=542\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u5229\u7528\u4e34\u65f6\u8868\uff0c\u52a0\u5feb\u5b58\u50a8\u8fc7\u7a0b\u7684\u6267\u884c\u901f\u5ea6\u3002<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,4],"tags":[],"class_list":["post-542","post","type-post","status-publish","format-standard","hentry","category-mysql","category-oracle"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=542"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/542\/revisions"}],"predecessor-version":[{"id":654,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/542\/revisions\/654"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}