0

I have few fields in one table which are storing comma separated values. I can show query using like or FIND_IN_SET to find data from comma separated values.

MySQL query finding values in a comma separated string

However, I would like to know that how much both options FIND_IN_SET('red',colors) & like with comma giving performance impact? Are they used field indexing to provide result?

If not then how can we optimize query and fetch data fast from comma separated fields using index?

Community
  • 1
  • 1
Amit S
  • 44
  • 5

1 Answers1

0

A basic rule in query performance: Have a suitable index tuned for the query. What is your query? Let's also see SHOW CREATE TABLE.

A basic rule in index usage: Don't hide an indexed column inside a function. Doing so leads to ignoring the index. That leads to scanning the entire table. That is slow. I am referring to color hidden in FIND_IN_SET().

A basic rule in building a schema is that "arrays" need to be represented as rows, usually in a separate table. Not in a commalist. Not splayed across columns.

Rick James
  • 135,179
  • 13
  • 127
  • 222