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 閱讀(677) 評論(0)  編輯  收藏 所屬分類: mysql

          主站蜘蛛池模板: 庆阳市| 石屏县| 南木林县| 沿河| 渝北区| 宁陵县| 定西市| 六安市| 东丰县| 南川市| 博乐市| 伊吾县| 长武县| 麦盖提县| 水富县| 德钦县| 贵定县| 辰溪县| 航空| 凤山县| 定南县| 拜泉县| 太仓市| 西乌| 灵川县| 青冈县| 崇信县| 安乡县| 松桃| 鱼台县| 遵化市| 沐川县| 嘉善县| 云阳县| 革吉县| 普兰县| 河东区| 白城市| 潞西市| 龙井市| 海宁市|