title: Mysql Join Query optimization
body: <p>I have two tables in mysql:</p>
  
  <pre><code>Results Table : 1046928 rows.
  Nodes Table :  50 rows.
  </code></pre>
  
  <p>I am joining these two tables with the following query and the execution of the query is very very slow.</p>
  
  <pre><code>select res.TIndex, res.PNumber, res.Sender, res.Receiver, 
  sta.Nickname, rta.Nickname from ((Results res join 
  Nodes sta) join Nodes rta) where ((res.sender_h=sta.name) and
  (res.receiver_h=rta.name));
  </code></pre>
  
  <p>Please help me optimize this query. Right now if I want to pull just top 5 rows, It takes about 5-6 MINUTES. Thank you.</p>
  
  <pre><code>CREATE TABLE `nodes1` (
    `NodeID` int(11) NOT NULL,
    `Name` varchar(254) NOT NULL,
    `Nickname` varchar(254) NOT NULL,
    PRIMARY KEY (`NodeID`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  
  CREATE TABLE `Results1` (
    `TIndex` int(11) NOT NULL,
    `PNumber` int(11) NOT NULL,
    `Sender` varchar(254) NOT NULL,
    `Receiver` varchar(254) NOT NULL,
    `PTime` datetime NOT NULL,
    PRIMARY KEY (`TIndex`,`PNumber`),
    KEY `PERIOD_TIME_IDX` (`PTime`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  </code></pre>