• unknown's avatar
    Bug #21456: SELECT DISTINCT(x) produces incorrect results when using order by · 2baf2fdf
    unknown authored
    GROUP BY/DISTINCT pruning optimization must be done before ORDER BY 
    optimization because ORDER BY may be removed when GROUP BY/DISTINCT
    sorts as a side effect, e.g. in 
      SELECT DISTINCT <non-key-col>,<pk> FROM t1
      ORDER BY <non-key-col> DISTINCT
    must be removed before ORDER BY as if done the other way around
    it will remove both.
    
    
    mysql-test/r/distinct.result:
      Test for BUG#21456.
    mysql-test/t/distinct.test:
      Test for BUG#21456.
    sql/sql_select.cc:
      Bug #21456: SELECT DISTINCT(x) produces incorrect results when using order by
      
      GROUP BY/DISTINCT pruning optimization must be done before ORDER BY 
      optimization because ORDER BY may be removed when GROUP BY/DISTINCT
      sorts as a side effect.
    2baf2fdf
distinct.test 14.4 KB