waterye

使用temporary memory table优化union

sharding听上去很过瘾,但实现成本也挺高的.对于通过按data进行split的表,某些select要用到union,这样可能导致lock的时间变得很长.使用temporary memory table作为中转,可以大大减少lock table的时间,使查询更快.
drop temporary table IF EXISTS table_name_tmp;
create temporary table IF NOT EXISTS table_name_tmp (a int not null,b int not null,primary key (a, b)) ENGINE = MEMORY;

insert ignore into table_name_tmp select * from table_name_1 where ;
insert ignore into table_name_tmp select * from table_name_2 where ;
insert ignore into table_name_tmp select * from table_name_3 where ;
insert ignore into table_name_tmp select * from table_name_4 where ;


select * from table_name_tmp where ;

posted on 2008-06-22 22:27 waterye 阅读(658) 评论(0)  编辑  收藏 所属分类: mysql


只有注册用户登录后才能发表评论。


网站导航: