I have a test table with following structure.
CREATE TABLE [dbo].[DW_test](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[CourtCaseID] [int] NOT NULL,
[ActionID] [int] NOT NULL,
PRIMARY KEY CLUSTERED([ID] ASC)
Next I populated my table with about 470 million records with the following script.
insert into DW_test
--select count(*)
--from (
select top 1000000 abs(checksum(newid())) % 100000 + 1 a, abs(checksum(newid())) % 10 + 1 b
from sys.all_objects
cross join sys.all_objects a
cross join sys.all_objects b
cross join sys.all_objects c
cross join sys.all_objects d
cross join sys.all_objects e
cross join sys.all_objects f
cross join sys.all_objects g
--) t
GO
The script was executed about 470 times to generate 470 million records in the table and created NCCI on that table.
CREATE NONCLUSTERED COLUMNSTORE INDEX [IX_test1] ON [dbo].[DW_test]
(
[CourtCaseID],
[ActionID]
)
Next I test simple query to count the records in the table.
DBCC DROPCLEANBUFFERS
GO
select COUNT_BIG(*)
from DW_test
If I turn SET STATISTICS IO ON I get the following results
With cold cache
Table 'DW_test'. Scan count 25, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 469697, lob physical reads 1, lob read-ahead reads 1877324.
Table 'DW_test'. Segment reads 453, segment skipped 0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
With warm cache
Table 'DW_test'. Scan count 25, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 229248, lob physical reads 0, lob read-ahead reads 0.
Table 'DW_test'. Segment reads 453, segment skipped 0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.`
I know that 1 logical read is a single data page read from buffer pool during query execution and 1 physical read is a single data page read from disk. RedGate tells us that read-ahead read is:
This number tells us how many of the physical reads were satisfied by SQL Servers ‘Read-ahead’ mechanism. This is directly tied to physical reads, so if there are no physical reads, you will have 0 for Read-Ahead reads.
In my case I am dealing with lob logical, physical and read ahead reads. I want to understand what this number means in my particular case.
How it is possible to have only 1 lob physical read with cold cache if the table has about 470 million records?
How it is possible the total number of lob pages decreased from about 2.3 million in cold cache to about 220k in warm cache?