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

          主站蜘蛛池模板: 通许县| 齐齐哈尔市| 崇信县| 儋州市| 获嘉县| 屏东市| 鹤峰县| 昔阳县| 安阳县| 治多县| 徐汇区| 连江县| 独山县| 略阳县| 睢宁县| 友谊县| 柏乡县| 泗洪县| 石家庄市| 山东| 水富县| 济南市| 平泉县| 咸丰县| 阿尔山市| 定陶县| 包头市| 西充县| 都昌县| 临江市| 南宁市| 正宁县| 岑溪市| 迭部县| 南召县| 新龙县| 甘孜县| 永靖县| 泾川县| 斗六市| 巴马|