Paul White does some amazing things with T-SQL, news at 11:
I will be looking for distinct values in the
BountyAmount
column of thedbo.Votes
table, presented in bounty amount order ascending. The Votes table has just under 53 million rows (52,928,720 to be exact). There are just 19 different bounty amounts, includingNULL
.The Stack Overflow 2013 database comes without nonclustered indexes to minimize download time. There is a clustered primary key index on the
Id
column of thedbo.Votes
table. It comes set to SQL Server 2008 compatibility (level 100), but we will start with a more modern setting of SQL Server 2017 (level 140):
Getting the query down from 10.5 seconds to 1ms is crazy.