I have the following tables
Create Table dbo.product
(
productId varchar(100) primary key,
productStatus varchar(100),
productRegion varchar(100),
productCreated datetime,
productUpdated datetime
)
Go
declare @id int = 1
while @id <= 100
Begin
Insert Into dbo.product values ('product'+cast(@id as varchar(10)),'Active','North',getdate(),getdate())
set @id = @id + 1
End
set @id = 1
while @id <= 100
Begin
Insert Into dbo.product values ('inprod'+ cast(@id as varchar(10)),'InActive','South',getdate(),getdate())
set @id = @id + 1
End
Go
Create Table dbo.productRef
(
productRef int Identity(1,1) primary key,
productId varchar(100),
productName varchar(100)
)
Go
Insert Into dbo.productRef (productId)
Select top 20 productId
from dbo. product
Go
declare @id int = 1
while @id <= 20
Begin
update dbo.productRef
set productName = 'productName'+convert(varchar(10),@id)
where productRef = @id
set @id = @id + 1
End
Go
Create nonclustered index idx_productRef1 On dbo.productRef(productId)
Which one of these selects will perform better?
select p.*
from dbo.product p
join dbo.productref pr
on p.productid = pr.productid
order by p.productUpdated
select p.productId
from dbo.product p
join dbo.productref pr
on p.productid = pr.productid
order by p.productUpdated
Here's the query plans for both the select statements:
select * plan:
https://www.brentozar.com/pastetheplan/?id=SyY21P0Jo
select productId plan:
https://www.brentozar.com/pastetheplan/?id=BkK-gwA1i
From what I see both the plans are same. Is there a performance difference when doing select * order by vs select column order by?