title: mysql - OR operator not using index
body: <p>I have a simple invitation table:</p>
  
  <pre><code>CREATE TABLE `invitation` (
    `invitation_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `inviter_id` int(10) unsigned NOT NULL,
    `invitee_id` int(10) unsigned NOT NULL,
    PRIMARY KEY (`invitation_id`),
    UNIQUE KEY `invitee_inviter_idx` (`invitee_id`,`inviter_id`)
  )
  </code></pre>
  
  <p>I want to select an invitation by inviter 70 to invitee 62 and vice versa:</p>
  
  <pre><code>EXPLAIN SELECT * FROM `invitation` WHERE 
  (invitee_id = 70 AND inviter_id = 62) OR (invitee_id = 62 AND inviter_id = 70)
  </code></pre>
  
  <p>But this query is of type ALL and doesn't use the invitee_inviter_idx.
  Please tell me what is wrong here ?</p>
  
  <p>Thank you!</p>
  
  <p>==EDIT==
  Sorry, i was wrong about the schema, it has one more field: request_ts. This time the query plan is ALL.</p>
  
  <pre><code>    CREATE TABLE `invitation` (
        `invitation_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `inviter_id` int(10) unsigned NOT NULL,
        `invitee_id` int(10) unsigned NOT NULL,
        `request_ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
        PRIMARY KEY (`invitation_id`),
        UNIQUE KEY `invitee_inviter_idx` (`invitee_id`,`inviter_id`)
      )
  </code></pre>
  
  <p>Here is my exlain result:</p>
  
  <pre><code>id  select_type table   type    possible_keys   key key_len ref rows    Extra
  1   SIMPLE  invitation  ALL invitee_inviter_idx \N  \N      \N  1   Using where
  </code></pre>