1
2
3
4
5
|
CREATE
TABLE
`testhash` (
`fname`
varchar
(50)
NOT
NULL
,
`lname`
varchar
(50)
NOT
NULL
,
KEY
`fname` (`fname`) USING HASH
) ENGINE=MEMORY
DEFAULT
CHARSET=utf8 |
|
f('Arjen') = 2323 |
f('Baron') = 7437 |
f('Peter') = 8784 |
f('Vadim') = 2458 |
槽 | 值 |
2323 | 指向第1行指针 |
2458 | 指向第4行指针 |
7437 | 指向第2行指针 |
8784 | 指向第3行指针 |
1
|
select
*
from
testhash
where
fname=
'Peter'
;
|
1
|
select
*
from
url
where
url=
"http://www.baidu.com"
;
|
1
|
select * from url where url_crc=crc32(
"http://www.baidu.com"
) and url=
"http://www.baidu.com"
;
|
1
2
3
4
5
6
|
CREATE
TABLE
`pseudohash` (
`id`
int
(10) unsigned
NOT
NULL
AUTO_INCREMENT,
`url`
varchar
(255)
NOT
NULL
,
`url_crc`
int
(10) unsigned
NOT
NULL
DEFAULT
'0'
,
PRIMARY
KEY
(`id`)
) ENGINE=InnoDB
DEFAULT
CHARSET=utf8;
|
1
2
3
4
5
6
|
//插入
delimiter $$
create
trigger
pseudohash_crc_ins before
insert
on
pseudohash
for
each row
begin
set
NEW.url_crc=crc32(NEW.url);
end
;$$
//更新
create
trigger
pseudohash_crc_upd before
update
on
pseudohash
for
each row
begin
set
NEW.url_crc=crc32(NEW.url);
end
;$$
delimiter ;
|