SQL设计技巧优化

2014-11-24 16:05:55 · 作者: · 浏览: 0
SQL设计技巧优化
TRANSACTION
大型交易拆成 小型交易
增 修之 如果有包含大量查 法,一 造成transaction等待
ex. 下列 法table1 新增的 料 被lock 直到 commit =5秒後
Begin transaction
insert into table1 (1,1,1,1) --// 1ms
select * from tableX --// 5000ms
update table1 set col1=2 where id = 1 --//1ms
Commit transacton
VIEW
加工後的view可能 影 索引查
合 料
TEMP TABLE
法以 一查 取得 果集,需要 的 理,才能得到 果, 後才使用temp table
temp table 的 容要量少 精
WHERE
少子查 ,以JOIN 取代,目的是 料
以true , false 果取代所有 料集
ex1. 
Select * from table1 where m_id in (select id from table2)
Select * from table1 a where exists (select 1 from table2 where id = a.m_id)