使用視圖提高查詢性能

[英]Improving query performance by using views


I have a large table with 10+ millions records in a SQL Server database. The table contains certain type of data for all 50 states in the US. So if I create 50 views, one for each state, from this table, would the performance of making queries from my application be improved? Other suggestions?

我在SQL Server數據庫中有一個包含10多萬條記錄的大表。該表包含美國所有50個州的特定類型的數據。因此,如果我從這個表創建50個視圖,每個狀態一個,那么從我的應用程序中進行查詢的性能是否會提高?其他建議?

6 个解决方案

#1


8  

No. A view is a macro that expands so the same tables end up in the plan anyway.

不是。視圖是一個擴展的宏,因此無論如何,相同的表最終會在計划中結束。

Unless it's indexed. 50 indexed views is most likely overkill.

除非它被索引。 50個索引視圖很可能是矯枉過正。

If you have slow performance with 50 million rows (it's not that much really) then it's an indexing problem.

如果你有5000萬行的性能很慢(實際上並不是那么多),那么它就是一個索引問題。

Edit:

To start with, I'd use the weighted missing index dmv query to see where you get the most bang for your buck

首先,我將使用加權缺失索引dmv查詢來查看您獲得最大收益的位置

#2


2  

Normal (non-indexed) views cannot improve performance - they could be thought of as 'shorthands' or 'aliases' for SELECT queries, as they have no physical structure under them.

正常(非索引)視圖無法提高性能 - 它們可以被認為是SELECT查詢的“縮寫”或“別名”,因為它們下面沒有物理結構。

Indexed views are a different beast, but it doesn't seem that you need them so far.

索引視圖是一種不同的野獸,但到目前為止你似乎並不需要它們。

What you need is to create appropriate indexes on your table, and, possibly, to redesign the table (for instance, split it to several tables).

您需要的是在表上創建適當的索引,並且可能重新設計表(例如,將其拆分為多個表)。

If you want more specific advice, post here the table structure and some examples of typical queries (the ones you want to optimise for).

如果您需要更具體的建議,請在此處發布表結構和典型查詢的一些示例(您要優化的查詢)。

#3


0  

You're on the right track:

你走在正確的軌道上:

Start with making sure you index the data to reflect the reads you need to be fast. Then, since filtering does make it faster, I would consider require filtering on state by allowing access to the data via a stored procedure (with a parameter for state).

首先確保索引數據以反映您需要快速讀取的數據。然后,由於過濾確實使它更快,我會考慮通過允許通過存儲過程(具有狀態參數)訪問數據來過濾狀態。

#4


0  

If you have the proper index and usage in your execution plans, then the big issues is the quantity of memory cache and read speed of the disk. Creating views won't fix any of those, it is still the same data on the same disk/cache, just a different logical way of referring to it.

如果您的執行計划中有正確的索引和用法,那么最大的問題是內存緩存的數量和磁盤的讀取速度。創建視圖不會解決任何問題,它仍然是同一磁盤/緩存上的相同數據,只是引用它的不同邏輯方式。

#5


0  

One simple suggestion:

一個簡單的建議:

use [YourDataBase]
select * from sys.dm_db_missing_index_details as ddmid

#6


0  

That is such a tiny database that if you are having performance problems your indexing wrong, you databases design is bad or you have designed poorly performing queries. SQL server can handle trillions of records without breaking a sweat if designed correctly.

這是一個如此小的數據庫,如果您遇到性能問題,索引錯誤,您的數據庫設計很糟糕,或者您設計的性能不佳的查詢。如果設計正確,SQL服務器可以處理數萬億條記錄而不會出汗。

Views BTW can be performance Killers if you use views that call views.

如果您使用調用視圖的視圖,BTW可能是性能殺手。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/09/14/7298ca5cefe4906b13a6460b51efce0a.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com