[英]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.
我可以使用like或FIND_IN_SET来显示查询,以从逗号分隔的值中查找数据。
MySQL query finding values in a comma separated string MySQL查询以逗号分隔的字符串查找值
However, I would like to know that how much both options FIND_IN_SET('red',colors)
& like with comma giving performance impact? 但是,我想知道
FIND_IN_SET('red',colors)
和诸如此类的两个选项对性能有何影响? 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
. 我们
SHOW CREATE TABLE
一下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()
. 我指的是隐藏在
FIND_IN_SET()
color
。
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.
跨列未展开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.