02 索引 堆表

2022-02-09 05:44:08 字數 2721 閱讀 8169

堆表查詢

首先在沒有任何索引的情況下檢視 分頁情況

select

database_id

,index_id

,index_type_desc

,index_depth

,index_level

,page_count

from

sys.

dm_db_index_physical_stats

(db_id

('indexdb'

),object_id

('employee001'

),null,null,null)

0 = heap

1 = clustered index

> 1 = nonclustered index

總共有 1688 頁

然後檢視頁的明細情況

truncate

table

dbccindresult

insert

into

dbccindresult

exec

('dbcc ind(indexdb,employee001,-1)'

)select

*from

[indexdb]

.[dbo]

.[dbccindresult]

檢視其中一筆資料頁

--檢視分頁情況

select

*from

dbccindresult

--檢視頁的詳細資料

dbcc

traceon

(3604

)truncate

table

dbccpageresult

--選中一頁 例如 145頁

insert

into

dbccpageresult

exec

('dbcc page (indexdb, 1, 145, 3) with tableresults'

)select

*from

dbccpageresult

where

field

in('id'

,'name'

,'department'

,'organization'

,'company'

)在沒有任何索引(聚集索引)的堆表中,所有欄位都是無序排列的

查詢查一筆資料

開啟包括實際的執行計畫

並設定 statistics io on 

setstatistics

ioon

select

name

from

employee001

whereid=

'43107053d74e484eb02b5b395178f682'

檢視io

執行計畫

另外,可以通過檢視一次查詢中申請的鎖的情況,看看到底讀取了哪些頁

use[indexdb]

goset

transaction

isolation

level

repeatable

read

gobegin

tran

setstatistics

ioon

select

name

from

employee001

whereid=

'43107053d74e484eb02b5b395178f682'

setstatistics

iooff

use[indexdb]

--要查詢申請鎖的資料庫

goselect

[request_session_id],c

.[program_name]

,db_name(c

.[dbid])as

dbname

,[resource_type]

,[request_status]

,[request_mode]

,[resource_description]

,object_name(p

.[object_id])as

objectname,p

.[index_id]

from

sys.

[dm_tran_locks]asa

left

join

sys.

[partitions]asp

ona.[resource_associated_entity_id]=p

.[hobt_id]

left

join

sys.

[sysprocesses]asc

ona.[request_session_id]=c

.[spid]

wherec.

[dbid]

=db_id

('indexdb'

)anda.

[request_session_id]

=@@spid

order

by[request_session_id]

,[resource_type]

commit

tran

可以看到共申請了1692個鎖,其中

頁鎖為1688 正好對應1688個資料頁

1692=1688+3+1

mysql堆表和索引組織 堆表與索引組織表

堆表 資料存放在資料裡面,索引存放在索引裡 堆就是無序資料的集合,索引就是將資料變得有序,在索引中鍵值有序,資料還是無序的 堆表中,主鍵索引和普通索引一樣的,葉子節點存放的是指向堆表中資料的指標 可以是乙個頁編號加偏移量 指向實體地址,沒有回表的說法 堆表中,主鍵和普通索引基本上沒區別,和非空的唯一...

堆表和索引組織表區別

堆表 heap table 資料插入時時儲存位置是隨機的,主要是資料庫內部塊的空閒情況決定,獲取資料是按照命中率計算,全表掃表時不見得先插入的資料先查到。索引表 iot 資料儲存是把表按照索引的方式儲存的,資料是有序的,資料的位置是預先定好的,與插入的順序沒有關係。索引表的查詢效率逼堆表高 相當於查...

堆表和索引組織表區別

堆表 heap table 資料插入時時儲存位置是隨機的,主要是資料庫內部塊的空閒情況決定,獲取資料是按照命中率計算,全表掃表時不見得先插入的資料先查到。索引表 iot 資料儲存是把表按照索引的方式儲存的,資料是有序的,資料的位置是預先定好的,與插入的順序沒有關係。索引表的查詢效率逼堆表高 相當於查...