全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1008
推到 Plurk!
推到 Facebook!

請問如何正確建構索引以提升效率?

尚未結案
ying0515
中階會員


發表:90
回覆:168
積分:81
註冊:2003-01-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-06-14 14:13:05 IP:61.218.xxx.xxx 未訂閱
我有一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_05     
Delphi follower 發表人 - ying0515 於 2004/06/14 14:48:24
------
Delphi
yachanga
資深會員


發表:24
回覆:335
積分:296
註冊:2003-09-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-06-14 19:14:58 IP:210.68.xxx.xxx 未訂閱
Hi ying0515您好: 小弟手上沒有 MS SQL2000, 也沒有用過叢集/非叢集/ 複合索引, 純粹討論一下 小弟想請教您為什麼用 <>> 既要提升效率..就盡量避免用 > <>~悠遊法國號~
stillalive
初階會員


發表:7
回覆:148
積分:41
註冊:2004-04-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-06-14 23:05:23 IP:211.75.xxx.xxx 未訂閱
ying0515 你好 like 後面應該接 '%' 吧 , 不解你的用法 . cluster index 用在 primary key 應該比較好 , 其它復合式index 應該只能用non cluster , 這好像是 MSSQL SERVER 的限制 , 試試看吧 , 有結果麻煩請回報一下 .
ying0515
中階會員


發表:90
回覆:168
積分:81
註冊:2003-01-04

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-06-15 08:54:02 IP:61.218.xxx.xxx 未訂閱
 
程式架構用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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-06-15 10:27:28 IP:211.75.xxx.xxx 未訂閱
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
系統時間:2024-06-24 20:03:01
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!