I have large mysql database (5 million rows) and data is phone number.
I tried many solution but it’s still slow. Now, I’m using INT type and LIKE sql query for store and searching phone number.
Ex: SELECT phonenumber FROM tbl_phone WHERE phonenumber LIKE '%4567'
for searching phone numbers such as 170**4567**, 249**4567**,…
I need a solution which make it run faster. Help me, please!
You are storing numbers as INT, but querying then as CHAR (the LIKE operator implicitly converts INTs to CHARs) and it surely is not optimal. If you’d like to keep numbers as INT (probably the best idea in IO performance therms), you’d better change your queries to use numerical comparisons:
Besides choosing a homogeneous way to store and query data, you should keep in mind to create the appropriate index
CREATE INDEX IDX0 ON table (phone_number);.Unfortunately, even then your query might not be optimal, because of effects similar to @ron have commented about. In this case you might have to tune your table to break this column into more manageable columns (like national_code, area_code and phone_number). This would allow an index efficient query by area-codes, for example.