SQL Server 中,Index Location(索引的位置)
在 SQL Server 中,Index Location(索引的位置) 通常是指「索引資料實際儲存的檔案位置」或「索引是放在哪個資料表分割區(partition)、資料檔案(filegroup)或頁面(page)上」。
CREATE INDEX ... ON <filegroup|partition_scheme>
若將非叢集索引放到與資料表不同的 filegroup 且位於不同磁碟,可能提升查詢效能,因為可以平衡 I/O 載荷;亦可利用 partition scheme 將 Clustered / Nonclustered index 分散到多個 filegroup 之上
https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-index-design-guide?view=sql-server-ver17
官方 T‑SQL 語法說明 CREATE INDEX
對比 ON filegroup_name、ON partition_scheme(column) 與 ON [default]
若不指定,非分割資料表的 index 將放在與 base table 相同檔案群組。
[default] 並非資料庫預設組,而是指基表使用的 filegroup 或 partition scheme
https://learn.microsoft.com/zh-tw/sql/t-sql/statements/create-index-transact-sql?view=sql-server-ver17
建立索引時指定特定檔案 or filegroup
https://stackoverflow.com/questions/7823882/how-to-create-indexs-on-a-different-file-of-filegroup?utm_source=chatgpt.com
將現有的索引移至不同的檔案群組
https://learn.microsoft.com/zh-tw/sql/relational-databases/indexes/move-an-existing-index-to-a-different-filegroup?view=sql-server-ver17&utm_source=chatgpt.com
Data Space 對照說明
https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-data-spaces-transact-sql?view=sql-server-ver17
https://learn.microsoft.com/en-us/sql/relational-databases/pages-and-extents-architecture-guide?view=sql-server-ver17
分區索引教學
https://learn.microsoft.com/en-us/sql/relational-databases/partitions/partitioned-tables-and-indexes?view=sql-server-ver17
查詢現有索引的位置
SELECT
i.name AS IndexName,
fg.name AS FileGroupName,
ds.physical_name AS FileLocation
FROM sys.indexes i
JOIN sys.data_spaces ds ON i.data_space_id = ds.data_space_id
JOIN sys.filegroups fg ON ds.data_space_id = fg.data_space_id
WHERE i.object_id = OBJECT_ID('dbo.YourTableName');
指定 Filegroup 建立索引
CREATE NONCLUSTERED INDEX IX_Customer_Name
ON dbo.Customer (Name)
ON [IndexFileGroup]; -- 指定 filegroup 名稱
留言
張貼留言