简体   繁体   中英

MySQL - FIND_IN_SET for comma separated field values

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM