我最近对这个问题做了一些研究。如果字段是文本字段,非唯一字段,则实现该字段的方式必须是不同的。我用文本字段做了一些测试。考虑到我们有一个包含1M条目的表。37项等于“某物”:SELECT * FROM test WHERE texte LIKE '%something%' LIMIT 1带着mysql_num_rows():0.039061069488525(更快)SELECT count(*) as count FROM test WHERE text LIKE '%something%:16.028197050095s。SELECT EXISTS(SELECT 1 FROM test WHERE text LIKE '%something%'):0.87045907974243。SELECT EXISTS(SELECT 1 FROM test WHERE text LIKE '%something%'
LIMIT 1):0.044898986816406 s。但是现在,对于BIGINTPK字段,只有一个条目等于“321321”:SELECT * FROM test2 WHERE id ='321321' LIMIT 1带着mysql_num_rows():0.0089840888977051。SELECT count(*) as count FROM test2 WHERE id ='321321':0.00033879280090332 s。SELECT EXISTS(SELECT 1 FROM test2 WHERE id ='321321')*0.00023889541625977SELECT EXISTS(SELECT 1 FROM test2 WHERE id ='321321' LIMIT 1)*0.00020313262939453(更快)