patternMinor
is "%LIKE%" faster than executing multiple queries?
Viewed 0 times
executingthanlikefastermultiplequeries
Problem
for example, each user on my site has 2 phone numbers (i.e. let say 1234 and 6789) .
but about performance , which is faster:
to save the numbers in one column(separated by comma,like
or saving values into 2 columns
which will be faster? lets say i have thousands or millions of rows.
but about performance , which is faster:
to save the numbers in one column(separated by comma,like
[1234,6789] ), and thus, searching the columns with :select userID from table where number LIKE %1234%or saving values into 2 columns
select userID from table where number1=1234 or number2=1234which will be faster? lets say i have thousands or millions of rows.
Solution
This is bad - it is a table scan
But thousands of rows is not much
Best would be to have second table with phone
if you don't want to fix the data design then two column with = will be faster
LIKE %1234But thousands of rows is not much
Best would be to have second table with phone
phone:
userID PK FK to user
number PK
select *
from user
join phone
on phone.userID = user.userid
and phone.numer = '1234'if you don't want to fix the data design then two column with = will be faster
Code Snippets
phone:
userID PK FK to user
number PK
select *
from user
join phone
on phone.userID = user.userid
and phone.numer = '1234'Context
StackExchange Database Administrators Q#143923, answer score: 3
Revisions (0)
No revisions yet.