title: SQL Infinite loading
body: <p>I have a database with 1 million records, it's working fine with around to 1.2s response time for simple queries using <em>JOIN, GROUP BY, ORDER</em>, .. It's ok and there are no problems with that. I'm working to simplify my queries using table aliases, but when I execute a simple query with two table aliases or more, the request never ends and MariaDB doesn't respond anymore, I have to restart the service manually.</p>
  
  <p>Whats is going wrong ?</p>
  
  <p><strong>Here it's structure:</strong></p>
  
  <pre><code>CREATE TABLE `values` (
    `id` mediumint(11) UNSIGNED NOT NULL,
    `date` int(11) NOT NULL DEFAULT '0',
    `indexVar` int(11) NOT NULL,
    `value` float NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  </code></pre>
  
  <p>Data:
  <a href="https://i.stack.imgur.com/FUC2o.png" rel="nofollow noreferrer">exemple</a></p>
  
  <p><strong>Working query:</strong></p>
  
  <pre><code>SELECT
      v.date,
      v.value
  FROM
      `values` AS v
  WHERE
      v.date &gt; 1548460800 AND v.indexVar = 6 OR v.indexVar = 2
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/VDI01.png" rel="nofollow noreferrer">expected result</a></p>
  
  <p><strong>Infinite loading query:</strong></p>
  
  <pre><code>SELECT DISTINCT
      v.date,
      v1.value,
      v2.value
  FROM
      `values` AS v,
      `values` AS v1,
      `values` AS v2
  WHERE
      v.date &gt; 1548460800 AND v1.indexVar = 6 AND v2.indexVar = 2
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/irEha.png" rel="nofollow noreferrer">expected result</a></p>