What is "Clustered Index Scan (Clustering)" in SQL Server Runtime?

I have a query that fails with "Failed to allocate a new page for the database" TEMPDB "due to insufficient disk space in the file group" DEFAULT ".

On the way to troubleshooting, I am studying the execution plan. There are two expensive steps labeled "Clustered Index Scanning (Clustering)." I find it difficult to know what this means?

I would appreciate any explanation of “Cluster Index Scan (Cluster)” or suggestions on where to find the appropriate document?

+5
source share
3 answers

I would appreciate any clarification to the "Cluster Index Scan" (Cluster) "

I will try to do this the easiest way, for a better understanding you need to understand both index search and scanning.

SO allows you to create a table

use tempdb GO create table scanseek (id int , name varchar(50) default ('some random names') ) create clustered index IX_ID_scanseek on scanseek(ID) declare @i int SET @i = 0 while (@i <5000) begin insert into scanseek select @i, 'Name' + convert( varchar(5) ,@i) set @i =@i +1 END 

Index search is where the SQL server uses the index b-tree structure to search directly to match records

enter image description here

you can check your root and leaf nodes of the table using the DMV below

 -- check index level SELECT index_level ,record_count ,page_count ,avg_record_size_in_bytes FROM sys.dm_db_index_physical_stats(DB_ID('tempdb'),OBJECT_ID('scanseek'),NULL,NULL,'DETAILED') GO 

Now we have a clustered index in the "ID" column

allows you to search for some direct match records

 select * from scanseek where id =340 

and see the execution plan

enter image description here

your requested rows directly in the query, so you have a SEEK clustered index.

Cluster Index Scan:. When the Sql server reads rows (rows) from top to bottom in a clustered index. for example, finding data in a column without a key. In our table, NAME is not a key column, so if we look for some data in the name column, we will see a scan with a cluster index, because all rows are in the cluster level of the index sheet.

Example

 select * from scanseek where name = 'Name340' 

enter image description here

Please note: I made this answer short for a better understanding, if you have any questions or suggestions, please comment below.

+14
source

Expanding in Gordon's answer in the comments, a clustered index scan scans one of the table indices to find the values ​​you use for the where clause filter, or to connect to the next table in the query plan.

Tables can have multiple indexes (one clustered and many non-clustered), and SQL Server will search for the appropriate file based on a filter or connection.

Clustered indexes are very well explained on MSDN. The key difference between clustered and non-clustered is that the clustered index determines how the rows are stored on disk.

If your clustered index is very expensive to search due to the number of records, you can add a nonclustered index to the table for fields that you frequently view, such as date fields used to filter record ranges.

+3
source

A clustered index is an index in which the index (sheet) of the index node is the actual data page itself. There can only be one clustered index in a table because it determines how records are arranged on the data page. Usually (and with some exceptions) it is considered the most effective type of index (primarily because there is one lesser level of indirection before you get into your actual data record).

“Clustered index scanning” means that the SQL engine moves your clustered index in search of a specific value (or set of values). This is one of the most effective ways to determine the location of a record (beat the “search for a clustered index” in which SQL Engine seeks to match a single selected value).

The error message is completely unrelated to the query plan. It just means that you are out of place on TempDB.

+3
source

All Articles