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:

execution plan

my indexes:

  1. [user].[users]:

[userid] (asc) - primary key

  1. [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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -