我有一個數據庫在ms-sql-server express 2008中,它可以從同一臺PC的linq-to-sql進行訪問。 (沒有太多的併發訪問,但複雜的查詢)爲'foreign_key = x'查詢增加數據庫性能
它有幾個表,每個表可以變得非常大,以至於查詢,刪除,更新和插入的性能變得太慢。
有一個主表項目和幾乎所有其他表有
- 與項目
- 或一個表,有一個1的1-N關係的直接1-n的關係n與項目的關係,
- 或與這些表格之一的1-n關係等。
選擇,刪除,更新和插入始終對單個項目進行操作。 我從來不需要更新不同項目的條目或從2個項目中選擇匹配的項目等。
有沒有什麼方法可以用這個事實來提高數據庫的性能?
只要適用,我已經在外鍵project_ID上有一個非聚集索引。
還有什麼我可以做的嗎? 分區幫助我,如果它可用於sql-express?
編輯:
delete from items
where items.projectID=X
AND (items.prop1=a OR items.prop2=b OR items.prop3=c)
(deletes a few 1000 items, fast when database is empty, slow when lots of other projects exist)
select top 1 itemprops
from itemprops
inner join items on items.id = itemprops.itemid
inner join project on item.projectid=project.id
inner join modes on itemprops.modeId = mode.id
where item.name = X and project.id = Y and mode.name = z
(find a certain itemprop corresponding to an item and a mode)
select top 1 * from foo where projectID=x and name=Y and type=z
(nonclustered index on projectID + name + type exists)
的公共點:慢查詢(轉述,最多的是LINQ到SQL查詢,針對一些刪除我直接執行SQL)的
例子我所有的查詢之間是這樣的:他們都有一個where projectID=XY
在那裏
您可以舉一個慢查詢的例子,以及相關的模式嗎? – mwigdahl 2012-04-27 19:30:17
你有維護工作嗎? – 2012-04-27 21:06:52
re:查詢2 - 連接中的列上是否有索引?那麼WHERE子句中的列呢?查詢3 - 表中有多少個字段(使用SELECT *是一種不好的做法 - 只選擇你需要的) - 表格是否被標準化?另外,請記住任何僅當[有選擇性](http://www.akadia.com/services/ora_index_selectivity.html) – 2012-04-27 21:34:31