I have a question about using Top with tables with Clustered Clustered Index on SQL Azure.
Both of the tables have Clustered Columnstore Index, table HeaderTable has 300K rows, table ValuesTable has 6.5M rows.
-- with no "Top"
--responce after 2 sec
declare @Date datetime = getdate()
select zp.idCol1, Value1, zp.idcol2 from [HeaderTable] zp
inner join [dbo].[ValuesTable] zpp
on zp.idcol2 = zpp.idcol2
where zp.Date > @Date-30 and zp.Date < @Date-10 and zp.idCol1>0 and zpp.Value2 = 'SZT'
order by idcol2
go
-- with "Top 100"
--responce after 27 sec
declare @Date datetime = getdate()
select top 100 zp.idCol1, Value1, zp.idcol2 from [HeaderTable] zp
inner join [dbo].[ValuesTable] zpp
on zp.idcol2 = zpp.idcol2
where zp.Date > @Date-30 and zp.Date < @Date-10 and zp.idCol1>0 and zpp.Value2 = 'SZT'
order by idcol2
go
-- Result into Temporary Table and Select top 100 from Temporaty Table
-- responce after 2 sec
declare @Date datetime = getdate()
select zp.idCol1, Value1, zp.idcol2 into #d from [HeaderTable] zp
inner join [dbo].[ValuesTable] zpp
on zp.idcol2 = zpp.idcol2
where zp.Date > @Date-30 and zp.Date < @Date-10 and zp.idCol1>0 and zpp.Value2 = 'SZT'
select top 100 * from #d order by #d.idcol2
drop table #d
go
As You see the top operation in the second query is extremely slow. Maybe someone has some hints with this problem?