請問如何正確建構索引以提升效率? |
尚未結案
|
ying0515
中階會員 發表:90 回覆:168 積分:81 註冊:2003-01-04 發送簡訊給我 |
我有一spot資料表,spot_01欄位為主索引,
下列為我有用到的SQL,請問如何正確建立叢集索引與非叢集索引,或複合索引
以提升效率?
MS SQL2000,資料比數五十萬筆
select * from spot where spot_01 = :spot_01 select spot_06,spot_13, count(spot_04) as "sum" from spot where spot_04 like :spot_04 and spot_05 = :spot_05 group by spot_06,spot_13 order by spot_06,spot_13 select count(*) as cnt from spot where spot_04 like :spot_04 and spot_12 = :spot_12 and spot_05 = :spot_05 and spot_06 = :spot_06 and spot_13 = :spot_13 select count(*) as cnt from spot where spot_04 like :spot_04 and spot_05 = :spot_05 and spot_06 = :spot_06 and spot_12 = :spot_12 select distinct spot_12 from spot(nolock) where spot_04 like :spot_04 and spot_05 = :spot_05Delphi follower 發表人 - ying0515 於 2004/06/14 14:48:24
------
Delphi |
yachanga
資深會員 發表:24 回覆:335 積分:296 註冊:2003-09-27 發送簡訊給我 |
|
stillalive
初階會員 發表:7 回覆:148 積分:41 註冊:2004-04-07 發送簡訊給我 |
|
ying0515
中階會員 發表:90 回覆:168 積分:81 註冊:2003-01-04 發送簡訊給我 |
程式架構用Delphi Client/Server方式連資料庫,Client端約150台電腦, 上述的SQL為TQuery裡的SQL. query1.close; query1.sql.clear; query1.sql.add('select * from spot where spot_01 = :spot_01'); query1.ParamByName('spot_01').AsString := 'A001'; query1.open; 下列小弟針對spot資料表所建的Index為: pk_spot(spot_01)為primary key並有叢集索引. ix_spot_1(spot_04)為非叢集索引. ix_spot_2(spot_05)為非叢集索引. ix_spot_3(spot_06)為非叢集索引. ix_spot_4(spot_09)為非叢集索引. ix_spot_5(spot_12)為非叢集索引. 請問有何改善空間.Delphi follower
------
Delphi |
stillalive
初階會員 發表:7 回覆:148 積分:41 註冊:2004-04-07 發送簡訊給我 |
select spot_06,spot_13, count(spot_04) as "sum"
from spot
where spot_04 like :spot_04
and spot_05 = :spot_05
group by spot_06,spot_13
order by spot_06,spot_13 以上面 ORDER BY 需求 ,
你只要建立 spot_06,spot_13 index ,
其它的不需再建 ,
以免影響資料庫 IO 效率 . 另外你說CLIENT端有150台電腦 ,
建議你規劃成 3 TIER 架構 ,
不然150台全上資料庫 ,
資料庫再如何規劃都很慢 .
發表人 - stillalive 於 2004/06/15 10:46:09
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |