title: How to speed up MySQL query that is a carthesian
body: <p>Suppose having a table named <code>contact</code> with next structure:</p>
  
  <pre><code>id INT -- primary key,autoincrement,index 
  firstname VARCHAR (255),
  lastname VARCHAR(255),
  type ENUM
  </code></pre>
  
  <p>Executing such query:</p>
  
  <pre><code>SELECT c1.id AS c1_id, c2.id AS c2_id
  FROM contact c1
  INNER JOIN contact c2 ON c1.firstname = c2.firstname AND c1.lastname = c2.lastname
  WHERE c1.id &lt;&gt; c2.id AND c1.type=c2.type
  </code></pre>
  
  <p>is ok on a small ammount of records... but when the record count grows from 30-40 to 1000 this query is very slow.Need to abstract from the record count and speed up this query maximum as possible.Any suggestions?</p>