I need the fastest performance way to retrieve integers that need to be pulled up fast. Here is my use case: There is a "sort/filter" option on my site. I have attributes for dogs, like long hair, short hair, big, dog, etc... I want users to be able to filter by attributes of the dogs.
Here is my table:
dogs
- id
- attributes
Here is the reference to attributes about the dogs (not very important for the question, it is just to give you an idea):
0 = adoptable pet
1 = short hair
2 = long hair
3 = fluffy
4 = black
5 = brown
6 = white
7 = golden/yellow
8 = etc...
Right now, I have attributes saved in a TEXT
data type in JSON format. For example, ["0","4"]
or ["0"]
or ["2"]
.
So I want to select all the attributes like so:
SELECT * FROM dogs WHERE attributes LIKE %0% OR attributes LIKE %1% OR attributes LIKE %4% attributes LIKE %7%
How can I select all rows where the attributes contain 0, or 1, or 4, or 7 (not and). If a row has one of those attributes, select them.
What is the best way to approach it? Should I store as JSON datatype in MySQL or should I do something else? I want to be able to SELECT
and pull it up FAST. I feel like the way I have it LIKE
won't be very fast.
What is the the best and fastest way especially with hundreds of thousands of rows to millions?
Thank you in advanced!