<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2chinesetwfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>P.Linux Laboratory</title>
	
	<link>http://www.penglixun.com</link>
	<description>MySQL DBA &amp; Linux SA</description>
	<lastBuildDate>Wed, 10 Mar 2010 08:13:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type="text/javascript" src="http://www.penglixun.com/wp-includes/js/jquery/jquery.js?ver=1.3.2" />
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/plinux" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="plinux" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fplinux" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><item>
		<title>MySQL多服务器批量执行SQL脚本</title>
		<link>http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html</link>
		<comments>http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html#comments</comments>
		<pubDate>Wed, 10 Mar 2010 08:12:37 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mybatsql]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[脚本]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1046</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html 
主要应用场景是，假设我们... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html </p>
<p></span>主要应用场景是，假设我们有一个库DB进行了水平拆分，DB1~10都需要更改表结构，如果手动到各个服务器去执行，效率太低，写了个脚本来做这个事情，叫mybatsql。</p>
<p>用法很简单，需要两个文件，server.list和sql.list，跟脚本放在同一目录下。<br />
server.list中放服务器的主机名/<acronym title="Internet Protocol">IP</acronym>，用户名，密码；sql.list中放需要批量执行的<acronym title="Structured Query Language">SQL</acronym>。<br />
例如：<br />
server.list</p>
<blockquote><p>
127.0.0.1,root,111<br />
127.0.0.2,root,111
</p></blockquote>
<p>sql.list</p>
<blockquote><p>
show status;<br />
show variables;
</p></blockquote>
<p>这两个文件表示，我要在127.0.0.1和127.0.0.2上执行show status;show variables;语句。</p>
<p>也可以通过参数-l/-s指定这两个文件的地址：perl mybatsql.pl  -l server_server_file -s sql_file</p>
<p>Note: There is a file embedded within this post, please visit this post to download the file.<br />
<span id="more-1046"></span></p>

<div class="wp_codebox"><table><tr id="p10462"><td class="code" id="p1046code2"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Create: P.Linux</span>
<span style="color: #666666; font-style: italic;"># Function: Run DDL On Server List</span>
<span style="color: #666666; font-style: italic;"># Usage: Run on any computer with Perl</span>
<span style="color: #666666; font-style: italic;"># License: GPL v2</span>
<span style="color: #666666; font-style: italic;"># Site: PengLiXun.COM</span>
<span style="color: #666666; font-style: italic;"># Modify: </span>
<span style="color: #666666; font-style: italic;"># P.Linux 2010-03-10 </span>
<span style="color: #666666; font-style: italic;">#    -Create 1.0 Release</span>
<span style="color: #666666; font-style: italic;">########################################################</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBD<span style="color: #339933;">::</span><span style="color: #006600;">mysql</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Getopt<span style="color: #339933;">::</span><span style="color: #006600;">Std</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> vars <a href="http://perldoc.perl.org/functions/qw.html"><span style="color: #000066;">qw</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$opt_l</span> <span style="color: #0000ff;">$opt_s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">########################################################</span>
<span style="color: #666666; font-style: italic;"># Global Status Var</span>
<span style="color: #666666; font-style: italic;"># 全局状态变量</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@server_list</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sql</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># Connect to database via DBI</span>
<span style="color: #666666; font-style: italic;"># 通过DBI连接数据库</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@dbconn</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># CmdLine Option vars</span>
<span style="color: #666666; font-style: italic;"># 命令行参数变量</span>
<span style="color: #b1b100;">my</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$server_file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$sql_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Version</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$version</span><span style="color: #339933;">=</span><span style="color: #ff0000;">'1.0 Release'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Main Program</span>
<span style="color: #666666; font-style: italic;"># 主程序</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Get CmdLine Options</span>
<span style="color: #666666; font-style: italic;"># 获取命令行参数</span>
<span style="color: #0000ff;">&amp;get_option</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Read Server List From File</span>
<span style="color: #666666; font-style: italic;"># 从文件中读取服务器列表</span>
<span style="color: #0000ff;">&amp;read_file</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Crate MySQL Database Connect</span>
<span style="color: #666666; font-style: italic;"># 创建MySQL数据库连接</span>
<span style="color: #0000ff;">&amp;create_conn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Run SQL</span>
<span style="color: #666666; font-style: italic;"># 执行SQL</span>
<span style="color: #0000ff;">&amp;run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Disconnect from MySQL</span>
<span style="color: #666666; font-style: italic;"># 从数据库断开连接</span>
<span style="color: #0000ff;">&amp;close_conn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Print Usage</span>
<span style="color: #666666; font-style: italic;"># 打印使用方法</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #000000; font-weight: bold;">sub</span> print_usage <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://perldoc.perl.org/functions/printf.html"><span style="color: #000066;">printf</span></a> <span style="color: #339933;">&lt;&lt;</span>EOF
 NAME<span style="color: #339933;">:</span>
        mybatsql
&nbsp;
 SYNTAX<span style="color: #339933;">:</span>
        mybatsql  <span style="color: #339933;">-</span>l server_server_file <span style="color: #339933;">-</span><a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a> sql_file
&nbsp;
 FUNCTION<span style="color: #339933;">:</span>
        Run SQL on Server List
&nbsp;
 PARAMETER<span style="color: #339933;">:</span>
      <span style="color: #339933;">-</span>l   Database Server List File DEFAULT<span style="color: #339933;">:</span>server<span style="color: #339933;">.</span>list
      <span style="color: #339933;">-</span><a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a>   SQL File DEFAULT<span style="color: #339933;">:</span>sql<span style="color: #339933;">.</span>list
EOF
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Get Options</span>
<span style="color: #666666; font-style: italic;"># 获取命令行参数</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #000000; font-weight: bold;">sub</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rtn</span> <span style="color: #339933;">=</span> getopts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'l:s'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span> <span style="color: #ff0000;">&quot;$rtn&quot;</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> print_usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$server_file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$opt_l</span><span style="color: #339933;">?</span><span style="color: #0000ff;">$opt_l</span><span style="color: #339933;">:</span><span style="color: #ff0000;">'server.list'</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$sql_file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$opt_s</span><span style="color: #339933;">?</span><span style="color: #0000ff;">$opt_s</span><span style="color: #339933;">:</span><span style="color: #ff0000;">'sql.list'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$server_file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$sql_file</span><span style="color: #339933;">=</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">$server_file</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/lc.html"><span style="color: #000066;">lc</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$server_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$sql_file</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/lc.html"><span style="color: #000066;">lc</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Read Server List &amp; SQL From File</span>
<span style="color: #666666; font-style: italic;"># 从文件中读取服务器列表和SQL。</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #000000; font-weight: bold;">sub</span> read_file<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Read Server List File</span>
    <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a><span style="color: #009900;">&#40;</span>FILE<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$server_file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;FILE&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <a href="http://perldoc.perl.org/functions/chomp.html"><span style="color: #000066;">chomp</span></a><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$server_list</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/,/</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	    <span style="color: #0000ff;">$i</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
    <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a><span style="color: #009900;">&#40;</span>FILE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># Read SQL List File</span>
    <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a><span style="color: #009900;">&#40;</span>FILE<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;$sql_file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009999;">&lt;FILE&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	    <a href="http://perldoc.perl.org/functions/chomp.html"><span style="color: #000066;">chomp</span></a><span style="color: #339933;">;</span>
	    <span style="color: #0000ff;">$sql</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">;</span>
	    <span style="color: #0000ff;">$i</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
    <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a><span style="color: #009900;">&#40;</span>FILE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Create MySQL Database Connect </span>
<span style="color: #666666; font-style: italic;"># 创建MySQL数据库连接</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #000000; font-weight: bold;">sub</span> create_conn<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$server</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@server_list</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@srv</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$server</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$srv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$srv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$pwd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$srv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">#print &quot;$host.$user.$pwd\n&quot;;</span>
        <a href="http://perldoc.perl.org/functions/eval.html"><span style="color: #000066;">eval</span></a><span style="color: #009900;">&#123;</span>
            <a href="http://perldoc.perl.org/functions/local.html"><span style="color: #000066;">local</span></a> <span style="color: #0000ff;">$SIG</span><span style="color: #009900;">&#123;</span>ALRM<span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;连接数据库超时<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <a href="http://perldoc.perl.org/functions/alarm.html"><span style="color: #000066;">alarm</span></a> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$dbconn</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;DBI:mysql:host=$host&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$pwd</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'RaiseError'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> 
            <span style="color: #b1b100;">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;Connect to $host error:&quot;</span><span style="color: #339933;">.</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">errstr</span><span style="color: #339933;">;</span>
            <a href="http://perldoc.perl.org/functions/alarm.html"><span style="color: #000066;">alarm</span></a> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>   
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$@</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <a href="http://perldoc.perl.org/functions/printf.html"><span style="color: #000066;">printf</span></a> <span style="color: #ff0000;">&quot;Connect to $host database error:&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$@</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #0000ff;">$i</span><span style="color: #339933;">++;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Main Program to Run SQL on Server List</span>
<span style="color: #666666; font-style: italic;"># 在服务器列表上执行一组SQL</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #000000; font-weight: bold;">sub</span> run<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$conn</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@dbconn</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">#print $sql;</span>
        <span style="color: #0000ff;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">do</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #0000ff;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #666666; font-style: italic;"># Disconnect from MySQL</span>
<span style="color: #666666; font-style: italic;"># 从数据库断开连接</span>
<span style="color: #666666; font-style: italic;">#######################################################</span>
<span style="color: #000000; font-weight: bold;">sub</span> close_conn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$conn</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@dbconn</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$conn</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">disconnect</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年01月26日 -- <a href="http://www.penglixun.com/work/program/mysql_realtime_status_moniter_mystat.html" title="自己写的MySQL实时监控脚本&#8211;mystat">自己写的MySQL实时监控脚本&#8211;mystat</a> (0)</li><li>2010年03月5日 -- <a href="http://www.penglixun.com/work/database/mysql_cast_ifnull_problem.html" title="MySQL的CAST和IFNULL函数的问题">MySQL的CAST和IFNULL函数的问题</a> (0)</li><li>2010年02月11日 -- <a href="http://www.penglixun.com/work/database/innodb_next_key_locking.html" title="InnoDB行锁的实现分析">InnoDB行锁的实现分析</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>数据库的拆分与合并</title>
		<link>http://www.penglixun.com/work/database/split_and_merge_database.html</link>
		<comments>http://www.penglixun.com/work/database/split_and_merge_database.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 15:24:15 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[DBA笔记]]></category>
		<category><![CDATA[合并]]></category>
		<category><![CDATA[拆分]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1044</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/database/split_and_merge_database.html 
数据库每天都承受着数据量的... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/database/split_and_merge_database.html </p>
<p></span>数据库每天都承受着数据量的增长，慢慢的我们发现，对数据库得访问变得非常慢了，这个时候，不外乎两种做法：一是增加单机的配置，升CPU升内存升硬盘；二是“脑裂”，把数据库拆成多份分开存放。<br />
第二个思路必然是最终的方案，因为无论如何单机的承受能力是有限的，业务量的增长必然最终还是要走第二条路。<br />
其实拆分，并不是一个难事，按主键水平拆分，按列垂直拆分，操作上都难，最难的问题是发生在合并的时候，尤其是需要排序的时候（数据库的GROUP/DISTINCT也是先排序做的），合并会变得很麻烦。<br />
一个很糟糕的办法是，设置一台排序专用的机器，访问数据库通过这台机器，发现要排序了就在本地排序，把结果转发给客户端。并发量一大，这台排序用的机器就悲剧了。<br />
第二个方法是，我们希望我们从各个分库中拿出的数据，本身就是按我们所要的方式排序的，数据路由只要组装数据即可，不需要再次排序。<br />
这个如何实现呢，来举个例子，假设我们有个社区系统，有一张用户表U(U_ID,Info,Date)三个字段，分别是主键、信息、注册时间。有一张关系表R(U_ID_1,U_ID_2)，表示U_ID_1和U_ID_2是朋友。我们经常有这样的需求，想知道某个人有哪些朋友。<br />
假设A和B是朋友，我们就在R表插入2条记录R(A,B),(B,A)，为什么要两条呢，数据冗余啦！不错，就是要冗余，冗余可以让后面的工作很Easy。<br />
现在数据量大的惊人，要拆表！<br />
假设业务需求如下：<br />
1. 用户的U.Info查询很少，但是这个部分很长。<br />
2. 经常用U.Date经常被用来排序。<br />
3. 经常要知道某个人有哪些好友。<br />
4. 凡是显示用户都按注册先后排序。<br />
<span id="more-1044"></span></p>
<p>那么怎么拆捏，首先第一个需求，Info查询少，实际中这部分可能包含VARCHAR、TEXT等文本字段，最好需要把它们拆分出去，单独成表，可以提高效率，因为它们不常用。U被拆分为U(U_ID,Date)，U_Info(U_ID,Info)，U_Date(U_ID,Date)。为什么这样拆分？Date不是冗余了嘛，还是为了效率，制造冗余。<br />
然后表怎么拆分呢，当然水平拆分，按ID？那要按Date排序的时候，就悲剧了，所以可以这么分：<br />
U表按Date分区，U_ID建立索引；U_Info/U_Date表按U_ID分区。<br />
这样分区什么好处？为了第2和4个需求，知道了要显示的用户ID列表，到U_Date去拿Date，然后到U表去访问，因为有拆分，所以到所需的时间范围所在的实例去读出新的ID序列，这样拿到的ID就是有序的，原来的ID可以抛弃了，用新的ID序列去拿可能需要的Info，这样取出的数据就是有序的。<br />
然后R表怎么拆呢，很简单，按U_ID_1或者U_ID_2拆都可以，为什么？因为制造了冗余，两边都是对称的，从哪边取都能获得一个人的全部好友，所以就没关系了。<br />
这样还是有一点不方便，拆分可能扩容，怎么办，不能每次都改程序吧？这好办建立1个分区路由表，记录下所有的分区信息，这样查询前先查分区表，再去相应的实例上取数据。</p>
<p>于是得到Schema的设计如下图：<br />
<a href="http://www.flickr.com/photos/penglixun/4420199158/" title="Flickr 上 P.Linux 的 数据库拆分"><img src="http://farm3.static.flickr.com/2738/4420199158_71bff80c69_o.png" width="598" height="453" alt="数据库拆分" /></a></p>
<p>当需要查询A用户的全部好友并且显示列表，再获取第一个好友的详细信息，我们就这么做：<br />
1. 从Route路由表查找A用户所在实例名：SELECT instance FROM Route WHERE Start_ID >= A AND End_ID <=A AND Table = 'R'。<br />
2. 拿到了Instance，就连接到相应的实例去：SELECT U_ID_2 FROM R WHERE U_ID_1 = 'A'。<br />
3. 根据拿到的U_ID，再查所在的Instance，：ELECT instance FROM Route WHERE Start_ID >= u_id_2 AND End_ID <=u_id_2 AND Table = 'U_Date'。<br />
4. 根据拿到的Instance，连接上去，去查U.Date：SELECT Date FROM R WHERE U_ID in (u_id_2)。<br />
5. 有了U.Date，就可以到U去重新查询排序好的ID：SELECT U_ID FROM U WHERE Date in (date)；<br />
6. 然后拿列表中的第一个ID，去取U.Info，查Instance：SELECT instance FROM Route WHERE Start_ID >= u_id AND End_ID <=u_id AND Table = &#8216;U_Info&#8217;。<br />
7. 根据拿到的Instance，连上数据库去取Info：SELECT Info FROM U_Info WHERE U_ID = u_id；<br />
所有任务完成，没有任何的排序产生。</p>
<p>这样大费周折值得吗，我觉得值得，当数据量大的惊人的时候，不可能在中间节点排序，只能是取出的数据就要有序，那么这种拆分思想，就是可以避免排序的。<br />
有了思路，我会自己做一个小实验验证我的方法可行性和效率。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年02月3日 -- <a href="http://www.penglixun.com/work/database/column-oriented_dbms_analyse.html" title="列式数据库的简单分析">列式数据库的简单分析</a> (1)</li><li>2009年12月8日 -- <a href="http://www.penglixun.com/work/database/database_schema_design_traning_2009_12.html" title="今天的数据库设计培训">今天的数据库设计培训</a> (4)</li><li>2009年08月20日 -- <a href="http://www.penglixun.com/work/database/vs2008_data_source_config_problem.html" title="关于VS2008与一些数据源配置的问题">关于VS2008与一些数据源配置的问题</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/database/split_and_merge_database.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item><title>数据库拆分 [Flickr]</title><link>http://www.flickr.com/photos/penglixun/4420199158/</link><dc:creator>P.Linux</dc:creator><pubDate>Tue, 09 Mar 2010 07:22:07 PST</pubDate><guid isPermaLink="false">tag:flickr.com,2005:/photo/4420199158</guid><description>&lt;p&gt;&lt;a href="http://www.flickr.com/people/penglixun/"&gt;P.Linux&lt;/a&gt; posted a photo:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/penglixun/4420199158/" title="数据库拆分"&gt;&lt;img src="http://farm3.static.flickr.com/2738/4420199158_288895ed99_m.jpg" width="240" height="182" alt="数据库拆分" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;一个数据库拆分实验计划：http://www.penglixun.com/work/database/split_and_merge_database.html&lt;/p&gt;</description><enclosure url="http://farm3.static.flickr.com/2738/4420199158_71bff80c69_o.png" length="0" type="image/jpeg" /><dc:date.Taken>2010-03-09T07:22:07-08:00</dc:date.Taken></item><item>
		<title>每周推特 2010-03-09</title>
		<link>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html</link>
		<comments>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html#comments</comments>
		<pubDate>Mon, 08 Mar 2010 17:00:00 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[生活轨迹]]></category>
		<category><![CDATA[tweets]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html 


没玩过这么好的服... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html </p>
<p></span>
<ul class="aktt_tweet_digest">
<li>没玩过这么好的服务器，还没反应过来就导完数据了 <a href="http://twitter.com/plinux/statuses/10111001450" class="aktt_tweet_time">#</a></li>
<li>加班ing，今天没有晚餐票~哇呜~等待项目发布完吃个KFC去？犹豫中 <a href="http://twitter.com/plinux/statuses/10115236849" class="aktt_tweet_time">#</a></li>
<li>项目发布完成，Oh,Yeah <a href="http://twitter.com/plinux/statuses/10115516787" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/anyshpm" class="aktt_username">anyshpm</a>: @<a href="http://twitter.com/plinux" class="aktt_username">plinux</a> 你用什么同步微博？//Twitter Tools <a href="http://twitter.com/plinux/statuses/10123842772" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/nzinfo" class="aktt_username">nzinfo</a> 投资固定建设还能创造一点价值，如果是抄投资品，那就悲剧了，最终要么是价格松动带来抛售，要么是价格超越承受范围无人接盘还是会跌，这样的经济很危险。投资可以刺激经济，抄投资品没什么效果。 <a href="http://twitter.com/nzinfo/statuses/10122023184" class="aktt_tweet_reply">in reply to nzinfo</a> <a href="http://twitter.com/plinux/statuses/10123958717" class="aktt_tweet_time">#</a></li>
<li>昨天12点项目发布成功才睡，今天我竟然按时起床了，哈哈~ <a href="http://twitter.com/plinux/statuses/10154413783" class="aktt_tweet_time">#</a></li>
<li>PostgreSQL的商业版EnterpriseDB是很有潜力的~ <a href="http://twitter.com/plinux/statuses/10155675977" class="aktt_tweet_time">#</a></li>
<li>分析性能问题不是一门科学，而是一门艺术 <a href="http://twitter.com/plinux/statuses/10156839217" class="aktt_tweet_time">#</a></li>
<li>一激动又买了300多块钱的书，4本MySQL的，1本<acronym title="Practical Extraction and Report Language">Perl</acronym>，要全面深入学习源代码 <a href="http://twitter.com/plinux/statuses/10159183021" class="aktt_tweet_time">#</a></li>
<li>一份投诉信，IDC就乖了 <a href="http://twitter.com/plinux/statuses/10163477839" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/xuxuzoe" class="aktt_username">xuxuzoe</a>: 有没有人跟我一样有文件夹和文件名整理强迫症？ {me,too} <a href="http://twitter.com/plinux/statuses/10170300065" class="aktt_tweet_time">#</a></li>
<li>LARGE PAGE虽说会减少缺页中断，但是也会带来更多的内存浪费，适合大块数据的随机访问 <a href="http://twitter.com/plinux/statuses/10172448870" class="aktt_tweet_time">#</a></li>
<li>大学学的理论还是有点用得，从操作系统原理来看一些性能数据，就清晰了 <a href="http://twitter.com/plinux/statuses/10174367236" class="aktt_tweet_time">#</a></li>
<li>看完段页式管理和文件系统，大亮啊，睡觉 <a href="http://twitter.com/plinux/statuses/10177859890" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年03月7日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html" title="每周推特 2010-03-07">每周推特 2010-03-07</a> (0)</li><li>2010年02月28日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html" title="每周推特 2010-02-28">每周推特 2010-02-28</a> (0)</li><li>2010年02月21日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html" title="每周推特 2010-02-21">每周推特 2010-02-21</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>当国家的经济指标被投资品绑架之后</title>
		<link>http://www.penglixun.com/study/economic/china_economic_status.html</link>
		<comments>http://www.penglixun.com/study/economic/china_economic_status.html#comments</comments>
		<pubDate>Sun, 07 Mar 2010 14:32:21 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[经济管理]]></category>
		<category><![CDATA[房价]]></category>
		<category><![CDATA[投资品]]></category>
		<category><![CDATA[经济]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1040</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/study/economic/china_economic_status.html 
和阳哥聊天的时候，突然意识到... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/study/economic/china_economic_status.html </p>
<p></span>和<a href="http://blog.egaoyang.com">阳哥</a>聊天的时候，突然意识到这个问题。<br />
一个正常的经济体系，经济的增长点应该是在消费上，消费产生需求，需求带动生产，生产产生价值，价值回馈消费者，消费者购买产品，消费用于再生产……这样一个循环是经济良性循环的增长点，经济的增量是依靠生产和消费来互相刺激的，具有很好的可持续性，因为只要有消费，就会有生产，这个作用是循环的，但本质上是消费刺激生产。<br />
但是当一个经济体的主要组成部分是投资品之后，维护经济的增长就只能靠一个手段，投资品不断的升值，否则，经济会迅速下滑。原理很简单，投资品，它必须有投资价值，就是它的价值必然会上涨，如果不满足这个条件，资金就会从这个投资品中撤出，价格就会下跌，这个是连锁反应，在都想止损的情况下，一旦投资品价格下跌成定局，价格下泄速度将不可逆转。<br />
如今中国的经济，就是彻底被投资品绑架了，当房屋从家的作用变成投资的作用，当这件投资品被当做经济的主要增长点，那么，要想经济量增长，就必须维持这件投资品的高位，并且给出上涨的趋势，否则，价值一旦松动，投资者必然转而投资其他有上涨趋势的产品，于是价值继续下跌，带动更多的抛售，抛售引起更大的下跌……进入一个恶性循环。<br />
但投资品的价值总是有一个合理点，一旦远远超出了这个合理点，将无人接盘，没有买家接盘，就会失去市场，结果也是必然引起价值下降，一样的后果。<br />
被投资品绑架的经济，我很担忧。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2009年12月16日 -- <a href="http://www.penglixun.com/life/diary/i_got_several_offers_again_2009_12.html" title="最近又收到几个Offer">最近又收到几个Offer</a> (0)</li><li>2009年05月27日 -- <a href="http://www.penglixun.com/study/economic/gray_system_in_administrative_decision_making.html" title="灰色系统在经济和行政决策方面的若干简单应用">灰色系统在经济和行政决策方面的若干简单应用</a> (4)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/study/economic/china_economic_status.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>把自己的小房间收拾好了</title>
		<link>http://www.penglixun.com/life/diary/house_cleaned.html</link>
		<comments>http://www.penglixun.com/life/diary/house_cleaned.html#comments</comments>
		<pubDate>Sun, 07 Mar 2010 11:22:43 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[随笔日记]]></category>
		<category><![CDATA[Home]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1037</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/diary/house_cleaned.html 
昨天我买的书架和从学校快递过来的包裹... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/diary/house_cleaned.html </p>
<p></span>昨天我买的书架和从学校快递过来的包裹都到了，晚上就组装了一下，把书整理了一下。<br />
今天晚上再稍微打扫下，呵呵。<br />
硬硬的床板终于有垫子了，厚被子也来了，哈哈~<br />
今天睡得很舒服。</p>
<p><span id="more-1037"></span><a href="http://www.flickr.com/photos/penglixun/4412780221/" title="Flickr 上 P.Linux 的 书架2"><img src="http://farm5.static.flickr.com/4001/4412780221_7840c5b00d_b.jpg" width="768" height="1024" alt="书架2" /></a></p>
<p><a href="http://www.flickr.com/photos/penglixun/4413549194/" title="Flickr 上 P.Linux 的 书架1"><img src="http://farm5.static.flickr.com/4031/4413549194_8b72f992da_b.jpg" width="768" height="1024" alt="书架1" /></a></p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年01月11日 -- <a href="http://www.penglixun.com/it/ai/mechanization_of_the_simple_geometric_proof_of_further_study.html" title="[论文]对简易几何机械化证明的进一步研究">[论文]对简易几何机械化证明的进一步研究</a> (0)</li><li>2009年03月18日 -- <a href="http://www.penglixun.com/work/program/thinkinf_about_uml_smart.html" title="明智軟件開發的共鳴與思考">明智軟件開發的共鳴與思考</a> (0)</li><li>2010年02月7日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html" title="每周推特 2010-02-07">每周推特 2010-02-07</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/diary/house_cleaned.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item><title>工作环境 [Flickr]</title><link>http://www.flickr.com/photos/penglixun/4413549702/</link><dc:creator>P.Linux</dc:creator><pubDate>Sun, 07 Mar 2010 03:10:38 PST</pubDate><guid isPermaLink="false">tag:flickr.com,2005:/photo/4413549702</guid><description>&lt;p&gt;&lt;a href="http://www.flickr.com/people/penglixun/"&gt;P.Linux&lt;/a&gt; posted a photo:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/penglixun/4413549702/" title="工作环境"&gt;&lt;img src="http://farm5.static.flickr.com/4031/4413549702_87abdc9b79_m.jpg" width="240" height="180" alt="工作环境" /&gt;&lt;/a&gt;&lt;/p&gt;

</description><enclosure url="http://farm5.static.flickr.com/4031/4413549702_ace5e81fa5_o.jpg" length="0" type="image/jpeg" /><dc:date.Taken>2010-03-07T19:54:37-08:00</dc:date.Taken></item><item><title>阿里技术，擎天一柱 [Flickr]</title><link>http://www.flickr.com/photos/penglixun/4413549536/</link><dc:creator>P.Linux</dc:creator><pubDate>Sun, 07 Mar 2010 03:10:32 PST</pubDate><guid isPermaLink="false">tag:flickr.com,2005:/photo/4413549536</guid><description>&lt;p&gt;&lt;a href="http://www.flickr.com/people/penglixun/"&gt;P.Linux&lt;/a&gt; posted a photo:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/penglixun/4413549536/" title="阿里技术，擎天一柱"&gt;&lt;img src="http://farm3.static.flickr.com/2780/4413549536_9144fe17ee_m.jpg" width="240" height="180" alt="阿里技术，擎天一柱" /&gt;&lt;/a&gt;&lt;/p&gt;

</description><enclosure url="http://farm3.static.flickr.com/2780/4413549536_135515fdf8_o.jpg" length="0" type="image/jpeg" /><dc:date.Taken>2010-03-07T19:54:27-08:00</dc:date.Taken></item><item><title>运维之虎 [Flickr]</title><link>http://www.flickr.com/photos/penglixun/4413549346/</link><dc:creator>P.Linux</dc:creator><pubDate>Sun, 07 Mar 2010 03:10:23 PST</pubDate><guid isPermaLink="false">tag:flickr.com,2005:/photo/4413549346</guid><description>&lt;p&gt;&lt;a href="http://www.flickr.com/people/penglixun/"&gt;P.Linux&lt;/a&gt; posted a photo:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/penglixun/4413549346/" title="运维之虎"&gt;&lt;img src="http://farm5.static.flickr.com/4011/4413549346_d3683f356f_m.jpg" width="240" height="180" alt="运维之虎" /&gt;&lt;/a&gt;&lt;/p&gt;

</description><enclosure url="http://farm5.static.flickr.com/4011/4413549346_251381f3f5_o.jpg" length="0" type="image/jpeg" /><dc:date.Taken>2010-03-07T19:54:08-08:00</dc:date.Taken></item><item><title>书架1 [Flickr]</title><link>http://www.flickr.com/photos/penglixun/4413549194/</link><dc:creator>P.Linux</dc:creator><pubDate>Sun, 07 Mar 2010 03:10:17 PST</pubDate><guid isPermaLink="false">tag:flickr.com,2005:/photo/4413549194</guid><description>&lt;p&gt;&lt;a href="http://www.flickr.com/people/penglixun/"&gt;P.Linux&lt;/a&gt; posted a photo:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.flickr.com/photos/penglixun/4413549194/" title="书架1"&gt;&lt;img src="http://farm5.static.flickr.com/4031/4413549194_8b72f992da_m.jpg" width="180" height="240" alt="书架1" /&gt;&lt;/a&gt;&lt;/p&gt;

</description><enclosure url="http://farm5.static.flickr.com/4031/4413549194_eeb2e18812_o.jpg" length="0" type="image/jpeg" /><dc:date.Taken>2010-03-07T15:15:10-08:00</dc:date.Taken></item><item>
		<title>每周推特 2010-03-07</title>
		<link>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html</link>
		<comments>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html#comments</comments>
		<pubDate>Sun, 07 Mar 2010 04:00:00 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[生活轨迹]]></category>
		<category><![CDATA[tweets]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html 


抵杭 #
公司里江西... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html </p>
<p></span>
<ul class="aktt_tweet_digest">
<li>抵杭 <a href="http://twitter.com/plinux/statuses/9776531963" class="aktt_tweet_time">#</a></li>
<li>公司里江西人这么多 <a href="http://twitter.com/plinux/statuses/9821391994" class="aktt_tweet_time">#</a></li>
<li>我已经成了公司宅 <a href="http://twitter.com/plinux/statuses/9968475080" class="aktt_tweet_time">#</a></li>
<li>有点工作的感觉了 <a href="http://twitter.com/plinux/statuses/10019929012" class="aktt_tweet_time">#</a></li>
<li>把博客从Linode上迁移出来了，VPS玩够了，等有人合租再买 <a href="http://twitter.com/plinux/statuses/10024510789" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/xiaolai" class="aktt_username">xiaolai</a>: 直接用内嵌的英英词典吧。RT @<a href="http://twitter.com/BoJia" class="aktt_username">BoJia</a>: @<a href="http://twitter.com/xiaolai" class="aktt_username">xiaolai</a> 笑来老师，灵格斯在Mac的最佳代替软件什么呀？ <a href="http://twitter.com/plinux/statuses/10024536345" class="aktt_tweet_time">#</a></li>
<li>百阿的培训推迟了，估计新人不到岗都抽不出时间，现在才同时支持3个项目就要耗这么多时间 <a href="http://twitter.com/plinux/statuses/10024726581" class="aktt_tweet_time">#</a></li>
<li>阳哥要来杭州了，以后周末就和阳哥一起学学高数和大物，准备和09级的小朋友们一起考试 <a href="http://twitter.com/plinux/statuses/10024789953" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/dyf101" class="aktt_username">dyf101</a>: RT @<a href="http://twitter.com/Fenng" class="aktt_username">Fenng</a>: 大赞 央视春晚会最火爆的“吊带装”(组图) <a href="http://ent.enorth.com.cn/system/2010/03/05/004525143.shtml" rel="nofollow">http://ent.enorth.com.cn/system/2010/03/05/004525143.shtml</a> <a href="http://twitter.com/plinux/statuses/10025042613" class="aktt_tweet_time">#</a></li>
<li>迁移了数据库发现这个版本的MYSQL支持CAST和IFNULL有问题…… <a href="http://twitter.com/plinux/statuses/10025664553" class="aktt_tweet_time">#</a></li>
<li>mystat更新，支持windows，已经传到服务器上了。 <a href="http://twitter.com/plinux/statuses/10026627107" class="aktt_tweet_time">#</a></li>
<li>到家了，悲剧，坐公司班车不认路 <a href="http://twitter.com/plinux/statuses/10029136375" class="aktt_tweet_time">#</a></li>
<li>未来一周之内温度预计从零下二度飚升至二十六度，这就是南京的霸气！ <a href="http://twitter.com/plinux/statuses/10032746667" class="aktt_tweet_time">#</a></li>
<li>貌似有下雪的迹象，下雪就去西湖看看 <a href="http://twitter.com/plinux/statuses/10033322855" class="aktt_tweet_time">#</a></li>
<li>mixero这个客户端真不错 <a href="http://twitter.com/plinux/statuses/10034017709" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/DavidFeng" class="aktt_username">DavidFeng</a>: RT @<a href="http://twitter.com/36172417" class="aktt_username">36172417</a>: 江西省宜春市的旅游政务网打出“宜春，一座叫春的城市”的宣传语，宝鸡市不服了，幸好没有宝鸭市，不然太热闹了。 　//我老家，太操蛋了 <a href="http://twitter.com/plinux/statuses/10057426625" class="aktt_tweet_time">#</a></li>
<li>到公司加班中~ <a href="http://twitter.com/plinux/statuses/10062054796" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/chndonny" class="aktt_username">chndonny</a> 的这三句话经典啊：“认为可能会出问题的事情，一定会出问题。<br />
没有做过的事情，风险一定非常高。<br />
着重沟通的细节，让部门间的合作更顺畅。” <a href="http://twitter.com/plinux/statuses/10065732931" class="aktt_tweet_time">#</a></li>
<li>终于可以睡觉了，把书架组装起来了，不得不批评下商家的设计，组装书架耗掉我半条命 <a href="http://twitter.com/plinux/statuses/10086833036" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年03月9日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html" title="每周推特 2010-03-09">每周推特 2010-03-09</a> (0)</li><li>2010年02月28日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html" title="每周推特 2010-02-28">每周推特 2010-02-28</a> (0)</li><li>2010年02月21日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html" title="每周推特 2010-02-21">每周推特 2010-02-21</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mystat脚本更新Windows支持</title>
		<link>http://www.penglixun.com/work/program/mystat_win_support.html</link>
		<comments>http://www.penglixun.com/work/program/mystat_win_support.html#comments</comments>
		<pubDate>Sat, 06 Mar 2010 07:04:31 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mystat]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1012</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/program/mystat_win_support.html 
mystat脚本更新为1.1版本，加入了Windo... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/program/mystat_win_support.html </p>
<p></span>mystat脚本更新为1.1版本，加入了Windows下的支持。<br />
主要因为Linux版本使用了Bash的彩色显示，所以到了Windows下这个就不兼容了，会看到Bash下控制颜色的代码被现实出来，很难看。<br />
于是加入了操作系统的判断，Windows操作系统跳过颜色控制部分，Linux系统则显示。<br />
然后加入了Inert/Update/Delete流量的实时监控。</p>
Note: There is a file embedded within this post, please visit this post to download the file.<h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年02月5日 -- <a href="http://www.penglixun.com/work/program/mystat_release.html" title="mystat 1.0 release 发布">mystat 1.0 release 发布</a> (0)</li><li>2010年01月28日 -- <a href="http://www.penglixun.com/work/program/mystat_usage.html" title="mystat 0.5 beta 的使用介绍">mystat 0.5 beta 的使用介绍</a> (0)</li><li>2010年01月26日 -- <a href="http://www.penglixun.com/work/program/mysql_realtime_status_moniter_mystat.html" title="自己写的MySQL实时监控脚本&#8211;mystat">自己写的MySQL实时监控脚本&#8211;mystat</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/program/mystat_win_support.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL的CAST和IFNULL函数的问题</title>
		<link>http://www.penglixun.com/work/database/mysql_cast_ifnull_problem.html</link>
		<comments>http://www.penglixun.com/work/database/mysql_cast_ifnull_problem.html#comments</comments>
		<pubDate>Fri, 05 Mar 2010 14:38:31 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[DBA笔记]]></category>
		<category><![CDATA[CAST]]></category>
		<category><![CDATA[IFNULL]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1004</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/database/mysql_cast_ifnull_problem.html 
关于MySQL的一个CAST和IFNULL函数... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/database/mysql_cast_ifnull_problem.html </p>
<p></span>关于MySQL的一个CAST和IFNULL函数诡异问题，不明原因，记录一下，明天继续分析。</p>
<p>这个是<acronym title="WordPress">WP</acronym>-PostView插件的一段<acronym title="Structured Query Language">SQL</acronym>：</p>

<div class="wp_codebox"><table><tr id="p10046"><td class="code" id="p1004code6"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> p<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>post_title<span style="color: #66cc66;">,</span>
IFNULL<span style="color: #66cc66;">&#40;</span> CAST<span style="color: #66cc66;">&#40;</span> pm<span style="color: #66cc66;">.</span>meta_value <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> views
<span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">AS</span> p
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> wp_postmeta <span style="color: #993333; font-weight: bold;">AS</span> pm <span style="color: #993333; font-weight: bold;">ON</span> pm<span style="color: #66cc66;">.</span>post_id <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #993333; font-weight: bold;">AND</span> pm<span style="color: #66cc66;">.</span>meta_key <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;views&quot;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span>post_date <span style="color: #66cc66;">&lt;</span>  <span style="color: #ff0000;">&quot;2010-03-05 22:19:55&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_status <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;publish&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_type <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;post&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_password <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> views <span style="color: #993333; font-weight: bold;">DESC</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">5</span></pre></td></tr></table></div>

<p>在我的数据库上查询结果非常诡异：</p>
<blockquote><p>ID post_title views<br />
10 [论文]对简易几何机械化证明的进一步研究 9<br />
32 页面总算基本修正好了 9<br />
51 一个很好玩的钢琴Flash游戏 9<br />
60 修改友情链接的排列方式 9<br />
93 UML之父——Ivar Jacobson介紹SMART方法 9</p></blockquote>
<p>选出来的views列全部是9，不知道为什么。</p>
<p>如果我去掉IFNULL，</p>

<div class="wp_codebox"><table><tr id="p10047"><td class="code" id="p1004code7"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> p<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>post_title<span style="color: #66cc66;">,</span> 
CAST<span style="color: #66cc66;">&#40;</span> pm<span style="color: #66cc66;">.</span>meta_value <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> views
<span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">AS</span> p
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> wp_postmeta <span style="color: #993333; font-weight: bold;">AS</span> pm <span style="color: #993333; font-weight: bold;">ON</span> pm<span style="color: #66cc66;">.</span>post_id <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #993333; font-weight: bold;">AND</span> pm<span style="color: #66cc66;">.</span>meta_key <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;views&quot;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span>post_date <span style="color: #66cc66;">&lt;</span>  <span style="color: #ff0000;">&quot;2010-03-05 22:19:55&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_status <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;publish&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_type <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;post&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_password <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> views <span style="color: #993333; font-weight: bold;">DESC</span></pre></td></tr></table></div>

<p>得到的结果将是对的，<br />
如果去掉CAST，</p>

<div class="wp_codebox"><table><tr id="p10048"><td class="code" id="p1004code8"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> p<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>post_title<span style="color: #66cc66;">,</span> IFNULL<span style="color: #66cc66;">&#40;</span> pm<span style="color: #66cc66;">.</span>meta_value<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> views
<span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">AS</span> p
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> wp_postmeta <span style="color: #993333; font-weight: bold;">AS</span> pm <span style="color: #993333; font-weight: bold;">ON</span> pm<span style="color: #66cc66;">.</span>post_id <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>ID
<span style="color: #993333; font-weight: bold;">AND</span> pm<span style="color: #66cc66;">.</span>meta_key <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;views&quot;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span>post_date <span style="color: #66cc66;">&lt;</span>  <span style="color: #ff0000;">&quot;2010-03-05 22:19:55&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_status <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;publish&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_type <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;post&quot;</span>
<span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>post_password <span style="color: #66cc66;">=</span>  <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> views <span style="color: #993333; font-weight: bold;">DESC</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">5</span></pre></td></tr></table></div>

<p>得到的就是错的，并且只有2位数一下的结果，2位数以上的结果出不来，但不是9或者99了。</p>
<p>明天继续分析这个问题。<br />
暂时通过去掉IFNULL来解决。</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年03月10日 -- <a href="http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html" title="MySQL多服务器批量执行SQL脚本">MySQL多服务器批量执行SQL脚本</a> (0)</li><li>2010年02月11日 -- <a href="http://www.penglixun.com/work/database/innodb_next_key_locking.html" title="InnoDB行锁的实现分析">InnoDB行锁的实现分析</a> (2)</li><li>2010年02月5日 -- <a href="http://www.penglixun.com/work/program/mystat_release.html" title="mystat 1.0 release 发布">mystat 1.0 release 发布</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/database/mysql_cast_ifnull_problem.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPU负载的分析</title>
		<link>http://www.penglixun.com/work/maintenance/cpu_load_analyse.html</link>
		<comments>http://www.penglixun.com/work/maintenance/cpu_load_analyse.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 12:21:14 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[系统运维]]></category>
		<category><![CDATA[Context Switch]]></category>
		<category><![CDATA[CPU Load]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=1000</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/maintenance/cpu_load_analyse.html 
最近对我的本本（4核8线程）用top... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/maintenance/cpu_load_analyse.html </p>
<p></span>最近对我的本本（4核8线程）用top命令看系统状况出现了CPU利用率超过200%的情况，非常诧异，查了下相关资料，把这个问题弄清楚了。<br />
首先来分析下CPU Load</p>
<blockquote><p>load average: 0.09, 0.05, 0.01</p></blockquote>
<p>分别是1分钟、5分钟、15分钟的平均Load。<br />
Load这个东西怎么理解呢，就像一条马路，有N个车道，如果N个进程进入车道，那么正好一人一个，再多一辆车就占不到车道，要等有一个车空出车道。<br />
在CPU中可以理解为CPU可以并行处理的任务数，那么就是“CPU个数 * 核数”，如果CPU Load = CPU个数 * 核数 那么就是说CPU正好满负载，再多一点，可能就要出问题了，有任务不能被及时分配处理器，那么保证性能的话，最好是小于CPU个数 * 核数 *0.7。</p>
<blockquote><p>查看CPU核数可以通过：grep &#8216;model name&#8217; /proc/cpuinfo</p></blockquote>
<p>那么以哪个平均值为准呢？如果1分钟平均出现大于CPU个数 * 核数的情况，还不用担心，如果5分钟平均也是，那就要警惕了，15分钟平均也是这样，就要分析哪里出问题了，防范于未然<br />
CPU利用率超过100%的问题，也是差不多，top命令应该是把每个核的CPU占用率加起来，算一个和，于是多核情况下会出现超过100%。</p>
<p>另外Context Switch Rate也是个非常值得注意的值，因为线程间切换的代价也是非常高的。</p>
<blockquote><p>引用一个公式：Context Switch Rate = Interrupt Rate + TPS* N</p></blockquote>
<p>对于一个多线程的程序，我觉得准备一个控制线程来调度任务是非常必要的，免得线程过于高并发，导致资源的争用和线程切换带来性能问题，最好控制并发的线程数基本等于CPU的总核数，减少这个N，获得更好的处理器性能。</p>
<p>参考了如下几篇文章：<br />
<a href="http://blog.csdn.net/marising/archive/2010/01/12/5182771.aspx">压力测试衡量CPU的三个指标：CPU Utilization、Load Average和Context Switch Rate</a><br />
<a href="http://www.blogjava.net/cenwenchu/archive/2008/06/30/211712.html">理解Load Average做好压力测试</a><br />
<a href="http://www.gracecode.com/archives/2973/">理解 Linux 的处理器负载均值</a><br />
<a href="http://blog.csdn.net/marising/archive/2010/01/13/5186643.aspx">高性能服务器架构</a></p>
<p>PS. 最近博客写得少，都要长草了。顺便赞一下阿里的食堂，比我们学校食堂四年不变菜饭还贵好多了。</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年03月5日 -- <a href="http://www.penglixun.com/work/program/all_page_fixed.html" title="页面总算基本修正好了">页面总算基本修正好了</a> (2)</li><li>2009年10月11日 -- <a href="http://www.penglixun.com/study/science/paradox_about_relativity.html" title="有趣的相对论“悖论”">有趣的相对论“悖论”</a> (1)</li><li>2009年09月28日 -- <a href="http://www.penglixun.com/work/program/asp_net_div_radiobuttonlist_center_problem.html" title="DIV中RadioButtonList居中的问题">DIV中RadioButtonList居中的问题</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/maintenance/cpu_load_analyse.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>每周推特 2010-02-28</title>
		<link>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html</link>
		<comments>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html#comments</comments>
		<pubDate>Sun, 28 Feb 2010 04:00:00 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[生活轨迹]]></category>
		<category><![CDATA[tweets]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html 


Discovery那位老头原... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html </p>
<p></span>
<ul class="aktt_tweet_digest">
<li>Discovery那位老头原来叫加来道雄，理论物理学家 <a href="http://twitter.com/plinux/statuses/9417578964" class="aktt_tweet_time">#</a></li>
<li>论文看得好头痛 <a href="http://twitter.com/plinux/statuses/9428545191" class="aktt_tweet_time">#</a></li>
<li>name.com注册的域名，修改了指向，很快就在<acronym title="Domain Name Server">DNS</acronym>里更新，新网注册，改了2小时了没动静 <a href="http://twitter.com/plinux/statuses/9434315096" class="aktt_tweet_time">#</a></li>
<li>测试了下MySQL使用索引的极限，如果使用索引无法筛掉80%左右的数据，MySQL会选择不走索引。还没有考虑索引长度的问题，明天继续搞清楚。 <a href="http://twitter.com/plinux/statuses/9527250734" class="aktt_tweet_time">#</a></li>
<li>发现MySQL索引的长度对使用索引的决策影响不是特别大，测试了int/mediumint/smallint/tinyint/varchar，大约都是在剩下20%左右结果集的时候开始使用索引。 <a href="http://twitter.com/plinux/statuses/9562688777" class="aktt_tweet_time">#</a></li>
<li>where+sort的情况，MySQL走错索引的概率很高。 <a href="http://twitter.com/plinux/statuses/9563365225" class="aktt_tweet_time">#</a></li>
<li>mystat脚本就快完善了，Windows下也显示正常，只是无彩色。下一步转成Curses显示，就可以通用了。然后加入socket通讯函数，就可以做成在线呈现的了 <a href="http://twitter.com/plinux/statuses/9629271645" class="aktt_tweet_time">#</a></li>
<li>学生就业搞不懂学校插个什么劲，非得掺和进来 <a href="http://twitter.com/plinux/statuses/9675376738" class="aktt_tweet_time">#</a></li>
<li>明天的人工智能，God Bless，烦死了 <a href="http://twitter.com/plinux/statuses/9675400054" class="aktt_tweet_time">#</a></li>
<li>从Gmail上Down课件，慢的要死，转发到QQ邮箱，下载飞速，我无语了，GFW发威了么 <a href="http://twitter.com/plinux/statuses/9683764843" class="aktt_tweet_time">#</a></li>
<li>天将降大任于斯人也，必先苦其心志，劳其筋骨，饿其体肤，空伐其身，行弗乱其所为，所以动心忍性，曾益其所不能。再艰难也要挺过这段时期，曾益吾所不能。 <a href="http://twitter.com/plinux/statuses/9685168208" class="aktt_tweet_time">#</a></li>
<li>百感交集的夜晚，要烦协议的事情，要安慰GF，还要备考明天的人工智能 <a href="http://twitter.com/plinux/statuses/9686996413" class="aktt_tweet_time">#</a></li>
<li>GF终于睡觉去了，好好看书……博弈树Alpa/Beta剪枝其实蛮简单……代数合一就更简单了……关键要格式对，Prolog命中即终止匹配，期末这里悲剧了15分，不然就过了 <a href="http://twitter.com/plinux/statuses/9688373378" class="aktt_tweet_time">#</a></li>
<li>看A*算法又看到了完备性的博弈，h(x)启发函数控制纵向扩展，速度快，这样可能使搜索不完备，g(x)代价值控制横向扩展，这样可以提高完备性，但效率低。f(x)=g(x)+h(x)就可以控制好横向和纵向的扩展方向，互相牵制。 <a href="http://twitter.com/plinux/statuses/9688800639" class="aktt_tweet_time">#</a></li>
<li>在这个屁股决定脑袋的行政体系里，一切莫名其妙的事情都可能发生。 <a href="http://twitter.com/plinux/statuses/9738983484" class="aktt_tweet_time">#</a></li>
<li>终于领略了3D电影，就是眼睛痛，人工只能Passed，又做完一件事 <a href="http://twitter.com/plinux/statuses/9739789022" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年03月9日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html" title="每周推特 2010-03-09">每周推特 2010-03-09</a> (0)</li><li>2010年03月7日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html" title="每周推特 2010-03-07">每周推特 2010-03-07</a> (0)</li><li>2010年02月21日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html" title="每周推特 2010-02-21">每周推特 2010-02-21</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>每周推特 2010-02-21</title>
		<link>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html</link>
		<comments>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html#comments</comments>
		<pubDate>Sun, 21 Feb 2010 04:00:00 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[生活轨迹]]></category>
		<category><![CDATA[tweets]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html 


看了看老外的设想... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html </p>
<p></span>
<ul class="aktt_tweet_digest">
<li>看了看老外的设想，跟我们的设想几乎一致，每个有Wifi的手机，可以作为一个节点，既是客户端也是服务端，只要一个自组织网络里有一个手机能连上基站，或者互联网，那么基于<acronym title="Peer to Peer">P2P</acronym>协议，网络内每个手机都可以连上。 <a href="http://twitter.com/plinux/statuses/9085136104" class="aktt_tweet_time">#</a></li>
<li>当年自己掏了那么多钱去研究这个东西，在开发板上都做好了Demo，被狗P评委给Kill了，现在老外开始搞了，还拿到了300万美金的投资，这些狗P评委还有什么可说的，不就是为了保护中国移动之类的运营商可以肆无忌惮的剥削百姓么 <a href="http://twitter.com/plinux/statuses/9085226072" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/wolfdeng" class="aktt_username">wolfdeng</a> 可惜被挑战杯Kill了，参赛资格都没有，杯具 <a href="http://twitter.com/wolfdeng/statuses/9085488327" class="aktt_tweet_reply">in reply to wolfdeng</a> <a href="http://twitter.com/plinux/statuses/9085558274" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/yanzisky1989" class="aktt_username">yanzisky1989</a> 我知道了…… <a href="http://twitter.com/yanzisky1989/statuses/9085492025" class="aktt_tweet_reply">in reply to yanzisky1989</a> <a href="http://twitter.com/plinux/statuses/9085621980" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/51isoft" class="aktt_username">51isoft</a> 好吧，评委想的比我们远…… <a href="http://twitter.com/51isoft/statuses/9085813967" class="aktt_tweet_reply">in reply to 51isoft</a> <a href="http://twitter.com/plinux/statuses/9085888978" class="aktt_tweet_time">#</a></li>
<li>我选Linux发行版就是选包管理器，现在还是偏向于源码的包管理器，在ArchLinux和Gentoo中选 <a href="http://twitter.com/plinux/statuses/9090407527" class="aktt_tweet_time">#</a></li>
<li>每次听到春晚歌颂党的歌，我就感到由衷的恶心，自己做的好，要人来唱干什么，老百姓心里自然会记得，对自己作恶想掩盖，才造出一堆的歌来歌颂自己，欲盖弥彰 <a href="http://twitter.com/plinux/statuses/9091577625" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/yanzisky1989" class="aktt_username">yanzisky1989</a> 吃饭去了…… <a href="http://twitter.com/yanzisky1989/statuses/9092208603" class="aktt_tweet_reply">in reply to yanzisky1989</a> <a href="http://twitter.com/plinux/statuses/9093786570" class="aktt_tweet_time">#</a></li>
<li>又看到金龟子了，我那时候天天看她主持节目，现在竟然还在主持～金龟子也是一代神器…… <a href="http://twitter.com/plinux/statuses/9093820313" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/tinyfool" class="aktt_username">tinyfool</a>: RT @<a href="http://twitter.com/delphij" class="aktt_username">delphij</a>: 某前同事<acronym title="Microsoft Network">MSN</acronym>：身为一个技术人员,当不能用本职工作为公司创造生产力的时候,还可以以休年假的方法为公司增加利润 <a href="http://twitter.com/plinux/statuses/9093949621" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/hsin747" class="aktt_username">hsin747</a>: 在台灣，無論是陳水扁或馬英九都必需在過年期間發紅包給民眾，為何不見北京及香港領導人發紅包給市民呀？？ <a href="http://twitter.com/plinux/statuses/9095423494" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/ma_shao_bo" class="aktt_username">ma_shao_bo</a>: 来自推外的技术指导：纯从技术角度给各位光棍出个主意：给所有你认识的异性发个短信说“我喜欢你”，然后忍三个小时，从回短信里的人里挑一个，剩下的再发一个短信“不好意思，喝多了&#8230;&#8230;”。搞定。 <a href="http://twitter.com/plinux/statuses/9100949085" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/Natural__Light" class="aktt_username">Natural__Light</a> 家里呆着 <a href="http://twitter.com/Natural__Light/statuses/9101031408" class="aktt_tweet_reply">in reply to Natural__Light</a> <a href="http://twitter.com/plinux/statuses/9101711689" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/wolfdeng" class="aktt_username">wolfdeng</a> 现在还是偏向Arch Linux，既有二进制也有源码分发包 <a href="http://twitter.com/wolfdeng/statuses/9101060797" class="aktt_tweet_reply">in reply to wolfdeng</a> <a href="http://twitter.com/plinux/statuses/9101739714" class="aktt_tweet_time">#</a></li>
<li>EMS早就可以倒闭了，限时隔天件，第四天了还不到，没打我电话就说我不在 <a href="http://twitter.com/plinux/statuses/9124817681" class="aktt_tweet_time">#</a></li>
<li>买个XV6800，跟卖家买的时候谈判有歧义，又被耍了，已经气的没气了，淘宝买个AA/AAA码上EVDO算了 <a href="http://twitter.com/plinux/statuses/9171434265" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a>: RT @<a href="http://twitter.com/yeka52" class="aktt_username">yeka52</a>: 姚滨一直是清高的，在最举步维艰的时候，他不抱怨，不指责任何人。他的原则是，有能耐你就挺住，做出成绩来给别人看。别人争利益，谈条件，他从来不争不抢。他是真的不屑，认为争那些不值。 <a href="http://twitter.com/plinux/statuses/9173945630" class="aktt_tweet_time">#</a></li>
<li>被称为经济适用男 <a href="http://twitter.com/plinux/statuses/9179159896" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/newsinchina" class="aktt_username">newsinchina</a>: 其实很多老人在事实举证上是根本无法说服年轻人接受他们那老朽的观点的,然后他们往往会以长者和权威的态度中止和你平等地讨论下去! <a href="http://twitter.com/plinux/statuses/9181291690" class="aktt_tweet_time">#</a></li>
<li>才发现介川是浩二 <a href="http://twitter.com/plinux/statuses/9183734251" class="aktt_tweet_time">#</a></li>
<li>点优酷看到一个视频，德国高速259辆车相撞，没死一个，伤66个，这车得啥质量呀……德国车威武 <a href="http://twitter.com/plinux/statuses/9185923416" class="aktt_tweet_time">#</a></li>
<li>夜深人静是写技术博文的好时候 <a href="http://twitter.com/plinux/statuses/9187617370" class="aktt_tweet_time">#</a></li>
<li>想把Wordpress换个简约点的主题，搞的跟个八卦博客一样 <a href="http://twitter.com/plinux/statuses/9191364455" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/Aro_Carter" class="aktt_username">Aro_Carter</a>: RT @<a href="http://twitter.com/Z1scar" class="aktt_username">Z1scar</a>:～RT @<a href="http://twitter.com/crystallys" class="aktt_username">crystallys</a>: RT @<a href="http://twitter.com/singinrain" class="aktt_username">singinrain</a>: RT @<a href="http://twitter.com/Mr_Lau" class="aktt_username">Mr_Lau</a>: CCAV不转播国足，国足夺冠了；CCAV转播冬奥会开幕式，结果火炬坏了 <a href="http://twitter.com/plinux/statuses/9192260808" class="aktt_tweet_time">#</a></li>
<li>如果我向黄牛买票。黄牛说：“加10元”。我肯定说：“不，我至少加您30元。”并说：“谢谢！”。警察就知道抓这种赚辛苦钱的，加300的黄牛都TMD是内部的人，警匪一家。 <a href="http://twitter.com/plinux/statuses/9224825968" class="aktt_tweet_time">#</a></li>
<li>搜括民财还要看刮来的钱用在什么地方，隋炀帝搜刮民力最后用在了开大运河上，罪在当代利在千秋。用在自己身上，那就是千古罪人，永世不得翻身。 <a href="http://twitter.com/plinux/statuses/9225980184" class="aktt_tweet_time">#</a></li>
<li>原来一次性筷子是这么回事，http://goo.gl/eN8p <a href="http://twitter.com/plinux/statuses/9237684053" class="aktt_tweet_time">#</a></li>
<li>还是ArchLinux用的爽，要二进制包有二进制包，要源码包有源码包 <a href="http://twitter.com/plinux/statuses/9243623608" class="aktt_tweet_time">#</a></li>
<li>淘宝出信用卡了？嘛时候支付宝也开个银行好了，AliBank <a href="http://twitter.com/plinux/statuses/9275350969" class="aktt_tweet_time">#</a></li>
<li>吴军老师的数学之美真不错，毕设的做法有些修正，基于文法的分词不如基于概率的分词 <a href="http://twitter.com/plinux/statuses/9275829762" class="aktt_tweet_time">#</a></li>
<li>刘谦被称为国内都市泡妞魔术青年的精神领袖，”都市泡妞魔术青年“，我觉得勺子挺像，@Natural__Light 你觉得呢？ <a href="http://twitter.com/plinux/statuses/9276368287" class="aktt_tweet_time">#</a></li>
<li>孙茂松教授的《Chinese word segmentation without using lexicon and hand-crafted training data》写的很好 <a href="http://twitter.com/plinux/statuses/9278191489" class="aktt_tweet_time">#</a></li>
<li>备案网站只要TMD做的像个人类使用的网站，我也不会这么抵制备案 <a href="http://twitter.com/plinux/statuses/9283706128" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/Fenng" class="aktt_username">Fenng</a>: 保持关注 RT: @<a href="http://twitter.com/linglingfa" class="aktt_username">linglingfa</a>: 今天才发现，ebay和eachnet又分开了？现在ebay.cn专心做走私，原来不用的eachnet域名又启用了。什么时候的事儿啊？这淘宝虽然强大吧，也不用如此自乱阵脚吧？ <a href="http://twitter.com/plinux/statuses/9288244607" class="aktt_tweet_time">#</a></li>
<li>我这破神舟本装MacOS就是装不上，还是继续用Linux <a href="http://twitter.com/plinux/statuses/9338532939" class="aktt_tweet_time">#</a></li>
<li>时间会坍塌么？有学理论物理的推友能解释下么？时间存在加速度么？ <a href="http://twitter.com/plinux/statuses/9343806505" class="aktt_tweet_time">#</a></li>
<li>当年Discovery讲超弦理论理论的物理学家现在头发都白了，又在Discovery讲力场防护罩，围观中…… <a href="http://twitter.com/plinux/statuses/9343905691" class="aktt_tweet_time">#</a></li>
<li>原来太阳是电浆…… <a href="http://twitter.com/plinux/statuses/9344108560" class="aktt_tweet_time">#</a></li>
<li>这位老头设计的力场除了纳米碳管还不能大量生产以外，都可以做出来，看来实现并不难 <a href="http://twitter.com/plinux/statuses/9344852578" class="aktt_tweet_time">#</a></li>
<li>原来Google的在线翻译并不是语义分析，而是通过概率统计，词出现的概率和句子出现的概率来计算，这实际上考虑了人类语言习惯的问题，很多时候我们说话并没有严格的语法，但是却含有很多的习惯，通过概率来反应这种习惯，做出来的翻译效果应该更接近日常用语，分词同理。 <a href="http://twitter.com/plinux/statuses/9352457053" class="aktt_tweet_time">#</a></li>
<li>金价、美元同时高涨，各国货币都下跌，唯独美元猛涨。看来华尔街的财主们又在狂买黄金，炒高金价，吸引各国投资者抛售本国货币购买美金来买黄金，两者同时被水涨船高。 <a href="http://twitter.com/plinux/statuses/9376332554" class="aktt_tweet_time">#</a></li>
<li>汇市上，美元兑各国货币全涨，各国货币兑美金全跌，金价和美金再次同时彪高，吸引投资者抛售本国货币购买美金买黄金炒高美金价格的招数老美玩过一次了，这次又这么多人跟风 <a href="http://twitter.com/plinux/statuses/9376473243" class="aktt_tweet_time">#</a></li>
<li>还有探亲假这种东西，从未听说……不知道阿里有没有 <a href="http://twitter.com/plinux/statuses/9380374883" class="aktt_tweet_time">#</a></li>
<li>我妈为啥总觉得我头大，说我们是大头儿子小头爸爸 <a href="http://twitter.com/plinux/statuses/9380623685" class="aktt_tweet_time">#</a></li>
<li>民企是员工养企业，没有员工的努力就没有企业的今天；国企是企业养员工，没有企业的垄断就没有员工的今天 <a href="http://twitter.com/plinux/statuses/9384456906" class="aktt_tweet_time">#</a></li>
<li>Statistical Language Models看得我天昏地转 <a href="http://twitter.com/plinux/statuses/9385196866" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/dttoo" class="aktt_username">dttoo</a>: tooRT @<a href="http://twitter.com/yqhbp" class="aktt_username">yqhbp</a>: meRT @<a href="http://twitter.com/twjacy" class="aktt_username">twjacy</a>: 推上学生多不？ //me <a href="http://twitter.com/plinux/statuses/9385235827" class="aktt_tweet_time">#</a></li>
<li>删掉了花俏的主题，换了一个很Simple的主题，感觉好多了，而简约不简单，技术的追求。 <a href="http://twitter.com/plinux/statuses/9388976944" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年03月9日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-09.html" title="每周推特 2010-03-09">每周推特 2010-03-09</a> (0)</li><li>2010年03月7日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-03-07.html" title="每周推特 2010-03-07">每周推特 2010-03-07</a> (0)</li><li>2010年02月28日 -- <a href="http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-28.html" title="每周推特 2010-02-28">每周推特 2010-02-28</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-21.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mystique主题与WP-PostViews Plus插件的冲突问题</title>
		<link>http://www.penglixun.com/work/program/mystique_postviews.html</link>
		<comments>http://www.penglixun.com/work/program/mystique_postviews.html#comments</comments>
		<pubDate>Tue, 16 Feb 2010 17:48:29 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[Mystique]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=980</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/program/mystique_postviews.html 
今天升级了Mystique主题到1.72版，原... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/program/mystique_postviews.html </p>
<p></span>今天升级了Mystique主题到1.72版，原来的那个Bug又出现了，会在页面的顶头显示一段代码，查看了源码，发现是<acronym title="WordPress">WP</acronym>-PostViews Plus的代码和Mystique主题冲突了，我们来看原始输出的<acronym title="HyperText Markup Language">HTML</acronym>：</p>

<div class="wp_codebox"><table><tr id="p98012"><td class="code" id="p980code12"><pre class="html" style="font-family:monospace;">&lt;body class=&quot; 
&lt;!-- Start Of Script Generated By WP-PostViews Plus --&gt; 
&lt;script type=&quot;text/javascript&quot;&gt; 
/* &lt;![CDATA[ */
jQuery.ajax({type:'GET',url:'http://www.penglixun.com/wp-content/plugins/wp-postviews-plus/postviews_plus.php',data:'todowppvp=&amp;type=index&amp;id=1',cache:false,dataType:'script'});
/* ]]&gt; */
&lt;/script&gt; 
&lt;!-- End Of Script Generated By WP-PostViews Plus --&gt; 
home blog col-2-right loggedin browser-chrome&quot;&gt;</pre></td></tr></table></div>

<p>这不出问题才怪呢，正常的情况应该是</p>

<div class="wp_codebox"><table><tr id="p98013"><td class="code" id="p980code13"><pre class="html" style="font-family:monospace;">&lt;!-- Start Of Script Generated By WP-PostViews Plus --&gt; 
&lt;script type=&quot;text/javascript&quot;&gt; 
/* &lt;![CDATA[ */
jQuery.ajax({type:'GET',url:'http://www.penglixun.com/wp-content/plugins/wp-postviews-plus/postviews_plus.php',data:'todowppvp=&amp;type=index&amp;id=1',cache:false,dataType:'script'});
/* ]]&gt; */
&lt;/script&gt; 
&lt;!-- End Of Script Generated By WP-PostViews Plus --&gt; 
&lt;body class=&quot;home blog col-2-right loggedin browser-chrome&quot;&gt;</pre></td></tr></table></div>

<p>或者<body class="home blog col-2-right loggedin browser-chrome">在上面。</p>
<p>刨根问底，元凶指向mystique_body_class这个函数，发现在core.php文件中。<br />
问题在哪呢？</p>

<div class="wp_codebox"><table><tr id="p98014"><td class="code" id="p980code14"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Special classes for BODY element when a single post</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
    <span style="color: #000088;">$postID</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
    the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Adds 'single' class and class with the post ID</span>
    <span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'single-post postid-'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$postID</span><span style="color: #339933;">;</span>
<span style="color: #339933;">......</span>
  <span style="color: #666666; font-style: italic;">// And tada!</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$print</span> ? <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>就是the_post()函数，调用the_post()时，<acronym title="WordPress">WP</acronym>-PostViews Plus的代码就被加入了，而<strong>body class=</strong> 已经输出了。<br />
解决方法很简单，把the_post()转移到最后，就是print的下一行，这样就OK了。把这个函数里其他the_post()都删除，留一个在print的下一行就行。</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年07月9日 -- <a href="http://www.penglixun.com/work/program/add_database_module_for_php.html" title="为PHP添加数据库模块">为PHP添加数据库模块</a> (0)</li><li>2009年03月5日 -- <a href="http://www.penglixun.com/entertainment/good_piano_game.html" title="一个很好玩的钢琴Flash游戏">一个很好玩的钢琴Flash游戏</a> (3)</li><li>2009年06月11日 -- <a href="http://www.penglixun.com/work/program/compile_qt_oci.html" title="QOCI的编译">QOCI的编译</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/program/mystique_postviews.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>锁的粒度与死锁概率</title>
		<link>http://www.penglixun.com/work/database/lock_granularity_deadlock_probability.html</link>
		<comments>http://www.penglixun.com/work/database/lock_granularity_deadlock_probability.html#comments</comments>
		<pubDate>Tue, 16 Feb 2010 15:55:32 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[DBA笔记]]></category>
		<category><![CDATA[死锁]]></category>
		<category><![CDATA[锁的粒度]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=977</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/database/lock_granularity_deadlock_probability.html 
首先，我们要定义下... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/database/lock_granularity_deadlock_probability.html </p>
<p></span>首先，我们要定义下什么是“<strong>锁的粒度</strong>”：所谓粒度就是作用范围，锁的粒度就是锁的作用范围。数据库中锁的粒度从高到低依次划分为：数据库、表、页、行。<br />
什么是<strong>死锁</strong>，顺带说一下吧，当多个操作竞争资源，每个操作都无法获得全部所需资源时，系统进入死锁，如无外力作用，系统将无限等待下去，死锁的四个必要条件：<br />
（1） 互斥条件：一个资源每次只能被一个进程使用。<br />
（2） 请求与保持条件：一个进程因请求资源而阻塞时，对已获得的资源保持不放。<br />
（3） 不剥夺条件：进程已获得的资源，在末使用完之前，不能强行剥夺。<br />
（4） 循环等待条件：若干进程之间形成一种头尾相接的循环等待资源关系。<br />
打破任何一个条件就不会发生死锁。</p>
<p>我们先来看一个生活场景：<br />
有两个文具盒，一个放的是笔（圆珠笔、铅笔等等），一个放的是修正工具（橡皮擦、改正带等等）.<br />
现在有两个人，他们要画图，可能需要的物品当然有笔和修正工具。<br />
假设我们用全局的独享，就是两个文具盒都只能同时被一个人拥有，一个人来拿笔，连带修正工具一起归他，这样绝对不会发生图画不下去的问题，因为所要的工具都会一次性给同一个人。但是问题也很严重，资源严重浪费，因为笔和橡皮擦肯定不会同时使用，也不会同时用2支笔。<br />
假设我们用的是文具盒的独享，就是同时一个文具盒只能被一个人拥有，一个人要笔，整个放笔的文具盒都给他，一个人要修正图画，则整个放修正工具的文具盒都给他。这可能出现的问题就是，一个人想，我要画图，橡皮擦肯定要，橡皮擦的文具盒正好在，就先把这个文具盒拿下，等笔盒回来了再继续画。另一个人拿了笔盒，画了一会要修正，一看，放橡皮擦的文具盒没了，就等文具盒放回来。这样两个人就无限等待了，只要其中一个人看到东西不全就不拿，就不会无限等。<br />
假设我们用的是物品独享，就是一支笔、一个橡皮擦只能被一个人拥有，一个人要画图，就拿一支笔，要改就拿一个橡皮擦或者改正带。除非只有一支笔，否则不会出现无限等待。当然，只有一支笔跟独享一个文具盒没区别。</p>
<p><span id="more-977"></span><br />
例子中的独享就是锁的概念。</p>
<p>再来看数据库中的实例：<br />
假设有A,B两个数据库，A库有A1,A2两个表，B库也有B1和B2两个表，每个表都有都有N条记录（N>1）.<br />
现在有两个操作P1和P2并发，我们来看一个场景：<br />
P1要操作A1表的一行和B2表的一行，P2要操作A2表的一行和B1表的一行。<br />
现在假设我们用库锁，P1先行，A库被锁住，P2后行，先锁住了B库，P1再去锁B库，已经被P2锁住了，P2去锁A库，被P1锁住了，这样P1，P2就陷入死锁，都占用部分资源。<br />
假设我们用的是表锁呢，P1先行，A1被锁住，P2后行，A2被锁住，P1再锁B1，P2再锁B2，怎么也不会发生死锁。<br />
采用行锁的话就更不会死锁了，操作的表都不同。<br />
看到这里，大家就说，锁的粒度越大，越容易死锁，真的吗？那我再来个最大的锁，实例锁，一次性锁住整个实例，P1先行，整个实例被锁住，P2被阻塞，等P1操作完P2再来，肯定不会死锁，为什么？因为这已经退化成串行操作了。</p>
<p>也就是说，虽然一般情况下锁的粒度越大，死锁概率越大，但是，当锁的粒度成为全局锁，把操作变成串行后，就不一样了，根本不会死锁。</p>
<p>我们把P1和P2操作改一下，P1操作A1表的i行和A2表的j行，P2操作A1表的j行和A2表的i行（i<>j），再来看：<br />
假设我们使用库锁，P1先行，A库就锁住，P2阻塞，P1完成P2锁A库，不会死锁。<br />
假设我们使用表锁，P1先行，A1表锁住，P2后行，A2表锁住，P1再去锁A2表，已经被P2锁了，死锁发生。<br />
假设我们使用行锁，P1先行，锁住A1表第i行，P2后行，锁住A1表第j行，P1再锁A2表j行，P2再锁A1表j行，完成操作。</p>
<p>也就是说，不能就认为所有情况都是锁的粒度越大死锁概率越大，而是要看操作的粒度，如果锁的粒度比操作的粒度大或相同，操作就会变成串行，根本不可能发生死锁。</p>
<p>顺便说以下，数据库中并行操作的情况很多，为什么很少发生死锁呢，因为只要打破死锁四个条件任意一个，就可以避免死锁，只会发生阻塞，一个操作释放资源后就可以继续进行。<br />
方法很多，例如把锁的粒度提高到跟操作的粒度大，并发一个表，我就一次锁一个表，并发一个库，我就一次锁一个库，这实际上是什么呢，就是把并行弄成串行了，一般没人这么做，并发只有1，效率太低。<br />
一般是多管齐下避免死锁，一是使用不同等级的锁，例如意向锁，互斥锁等，其实就是打破死锁第一条件——互斥条件，资源某些时候可以共享，例如读锁可以共享读，不过因为还是存在互斥锁，依然可能死锁。<br />
第二就是可以按顺序锁资源，例如锁表只能按A->B->C的顺序锁，如果我要A,B表，锁了A表后发现B表已经被锁了，就释放A表的锁（或者使用意向锁），延时再尝试，直到所有资源都可以锁住（互斥锁/共享锁），这就是打破了死锁第二条件——请求与保持条件，不能获得全部资源就先释放锁，等能获得了再说，这样操作可以完全避免死锁。</p>
<p>如有不对请指正！</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年10月14日 -- <a href="http://www.penglixun.com/it/embedded/sjf_board_usingpci_to_ltp.html" title="使用PCI转并口实现SJF刷写嵌入式开发板">使用PCI转并口实现SJF刷写嵌入式开发板</a> (0)</li><li>2009年10月14日 -- <a href="http://www.penglixun.com/work/program/orm_or_rom.html" title="ORM or ROM？">ORM or ROM？</a> (0)</li><li>2010年02月17日 -- <a href="http://www.penglixun.com/work/program/mystique_postviews.html" title="Mystique主题与WP-PostViews Plus插件的冲突问题">Mystique主题与WP-PostViews Plus插件的冲突问题</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/database/lock_granularity_deadlock_probability.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>每周推特 2010-02-14</title>
		<link>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-14.html</link>
		<comments>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-14.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 04:00:00 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[生活轨迹]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/work/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-14.html</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-14.html 


RT @ranyunfei: 美国早... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-14.html </p>
<p></span>
<ul class="aktt_tweet_digest">
<li>RT @<a href="http://twitter.com/ranyunfei" class="aktt_username">ranyunfei</a>: 美国早该如此做，这才是推进中国民主进程最妙的一招。RT @<a href="http://twitter.com/yuanxinting" class="aktt_username">yuanxinting</a>  北京吠得紧，这招捏住中共睾丸，可不战而屈人之兵；老美不会捏爆其睾丸！ RT @<a href="http://twitter.com/yaoraonan" class="aktt_username">yaoraonan</a>: 美国亮棒：要爆光中国180万官员国外子女档案 <a href="http://twitter.com/plinux/statuses/8788716540" class="aktt_tweet_time">#</a></li>
<li>要想一出校门就找到好工作，就不要在学校只谈恋爱不学习，也不要只学死课本而不关心现实中的新技术，更不要只学习自己的专业。 <a href="http://twitter.com/plinux/statuses/8789733811" class="aktt_tweet_time">#</a></li>
<li>此次出门是我最悲剧的一次，被骗钱，还被家里骂，不用他们管，我还饿不死，幸亏房子好了，呆着就行了 <a href="http://twitter.com/plinux/statuses/8796212368" class="aktt_tweet_time">#</a></li>
<li>都是欺负我老实，知道忽悠我没事，我X你黑中介 <a href="http://twitter.com/plinux/statuses/8796321333" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/hellodba" class="aktt_username">hellodba</a> 如果不是要求很实时的话，记录下当前页条目的ID然后往后取相应条数优化效果应该蛮好的。 <a href="http://twitter.com/hellodba/statuses/8796554407" class="aktt_tweet_reply">in reply to hellodba</a> <a href="http://twitter.com/plinux/statuses/8796703590" class="aktt_tweet_time">#</a></li>
<li>500块钱没事，我不过这两天买不起被子而已，不过我会让我身边每个人都知道5i5j是什么货色。 <a href="http://twitter.com/plinux/statuses/8797591860" class="aktt_tweet_time">#</a></li>
<li>看房最好要试住，有些问题一时半会根本看不出来，也别听中介瞎忽悠，自己仔细看一看，试一试，尤其是之前没住过人的，不确信没有隐含问题之前不要交任何钱，都是出来赚钱的，中国有几个企业真正讲信用，要钱不要脸，给钱就翻脸。 <a href="http://twitter.com/plinux/statuses/8799368973" class="aktt_tweet_time">#</a></li>
<li>悲剧了，花费又通知低于20了，出来的时候还100多，万恶的中国移动 <a href="http://twitter.com/plinux/statuses/8800357915" class="aktt_tweet_time">#</a></li>
<li>没有被子好冷啊…… <a href="http://twitter.com/plinux/statuses/8800449537" class="aktt_tweet_time">#</a></li>
<li>极度的郁闷中，套上所有外套躺着 <a href="http://twitter.com/plinux/statuses/8800907840" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a> 在这个没有信用的社会，我不知道说啥好了。我不想把每个人都想的那么坏，但不这么做自己总是吃亏。 <a href="http://twitter.com/yxwlmxy/statuses/8801127754" class="aktt_tweet_reply">in reply to yxwlmxy</a> <a href="http://twitter.com/plinux/statuses/8801332508" class="aktt_tweet_time">#</a></li>
<li>实在不好意思找家里要钱了，勒紧裤腰带扛过去 <a href="http://twitter.com/plinux/statuses/8801399705" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a>: RT @<a href="http://twitter.com/plinux" class="aktt_username">plinux</a>: @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a> 在这个没有信用的社会，我不知道说啥好了。我不想把每个人都想的那么坏，但不这么做自己总是吃亏。//有时候吃亏就是沾光，我也有过被自己信任的人骗的经历，现在回头想想经过那些事自己更清楚地看清楚了某些人。{同感} <a href="http://twitter.com/plinux/statuses/8801561507" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yujie89" class="aktt_username">yujie89</a>: “兄弟如手足，妻子如衣服”，这是中国文化中最龌龊的部分。爱自己妻子的人，才能以天下苍生为念。读林觉民之《与妻书》，当代唯有晓波和刘霞的情书才能与之媲美。 <a href="http://twitter.com/plinux/statuses/8804900763" class="aktt_tweet_time">#</a></li>
<li>准备睡觉，我想坐着睡还是躺着睡，先再穿件保暖内衣再说 <a href="http://twitter.com/plinux/statuses/8811127440" class="aktt_tweet_time">#</a></li>
<li>冻醒了，悲剧，不得不靠下老爸了 <a href="http://twitter.com/plinux/statuses/8824718149" class="aktt_tweet_time">#</a></li>
<li>悲剧的是下雨没带钥匙，更悲剧的是门禁系统坏了呼叫不了室房主甚至管理中心，最悲剧的是发现走到车库不用刷卡就可以直接上楼…… <a href="http://twitter.com/plinux/statuses/8859032949" class="aktt_tweet_time">#</a></li>
<li>mystat又发现一个bug，修复中 <a href="http://twitter.com/plinux/statuses/8861391984" class="aktt_tweet_time">#</a></li>
<li>今天帮人用mystat检查出数据库的错误，非常爽，我要完善这个脚本的功能，最好能配合Web界面做成实时呈现的系统 <a href="http://twitter.com/plinux/statuses/8861426944" class="aktt_tweet_time">#</a></li>
<li>bin-log中的记录延时将近1小时，太扯淡了吧，14点之后出现了13点的log，无厘头，无法还原场景，什么诡异问题？ <a href="http://twitter.com/plinux/statuses/8894817148" class="aktt_tweet_time">#</a></li>
<li>求助：有没有人遇到过binlog中<acronym title="Structured Query Language">SQL</acronym>出现的顺序跟执行明显不一致的情况？例如2点执行了一条插入，主库可以查到这条记录，1小时候这条<acronym title="Structured Query Language">SQL</acronym>才被记录到bin-log，我现在还原不出场景，间歇性遇到。 <a href="http://twitter.com/plinux/statuses/8895271227" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/fire9" class="aktt_username">fire9</a> 问题在于主库的bin-log有时会延时一小时才记录到，不定期出现，很诡异，出现多为update和insert语句。 <a href="http://twitter.com/fire9/statuses/8895377692" class="aktt_tweet_reply">in reply to fire9</a> <a href="http://twitter.com/plinux/statuses/8897782906" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/fire9" class="aktt_username">fire9</a> 5.1.43最新版，我怀疑可能是Bug，现在没法还原场景，只能遇到了就去看下，出问题的都是延时1小时才写入 <a href="http://twitter.com/fire9/statuses/8897936358" class="aktt_tweet_reply">in reply to fire9</a> <a href="http://twitter.com/plinux/statuses/8900107739" class="aktt_tweet_time">#</a></li>
<li>公安部立功了……中国足球总算像了次爷们 <a href="http://twitter.com/plinux/statuses/8902464063" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/NinGoo" class="aktt_username">NinGoo</a> 淘宝不是想用飞天系统么 <a href="http://twitter.com/NinGoo/statuses/8891839308" class="aktt_tweet_reply">in reply to NinGoo</a> <a href="http://twitter.com/plinux/statuses/8902692669" class="aktt_tweet_time">#</a></li>
<li>不逃课的学生不是好学生。什么课都不逃，跟什么课都逃掉没什么两样。一定要掌握学习的主动性，不要像读中学一样被老师牵着鼻子走。逃课没有错，但是不要逃错课。同时，既要逃课，又要让老师给高分。（这话非常好） <a href="http://twitter.com/plinux/statuses/8930528885" class="aktt_tweet_time">#</a></li>
<li>对社会的简单形容就是：全是人、全是人、全是人——但社会肯定会分出层次，只有一个办法，那就是竞争，你必须努力，必须使自己成为社会的强者，强者才能拥有一切，而不是金钱可以买到一切，否则结局就是被压在社会的底层。（精神鸦片） <a href="http://twitter.com/plinux/statuses/8930576106" class="aktt_tweet_time">#</a></li>
<li>写写InnoDB的范围锁的实现代码，深入体会体会范围锁机制。 <a href="http://twitter.com/plinux/statuses/8947972816" class="aktt_tweet_time">#</a></li>
<li>语言能力不行，只能用代码 注释来说明问题能讲的更清晰 <a href="http://twitter.com/plinux/statuses/8953246491" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/rtmeme" class="aktt_username">rtmeme</a>: RT @<a href="http://twitter.com/pufei" class="aktt_username">pufei</a> RT @<a href="http://twitter.com/zetifree" class="aktt_username">zetifree</a> 澳洲小孩每周作业是一张A4纸，中国小孩每周记作业是一张A4纸 <a href="http://twitter.com/plinux/statuses/8953475546" class="aktt_tweet_time">#</a></li>
<li>淘宝上也有旅游、酒店、机票、线路了 <a href="http://twitter.com/plinux/statuses/8953644589" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/hellodba" class="aktt_username">hellodba</a> 现在只通了广深线，跟地铁似的，随买票随走，往粤西方向去的专线不晓得还要多久才能修好 <a href="http://twitter.com/hellodba/statuses/8953615138" class="aktt_tweet_reply">in reply to hellodba</a> <a href="http://twitter.com/plinux/statuses/8953684148" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/Fenng" class="aktt_username">Fenng</a>:@HeseyWang 等你毕业的时候，更多的公司要博士了；等你博士毕业了，更多的公司不招聘了，那你怎么办？是你能改变自己的命运还是环境能改变你自己的命运？ <a href="http://twitter.com/plinux/statuses/8961260165" class="aktt_tweet_time">#</a></li>
<li>新被子好舒服~ <a href="http://twitter.com/plinux/statuses/8961739999" class="aktt_tweet_time">#</a></li>
<li>读了这么多年书，只能靠学位唬人，我想不出比这更悲惨而且丢人的人生了 <a href="http://twitter.com/plinux/statuses/8989478537" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/BillGates" class="aktt_username">BillGates</a>: Seth Berkeley at #<a href="http://search.twitter.com/search?q=%23ted" class="aktt_hashtag">ted</a> &#8211; &quot;we once knew a world without AIDS, we owe our children a world without AIDS&#8230;&quot; {盖茨大叔竟然发言了} <a href="http://twitter.com/plinux/statuses/8989558865" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/wolfdeng" class="aktt_username">wolfdeng</a>:RT @<a href="http://twitter.com/huairen" class="aktt_username">huairen</a>: 开始拼的都是做事，最后拼的都是做人。 开始拼的都是能力，最后拼的都是人品。 <a href="http://twitter.com/plinux/statuses/9010563207" class="aktt_tweet_time">#</a></li>
<li>粒度和死锁的问题不是个简单的对应问题，而是个非常有意思的逻辑问题，我想简单了 <a href="http://twitter.com/plinux/statuses/9012256052" class="aktt_tweet_time">#</a></li>
<li>广深线大年30还这么繁忙 <a href="http://twitter.com/plinux/statuses/9055593580" class="aktt_tweet_time">#</a></li>
<li>对春晚实在没兴趣 <a href="http://twitter.com/plinux/statuses/9060967194" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年10月14日 -- <a href="http://www.penglixun.com/work/architecture/staruml_and_argouml_compare.html" title="starUML和argoUML的对比">starUML和argoUML的对比</a> (2)</li><li>2009年10月10日 -- <a href="http://www.penglixun.com/life/feeling/working_for_the_dream.html" title="年级大会上的发言内容：为梦想而工作">年级大会上的发言内容：为梦想而工作</a> (0)</li><li>2009年10月10日 -- <a href="http://www.penglixun.com/study/science/how_we_know_about_world.html" title="关于世界，我们知道多少？">关于世界，我们知道多少？</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-14.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>未来10年之规划</title>
		<link>http://www.penglixun.com/life/diary/future_10_years_plan.html</link>
		<comments>http://www.penglixun.com/life/diary/future_10_years_plan.html#comments</comments>
		<pubDate>Sat, 13 Feb 2010 15:46:16 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[随笔日记]]></category>
		<category><![CDATA[人生规划]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=974</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/diary/future_10_years_plan.html 
1989~2009，成长与求学之路20年，已经... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/diary/future_10_years_plan.html </p>
<p></span>1989~2009，成长与求学之路20年，已经走完。<br />
2010~2019，工作拼搏第一个10年，已经开始。</p>
<p>给自己一个规划，一步步的去实现。现在，我以我是个阿里人而自豪，未来，我要阿里以我是阿里人而骄傲。</p>
<p>第一目标：参与至少一个大项目，经历一次从项目立项到正式发布的全部数据库设计过程。现在最缺乏的就是经验，有阿里这样大的平台，就要铆足了劲去做事，积累经验。</p>
<p>第二目标：用1~2年时间编写一个功能全面的数据库辅助系统，包括实时监控、历史记录、趋势分析、故障预警、自动备份等功能。<acronym title="Database Administrator">DBA</acronym>工作中有很多工作都是可以自动化的，却普遍存在大量的人肉工作，编写一套<acronym title="Database Administrator">DBA</acronym>辅助工具，非常有必要，也方便自己工作。</p>
<p>第三目标：用3~5年时间写一本书——《数据库常用算法分析》，总结数据库的各种常用算法，各种数据库专用的调优书籍和数据库理论书籍都很全的，缺的是从算法角度来看数据库的书，无关具体数据库，只要了解所用数据库所用的算法，调优自然方法清晰。定这么长的时间，因为想学Knuth爷爷，充分检查错误，不想在序言中写“因作者水平有限，难免有错误……”，而是写上“如果您发现一个错误，请告知作者，将奖励您2.56RMB……”，尽力做完美，会把每一步的进展都写在博客，供大家先批评，我再修改，最后整理出版成书，不在于赚稿费，在于给自己一个技术上的总结。</p>
<p>第四目标：经历5~8年时间的磨练成为一位知名的运维领域专家，利用业余时间为一些有社会价值的互联网创业企业提供无偿的数据库架构顾问。</p>
<p>第五目标：用5~10年时间编写一个可自定义选择不同算法的数据库，或基于MySQL，或自己重新写，不在于能在生产环境用的多广，而在于让跟多人理解数据库如何运转，数据库算法对数据库产生何种影响，将各种不同的算法都写入代码，用户自选用哪种，一个设想，尽力去实现。</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2010年03月9日 -- <a href="http://www.penglixun.com/work/database/split_and_merge_database.html" title="数据库的拆分与合并">数据库的拆分与合并</a> (2)</li><li>2009年10月25日 -- <a href="http://www.penglixun.com/work/database/mysql_gui_tool_in_linux.html" title="MySQL GUI Tool在Linux下运行">MySQL GUI Tool在Linux下运行</a> (0)</li><li>2009年12月17日 -- <a href="http://www.penglixun.com/work/maintenance/active_request_and_passive_detection_monitoring_compare.html" title="主动请求式与被动探测式监控的比较">主动请求式与被动探测式监控的比较</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/diary/future_10_years_plan.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>InnoDB行锁的实现分析</title>
		<link>http://www.penglixun.com/work/database/innodb_next_key_locking.html</link>
		<comments>http://www.penglixun.com/work/database/innodb_next_key_locking.html#comments</comments>
		<pubDate>Thu, 11 Feb 2010 08:27:35 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[DBA笔记]]></category>
		<category><![CDATA[InnoDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[行锁]]></category>
		<category><![CDATA[锁机制]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=968</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/database/innodb_next_key_locking.html 
感谢Fenng的提醒，已删除锁粒度... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/database/innodb_next_key_locking.html </p>
<p></span><strong>感谢Fenng的提醒，已删除锁粒度和死锁的关系，专门撰文写了<a href="http://www.penglixun.com/work/database/lock_granularity_deadlock_probability.html">锁的粒度与死锁的关系</a>。</strong></p>
<p>InnoDB与MyISAM不同，它实现的是一个行级锁，而非MyISAM的表锁。锁的粒度越大，则<del datetime="2010-02-12T15:16:00+00:00">发生死锁的概率越小、</del>锁机制开销越小，但并发能力会越低。如果锁的粒度变细，则<del datetime="2010-02-12T15:16:00+00:00">发生死锁的概率也会增大，</del>锁机制的开销会更大，但是并发能力能提高。表锁是如何实现的呢，以MyISAM为例，是在每个表的结构中加入一个互斥变量记录锁状态，像：<br />
struct Table {<br />
    Row     rows[MAXROWS];<br />
    pthread_mutex_t lock;//表锁<br />
};<br />
这样做的好处就是锁非常简单，当操作表的时候，直接锁住整个表就行，锁机制的开销非常小。但是问题也很明显，并发量上不去，因为无论多小的操作，都必须锁整个表，这可能带来其他操作的阻塞。<br />
行锁又是如何实现的呢，Oracle是直接在每个行的block上做标记，而InnoDB则是靠索引来做。InnoDB的主键索引跟一般的索引不太一样，Key后面还跟上了整行的数据，互斥变量也是加载主键索引上的，像<br />
struct PK_Idx {<br />
    Row     row;<br />
    pthread_mutex_t lock;//行锁<br />
};<br />
multimap<int, PK_Idx> pk_idx;<br />
这样的形式。<br />
这样做的好处是锁的粒度小，只锁住需要的数据不被更改，但是问题也很明显，锁的开销很大，每个主键索引上都要加上一个标记，<del datetime="2010-02-12T15:16:00+00:00">因为锁的粒度很小</del>，可能两个不同的操作各锁住一部分行等待对方释放形成死锁，不过这个是有办法解决的，把上锁的操作封装成原子操作就行，不过并发量会受些影响。</p>
<p>下面是类似InnoDB的Next-Key locking算法的演示:<br />
编译需要加-lpthread参数，例如g++ inno.cpp -lpthread -o inno<br />
<span id="more-968"></span></p>

<div class="wp_codebox"><table><tr id="p96816"><td class="code" id="p968code16"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;cstdio&gt;</span>
<span style="color: #339900;">#include &lt;cstdlib&gt;</span>
<span style="color: #339900;">#include &lt;string&gt;</span>
<span style="color: #339900;">#include &lt;map&gt;</span>
<span style="color: #339900;">#include &lt;unistd.h&gt;</span>
<span style="color: #339900;">#include &lt;time.h&gt;</span>
<span style="color: #339900;">#include &lt;pthread.h&gt;</span>
<span style="color: #339900;">#include &lt;windows.h&gt;</span>
&nbsp;
<span style="color: #339900;">#define LOCK pthread_mutex_lock(&amp;lock)</span>
<span style="color: #339900;">#define UNLOCK pthread_mutex_unlock(&amp;lock)</span>
<span style="color: #339900;">#define PRINT(STR, ...) LOCK;fprintf(stderr, STR,  __VA_ARGS__);UNLOCK</span>
&nbsp;
<span style="color: #339900;">#define MAXROWS 100</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* 行结构 */</span>
<span style="color: #0000ff;">struct</span> Row <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span>     num<span style="color: #008080;">;</span>
    string  info<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* 主键索引结构 */</span>
<span style="color: #0000ff;">struct</span> PK_Idx <span style="color: #008000;">&#123;</span>
    Row     row<span style="color: #008080;">;</span>
    pthread_mutex_t lock<span style="color: #008080;">;</span><span style="color: #666666;">//行锁</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* 表结构 */</span>
<span style="color: #0000ff;">struct</span> Table <span style="color: #008000;">&#123;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>, PK_Idx<span style="color: #000080;">&gt;</span> pk_idx<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>      num_idx<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span>string, <span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>   info_idx<span style="color: #008080;">;</span>
    Row     rows<span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    pthread_mutex_t lock<span style="color: #008080;">;</span><span style="color: #666666;">//表锁</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
Table table<span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> pid<span style="color: #008080;">;</span>
<span style="color: #666666;">//全局锁</span>
pthread_mutex_t lock <span style="color: #000080;">=</span> PTHREAD_MUTEX_INITIALIZER<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* 随机字符 */</span>
<span style="color: #0000ff;">char</span> randChar<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color:#800080;">26</span><span style="color: #000040;">+</span><span style="color: #FF0000;">'A'</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* 随机字符串 */</span>
<span style="color: #0000ff;">void</span> randString<span style="color: #008000;">&#40;</span>string <span style="color: #000040;">&amp;</span>col, <span style="color: #0000ff;">int</span> len<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    col <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;&quot;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>len<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        col <span style="color: #000040;">+</span><span style="color: #000080;">=</span> randChar<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* 初始化数据 */</span>
<span style="color: #0000ff;">void</span> init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    pid <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    PK_Idx pk<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">srand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">time</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">//初始化表数据</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        pk.<span style="color: #007788;">row</span>.<span style="color: #007788;">num</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span>MAXROWS<span style="color: #008080;">;</span>
        randString<span style="color: #008000;">&#40;</span>pk.<span style="color: #007788;">row</span>.<span style="color: #007788;">info</span>, <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color:#800080;">10</span><span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">//初始化行锁</span>
        pk.<span style="color: #007788;">lock</span> <span style="color: #000080;">=</span> PTHREAD_MUTEX_INITIALIZER<span style="color: #008080;">;</span>
        <span style="color: #666666;">//写入表数据</span>
        table.<span style="color: #007788;">rows</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">num</span> <span style="color: #000080;">=</span> pk.<span style="color: #007788;">row</span>.<span style="color: #007788;">num</span><span style="color: #008080;">;</span>
        table.<span style="color: #007788;">rows</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">info</span> <span style="color: #000080;">=</span> pk.<span style="color: #007788;">row</span>.<span style="color: #007788;">info</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">//写入索引</span>
        table.<span style="color: #007788;">pk_idx</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>, PK_Idx<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>i, pk<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        table.<span style="color: #007788;">num_idx</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>, <span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>pk.<span style="color: #007788;">row</span>.<span style="color: #007788;">num</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        table.<span style="color: #007788;">info_idx</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span>string, <span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>pk.<span style="color: #007788;">row</span>.<span style="color: #007788;">info</span>, i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #666666;">//初始化表锁</span>
    table.<span style="color: #007788;">lock</span> <span style="color: #000080;">=</span> PTHREAD_MUTEX_INITIALIZER<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*获取范围数据*/</span>
<span style="color: #0000ff;">void</span> select_num<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> begin, <span style="color: #0000ff;">int</span> end<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> cur_pid<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> it, itlow, itup<span style="color: #008080;">;</span>
    PK_Idx <span style="color: #000040;">*</span>pk<span style="color: #008080;">;</span>
    <span style="color: #ff0000; font-style: italic;">/* 按字段范围查找ID */</span>
    itlow <span style="color: #000080;">=</span> table.<span style="color: #007788;">num_idx</span>.<span style="color: #007788;">lower_bound</span> <span style="color: #008000;">&#40;</span>begin<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    itup <span style="color: #000080;">=</span> table.<span style="color: #007788;">num_idx</span>.<span style="color: #007788;">upper_bound</span> <span style="color: #008000;">&#40;</span>end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    LOCK<span style="color: #008080;">;</span>
    cur_pid <span style="color: #000080;">=</span> pid<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
    UNLOCK<span style="color: #008080;">;</span>
    PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : * Start Select:%d,%d *<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid, begin, end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>it<span style="color: #000080;">=</span>itlow<span style="color: #008080;">;</span> it<span style="color: #000040;">!</span><span style="color: #000080;">=</span>itup<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        id <span style="color: #000080;">=</span> it<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008080;">;</span>
        pk <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>table.<span style="color: #007788;">pk_idx</span>.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #666666;">//根据ID去查主键索引</span>
        pthread_mutex_lock<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>lock<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #666666;">//在主键索引上加锁</span>
        PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : LOCK Row %d: %d<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid, id, pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>row.<span style="color: #007788;">num</span>, pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>row.<span style="color: #007788;">info</span>.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        Sleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>it<span style="color: #000080;">=</span>itlow<span style="color: #008080;">;</span> it<span style="color: #000040;">!</span><span style="color: #000080;">=</span>itup<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        id <span style="color: #000080;">=</span> it<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008080;">;</span>
        pk <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>table.<span style="color: #007788;">pk_idx</span>.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : UNLOCK Row %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid, id<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        pthread_mutex_unlock<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>lock<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #666666;">//使用完毕依次释放锁</span>
    <span style="color: #008000;">&#125;</span>
    PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : * Select Finished! *<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*修改范围数据*/</span>
<span style="color: #0000ff;">void</span> update_num<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> begin, <span style="color: #0000ff;">int</span> end<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> cur_pid<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> it, itlow, itup<span style="color: #008080;">;</span>
    PK_Idx <span style="color: #000040;">*</span>pk<span style="color: #008080;">;</span>
&nbsp;
    itlow <span style="color: #000080;">=</span> table.<span style="color: #007788;">num_idx</span>.<span style="color: #007788;">lower_bound</span> <span style="color: #008000;">&#40;</span>begin<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    itup <span style="color: #000080;">=</span> table.<span style="color: #007788;">num_idx</span>.<span style="color: #007788;">upper_bound</span> <span style="color: #008000;">&#40;</span>end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    LOCK<span style="color: #008080;">;</span>
    cur_pid <span style="color: #000080;">=</span> pid<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
    UNLOCK<span style="color: #008080;">;</span>
    PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : * Start Update:%d,%d *<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid, begin, end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>it<span style="color: #000080;">=</span>itlow<span style="color: #008080;">;</span> it<span style="color: #000040;">!</span><span style="color: #000080;">=</span>itup<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        id <span style="color: #000080;">=</span> it<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008080;">;</span>
        pk <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>table.<span style="color: #007788;">pk_idx</span>.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        pthread_mutex_lock<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>lock<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : LOCK Row %d: %d<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid, id, pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>row.<span style="color: #007788;">num</span>, pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>row.<span style="color: #007788;">info</span>.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        Sleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>it<span style="color: #000080;">=</span>itlow<span style="color: #008080;">;</span> it<span style="color: #000040;">!</span><span style="color: #000080;">=</span>itup<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        id <span style="color: #000080;">=</span> it<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008080;">;</span>
        pk <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>table.<span style="color: #007788;">pk_idx</span>.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span>id<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>second<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : UNLOCK Row %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid, id<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        pthread_mutex_unlock<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span><span style="color: #008000;">&#40;</span>pk<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>lock<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d : * Update Finished! *<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, cur_pid<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> test_select<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> begin, end<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">srand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">time</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        begin <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color: #008000;">&#40;</span>MAXROWS<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        end <span style="color: #000080;">=</span> begin<span style="color: #000040;">+</span><span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color: #008000;">&#40;</span>MAXROWS<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        select_num<span style="color: #008000;">&#40;</span>begin, end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        Sleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span><span style="color: #000040;">*</span> test_update<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span> <span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> begin, end<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">srand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span><span style="color: #008000;">&#41;</span><span style="color: #0000dd;">time</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        begin <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color: #008000;">&#40;</span>MAXROWS<span style="color: #000040;">/</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        end <span style="color: #000080;">=</span> begin<span style="color: #000040;">+</span><span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color: #008000;">&#40;</span>MAXROWS<span style="color: #000040;">/</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        update_num<span style="color: #008000;">&#40;</span>begin, end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        Sleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    pthread_t id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pthread_create<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span>, <span style="color: #0000ff;">NULL</span>, test_select, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%s&quot;</span>, <span style="color: #FF0000;">&quot;Create Thread Error!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>pthread_create<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>id<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span>, <span style="color: #0000ff;">NULL</span>, test_update, <span style="color: #0000ff;">NULL</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        PRINT<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%s&quot;</span>, <span style="color: #FF0000;">&quot;Create Thread Error!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
		Sleep<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">500</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>
<h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年01月14日 -- <a href="http://www.penglixun.com/work/database/xtradb_compile_error.html" title="XtraDB 1.0.6-9编译错误的解决">XtraDB 1.0.6-9编译错误的解决</a> (0)</li><li>2009年09月30日 -- <a href="http://www.penglixun.com/work/database/mysql_parameter_tuning.html" title="MySQL参数调优">MySQL参数调优</a> (0)</li><li>2010年03月10日 -- <a href="http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html" title="MySQL多服务器批量执行SQL脚本">MySQL多服务器批量执行SQL脚本</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/database/innodb_next_key_locking.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>每周推特 2010-02-07</title>
		<link>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html</link>
		<comments>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html#comments</comments>
		<pubDate>Sun, 07 Feb 2010 04:00:00 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[生活轨迹]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/work/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html 


RT @jason5ng32: 中国... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html </p>
<p></span>
<ul class="aktt_tweet_digest">
<li>RT @<a href="http://twitter.com/jason5ng32" class="aktt_username">jason5ng32</a>: 中国政府在处理冯正虎事件的这80多天表现出的专制、冷漠、狂妄、傲慢，同冯正虎先生始终坚持的执著、坚持、非暴力、耐心、温和、对话形成鲜明的对比 #<a href="http://search.twitter.com/search?q=%23GFW" class="aktt_hashtag">GFW</a> /via @<a href="http://twitter.com/daxa" class="aktt_username">daxa</a> <a href="http://twitter.com/plinux/statuses/8438632750" class="aktt_tweet_time">#</a></li>
<li>洗衣服把水都洗黑了，没有洗衣机我真活不下去，洗完手都冻僵了，米有热水好悲剧。妈妈冬天洗衣服不容易…… <a href="http://twitter.com/plinux/statuses/8442010236" class="aktt_tweet_time">#</a></li>
<li>今天洗了好多东西，洗黑了一桶又一桶的水，我的手已经麻木了…… <a href="http://twitter.com/plinux/statuses/8447156580" class="aktt_tweet_time">#</a></li>
<li>伯克利为计算机世界贡献了多少跨时代的产品啊~ <a href="http://twitter.com/plinux/statuses/8450502574" class="aktt_tweet_time">#</a></li>
<li>人活着不是为了上学工作赚钱买房子然后制造下一个循环，得活出点味道来，不要总是拿现实太残酷说话，任何恶劣的环境都不能成为懦弱的借口 <a href="http://twitter.com/plinux/statuses/8451222732" class="aktt_tweet_time">#</a></li>
<li>我觉得真正理解科学，研究科学的人，是不会排斥所谓的玄学、宗教，都是以承认某些无法证明的公理为基础，只是科学使用的公理更接近人类理性认知。否则哪来的基督教徒的诺贝尔奖，信神就不懂科学，没有这种理论。 <a href="http://twitter.com/plinux/statuses/8451455155" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/kisafran" class="aktt_username">kisafran</a> 奇函数则f(x)=-f(-x),那么f(x)-f(-x)/x=f(x) f(x)/x=(xf(x) f(x))/x&lt;0，那么假设x&lt;1，f(x)&lt;0,xf(x) f(x)&lt;0，成立。反之不成立。所以解集是x&lt;1。不知道对否,高等数学大一学到大四。 <a href="http://twitter.com/kisafran/statuses/8451458802" class="aktt_tweet_reply">in reply to kisafran</a> <a href="http://twitter.com/plinux/statuses/8451750629" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/OnlyLonely1984" class="aktt_username">OnlyLonely1984</a>: 这个真的是太郁闷了 RT @<a href="http://twitter.com/tinyfool" class="aktt_username">tinyfool</a>: RT @<a href="http://twitter.com/doubleaf" class="aktt_username">doubleaf</a>: 在北京到西安的火车上，隔壁有俩人票是一样的，同一天同一个铺位，还都是真票。。列车长来了，说找车站去。。 {难道是售票系统没有事务保证~} <a href="http://twitter.com/plinux/statuses/8451767536" class="aktt_tweet_time">#</a></li>
<li>跟GF讨论宇宙和量子力学的问题……对薛定谔同志的东西，我知道他证明了什么有什么意义，但恕我真的不会用，那个薛定谔方程，我死也不知道怎么算…… <a href="http://twitter.com/plinux/statuses/8452129098" class="aktt_tweet_time">#</a></li>
<li>超弦理论已经超过了我的认知范围……平行宇宙是我理解的极限了~咳咳，我还是搞数据库去吧……GF竟然能理解薛定谔的猫，鼓掌~ <a href="http://twitter.com/plinux/statuses/8452213909" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/rtmeme" class="aktt_username">rtmeme</a>: RT @<a href="http://twitter.com/911023" class="aktt_username">911023</a> RT @<a href="http://twitter.com/pufei" class="aktt_username">pufei</a>: RT @<a href="http://twitter.com/hsqianshuiting" class="aktt_username">hsqianshuiting</a>: 一只派驻美国的熊猫回天朝，那畜生要上CCAV，冯正虎先生回国，可以上除了CCAV以外的其他国家电视 <a href="http://twitter.com/plinux/statuses/8452451016" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/cosbeta" class="aktt_username">cosbeta</a>: 永远要跑在市场的前面才有利可图，国外的厂家大抵如此，他们在引领市场 {eBay就是来早了被淘宝干掉了，关键要看经营，如果eBay走现在淘宝的免费道路，不收费，先积攒用户，现在就不是淘宝的天下了} <a href="http://twitter.com/plinux/statuses/8452567238" class="aktt_tweet_time">#</a></li>
<li>讨论科学和伪科学就是扯淡，从可证伪性来说，数学就是最大的伪科学，数学理论存在大量不可证伪的地方。但是说数学不是科学，是伪科学，不被砖头砸死才怪。 <a href="http://twitter.com/plinux/statuses/8452658528" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/Fenng" class="aktt_username">Fenng</a>: 世界排名前 50 的网站，大约有 1/10 (5个左右)的技术团队是不到 50 人的。 <a href="http://twitter.com/plinux/statuses/8452712494" class="aktt_tweet_time">#</a></li>
<li>从玄学扯到宇宙，从量子力学扯到相对论平行宇宙，从神扯到科学的公理，然后扯到科学与伪科学界定，又扯到可证伪性，然后扯到数学不可证伪，然后又跳跃到集合论的不完备性，现在扯到哥德尔不完备定理，我已经进入状态了，跟GF继续扯…… <a href="http://twitter.com/plinux/statuses/8452840723" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/Fenng" class="aktt_username">Fenng</a> .NET我觉得还是设计上的问题，一上手，太好用了，太方便了，深入下去，我想做做这个行不行，不好意思不行，我换个方法看行不行，不好意思也不行，到最后越用越觉得不爽。.NET有微软再强大的支持也不能和Java活跃的社区相比。 <a href="http://twitter.com/Fenng/statuses/8452781769" class="aktt_tweet_reply">in reply to Fenng</a> <a href="http://twitter.com/plinux/statuses/8452917340" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/number5" class="aktt_username">number5</a>: &quot;久经GFW考验的穿墙战士“ &#8212; 我曾经在某论坛用过的title #<a href="http://search.twitter.com/search?q=%23GFW" class="aktt_hashtag">GFW</a> <a href="http://twitter.com/plinux/statuses/8454201157" class="aktt_tweet_time">#</a></li>
<li>爱国者3型能防御东风2就不让卖了，凭什么不让别人自卫，谁就活该挨打 <a href="http://twitter.com/plinux/statuses/8455397929" class="aktt_tweet_time">#</a></li>
<li>当Google发展成一个崇拜的对象，占据人们生活的每个部分，也需要克制一下，任何一个公司掌握如此多人的生活都是非常可怕的 <a href="http://twitter.com/plinux/statuses/8455997580" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/wangpei" class="aktt_username">wangpei</a>: 一老外朋友看到北京对美国军售的激烈反应，忧心忡忡地问我：“两国会断交吗？”我说：“不会。”他问why，我说：“夫妻吵架，小媳妇负气回娘家而已。”他听不懂。 <a href="http://twitter.com/plinux/statuses/8456320416" class="aktt_tweet_time">#</a></li>
<li>看有没有哪个同学有Nexus One，很想试试。 <a href="http://twitter.com/plinux/statuses/8477312962" class="aktt_tweet_time">#</a></li>
<li>有了Partition，Merge引擎可以退役了 <a href="http://twitter.com/plinux/statuses/8479286174" class="aktt_tweet_time">#</a></li>
<li>对于写多读少的表，采用HASH分区更能把负载平衡出去，写压力不会集中到一个分区；对于读多写少的表，采用RANGE分区更能平衡压力，读数据可以在少的分区内完成；对于数据分布明显依赖于某个字段的，则采用LIST手动分配来平衡负载。#learnmysql <a href="http://twitter.com/plinux/statuses/8480847884" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a>: RT @<a href="http://twitter.com/ktmud" class="aktt_username">ktmud</a>: 永远不要轻易否定别人的工作，有些你作为外行看起来很简单的东西，真正实现起来会很麻烦。在此深刻检讨一下。此事也充分说明，有一个明确而细致的前期规划是多么重要。 <a href="http://twitter.com/plinux/statuses/8490728058" class="aktt_tweet_time">#</a></li>
<li>王者之国，使人民富裕。霸者之国，使士人富裕。仅存之国，士大夫富裕。无道之国，国库富裕。 <a href="http://twitter.com/plinux/statuses/8490800887" class="aktt_tweet_time">#</a></li>
<li>不吐出我的转移码，我就一天一封邮件到<acronym title="Internet Corporation for Assigned Names and Numbers">ICANN</acronym>，绝不交转移费，反正发邮件又不要钱 <a href="http://twitter.com/plinux/statuses/8495337524" class="aktt_tweet_time">#</a></li>
<li>Cygwin好慢呀…… <a href="http://twitter.com/plinux/statuses/8495386519" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/hellodba" class="aktt_username">hellodba</a>: New blog post: Oracle Exadata技术浅析 <a href="http://www.hellodba.net/2010/02/oracle_exadata.html" rel="nofollow">http://www.hellodba.net/2010/02/oracle_exadata.html</a> <a href="http://twitter.com/plinux/statuses/8499072413" class="aktt_tweet_time">#</a></li>
<li>高僧都是扫地的，牛人都是卖书的 <a href="http://twitter.com/plinux/statuses/8500217599" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/fire9" class="aktt_username">fire9</a>: 希望Larry老大兑现对MySQL的10大承诺。 {说话算话就不是埃里森了} <a href="http://twitter.com/plinux/statuses/8525001552" class="aktt_tweet_time">#</a></li>
<li>InfiniDB专门用作数据分析的引擎，比较有意思，来编译用下试试。#learnmysql <a href="http://twitter.com/plinux/statuses/8525453289" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/ShooterPlayer" class="aktt_username">ShooterPlayer</a>: 『Nginx <acronym title="eXtensible Stylesheet Language Transformations">XSLT</acronym>模块性能与稳定性测试』  <a href="http://is.gd/7v2Vy" rel="nofollow">http://is.gd/7v2Vy</a> <acronym title="eXtensible Stylesheet Language Transformations">XSLT</acronym>模块性能比php提高10%以上，而且大为稳定。而纯静态xml xslt组合则可以提高服务能力3倍以上&#8230; <a href="http://twitter.com/plinux/statuses/8526361156" class="aktt_tweet_time">#</a></li>
<li>MySQL要是需要授权了，新的引擎必将大量出现，群雄涿鹿，看谁能最后一统江湖。InfiniDB、MariaDB、Falcon都是很好的引擎～也可能特殊用途的引擎能各分一块山头，像适用OLAP的InfiniDB等等～ <a href="http://twitter.com/plinux/statuses/8531346649" class="aktt_tweet_time">#</a></li>
<li>Infobright和InfiniDB都是列式存储，很适合全表选取一个或者几个字段，OLAP这样很合适。它们都是基于MySQL框架的，MySQL的数据引擎式的架构太有前瞻性了，为开源数据库/数据仓库的发展作出了不可磨灭的贡献～#learnmysql <a href="http://twitter.com/plinux/statuses/8531650250" class="aktt_tweet_time">#</a></li>
<li>Infobaright压缩比不是吹的，40多M的导入文件，导入后才1M多，吓到我了。 <a href="http://twitter.com/plinux/statuses/8535855902" class="aktt_tweet_time">#</a></li>
<li>基于列存储的引擎真的太爽了，晚上写篇博文分析下它的实现原理，比行存储更适合做大数据分析。 <a href="http://twitter.com/plinux/statuses/8537568781" class="aktt_tweet_time">#</a></li>
<li>终于把C指针给梳理清楚了，被折磨死了……语言不常用就忘了。 <a href="http://twitter.com/plinux/statuses/8580163421" class="aktt_tweet_time">#</a></li>
<li>在写行式存储和列式存储在动态和静态结构下分别在内存和磁盘上的性能，共[行式|列式][静态|动态][内存|磁盘]八种情况，采用STL的multimap做索引，内部红黑数实现，自己写的Splay平衡树性能实在拿不出手。 <a href="http://twitter.com/plinux/statuses/8580988537" class="aktt_tweet_time">#</a></li>
<li>内存中静态表行式和列式存储的测试结果，共1000000条记录，匹配466440行，行式存储完全索引，耗时50ms，列式存储&lt;=0ms，震惊了…… <a href="http://twitter.com/plinux/statuses/8581526594" class="aktt_tweet_time">#</a></li>
<li>列式存储的大数据查询效率惊人…… <a href="http://twitter.com/plinux/statuses/8581539562" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/ryangato" class="aktt_username">ryangato</a>: RT @<a href="http://twitter.com/secretaryzhang" class="aktt_username">secretaryzhang</a>: RT @<a href="http://twitter.com/hr6r" class="aktt_username">hr6r</a>: Cisco Evil ! 一边协助建造  #<a href="http://search.twitter.com/search?q=%23GFW" class="aktt_hashtag">GFW</a> ，一边卖VPN，真是不得好死！ <a href="http://twitter.com/plinux/statuses/8582813874" class="aktt_tweet_time">#</a></li>
<li>文件中读取测试，列式存储大数据获取比行式存储仍然要大，列式不存在索引的情况下，小数据读取行式占有，如果列上存在计算，列式存储优势明显。 <a href="http://twitter.com/plinux/statuses/8584322020" class="aktt_tweet_time">#</a></li>
<li>算完了大学的开销，学费住宿费24K，生活费38K，败家19K，大学一共花了81K 。奖学金20K，教奥赛19K，项目18K，工资7K，大学共收入64K。正负相抵大学花费17K。 <a href="http://twitter.com/plinux/statuses/8592379413" class="aktt_tweet_time">#</a></li>
<li>辗转反侧，睡不着，想不通为什么我的列式存储比Infobright慢那么多，处理方式有何不同，Infobright也是单文件无索引，是不是有隐含的类似索引的指针还是文件组织方式上有什么特殊的地方？我的程序时间消耗在文件指针的移动上。 <a href="http://twitter.com/plinux/statuses/8592876883" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/amoiist" class="aktt_username">amoiist</a>: RT @<a href="http://twitter.com/shaohuachen" class="aktt_username">shaohuachen</a>: 可耐滴老虎，满载而归。2 。。http://img.ly/rGv #<a href="http://search.twitter.com/search?q=%23fzhenghu" class="aktt_hashtag">fzhenghu</a> <a href="http://twitter.com/plinux/statuses/8592986573" class="aktt_tweet_time">#</a></li>
<li>对列式存储的测试程序做了个改进，采用多个文件指针，分别指向每个列的启示位置，这样通过条件查找的时候定位到id就可以使用要选择列的指针直接去取，时间从1000多ms降低到200多ms，如果能将一个表的多个列分别存储在一个文件，效率还能高。 <a href="http://twitter.com/plinux/statuses/8614007106" class="aktt_tweet_time">#</a></li>
<li>当同样的表存在于多个实例时，最多只能有一个实例中的表是自增ID，否则同步数据的时候很可能产生ID不一致的情况。A实例的表产生自增ID，同步到B实例的表的时候也插入ID，但ID要做主键约束唯一，这样同步起来才不会出现主键不一致。#learnmysql <a href="http://twitter.com/plinux/statuses/8617764941" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/tjmao" class="aktt_username">tjmao</a>: 买电脑我只有一个要求：可以装上10个8个虚拟机同时运行。主要区分一下，网购和网银的一台，不联网的一台，平时上网用的一台，剩下的用于开发…… {我要4个跑RAC，3个跑MySQL Cluster，再来1个写程序就行了} <a href="http://twitter.com/plinux/statuses/8618699068" class="aktt_tweet_time">#</a></li>
<li>每个翻墙女的背后，一定有一个翻墙男，或者她的室友/密友背后有一个翻墙男…… <a href="http://twitter.com/plinux/statuses/8618820125" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/Fenng" class="aktt_username">Fenng</a>: 阿里巴巴旗下公司 2009 年招聘超过 6000 人。相当惊人。http://www.jobsdigg.com/story/2643/ <a href="http://twitter.com/plinux/statuses/8619007741" class="aktt_tweet_time">#</a></li>
<li>测试Twitter/新浪围脖/人人网实时同步 <a href="http://twitter.com/plinux/statuses/8619490261" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/rtmeme" class="aktt_username">rtmeme</a>: RT @<a href="http://twitter.com/GTPAD" class="aktt_username">GTPAD</a> RT @<a href="http://twitter.com/beckyeeky" class="aktt_username">beckyeeky</a>: KDS还是非常Insight的：问：打过胎的女人还能要吗？答，死过人的二手房你还敢住吗？ (via 淫淫) <a href="http://twitter.com/plinux/statuses/8619580755" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/hidecloud" class="aktt_username">hidecloud</a>: 静茹是我们这批80后的一个童话。看到她的幸福，也同时感受到我们的成长与年华逝去。 <a href="http://twitter.com/plinux/statuses/8619586582" class="aktt_tweet_time">#</a></li>
<li>美不胜收的数据图，http://goo.gl/3CIW，运维中另一个美妙的世界就是数据图。 <a href="http://twitter.com/plinux/statuses/8620436701" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a>: RT @<a href="http://twitter.com/KrzyCube" class="aktt_username">KrzyCube</a>: RT @<a href="http://twitter.com/yeka52" class="aktt_username">yeka52</a>: RT @<a href="http://twitter.com/xjb" class="aktt_username">xjb</a>: 世界上任何书籍都不能带给你好运，但是它们能让你悄悄成为你自己&#8211;赫尔曼.黑塞 <a href="http://twitter.com/plinux/statuses/8621759803" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/bang590" class="aktt_username">bang590</a>: RT @<a href="http://twitter.com/feelinglucky" class="aktt_username">feelinglucky</a>: RT @<a href="http://twitter.com/huairen" class="aktt_username">huairen</a>: 宗曦@om19 同学成功求婚。。。。杭州兄弟见证求婚现场。 祝福 <a href="http://is.gd/7FeqE" rel="nofollow">http://is.gd/7FeqE</a> //祝福~有没有全过程解析~我好学习学习~ <a href="http://twitter.com/plinux/statuses/8621808642" class="aktt_tweet_time">#</a></li>
<li>求SAE邀请码～有朋友方便的话给我个邀请码～ <a href="http://twitter.com/plinux/statuses/8621859216" class="aktt_tweet_time">#</a></li>
<li>准备在国内搭建一个博客镜像，国外实在有点慢，数据库架在国外，网页放在国内一个副本，文件每天打包传到国外备份。不得不说GFW撑起了一个巨大的产业。 <a href="http://twitter.com/plinux/statuses/8621909673" class="aktt_tweet_time">#</a></li>
<li>博客加速方案:购买国内一合租主机，存放网页，数据库/VPN/Twitter <acronym title="Application Programming Interface">API</acronym>毫无疑问继续留在美国VPS。文件上传到国外主机，通过<acronym title="File Transfer Protocol">FTP</acronym>协议同步传输到国内主机。反正我有多个域名，一个指向国内，一个指向国外，挂掉任何一个都还能用。这么折腾就为了博客快一点，顺便练练程序。 <a href="http://twitter.com/plinux/statuses/8622274911" class="aktt_tweet_time">#</a></li>
<li>业余也看看Wordpress源码，看能不能改成读写分离的结构，这样的话就写国外，读国内，那爽多了，呵呵～ <a href="http://twitter.com/plinux/statuses/8622300213" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yanzisky1989" class="aktt_username">yanzisky1989</a>: 呃。看到韩寒开新浪围脖了。为了关注他，我也只好开通围脖。囧。我这记性，说不定哪天会忘记密码的说。 {搞个密码管理软件嘛} <a href="http://twitter.com/plinux/statuses/8623623039" class="aktt_tweet_time">#</a></li>
<li>给程式设计师的Vim入门图解说明 <a href="http://goo.gl/lGme" rel="nofollow">http://goo.gl/lGme</a> <a href="http://twitter.com/plinux/statuses/8624555401" class="aktt_tweet_time">#</a></li>
<li>小小的总结了下我的前20年，努力把我接下来的20年过的更精彩。 <a href="http://twitter.com/plinux/statuses/8636102980" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/onlyswan" class="aktt_username">onlyswan</a>: 不知道。RT @<a href="http://twitter.com/qianshuiting" class="aktt_username">qianshuiting</a>: @<a href="http://twitter.com/onlyswan" class="aktt_username">onlyswan</a> 求四万姐帮忙：知道有什么软件能够轻松的实现数据分类吗？就是类似于淘宝搜索后能够把搜索出来的东西按地区排列、按价格排列、按信用度高低排列，我需要有这样的功能的软件 {这是靠索引做的} <a href="http://twitter.com/plinux/statuses/8636564276" class="aktt_tweet_time">#</a></li>
<li>从总结中看，从我小学四年级第一次跟着杂志上瞎搞Red Hat 6开始，现在接触Linux 10年了，不过我应用Linux的水平…哎…不说了，伤心。当年好好用Linux就好了，那时代Win98和RH6相比其实RH6蛮好的，反正我都不会玩，学Win还是RH都差不多。 <a href="http://twitter.com/plinux/statuses/8636790938" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/blogkid" class="aktt_username">blogkid</a>: 早上炒菠菜炒多了，下锅之后，多到搅不开。还好菠菜越炒越少。后来想着也许是年前最后一次做饭，把一锅菠菜都吃了。 {早饭自己做啊，那得起多早呀} <a href="http://twitter.com/plinux/statuses/8659225826" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/blogkid" class="aktt_username">blogkid</a> 百度的上班时间果然很开放，来学校讲座的就说上班时间是很随意的，看来不是忽悠的 <a href="http://twitter.com/blogkid/statuses/8659256591" class="aktt_tweet_reply">in reply to blogkid</a> <a href="http://twitter.com/plinux/statuses/8659384160" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/DarthAnarchy" class="aktt_username">DarthAnarchy</a>: RT @<a href="http://twitter.com/rtmeme" class="aktt_username">rtmeme</a>: RT @<a href="http://twitter.com/pufei" class="aktt_username">pufei</a> RT @<a href="http://twitter.com/nyliulei" class="aktt_username">nyliulei</a> 经典语录：收费时说：“这符合国际惯例！”服务时却说：“要考虑中国国情！”（vir新浪微博） <a href="http://twitter.com/plinux/statuses/8659402626" class="aktt_tweet_time">#</a></li>
<li>Google App神器，我土了～才用起来 <a href="http://twitter.com/plinux/statuses/8663512291" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/FTChinese" class="aktt_username">FTChinese</a> 华远集团董事长任志强：“房地产打下去GDP就掉下去了，GDP掉下去，温总理比我们开发商还急。” <a href="http://twitter.com/plinux/statuses/8664432030" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a>: 如果你是硬件厂商，希望你的硬件能在 Linux kernel 下运作，那么就必须要有驱动程序。如果驱动程序的程序代码公开，等于硬件规格也公开的差不多了。许多厂商不愿意这么做，所以就提供编好的驱动程序，但不提供原始码。 <a href="http://twitter.com/plinux/statuses/8664730448" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/zheng" class="aktt_username">zheng</a>: 现在公务员、国企、事业单位人超多，为了证明自己存在的理由，就必须不断地找事，没事找事。。。 <a href="http://twitter.com/plinux/statuses/8664741145" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/hecaitou" class="aktt_username">hecaitou</a>: 淘宝UED博客亮了，看回帖：http://tinyurl.com/ygqlgru <a href="http://twitter.com/plinux/statuses/8666308086" class="aktt_tweet_time">#</a></li>
<li>注册了个域名dbawiki.org，准备搞个wiki，把自己今后做数据库的一些总结全部放上去，也欢迎大家一起修改。 <a href="http://twitter.com/plinux/statuses/8669029624" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/jeffz_cn" class="aktt_username">jeffz_cn</a> 应该是02和05两次，上交搞ACM恨，ACM班的就做题和上专业课就行了。清华还没这么猛，虽然清华招的苗子更好。 <a href="http://twitter.com/jeffz_cn/statuses/8669682417" class="aktt_tweet_reply">in reply to jeffz_cn</a> <a href="http://twitter.com/plinux/statuses/8669715597" class="aktt_tweet_time">#</a></li>
<li>面向对象设计解决业务执行逻辑问题，数据库设计解决数据高效的问题，由OR-mapping来连接它们 <a href="http://twitter.com/plinux/statuses/8670372944" class="aktt_tweet_time">#</a></li>
<li>RT @<a href="http://twitter.com/yxwlmxy" class="aktt_username">yxwlmxy</a>: RT @<a href="http://twitter.com/lianyue" class="aktt_username">lianyue</a>: 欲望、私心、逐利，都是人正常的构成，一点也不可耻。宣称自己没有这些东西的人才值得警惕。 <a href="http://twitter.com/plinux/statuses/8670776146" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/NinGoo" class="aktt_username">NinGoo</a> Google App Engine的存储就是这样，可以把一个对象丢进去，再完整的拿出来，GAE也提供Python或者Java的<acronym title="Software Development Kit">SDK</acronym>，可能实现方法跟GAE类似。C/C  的二进制读写也可以把一个结构体/对象完整的写入文件并且读取，只要不涉及指针。 <a href="http://twitter.com/NinGoo/statuses/8679552076" class="aktt_tweet_reply">in reply to NinGoo</a> <a href="http://twitter.com/plinux/statuses/8682239714" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/NinGoo" class="aktt_username">NinGoo</a> 《Python核心编程》，我最早看的这本，不过错误也蛮多，Python版本变化语法都有些小变化，有时很郁闷，书上程序都调通Python差不多就通了，入门看起来很吃力。《Python学习手册》这本蛮好的，现在看这本，相对简单。 <a href="http://twitter.com/NinGoo/statuses/8677732094" class="aktt_tweet_reply">in reply to NinGoo</a> <a href="http://twitter.com/plinux/statuses/8683437840" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/housyhou" class="aktt_username">housyhou</a> 收到，即刻查阅，这是哪个版本的问题，1.0么 <a href="http://twitter.com/housyhou/statuses/8699750042" class="aktt_tweet_reply">in reply to housyhou</a> <a href="http://twitter.com/plinux/statuses/8700272787" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/housyhou" class="aktt_username">housyhou</a> 可能InnoDB参数变化了，我也查查程序 <a href="http://twitter.com/housyhou/statuses/8700426599" class="aktt_tweet_reply">in reply to housyhou</a> <a href="http://twitter.com/plinux/statuses/8700587468" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/housyhou" class="aktt_username">housyhou</a> 我大约知道是什么错，不过我要输出一下我才知道，我的程序结构化拆的很离散，是一个变量没定义，你懂<acronym title="Practical Extraction and Report Language">Perl</acronym>么？在1470行上面写上if(!defined($status[$now]-&gt;{&quot;$val&quot;}))print $val;运行一下就停止然后看控制台输出什么。 <a href="http://twitter.com/housyhou/statuses/8700426599" class="aktt_tweet_reply">in reply to housyhou</a> <a href="http://twitter.com/plinux/statuses/8700782524" class="aktt_tweet_time">#</a></li>
<li>@<a href="http://twitter.com/housyhou" class="aktt_username">housyhou</a> 大概知道，你的版本没有这两个参数，所以运算的时候就没有初始化，不知道你打了Patch后有哪些参数。show global variables like &quot;%innodb%&quot;看看有哪些结果，发个邮件给我行么，penglixun(at)gmail.com <a href="http://twitter.com/housyhou/statuses/8701689823" class="aktt_tweet_reply">in reply to housyhou</a> <a href="http://twitter.com/plinux/statuses/8701816198" class="aktt_tweet_time">#</a></li>
</ul>
<p class="aktt_credit">Powered by <a href="http://alexking.org/projects/wordpress">Twitter Tools</a></p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年06月2日 -- <a href="http://www.penglixun.com/it/system/install_gnome_gui_in_freebsd.html" title="在FreeBSD下安装Gnome图形界面">在FreeBSD下安装Gnome图形界面</a> (0)</li><li>2009年08月20日 -- <a href="http://www.penglixun.com/work/database/vs2008_data_source_config_problem.html" title="关于VS2008与一些数据源配置的问题">关于VS2008与一些数据源配置的问题</a> (0)</li><li>2009年10月10日 -- <a href="http://www.penglixun.com/life/feeling/working_for_the_dream.html" title="年级大会上的发言内容：为梦想而工作">年级大会上的发言内容：为梦想而工作</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/%e6%af%8f%e5%91%a8%e6%8e%a8%e7%89%b9-2010-02-07.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的20年</title>
		<link>http://www.penglixun.com/life/diary/my_20_years.html</link>
		<comments>http://www.penglixun.com/life/diary/my_20_years.html#comments</comments>
		<pubDate>Fri, 05 Feb 2010 14:17:23 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[随笔日记]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=956</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/life/diary/my_20_years.html 
1989年11月10日，P.Linux闪亮登场，2009年11月10... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/life/diary/my_20_years.html </p>
<p></span>1989年11月10日，P.Linux闪亮登场，2009年11月10日，终于走完了第一个20年，在此记录一下。</p>
<p>1990~1991，太小，没回忆。</p>
<p><strong>&#8212;-学前阶段&#8212;-</strong><br />
1992年，<strong>3岁</strong>，幼儿园小班。<br />
记的当初是被妈妈拉着去幼儿园的，打小我就不喜欢上学。记得应该是这个时候，爸爸去了广东打工。<br />
1993年，<strong>4岁</strong>，幼儿园中班。<br />
妈妈腰经常痛，我立志要当军官，让警卫照顾妈妈，这个志向一直持续了十余年直到国防科大梦想的破灭。</p>
<p>1994年，<strong>5岁</strong>，幼儿园大班。<br />
看动画片知道有机器人这种东西，跟妈妈说，我要做一个机器人帮妈妈做家务，这个志向一直持续到现在，一直对人工智能的东西感兴趣。这个时候知道了银河巨型机这种东西，知道是国防科大搞的，结合我的两个志向，决定以后上国防科大，国防科大就是未来十余年我奋斗的目标。</p>
<p>1995年，<strong>6岁</strong>，进入小学学前班。<br />
记得这个时候，外婆去世了，外婆照顾了我很久，陪我睡觉的时候去世的，当时小，蒙了，后来才一直哭。</p>
<p><strong>&#8212;-小学阶段&#8212;-</strong><br />
1996年，<strong>7岁</strong>，升入小学一年级。<br />
这个时候应该是有门课叫自然，非常喜欢，对自然科学的兴趣就是这个时候产生的。<br />
好像还一门课叫社会，对人文科学的兴趣是看社会课本产生的。</p>
<p>1997年，<strong>8岁</strong>，升入小学二年级。<br />
没有什么特殊的事情，不知道是不是这个时候，跟我的同桌，有一次好几门课都是同时第一，很多人说我们抄袭~我X……</p>
<p>1998年，<strong>9岁</strong>，升入小学三年级。<br />
这个时候开始有了数学奥赛，开始周末去补课，第一次知道补课，此后补课一直伴随我~<br />
也是这一年，爸爸从广东带了电脑给我，我第一次碰了电脑，开始很喜欢打一个射击游戏，很原始，都打通关了。此后很长一段时间都打游戏。学习开始不太行，不过打游戏练就了我极快的反应能力和敲键盘速度，对以后的发展是好是坏说不清</p>
<p>1999年，<strong>10岁</strong>，升入小学四年级。<br />
游戏玩腻了，不晓得在什么地方知道了Red Hat这种东西，就跑去电脑城买光盘，Red Hat 6吧好像，就买了一张回家，不知道怎么折腾的，就给装上了……此后就知道了Linux这个东西~在Win98和RH6的抉择中，因为老爸帮我装了Win98，就放弃RH6了，要是当年一直用RH，早就成Linux专家了。</p>
<p>2000年，<strong>11岁</strong>，升入小学五年级。<br />
要竞赛了，我的数学却开始不行了，班主任施老师那个郁闷~<br />
不过很意外，比赛完我觉得没戏了，却意外得了二等奖，排名还比较前，差一点就一等奖。<br />
这一年就是先郁闷，然后意外的惊喜。</p>
<p><span id="more-956"></span><br />
<strong>&#8212;-初中阶段&#8212;-</strong><br />
2001年，<strong>12岁</strong>，保入初中一年级。<br />
因为华罗庚金杯赛二等奖，幸运的进了宜春中学的奥赛班。第一次分班考试，不知道哪根筋错位了，考了满分……不过此后就不行了。<br />
应该是这个时候，跟学校的组团去了北京，第一次离开父母出远门。</p>
<p>2002年，<strong>13岁</strong>，升入初中二年级。<br />
好像这个时候从临时教室搬到学校里面了吧，成绩很诡异，一次高一次低，就是这样大幅度波动，跟股市差不多。数学竞赛基本废了，再也没有获奖过。<br />
不过这个时候，家里开了网络，结识了一些黑客朋友，开始瞎折腾网络和破解技术，同时学习C、C++语言。其实开始就是瞎拿本书看看，叫《C++程序设计》，敲出Hello World的时候那个兴奋呀，此后就开始玩C++，后来又开始学习一点C。那时候觉得C++就是比C多了++，囧~<br />
后来结识了张皖龙，一起研究了一些程序设计问题，本来想一起做些东西，不过相隔两地，也没有<acronym title="Subversion">SVN</acronym>这种东西，也没做起来，第一次多人协作。</p>
<p>2003年，<strong>14岁</strong>，升入初中三年级。<br />
参加个什么生物竞赛，拿了个一等奖，我总是在不正确的时候喜欢不正确的科目，这个时候生物还不是考试科目，我却非常喜欢。参加省理科实验班考试，差半分，郁闷至极……<br />
不过后来学校决定把没有达到分数线一定距离的人也招入校实验班，我就这样进去了，免了中考，玩了半年。好好学了学C++，程序设计这个时候提升最快。</p>
<p><strong>&#8212;-高中阶段&#8212;-</strong><br />
2004年，<strong>15岁</strong>，保入高中一年级。<br />
因为被特招进了高中，又是在所谓的校实验班，还是有竞赛，不过已经没了兴趣。成绩起伏也很大，英语彻底的悲剧，从100分到150分的卷子，总分不断提高，不过我的成绩很稳定的在90分。老师也无语了，努力P用都没有，我相信学习需要一点天赋了。<br />
然后跟余竟老师认识了，开始是我开了自己的个人主页，照搬了余竟老师网站上关于学校的介绍，余老师很生气，说我盗版，汗……不过就这样认识了，从余老师口里知道宜春中学也搞信息学奥赛，我很激动。<br />
这个时候又从老爸口里知道了吴文虎老师，带国家信息学奥赛的，也知道了信息学获奖可以保送国防科大，就立志要搞计算机竞赛……<br />
开始接触Pascal，有点C++基础，上手还快，不过对数据结构和算法这种东西还是迷茫了很久~不过后来突然开窍，从写成绩分析的小程序开始，对算法开始极度感兴趣。</p>
<p>2005年，<strong>16岁</strong>，升入高中二年级。<br />
为了计算机竞赛，两上北京清北学堂学习，见到了传说中的刘汝佳老师~哈哈~去南昌，遇到易Pretty，现在这些结识的朋友都保送到各个名校了~我最挫~而且刘博洋这个时候也去了北京清北学堂，后来到了南航才知道。<br />
这是第一次自己一个人出远门。<br />
在学校成绩开始下滑，不过文科还好，因为文科我不太需要看也能学得不错，老师全以为我学文科，不过我还是学了理科，觉得不行就补补，文科我自己看都会了，不用专门学。<br />
第一次参加信息学比赛，初生牛犊不怕虎，不小心笔试全市第一，不过应该也没几个人。<br />
然后参加复赛，以为没戏了，结果不小心竟然还踩线获奖了，一等奖分数线100分，我110，幸好全输出NO骗了10分~<br />
获奖后一天国防科大的政委来学校了，愿意招我，那个兴奋呀……就去了趟国防科大跟政委面谈。<br />
后来中科大少年班又发了考试邀请，听到考试我就崩溃了，算了。<br />
后来参加全国夏令营，很悲剧，不说了……忘用高精度，最后一题本来方法正确，没用高精度，悲剧，泪目……加上RP不好，哈密顿通路才算出那么点。<br />
这个时候很郁闷，本来想去好一点的学校，爸妈想走点关系趋好学校，我还是决定，靠自己能去哪算哪，就去了南航~扛着家里的压力，留下来了。<br />
这一年也写出了我第一个人工智能程序，能做高中课本中简单的集合证明，本质就是双向宽搜，把公式序列化而已，写了五百多行，获得了全国青少年科技创新三等奖，当时觉得是个大程序，现在看来不过个小程序而已。<br />
也开始写一些应用软件，写了一个锁屏幕类似屏保的软件，还获得了全省软件设计二等奖，很水的奖。</p>
<p><strong>&#8212;-大学阶段&#8212;-</strong><br />
2006年，<strong>17岁</strong>，保送大学一年级<br />
来到大学，踌躇满志，好好学习，天天向上（因为开始没电脑），所有课都过了，就挂了个高数实在不会，高中还没学完呢。不过补考还是过了。<br />
这个时候还是想搞竞赛的，不过感觉自己做题能力已经很不行了，有点做应用开发的想法。<br />
读了一年之后，又想去国防科大，不过政委不答应我学计算机，放弃之，就此留在南航了~</p>
<p>2007年，<strong>18岁</strong>，升入大学二年级。<br />
这个时候，参加了个项目，第一次知道在大学可以做项目，不过没怎么上课，就挂了很多课，有的课现在还挂着~<br />
第一次知道了Oracle这种东西，知道了.Net，开始学习数据库，学习Oracle DB，学习.Net，做网站，做应用。基本上放弃了竞赛，只担任了几次裁判。</p>
<p>2008年，<strong>19岁</strong>，升入大学三年级。<br />
对Oracle到了狂热的程度，对数据库疯狂的热爱，报名参加Oracle University学习，获得Oracle认证专家，我承认很水，基本靠背题。400道题，全英文，我竟然5天全背完了，我真佩服自己，不过靠着OCP的头衔还是忽悠了不少人，实际上Oracle的水平，不说了，伤心。<br />
比较值得纪念的是我想了1年多的矢量化识别算法终于完稿了，投递出去很不幸，审稿人心情不好，就说训练部分没写细节，打回，没有任何其他说明，非常愤怒。后来自己把程序写出来了，很复杂的字也能识别，训练就是体力活，写进论文才是水。论文的事就耽搁了，给了班主任，让他折腾去吧。</p>
<p>2009年，<strong>20岁</strong>，升入大学四年级。<br />
最值得纪念的事情是见了Fenng，七公，Sky，Jacky等传说中的大牛。最重大的转折是在途牛实习，从Oracle转到了MySQL运维，MySQL的轻量、灵活非常吸引我，一发而不可收拾，对MySQL的各种架构形式都折腾了一下，知道了LVS这种神器，知道了Sphinx这种第三方索引工具，知道了Memecached这种K/V存储机制，结合理论理解了数据库中的各种算法，开始很喜欢用脚本语言……<br />
这一年对自己的提升是非常大的，平时的积累还是非常重要的，有理论基础，再深入应用去钻研，会得到意想不到的提高。<br />
最开心的事情，是如愿以偿的进入了阿里巴巴，能成为马云旗下的一员，能和大牛们一起工作，做最好的电子商务平台。</p>
<p>第一个20年，是求学的20年，就这样过去了。<br />
下一个20年，是工作拼搏的20年，要更加精彩，为自己加油！</p><h2  class="related_post_title">随机显示文章</h2><ul class="related_post"><li>2009年05月24日 -- <a href="http://www.penglixun.com/work/program/windows_vitual_keypress.html" title="Windows虚拟按键小程序">Windows虚拟按键小程序</a> (2)</li><li>2009年10月14日 -- <a href="http://www.penglixun.com/work/database/dba_essential_ability_summary.html" title="DBA必备能力总结">DBA必备能力总结</a> (4)</li><li>2009年07月9日 -- <a href="http://www.penglixun.com/work/program/add_database_module_for_php.html" title="为PHP添加数据库模块">为PHP添加数据库模块</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/life/diary/my_20_years.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mystat 1.0 release 发布</title>
		<link>http://www.penglixun.com/work/program/mystat_release.html</link>
		<comments>http://www.penglixun.com/work/program/mystat_release.html#comments</comments>
		<pubDate>Fri, 05 Feb 2010 07:21:06 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[mystat]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=952</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/program/mystat_release.html 
mystat是一款MySQL数据库实时监控脚本，P... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/program/mystat_release.html </p>
<p></span>mystat是一款MySQL数据库实时监控脚本，<acronym title="Practical Extraction and Report Language">Perl</acronym>编写，基于MySQL的show global status和show global variables结果进行分析实时显示。能通过参数控释轮询间隔、轮询次数、监控项目。使用了strict;DBI;Switch;DBD::mysql;Getopt::Std;Term::ANSIColor;这几个<acronym title="Practical Extraction and Report Language">Perl</acronym>模块，通过CPAN都可以安装。<br />
我已经尽力测试Bug，不过使用场景各异，如果发现Bug，请联系我，penglixun(at)gmail.com。</p>
<p><strong>脚本包括如下参数</strong><br />
-i    轮询间隔    默认1s<br />
-c   轮询次数    默认无限<br />
-n   监控项目    默认basic<br />
           包括: all(全部项目), basic(基本项目), innodb(InnoDB项目), myisam(MyISAM项目)四个套装<br />
           以及下面的单项：<br />
           traffic    &#8211; Network Traffic<br />
           kbuffer  &#8211; Key Buffer<br />
           qcache   &#8211; Query Cache<br />
           thcache  &#8211; Thread Cache<br />
           tbcache  &#8211; Table Cache<br />
           tmp        &#8211; Temporary Table<br />
           query     &#8211; Queries Statistics<br />
           select     &#8211; Select Statistics<br />
           sort        &#8211; Sort Statistics<br />
           innodb_bp &#8211; InnoDB Buffer Pool<br />
           项目之间可能有交叉的部分，取最大并集。<br />
-d    取消项目    默认noneDB<br />
           包括: var(变量部分), innodb(InnoDB部分), none(无)<br />
           同时跟-n出现一样的项目，则优先处理-d。也就是说-n innodb -d innodb，不会显示innodb的部分。<br />
-h    主机名    默认空<br />
-u    用户名    默认空<br />
-p    密码       默认空</p>
<p>例如：perl mystat.pl -n traffic,qcache,kbuffer,sort -d var -h 127.0.0.1 -u cactiuser -p cacti<br />
<strong>显示如下</strong><br />
<a title="Flickr 上 P.Linux 的 mystat 1.0 release" href="http://www.flickr.com/photos/penglixun/4332078758/"><img src="http://farm3.static.flickr.com/2706/4332078758_2360522596.jpg" alt="mystat 1.0 release" width="500" height="310" /></a></p>
<p><strong>猛击这里下载：</strong>Note: There is a file embedded within this post, please visit this post to download the file.</p>
<p><span id="more-952"></span><br />
再来一张图：<br />
<a href="http://www.flickr.com/photos/penglixun/4331340149/" title="Flickr 上 P.Linux 的 mystat 1.0 release"><img src="http://farm5.static.flickr.com/4012/4331340149_70d7ab1be3.jpg" width="469" height="500" alt="mystat 1.0 release" /></a></p>
<p>显示项含义可以看代码里面的注释，非常清晰，一行计算代码有2～3行注释，说的很明白了。</p>
<p><strong>代码结构</strong><br />
print_usage //显示用法<br />
get_option  //获取命令参数，设置命令默认值<br />
set_env     //获取系统环境变量<br />
do_loop     //循环控制函数<br />
format_val  //格式化数据为K/M/G/T单位<br />
same_char   //打印若干个相同的字符，用于排版<br />
quit        //退出操作，关闭数据库连接<br />
init_val    //初始化最大值<br />
init        //初始化总控函数<br />
get_stat_traffic   //获取流量相关数据<br />
get_stat_kbuffer   //获取索引缓冲相关数据<br />
get_stat_qcache    //获取查询缓存相关数据<br />
get_stat_thcache   //获取线程缓存相关数据<br />
get_stat_tbcache   //获取表缓存相关数据<br />
get_stat_tmp       //获取临时表相关数据<br />
get_stat_select    //获取SELECT相关数据<br />
get_stat_sort      //获取排序相关数据<br />
get_stat_innodb_bp //获取InnoDB缓冲池相关数据<br />
get_stat           //获取数据总控函数<br />
display_header    //显示表头信息和版权信息<br />
display_var_title //显示数据库变量栏标题信息<br />
display_var_cache //显示数据库变量缓存相关信息<br />
display_var_buffer//显示数据库变量缓冲相关信息<br />
display_var_log   //显示数据库变量日志相关信息<br />
display_var_conn  //显示数据库变量连接相关信息<br />
display_var_query //显示数据库变量查询相关信息<br />
display_vars      //显示数据库变量总控函数<br />
display_stat_traffic   //显示数据库状态流量相关信息<br />
display_stat_kbuffer   //显示数据库状态索引缓冲相关信息<br />
display_stat_qcache    //显示数据库状态查询缓存相关信息<br />
display_stat_thcache   //显示数据库状态线程缓存相关信息<br />
display_stat_tbcache   //显示数据库状态表缓存相关信息<br />
display_stat_query     //显示数据库状态查询语句相关信息<br />
display_stat_select    //显示数据库状态选择相关信息<br />
display_stat_sort      //显示数据库状态排序相关信息<br />
display_stat_tmp       //显示数据库状态临时表相关信息<br />
display_stat_innodb_bp //显示数据库状态InnoDB缓冲池相关信息<br />
display_stat           //显示数据库状态总控函数<br />
calc_val            //计算数值模板，包括当前值/平均值/最大值/最小值<br />
calc_stat_traffic   //计算数据库状态流量相关信息<br />
calc_stat_kbuffer   //计算数据库状态索引缓冲相关信息<br />
calc_stat_qcache    //计算数据库状态查询缓存相关信息<br />
calc_stat_thcache   //计算数据库状态线程缓存相关信息<br />
calc_stat_tbcache   //计算数据库状态表缓存相关信息<br />
calc_stat_query     //计算数据库状态查询语句相关信息<br />
calc_stat_select    //计算数据库状态选择语句相关信息<br />
calc_stat_sort      //计算数据库状态排序相关信息<br />
calc_stat_tmp       //计算数据库状态临时表相关信息<br />
calc_stat_innodb_bp //计算数据库状态InnoDB缓冲池相关信息<br />
calc_stat           //计算数据库状态总控函数<br />
refresh_all  //每次刷新数据控制</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年01月28日 -- <a href="http://www.penglixun.com/work/program/mystat_usage.html" title="mystat 0.5 beta 的使用介绍">mystat 0.5 beta 的使用介绍</a> (0)</li><li>2010年01月26日 -- <a href="http://www.penglixun.com/work/program/mysql_realtime_status_moniter_mystat.html" title="自己写的MySQL实时监控脚本&#8211;mystat">自己写的MySQL实时监控脚本&#8211;mystat</a> (0)</li><li>2010年03月10日 -- <a href="http://www.penglixun.com/work/program/mysql_bat_sql_script_mybatsql.html" title="MySQL多服务器批量执行SQL脚本">MySQL多服务器批量执行SQL脚本</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/program/mystat_release.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>列式数据库的简单分析</title>
		<link>http://www.penglixun.com/work/database/column-oriented_dbms_analyse.html</link>
		<comments>http://www.penglixun.com/work/database/column-oriented_dbms_analyse.html#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:04:03 +0000</pubDate>
		<dc:creator>P.Linux</dc:creator>
				<category><![CDATA[DBA笔记]]></category>
		<category><![CDATA[DW]]></category>
		<category><![CDATA[列式存储]]></category>
		<category><![CDATA[数据仓库]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[行式存储]]></category>

		<guid isPermaLink="false">http://www.penglixun.com/?p=944</guid>
		<description><![CDATA[本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明
网址: http://www.penglixun.com/work/database/column-oriented_dbms_analyse.html 
这些天看数据仓库的内容，... ]]></description>
			<content:encoded><![CDATA[<p><span style="color: #888888;">本文内容遵从<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" target="_blank">CC版权协议</a>, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明</br><br />
网址: http://www.penglixun.com/work/database/column-oriented_dbms_analyse.html </p>
<p></span>这些天看数据仓库的内容，发现一个新内容——列式存储。曾经有想过把数据库行列转置作成索引，不过没有深想，没想到列式数据库已经开始发展起来了。<br />
首先看下WIKI上对列式数据库的解释：</p>
<blockquote><p>列式数据库是以列相关存储架构进行数据存储的数据库，主要适合与批量数据处理和即席查询。相对应的是行式数据库，数据以行相关的存储体系架构进行空间分配，主要适合与小批量的数据处理，常用于联机事务型数据处理。<br />
数据库以行、列的二维表的形式存储数据，但是却以一维字符串的方式存储，例如以下的一个表：<br />
EmpId     Lastname    Firstname    Salary<br />
1            Smith           Joe               40000<br />
2            Jones           Mary             50000<br />
3            Johnson       Cathy           44000<br />
这个简单的表包括员工代码(EmpId), 姓名字段(Lastname and Firstname)及工资(Salary).<br />
这个表存储在电脑的内存(RAM)和存储(硬盘)中。虽然内存和硬盘在机制上不同，电脑的操作系统是以同样的方式存储的。数据库必须把这个二维表存储在一系列一维的“字节”中，又操作系统写到内存或硬盘中。<br />
行式数据库把一行中的数据值串在一起存储起来，然后再存储下一行的数据，以此类推。<br />
1,Smith,Joe,40000;2,Jones,Mary,50000;3,Johnson,Cathy,44000;<br />
列式数据库把一列中的数据值串在一起存储起来，然后再存储下一列的数据，以此类推。<br />
1,2,3;Smith,Jones,Johnson;Joe,Mary,Cathy;40000,50000,44000;<br />
这是一个简化的说法。</p></blockquote>
<p>昨天装了下两个基于MySQL的数据仓库，infindb和infobright，看了文档发现它们都是列式数据库，把40多M的数据导入infobright，没想到数据文件只有1M多，压缩比令我惊讶！<br />
然后测试了下选择某一列，在列上做计算，都比MyISAM和InnoDB要快，看了一些原理文档，就自己模拟了一下，写了个程序测试。<br />
从内存中读取效率很高，但是从磁盘中读取（假设行式数据库的索引在内存中）比行式数据库要慢（开始在Twitter上说比行式快是程序写错了），不过我觉得还是我设计上的问题，至少Infobright就比MyISAM/InnoDB快，列式应该也有其特殊的索引机制和缓存机制，例如每列分开存在不同的文件，这样文件指针转移会更快。<br />
2010-02-04补充：采用了多个文件指针后，列式存储明显加速，如果给每个列一个文件指针，效率会非常高，也可以肯定，如果每个列单独存储一个文件，效率还会提高。现在文件中列式表读取效率降低了4/5，接近行式表了。继续优化还能提高。</p>
<p><span id="more-944"></span></p>
<p>代码请展开：</p>

<div class="wp_codebox"><table><tr id="p94418"><td class="code" id="p944code18"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;fstream&gt;</span>
<span style="color: #339900;">#include &lt;cstdlib&gt;</span>
<span style="color: #339900;">#include &lt;memory&gt;</span>
<span style="color: #339900;">#include &lt;string&gt;</span>
<span style="color: #339900;">#include &lt;cstring&gt;</span>
<span style="color: #339900;">#include &lt;time.h&gt;</span>
<span style="color: #339900;">#include &lt;map&gt;</span>
&nbsp;
<span style="color: #339900;">#define MAXINT RAND_MAX</span>
<span style="color: #339900;">#define MAXROWS 1000000</span>
<span style="color: #339900;">#define MINVAL 1</span>
<span style="color: #339900;">#define MAXVAL 150000000</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*计时器*/</span>
<span style="color: #0000ff;">class</span> Timer <span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span> <span style="color: #008080;">:</span>
    <span style="color: #666666;">//构造函数</span>
    Timer <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//析构函数</span>
    ~Timer <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//开始计时</span>
    <span style="color: #0000ff;">void</span> begin<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//计时结束</span>
    <span style="color: #0000ff;">void</span> end<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//获取时间,ms</span>
    <span style="color: #0000ff;">double</span> get_time<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">private</span> <span style="color: #008080;">:</span>
    <span style="color: #0000ff;">clock_t</span> start, finish<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
Timer<span style="color: #008080;">::</span><span style="color: #007788;">Timer</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    start <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    finish <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Timer<span style="color: #008080;">::</span>~Timer <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    start <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    finish <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Timer<span style="color: #008080;">::</span><span style="color: #007788;">begin</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    start <span style="color: #000080;">=</span> <span style="color: #0000dd;">clock</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Timer<span style="color: #008080;">::</span><span style="color: #007788;">end</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    finish <span style="color: #000080;">=</span> <span style="color: #0000dd;">clock</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">double</span> Timer<span style="color: #008080;">::</span><span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>finish<span style="color: #000040;">-</span>start<span style="color: #008000;">&#41;</span><span style="color: #000040;">/</span><span style="color: #0000ff;">CLOCKS_PER_SEC</span><span style="color: #000040;">*</span><span style="color: #0000dd;">1000</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #666666;">//计时器</span>
Timer timer<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*记录各种结构表的空间占用*/</span>
<span style="color: #0000ff;">struct</span> Size <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">struct</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">struct</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">int</span> _static<span style="color: #008080;">;</span>
            <span style="color: #0000ff;">int</span> _dynamic<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span> col,row<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> mem,file<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> size<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*记录各种结构表的文件指针*/</span>
<span style="color: #0000ff;">struct</span> File <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">struct</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">struct</span> <span style="color: #008000;">&#123;</span>
            fstream _static<span style="color: #008080;">;</span>
            fstream _dynamic<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span> table,index<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> col,row<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> file<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*静态行式表结构*/</span>
<span style="color: #0000ff;">struct</span> StaticRowTable <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span>     id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span>    name<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span>     num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span>  score<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">bool</span>    flag<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> <span style="color: #000040;">*</span> static_row_table<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*静态行式表索引*/</span>
<span style="color: #0000ff;">struct</span> StaticRowTableIndex <span style="color: #008000;">&#123;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>    id<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>  name<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>    num<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> score<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">bool</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>   flag<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> static_row_table_index<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*静态列式表结构*/</span>
<span style="color: #0000ff;">struct</span> StaticColTable <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span>     id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span>     <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>name<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span>     num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span><span style="color: #000040;">*</span>  score<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">bool</span><span style="color: #000040;">*</span>    flag<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> static_col_table<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*动态行式表结构*/</span>
<span style="color: #0000ff;">struct</span> DynamicRowTable <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span>    id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span>    char_len<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span>   <span style="color: #000040;">*</span>name<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span>    num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span> score<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">bool</span>   flag<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> <span style="color: #000040;">*</span> dynamic_row_table<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*动态行式表索引*/</span>
<span style="color: #0000ff;">struct</span> DynamicRowTableIndex <span style="color: #008000;">&#123;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>    id<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>  name<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>    num<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> score<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">bool</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>   flag<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> dynamic_row_table_index<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*动态列式表结构*/</span>
<span style="color: #0000ff;">struct</span> DynamicColTable <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span>    id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span>    char_len<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span><span style="color: #000040;">**</span>  name<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span><span style="color: #000040;">*</span>    num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">double</span><span style="color: #000040;">*</span> score<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">bool</span><span style="color: #000040;">*</span>   flag<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span> <span style="color: #000040;">*</span> dynamic_col_table<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*随机字符*/</span>
<span style="color: #0000ff;">char</span> randChar<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color:#800080;">26</span><span style="color: #000040;">+</span><span style="color: #FF0000;">'A'</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*随机字符串*/</span>
<span style="color: #0000ff;">void</span> randString<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> col<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span>, <span style="color: #0000ff;">int</span> len<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>len<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        col<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> randChar<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*初始化表数据*/</span>
<span style="color: #0000ff;">void</span> init_StaticTable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;+-----静态数据-----+&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">//分配空间</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;分配空间中......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    static_row_table <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> StaticRowTable<span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    static_col_table.<span style="color: #007788;">id</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    static_col_table.<span style="color: #007788;">name</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    static_col_table.<span style="color: #007788;">num</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">int</span><span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    static_col_table.<span style="color: #007788;">score</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">double</span><span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    static_col_table.<span style="color: #007788;">flag</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">bool</span><span style="color: #008000;">&#91;</span>MAXROWS<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;空间分配完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl
         <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;分配空间耗时: &quot;</span> 
         <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">//产生随机数据和索引</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;生成数据中......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        static_col_table.<span style="color: #007788;">id</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> 
        static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">id</span> <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
        static_row_table_index.<span style="color: #007788;">id</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">id</span>,i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        randString<span style="color: #008000;">&#40;</span>static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">name</span>, <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color:#800080;">20</span><span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">strcpy</span><span style="color: #008000;">&#40;</span>static_col_table.<span style="color: #007788;">name</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>,static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        static_row_table_index.<span style="color: #007788;">name</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>static_col_table.<span style="color: #007788;">name</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>,i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        static_col_table.<span style="color: #007788;">num</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span>
        static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">num</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        static_row_table_index.<span style="color: #007788;">num</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">num</span>,i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        static_col_table.<span style="color: #007788;">score</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> 
        static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">score</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">/</span><span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        static_row_table_index.<span style="color: #007788;">score</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">double</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">score</span>,i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        static_col_table.<span style="color: #007788;">flag</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> 
        static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">flag</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">rand</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">%</span><span style="color:#800080;">2</span><span style="color: #008080;">;</span>
        static_row_table_index.<span style="color: #007788;">flag</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>pair<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">bool</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>.<span style="color: #007788;">flag</span>,i<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;数据生成完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;生成数据耗时: &quot;</span> 
         <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
&nbsp;
    <span style="color: #666666;">//初始化文件指针</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">open</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;row_table_static.dat&quot;</span>, ios<span style="color: #008080;">::</span><span style="color: #007788;">binary</span> <span style="color: #000040;">|</span> ios<span style="color: #008080;">::</span><span style="color: #007788;">out</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    file.<span style="color: #007788;">row</span>.<span style="color: #007788;">index</span>._static.<span style="color: #007788;">open</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;row_index_static.dat&quot;</span>, ios<span style="color: #008080;">::</span><span style="color: #007788;">binary</span> <span style="color: #000040;">|</span> ios<span style="color: #008080;">::</span><span style="color: #007788;">out</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">open</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;col_table_static.dat&quot;</span>, ios<span style="color: #008080;">::</span><span style="color: #007788;">binary</span> <span style="color: #000040;">|</span> ios<span style="color: #008080;">::</span><span style="color: #007788;">out</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span>file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static <span style="color: #000040;">||</span>
        <span style="color: #000040;">!</span>file.<span style="color: #007788;">row</span>.<span style="color: #007788;">index</span>._static <span style="color: #000040;">||</span>
        <span style="color: #000040;">!</span>file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;打开文件失败&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;正在将数据写入文件......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>static_row_table<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>StaticRowTable<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">row</span>.<span style="color: #007788;">index</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>static_row_table_index<span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>StaticRowTableIndex<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    file.<span style="color: #007788;">row</span>.<span style="color: #007788;">index</span>._static.<span style="color: #007788;">close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>static_col_table.<span style="color: #007788;">id</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>static_col_table.<span style="color: #007788;">name</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>static_col_table.<span style="color: #007788;">num</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>static_col_table.<span style="color: #007788;">score</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">write</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>static_col_table.<span style="color: #007788;">flag</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">bool</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;数据写入完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;写入数据耗时: &quot;</span> 
         <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">//计算总占用空间</span>
    size.<span style="color: #007788;">mem</span>.<span style="color: #007788;">row</span>._static <span style="color: #000080;">=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>static_row_table<span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>MAXROWS
                    <span style="color: #000040;">+</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>static_row_table_index<span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>MAXROWS<span style="color: #008080;">;</span>
    size.<span style="color: #007788;">mem</span>.<span style="color: #007788;">col</span>._static <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span><span style="color: #0000dd;">2</span><span style="color: #000040;">+</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #000040;">+</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">bool</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #000040;">+</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>MAXROWS<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;静态行式存储耗费空间: &quot;</span> 
         <span style="color: #000080;">&lt;&lt;</span> size.<span style="color: #007788;">mem</span>.<span style="color: #007788;">row</span>._static<span style="color: #000040;">/</span><span style="color: #0000dd;">1024</span><span style="color: #000040;">/</span><span style="color: #0000dd;">1024</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;M&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;静态列式存储耗费空间: &quot;</span> 
         <span style="color: #000080;">&lt;&lt;</span> size.<span style="color: #007788;">mem</span>.<span style="color: #007788;">col</span>._static<span style="color: #000040;">/</span><span style="color: #0000dd;">1024</span><span style="color: #000040;">/</span><span style="color: #0000dd;">1024</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;M&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> init_DynamicTable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;+-----动态数据-----+&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> time1, time2<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">srand</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">time</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;======生成数据======&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    init_StaticTable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    init_DynamicTable<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*
SELECT name
FROM table 
WHERE num BETWEEN MINVAL AND MAXVAL;
*/</span>
&nbsp;
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*测试内存中静态行存储*/</span>
<span style="color: #0000ff;">int</span> Mem_Static_testRow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> count <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> id<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> it,itlow,itup<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;正在测试内存中读取行式静态表......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    itlow <span style="color: #000080;">=</span> static_row_table_index.<span style="color: #007788;">num</span>.<span style="color: #007788;">lower_bound</span> <span style="color: #008000;">&#40;</span>MINVAL<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    itup <span style="color: #000080;">=</span> static_row_table_index.<span style="color: #007788;">num</span>.<span style="color: #007788;">upper_bound</span> <span style="color: #008000;">&#40;</span>MAXVAL<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>it<span style="color: #000080;">=</span>itlow<span style="color: #008080;">;</span> it<span style="color: #000040;">!</span><span style="color: #000080;">=</span>itup<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        id <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>it<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">second</span><span style="color: #008080;">;</span>
        StaticRowTable row <span style="color: #000080;">=</span> static_row_table<span style="color: #008000;">&#91;</span>id<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">//结果</span>
        <span style="color: #666666;">//cout &lt;&lt; row.id;</span>
        <span style="color: #ff0000; font-style: italic;">/*cout &lt;&lt; '\t' &lt;&lt; */</span>row.<span style="color: #007788;">name</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">//cout &lt;&lt; '\t' &lt;&lt; row.num;</span>
        <span style="color: #666666;">//cout &lt;&lt; endl;</span>
        <span style="color: #666666;">//计数</span>
        <span style="color: #000040;">++</span>count<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;内存中行式静态表读取测试完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;读取耗时:&quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> count<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*测试磁盘中静态行存储*/</span>
<span style="color: #0000ff;">int</span> File_Static_testRow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> count <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>name<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> pos<span style="color: #008080;">;</span>
    StaticRowTable row<span style="color: #008080;">;</span>
    multimap<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,<span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> it,itlow,itup<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">//初始化文件指针</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;正在测试磁盘中读取行式静态表......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">open</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;row_table_static.dat&quot;</span>, ios<span style="color: #008080;">::</span><span style="color: #007788;">binary</span> <span style="color: #000040;">|</span> ios<span style="color: #008080;">::</span><span style="color: #007788;">in</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//file.row.index._static.open(&quot;row_index_static.dat&quot;, ios::binary | ios::in);</span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;打开文件失败&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #666666;">//假设索引在内存中</span>
    itlow <span style="color: #000080;">=</span> static_row_table_index.<span style="color: #007788;">num</span>.<span style="color: #007788;">lower_bound</span> <span style="color: #008000;">&#40;</span>MINVAL<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    itup <span style="color: #000080;">=</span> static_row_table_index.<span style="color: #007788;">num</span>.<span style="color: #007788;">upper_bound</span> <span style="color: #008000;">&#40;</span>MAXVAL<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>it<span style="color: #000080;">=</span>itlow<span style="color: #008080;">;</span> it<span style="color: #000040;">!</span><span style="color: #000080;">=</span>itup<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        id <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>it<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">second</span><span style="color: #008080;">;</span>
        pos <span style="color: #000080;">=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>StaticRowTable<span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>id<span style="color: #008080;">;</span>
        file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">seekg</span><span style="color: #008000;">&#40;</span>pos<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">read</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>row<span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span>StaticRowTable<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">//结果</span>
        <span style="color: #666666;">//cout &lt;&lt; row.id;</span>
        <span style="color: #ff0000; font-style: italic;">/*cout &lt;&lt; '\t' &lt;&lt; */</span>row.<span style="color: #007788;">name</span><span style="color: #008080;">;</span>
        <span style="color: #666666;">//cout &lt;&lt; '\t' &lt;&lt; row.num;</span>
        <span style="color: #666666;">//cout &lt;&lt; endl;</span>
        <span style="color: #666666;">//计数</span>
        <span style="color: #000040;">++</span>count<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    file.<span style="color: #007788;">row</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//file.row.index._static.close();</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;磁盘中行式静态表读取测试完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;读取耗时:&quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> count<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*测试磁盘中静态列存储*/</span>
<span style="color: #0000ff;">int</span> Mem_Static_testCol<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> count <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>name<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;正在测试内存中列式静态表读取......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000ff;">int</span> num <span style="color: #000080;">=</span> static_col_table.<span style="color: #007788;">num</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>num<span style="color: #000080;">&gt;</span>MINVAL and num<span style="color: #000080;">&lt;</span>MAXVAL<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">//结果</span>
            <span style="color: #666666;">//cout &lt;&lt; i;</span>
            <span style="color: #ff0000; font-style: italic;">/*cout &lt;&lt; '\t' &lt;&lt; */</span>static_col_table.<span style="color: #007788;">name</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
            <span style="color: #666666;">//cout &lt;&lt; '\t' &lt;&lt; static_col_table.num[i];</span>
            <span style="color: #666666;">//cout &lt;&lt; endl;</span>
            <span style="color: #666666;">//计数</span>
            <span style="color: #000040;">++</span>count<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;内存中列式静态存储表读取测试完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;读取耗时:&quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> count<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/*测试磁盘中静态列存储*/</span>
<span style="color: #0000ff;">int</span> File_Static_testCol<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">double</span> <span style="color: #0000dd;">time</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> count <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>name <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> pos_num<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> pos_name<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">int</span> pos<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;正在测试磁盘中列式静态表读取......&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">open</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;col_table_static.dat&quot;</span>, ios<span style="color: #008080;">::</span><span style="color: #007788;">binary</span> <span style="color: #000040;">|</span> ios<span style="color: #008080;">::</span><span style="color: #007788;">in</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    fstream <span style="color: #0000dd;">tmpfile</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;col_table_static.dat&quot;</span>, ios<span style="color: #008080;">::</span><span style="color: #007788;">binary</span> <span style="color: #000040;">|</span> ios<span style="color: #008080;">::</span><span style="color: #007788;">in</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static <span style="color: #000040;">||</span> <span style="color: #000040;">!</span><span style="color: #0000dd;">tmpfile</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;打开文件失败&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    pos_name <span style="color: #000080;">=</span> <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>MAXROWS<span style="color: #008080;">;</span>
    pos_num <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>
            <span style="color: #000040;">+</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>MAXROWS<span style="color: #008080;">;</span>
    file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">seekg</span><span style="color: #008000;">&#40;</span>pos_num<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>MAXROWS<span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">read</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>num<span style="color: #008000;">&#41;</span>,
                                    <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>num<span style="color: #000080;">&gt;</span>MINVAL and num<span style="color: #000080;">&lt;</span>MAXVAL<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">//结果</span>
            id <span style="color: #000080;">=</span> i<span style="color: #008080;">;</span>
            <span style="color: #666666;">//cout &lt;&lt; id;</span>
            pos <span style="color: #000080;">=</span> pos_name<span style="color: #000040;">+</span><span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">*</span>id<span style="color: #008080;">;</span>
            <span style="color: #0000dd;">tmpfile</span>.<span style="color: #007788;">seekg</span><span style="color: #008000;">&#40;</span>pos<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #0000dd;">tmpfile</span>.<span style="color: #007788;">read</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">reinterpret_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>name<span style="color: #008000;">&#41;</span>,
                        <span style="color: #0000dd;">sizeof</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #ff0000; font-style: italic;">/*cout &lt;&lt; '\t' &lt;&lt; */</span>name<span style="color: #008080;">;</span>
            <span style="color: #666666;">//cout &lt;&lt; '\t' &lt;&lt; num;</span>
            <span style="color: #666666;">//cout &lt;&lt; endl;</span>
            <span style="color: #666666;">//计数</span>
            <span style="color: #000040;">++</span>count<span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    file.<span style="color: #007788;">col</span>.<span style="color: #007788;">table</span>._static.<span style="color: #007788;">close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    timer.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">time</span> <span style="color: #000080;">=</span> timer.<span style="color: #007788;">get_time</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;磁盘中列式静态存储表读取测试完毕!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;读取耗时:&quot;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000dd;">time</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; ms&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> count<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> count1, count2, count3, count4<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;=====内存存取测试=====&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;+----静态表测试中----+&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;*行式存储*&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #666666;">//内存中静态行式存储表</span>
    count1 <span style="color: #000080;">=</span> Mem_Static_testRow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//内存中静态列式存储表</span>
    count2 <span style="color: #000080;">=</span> Mem_Static_testCol<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;*列式存储*&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #666666;">//磁盘中静态行式存储表</span>
    count3 <span style="color: #000080;">=</span> File_Static_testRow<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//磁盘中静态行式存储表</span>
    count4 <span style="color: #000080;">=</span> File_Static_testCol<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>count1<span style="color: #000080;">==</span>count2 and count2<span style="color: #000080;">==</span>count3 and count3<span style="color: #000080;">==</span>count4<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;共匹配:&quot;</span> <span style="color: #000080;">&lt;&lt;</span> count1 <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; 行&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;错误:每次匹配行数不同&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    test<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;All OK!&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>2010-02-04测试结果：<br />
======生成数据======<br />
+&#8212;&#8211;静态数据&#8212;&#8211;+<br />
分配空间中&#8230;&#8230;<br />
空间分配完毕!<br />
分配空间耗时: 0ms<br />
生成数据中&#8230;&#8230;<br />
数据生成完毕!<br />
生成数据耗时: 4180ms<br />
正在将数据写入文件&#8230;&#8230;<br />
数据写入完毕!<br />
写入数据耗时: 2480ms<br />
静态行式存储耗费空间: 495M<br />
静态列式存储耗费空间: 259M<br />
+&#8212;&#8211;动态数据&#8212;&#8211;+<br />
=====内存存取测试=====<br />
+&#8212;-静态表测试中&#8212;-+<br />
*行式存储*<br />
正在测试内存中读取行式静态表&#8230;&#8230;<br />
内存中行式静态表读取测试完毕!<br />
读取耗时:10 ms<br />
正在测试内存中列式静态表读取&#8230;&#8230;<br />
内存中列式静态存储表读取测试完毕!<br />
读取耗时:0 ms<br />
*列式存储*<br />
正在测试磁盘中读取行式静态表&#8230;&#8230;<br />
磁盘中行式静态表读取测试完毕!<br />
读取耗时:190 ms<br />
正在测试磁盘中列式静态表读取&#8230;&#8230;<br />
磁盘中列式静态存储表读取测试完毕!<br />
读取耗时:210 ms<br />
共匹配:69650 行<br />
All OK!</p><h2  class="related_post_title">类似的文章</h2><ul class="related_post"><li>2010年02月2日 -- <a href="http://www.penglixun.com/work/database/data_warehouse_concept.html" title="数据仓库相关概念">数据仓库相关概念</a> (0)</li><li>2010年03月9日 -- <a href="http://www.penglixun.com/work/database/split_and_merge_database.html" title="数据库的拆分与合并">数据库的拆分与合并</a> (2)</li><li>2009年12月8日 -- <a href="http://www.penglixun.com/work/database/database_schema_design_traning_2009_12.html" title="今天的数据库设计培训">今天的数据库设计培训</a> (4)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.penglixun.com/work/database/column-oriented_dbms_analyse.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
