sql - What is the quickest way to check if user exists in a large table? (Performance Optimization) -


i'm working on website 500,000 users, issue im having when user goes create new account wait time extremely long because check if user exists using query.

select count(username) usernametotal user_table username = 'hellokitty' 

i decide if can create account based on if usernametotal greater 0.

i going index column think slow when try add user table, indexed column table need recreated every time user added.

is there faster way , should column indexed?

for query:

select count(username) usernametotal user_table username = 'hellokitty' 

you want index on user_table(username).

however, not efficient approach. should keep same index , use exists:

if (exists (select 1  user_table username = 'hellokitty')) begin   . . . end; 

this should faster aggregation version, because can stop @ first matching row.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -