sql server - SQL join query performance issue -
i have 2 tables:
1. [user].[users] -------------------------------------------------- |[userid] | int (primary key) | |[username] | nvarchar(50) | |[isverified] | bit | |[modifieddate] | datetime | -------------------------------------------------- 2. [user].[emailaddresses] -------------------------------------------------- |[userid] | int (foreign key) | |[emailaddressid] | int | |[emailaddress] | nvarchar(50) | |[isprimary] | bit | |[isverified] | bit | |[modifieddate] | datetime | --------------------------------------------------
now, when run query, performs great:
select u.[userid], u.[username], u.[isverified], e.[emailaddressid], e.[emailaddress] [user].[users] u inner join [user].[emailaddresses] e on e.[userid] = u.[userid] (@pemailaddress = e.[emailaddress]) , (@ppassword = u.[password])
but, when run query, performs horribly:
select u.[userid], u.[username], u.[isverified], e.[emailaddressid], e.[emailaddress], e.[isprimary], e.[isverified], e.[modifieddate] [user].[users] u inner join [user].[emailaddresses] e on e.[userid] = u.[userid] (@pemailaddress = e.[emailaddress]) , (@ppassword = u.[password])
note add 1 these 3 columns (e.[isprimary]
, e.[isverified]
, e.[modifieddate]
), , turns perform horribly (5-6 seconds delay)...
what be? not joining tables right? because have columns same name in both tables?
also, don't have many records... (about 20 records)...
update: found "(@ppassword = u.[password])" removes problem, performs great without it, have indexing?
here execution plan:
my indexes:
- [user].[users]:
[userid] (asc) - primary key
- [user].[emailaddresses]
[userid] (asc), [emailaddressid] (asc) - primary key
[emailaddress] (asc) - unique key
for query:
select u.[userid], u.[username], u.[isverified], e.[emailaddressid], e.[emailaddress], e.[isprimary], e.[isverified], e.[modifieddate] [user].[users] u inner join [user].[emailaddresses] e on e.[userid] = u.[userid] (@pemailaddress = e.[emailaddress]) , (@ppassword = u.[password]);
you want try following indexes: users(password, userid)
, email(emailaddress, userid)
.
Comments
Post a Comment