對url建立唯一性索引:
新增一列,該列存儲 url的 crc32計算結果,對該列建立唯一性索引.
如下:
create table url_list (
id int auto_increment,
url varchar(255) not null,
url_crc int unsigned not null default 0,
primary key (id)
)
然後建立觸發器
delimiter //
create trigger url_crc before insert on url_visit_times for each row begin
set new.url_crc = crc32(new.url);
end
//
create trigger url_crc_update before update on url_visit_times for each row begin
set new.url_crc = crc32(new.url);
end
//
delimiter ;