今天的问题!数据库结构

小传

‘(oneoo)’, 2005-12-28 17:22 :
问个问题
‘(oneoo)’, 2005-12-28 17:22 :
好傻仔的
‘(oneoo)’, 2005-12-28 17:22 :

小传, 2005-12-28 17:22 :

‘(oneoo)’, 2005-12-28 17:23 :
一个id 为 abc (字符) 另一个 id 为 100000000 (数字)
大家的表都有 100,000,000 条记录以上
边个取得记录快?
小传, 2005-12-28 17:24 :
数字快
‘(oneoo)’, 2005-12-28 17:24 :
怎么这么肯定呀
‘(oneoo)’, 2005-12-28 17:25 :
问问 DBA
‘(oneoo)’, 2005-12-28 17:25 :
数字那区,别以为 id 是顺着的噢, 是乱数来的
小传, 2005-12-28 17:25 :
数字要比字符快
‘(oneoo)’, 2005-12-28 17:25 :

小传, 2005-12-28 17:27 :
因为数字是顺序的
小传, 2005-12-28 17:27 :
如果你数据是乱序的,那就要看哪一个短
小传, 2005-12-28 17:27 :
如果字符短,就有可能快。
小传, 2005-12-28 17:27 :
如果全部数字都是顺序的,肯定数字快
‘(oneoo)’, 2005-12-28 17:27 :
_-!!
‘(oneoo)’, 2005-12-28 17:28 :
鬼都知道顺着的快了
小传, 2005-12-28 17:28 :
因为 100 条记录,你要揾第 50 条,佢可以计算出第 50 条的记录位置
‘(oneoo)’, 2005-12-28 17:29 :
如果数字是乱的
‘(oneoo)’, 2005-12-28 17:29 :
应该是字符快
小传, 2005-12-28 17:29 :
如果字符短,就有可能快。
小传, 2005-12-28 17:29 :
其实你做咗索引,问题就唔大了
‘(oneoo)’, 2005-12-28 17:30 :
就系字符可以索引到咯

略略谈

‘oneoo’, 2005-12-28 17:17 :
17:16: 表中 用 数字做 查询 还是 字符做查询 ,比较好?
17:16: 如 ID
17:16: id = 1 或 id =a
17:17: 很大量数据
略略谈, 2005-12-28 17:18 :
[color=#000000]当然是数字啦 [/color]‘(oneoo)’, 2005-12-28 17:18 :
id 是乱数,不是顺序数字
略略谈, 2005-12-28 17:18 :
[color=#000000]? [/color]‘(oneoo)’, 2005-12-28 17:19 :
不是 1 – 2 -3
略略谈, 2005-12-28 17:19 :
[color=#000000]条件? [/color]‘(oneoo)’, 2005-12-28 17:19 :
这样的可能是 10000 -1 – 100
‘(oneoo)’, 2005-12-28 17:19 :
这样呢
‘(oneoo)’, 2005-12-28 17:19 :
不是条件 _-!!
‘(oneoo)’, 2005-12-28 17:19 :
是那个 id 是随机生成的
略略谈, 2005-12-28 17:19 :
[color=#000000]用程序生成就OK了 [/color]‘(oneoo)’, 2005-12-28 17:20 :
就是问,效率那个高呀
‘(oneoo)’, 2005-12-28 17:20 :
也是数字高噢?
‘(oneoo)’, 2005-12-28 17:20 :

‘(oneoo)’, 2005-12-28 17:20 :
应该是
略略谈, 2005-12-28 17:20 :
[color=#000000]应该是数字 [/color]‘(oneoo)’, 2005-12-28 17:22 :
数字 100,000,000
‘(oneoo)’, 2005-12-28 17:22 :
还是数字快?
略略谈, 2005-12-28 17:22 :
[color=#000000][ZDY][33]CAC6F874155651EFA75A043E9EA90359.JPG[/33][/ZDY] [/color]‘(oneoo)’, 2005-12-28 17:22 :
比 abc 做 id 还要快?
略略谈, 2005-12-28 17:23 :
[color=#000000]我想应该会同参数的长度有关 [/color]略略谈, 2005-12-28 17:23 :
[color=#000000]如果你甘讲,两个差不多 [/color]‘(oneoo)’, 2005-12-28 17:23 :
_-!! ~
略略谈, 2005-12-28 17:23 :
[color=#000000]压栈 [/color]‘(oneoo)’, 2005-12-28 17:24 :
搞紧数据库机构
‘(oneoo)’, 2005-12-28 17:24 :
结构
‘(oneoo)’, 2005-12-28 17:24 :
/aaaa.a.html 甘样
略略谈, 2005-12-28 17:24 :
[color=#000000]汗. [/color]‘(oneoo)’, 2005-12-28 17:24 :
我要取区的页面信息可以用 url
‘(oneoo)’, 2005-12-28 17:24 :
也可以把 URL 转换到 数字 
‘(oneoo)’, 2005-12-28 17:24 :
就是在找,那个办法快
略略谈, 2005-12-28 17:25 :
[color=#000000]自己做下压力测试吧 [/color]‘(oneoo)’, 2005-12-28 17:25 :
_-!!
‘(oneoo)’, 2005-12-28 17:25 :
17:22: 问个问题
17:22: 好傻仔的
17:22: 嗯
17:22: 问
17:23: 一个id 为 abc (字符) 另一个 id 为 100000000 (数字)
大家的表都有 100,000,000 条记录以上
边个取得记录快?
17:24: 数字快
17:24: 怎么这么肯定呀
17:25: 问问 DBA
17:25: 数字那区,别以为 id 是顺着的噢, 是乱数来的
17:25: 数字要比字符快
‘(oneoo)’, 2005-12-28 17:26 :
好肯定的答复呀
略略谈, 2005-12-28 17:26 :
[color=#000000]无. [/color]

最终答案,我和小传都认为是字符快 )

apf 把垃圾给我挡在门外,但别的千万别挡呀 _-!!

#!/usr/bin/perl -w
# vim: set cindent expandtab tabstop=4 shiftwidth=4:
# apf-qmail.pl: An APF client client script to query APF Server
# using TCP/UDP protocol, written in pure perl.
#
# Feature: for qmail+apf_patch only, TCP/UDP protocol.
# Author: He zhiqiang <hzqbbc@damail.cn>
#
# Written in: 2004-05-08
# Rewrite in: 2005-06-14
#
# Usage: $0 [ protocol_state ] [ protocol_name ] [ helo_name ] [ sender ] [ recipient ] [ client_address]# Example: $0 RCPT SMTP mta.domain.tld foo@domain.tld bar@recpdomain.com 10.1.1.1
#
# Caution: under UDP mode, TIMEOUT should set high enough, to wait for the
# reply from server, WHERE blogid=151 higher will benefit for problematic
# network connection.
# ————————————————————————-
# Under TCP mode, please keep your active concurrency less than 5,
# or APF Server may refuse your connection.
#
# License: GPL v2
# /usr/local/bin/use.perl port <- ʹϵͳʹÓÃÐÂ×°µÄperl Ò»¶¨ÒªÊ¹Óà perl 5.6+ FreeBSD °æ±¾µÄ package Òª¶ÔÓ¦ÏÂÔØ°æ±¾
use strict;
use IO:Socket qw(DEFAULT);
use constant MAX_MSG_LEN => 1000;
use constant TIMEOUT => 30;
use constant MAX_RETRIES => 3;
use constant VERSION => 0.20;
use POSIX qw(strftime);
my $apf_ok =0;
my $apf_err =1;
my $log_file =’/tmp/apf_log_’;

# unbuffer output
select((select(STDOUT), $| = 1)[0]);
select((select(STDIN), $| =1)[0]);

# command line parameters and praser
use vars qw($proto $host $port $verbose);
$proto = ‘tcp’; # change to udp if you impact some tcp problem.
$host = ‘ns.apf.org.cn’;
$port = ’10030′;
$verbose = 1; # set to 1 if you want some debug

my $msg_out = undef;
my $action = undef;
$0 =~ s/.*/(S+)/$1/g;

&usage() if ( $#ARGV < 5 );

sub usage {
print “$0 [ protocol_state ] [ protocol_name ] [ helo_name ] [ sender ] [ recipient ] [ client_address]n”;
exit(255);
}

sub dolog {
my $hostname = `hostname`;
chomp($hostname);
open(FD, “>> $log_file”.(strftime “%Y%m”, localtime));
print FD (strftime “%b %e %H:%M:%S”, localtime) ,” $hostname $0[$$]: @_n”;
close(FD);
}

$msg_out =”request=smtpd_access_policyn”;
$msg_out .=”protocol_state=$ARGV[0]n”;
$msg_out .=”protocol_name=$ARGV[1]n”;
$msg_out .=”client_address=$ARGV[5]n”;
$msg_out .=”client_name=unknown”;
$msg_out .=”helo_name=$ARGV[2]n”;
$msg_out .=”sender=$ARGV[3]n”;
$msg_out .=”recipient=$ARGV[4]n”;
$msg_out .=”queue_id=nn”;

# XXX APF customize code runs here
$action=customize(map { /([^=]+)=(.*)/ } split(/n/, $msg_out));
if ($action eq ‘DUNNO’) {
# XXX APF PROC here
$action=smtpd_access_policy($msg_out);
}

dolog(“sent=(state=$ARGV[0] name=$ARGV[1] helo_name=$ARGV[2] sender=<$ARGV[3]> recipient=<$ARGV[4]> client_address=[$ARGV[5]]) recv=($action)”);
$_ = $action;

#在此加上 WHITE 返回的判断
if ( /^OK/i or /^DUNNO/i or /^WHITE/i ) {
exit($apf_ok);
} else {
# XXX return error msg to smtp client via stdout
print $action, “rn”;
exit($apf_err);
}

sub customize {
my %attr = @_;
# XXX do some job here and return some action
# if something match some rule

#自己加上的白名单查询
my $blfile = “/var/qmail/control/ip_white_list.txt”;
if( -r $blfile) {
open(FD, “< $blfile”) or die “Can’t open $blfile:$! n”;
my $line;
while ($line = <FD>) {
$line =~ s/r//g;# strip r if exists
chomp($line);
# if(/^$attr{client_address}$/) {
if(check_ip($line, $attr{client_address})==0){
return “WHITE”;
}
}
close FD;
}

# a simple ip blacklist implemention
$blfile = “/etc/apf/ip_black_list.txt”;
if( -r $blfile) {
open(FD, “< $blfile”.strftime “%Y%m%d”, localtime) or die “Can’t open $blfile:$! n”;
while (<FD>) {
s/r//g;# strip r if exists
chomp;
if(/^$attr{client_address}$/) {
return “554 Access denied, reason: $attr{client_address} blocked by local black list”;
}
}
close FD;
}

return ‘DUNNO’;
}

sub smtpd_access_policy {
my $data;
my ($msg_out) = @_;
my $loop = 0;
my $sock;
my $srvip;
# XXX simple DNS balance mechanism
my @addr = gethostbyname($host);
@addr = map { inet_ntoa($_) } splice(@addr, 4);
my $arrlen = scalar @addr;
my $random = int rand($arrlen-1);
do {
$loop++;
$srvip = $addr[$random++ % $arrlen];
dolog(“starting query to $proto:[$srvip:$port] ($loop)”) if $verbose;

$sock = IO:Socket::INET->new(
Proto => $proto,
PeerHost => $srvip,
PeerPort => $port,
Type => $proto eq ‘tcp’ ? SOCK_STREAM :
($proto eq ‘udp’ ? SOCK_DGRAM : undef),
Timeout => ’120′);
} until ($loop >= $arrlen-1 || $sock);
dolog(“Error on exec $0: $@”) and exit(254) if(!$sock);

# check proto
if($proto eq ‘tcp’) {
print $sock “$msg_outn”;
while(<$sock>) {
$data = (defined $data ? $data : “”) . $_ if ($_ ne “n”);
last if ($_ eq “n”);
}
close($sock);
# now $data contain only one n at the end.
$data .=”n”;# append one
}elsif($proto eq ‘udp’) {
my $retries = 0;
do {
$sock->send(“$msg_outn”) or die “send() failed: $!n”;
eval {
local $SIG{ALRM} = sub { ++$retries and die “timeoutn” };
alarm(TIMEOUT);
$sock->recv($data, MAX_MSG_LEN) or die “recv() failed: $!n”;
alarm(0);
};
dolog(“Retrying…$retriesn”) if $retries;
} while $@ eq “timeoutn” and $retries < MAX_RETRIES;
if ($data eq ”) {# means all retries failed
$data = ‘DUNNO’;# return DUNNO to let mail goes
}
}

# XXX fix a bug here, should strip all newlines
$data =~ s/^action=(.*)nn/$1/g;
return ‘DUNNO’ if not defined $data;
return “$data”;
}
#自己加的 IP 查询,支持 *,1-255 两种通配符
sub check_ip{
my $ip = shift;
my $cip = shift;
my $limit = 0;
my $max = 0;
my $cp;
if($cip =~ /^s*(d{0,3}).(d{0,3}).(d{0,3}).(d{0,3}|d{0,3}-d{0,3})s*$/){
$cip = $1*1000000000 + $2*1000000 + $3*1000 + $4;
}else{ return -1; }
if ($ip =~ /^s*(d{0,3}).(d{0,3}).(d{0,3}).(d{0,3}|d{0,3}-d{0,3}|*)s*$/){
$cp = $4;
$max = $limit = $1*1000000000 + $2*1000000 + $3*1000;
if($cp eq “*”){ $cp = “1-255″; }
if($cp =~ /^(d{0,3})-(d{0,3})/){
$limit += $1;
$max += $2;
if($cip > $limit && $cip < $max){ return 0; } else { return -1; }
return -3;
}else{
$max += $4;
if($cip == $max){ return 0; } else { return -1; }
}
}else{return -2;}
}
__END__

APF-qmail, a patch/addon client for qmail to query APF Server. Please
visit http://apf.org.cn/ for detail and welcome to join our development.

奇胜又一课 :)

同事跟我说,得8:30到场。所以今早 6:30 分就起床干车站啦 _-!!
去到广州 8:20 几分,但。。。有N人迟到 _-!! 还说是 9:30 正式上课,狂晕

今天的课是由谭雅量老师讲的(肯定没万老师讲的生动),但听下去,也不是太无趣。因为有很多讨论时间和休息时间,哈哈(抽烟)

当然也会发生不幸的事情,我们小组抽签,要写个 AMP 的网络布线方案 _-!!我们公司只做奇胜,却拿到个 AMP,另外一组不是搞奇胜的却拿到个奇胜。。。没天理哦 _-!!

我可没了解过 AMP 的产品,今天晚上唯有到网站下载一些案例来修改。呵呵,轻松多了。这个方案可值50分哦 _-!! 明天还要考试,又50分。总计100分,及格才能发工程师证书。

不知道我可否及格呢,呵呵 ) 我想认真听课应该没问题吧(上课千万别睡着咯 _-!! )

最近的一个 IdEa :)

我自己是个偏执狂 _-!! ~ Java 就只用 servlet ,JSP 基本不用。感觉好像就 servlet 性能高(其实差不了多少,呵呵)自己写模板引擎,不使用开源的模板引擎(那些东西都比较庞大)。就连 Web Server 也是使用简单版本的,只支持 servlet D Winstone 真好!就适合我这样的偏执狂,只支持 servlet,并且还很小呢,才 300多K。

不过时间也没太多,可能只能空想 _-!! 唉真希望我的工作就是做自己感兴趣的东西,但为了生活不行呀 _-!! 没饭开就惨咯 D 而业余时间又不太多。。。真比较郁闷。

太多的IdEa,太少的时间,渴望有更多的时间让我去一一实现!