SQL Server Tables – BTree or Linked List?
Is a clustered table in SQL Server a BTree or Linked List?
When you first learn about the structure behind clustered indexes in SQL Server, you find out that the clustered index is structured as a type of B+Tree where queries that make use of the tree structure to find the rows that you are looking for. However it is not the common belief that that table with the clustered index also happens to be a doubly linked list, and that the B+Tree can be completely skipped when running a query that uses the clustered index via a clustered index scan.
Take the following table and query as an example:
CREATE TABLE [dbo].[Orders]( [id] [int] IDENTITY(-2147483647,1) NOT NULL, [orderDate] [DATETIME] NOT NULL, [customerId] [int] NULL, [shippingType] varchar(100), [orderDetails] varchar(max), [totalPrice] DECIMAL(12, 2) CONSTRAINT [PK_Revenue] PRIMARY KEY CLUSTERED ([id] ASC, [orderDate]) );
Then insert a bunch of rows, and run a query.