sql server - How to index user table to improve searches by user's real name? -


in mvc app, uses linq sql, have number of pages allows filtering users real names, emails (and few other fields). user's first name, last name , fields stored in separate columns. right now, user table has no indexes (besides clustered index on user id).

linq produces query has (more or less) in section:

(firstname + " " + lastname) @searchterm or (lastname + " " + firstname) @searchterm 

what approach if index that?

i thinking of:

  1. adding 2 complex indexes (firstname,lastname) , (lastname,firstname)
  2. add index on firstname , on lastname
  3. something else?

will sql server use indexes first example on (firstname + " " + lastname) @searchterm searches?

when have more time i'll try conducting tests on own, maybe had solve similar problem?


solution proposed onskee made me remembered 1 i've came across few times when working databases made else. involved adding computed column of combinations of user's name (first name first, last name first etc.) , other columns, supposed searchable, , adding fulltext index on computed column. i'm not sure how effective is, guess have test too.

what adding computed column containing firstname , lastname, adding index this? have not tested performance, it's 1 way try.

alter table dbo.users add  fullname  firstname + ' ' + lastname go   create nonclustered index ix_fullname on dbo.users ( fullname ) with( statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary] go 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -