<div dir="ltr">What about writing a concatenated version of fields 1-10 into another field and then indexing & searching on that?<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 21 February 2014 11:22, Andrew Stewart <span dir="ltr"><<a href="mailto:boss@airbladesoftware.com" target="_blank">boss@airbladesoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello LRUG!<br>
<br>
At various points in my Rails app I run a query to find any near-duplicates a record has:<br>
<br>
SELECT col1, col2, ..., col10<br>
FROM widgets<br>
WHERE col1 = 'blah' AND col2 = 'blurgh' ... AND col10 = 'bleugh'<br>
AND id <> 123456<br>
<br>
There are about 200,000 widgets in the table so it's not massive. But the query is somewhat sluggish.<br>
<br>
When MySQL explains itself it says:<br>
<br>
select_type: SIMPLE<br>
table: widgets<br>
type: range<br>
possible_keys: PRIMARY<br>
key: PRIMARY<br>
key_len: 4<br>
ref: NULL<br>
rows: 84888<br>
Extra: Using where<br>
<br>
If I were just querying one or two columns I'd index them but I'm not sure indexing 10 columns is possible or helpful (it would slow down writes).<br>
<br>
Does anyone have any tips?<br>
<br>
Thanks in advance,<br>
<br>
Andy Stewart<br>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
<a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div><br></div>