title: Speed of query using FIND_IN_SET on MySql
body: <p>i have several problems with my query from a catalogue of products.
  The query is as follows:</p>
  
  <pre><code>SELECT DISTINCT (cc_id) FROM cms_catalogo 
  JOIN cms_catalogo_lingua ON ccl_id_prod=cc_id 
  JOIN cms_catalogo_famiglia ON (FIND_IN_SET(ccf_id, cc_famiglia) != 0) 
  JOIN cms_catalogo_categoria ON (FIND_IN_SET(ccc_id, cc_categoria) != 0) 
  JOIN cms_catalogo_sottocat ON (FIND_IN_SET(ccs_id, cc_sottocat) != 0) 
  LEFT JOIN cms_catalogo_order ON cco_id_prod=cc_id AND cco_id_lingua=1 AND cco_id_sottocat=ccs_id 
  WHERE ccc_nome='Alpine Skiing' AND ccf_nome='Ski'
  </code></pre>
  
  <p>I noticed that querying the first time it takes on average 4.5 seconds, then becomes rapid.
  I use FIND_IN_SET because in my Database on table "cms_catalogo" I have the column "cc_famiglia" , "cc_categoria" and "cc_sottocat" with inside ID separated by commas (I know it's stupid).</p>
  
  <p>Example:</p>
  
  <p><strong>Table</strong> <em>cms_catalogo</em></p>
  
  <p><strong>Column</strong> <em>cc_famiglia</em>: 1,2,3,4,5</p>
  
  <p><strong>Table</strong> <em>cms_catalogo_famiglia</em></p>
  
  <p><strong>Column</strong> <em>ccf_id</em>: 3</p>
  
  <p>The slowdown in the query may arise from the use of FIND_IN_SET that way?</p>
  
  <p>If instead of having IDs separated by comma have a table with ID as an index would be faster?</p>
  
  <p>I can not explain, however, why the first execution of the query is very slow and then speeds up</p>