查看Table的Index

Posted 悦光阴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查看Table的Index相关的知识,希望对你有一定的参考价值。

1,查看table中的index的定义

SELECT
    o.object_id,
    o.name,
    i.index_id,
    i.name as index_name,
    i.type_desc as index_type,
    ic.index_column_id,
    c.name AS columnname,
    iif(ic.is_descending_key=1,desc,asc) as sort_direction,
    ic.key_ordinal as index_key_ordinal,
    ic.is_included_column,
    i.fill_factor,
    i.is_padded,
    i.has_filter,
    i.filter_definition,
    ic.partition_ordinal
FROM sys.objects o
INNER JOIN sys.indexes i
    ON o.object_id = i.object_id
INNER JOIN sys.index_columns ic
    ON i.object_id = ic.object_id AND i.index_id = ic.index_id
INNER JOIN sys.columns c
    ON o.object_id = c.object_id AND ic.column_id = c.column_id
WHERE o.name = table_name
    --and i.name=‘index_name‘
ORDER BY i.index_id,ic.index_column_id

2,查看Index Page占用的物理存储空间

declare @db_id smallint
declare @object_id int
declare @index_id int 
declare @Model nvarchar(20)

set @db_id=db_id()
set @object_id=object_id(FactThread,U)
set @index_id=null
set @Model=NDETAILED  --DEFAULT, NULL, LIMITED, SAMPLED, or DETAILED

select *
from sys.dm_db_index_physical_stats(@db_id,@object_id,@index_id,null,@Model) ips
order by ips.index_id

 

Appendix:
Scanning Modes

The mode in which the function is executed determines the level of scanning performed to obtain the statistical data that is used by the function. mode is specified as LIMITED, SAMPLED, or DETAILED. The function traverses the page chains for the allocation units that make up the specified partitions of the table or index. sys.dm_db_index_physical_stats requires only an Intent-Shared (IS) table lock, regardless of the mode that it runs in.

The LIMITED mode is the fastest mode and scans the smallest number of pages. For an index, only the parent-level pages of the B-tree (that is, the pages above the leaf level) are scanned. For a heap, the associated PFS and IAM pages are examined and the data pages of a heap are scanned in LIMITED mode.

With LIMITED mode, compressed_page_count is NULL because the Database Engine only scans non-leaf pages of the B-tree and the IAM and PFS pages of the heap. Use SAMPLED mode to get an estimated value for compressed_page_count, and use DETAILED mode to get the actual value for compressed_page_count. The SAMPLED mode returns statistics based on a 1 percent sample of all the pages in the index or heap. Results in SAMPLED mode should be regarded as approximate. If the index or heap has fewer than 10,000 pages, DETAILED mode is used instead of SAMPLED.

The DETAILED mode scans all pages and returns all statistics.

The modes are progressively slower from LIMITED to DETAILED, because more work is performed in each mode. To quickly gauge the size or fragmentation level of a table or index, use the LIMITED mode. It is the fastest and will not return a row for each nonleaf level in the IN_ROW_DATA allocation unit of the index.

 

参考文档:

sys.dm_db_index_physical_stats (Transact-SQL)

sys.index_columns (Transact-SQL)

以上是关于查看Table的Index的主要内容,如果未能解决你的问题,请参考以下文章

查看Table的Index

oracle impdp时卡死Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX

Discuz代码片段

element表格添加查看操作

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段