<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="993718">
  <date_last_updated>2012-05-10 23:03:42.568321+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/993718</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~igorb-seattle</bug_owner_link>
    <milestone_link>https://api.launchpad.net/1.0/maria/+milestone/5.2</milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/993718/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/993718/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/993718</bug_web_link>
  <owner>Igor Babaev</owner>
  <assignee>Vladislav Vaintroub</assignee>
  <milestone_title>Maria 5.2</milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>Wrong result from a query with GROUP BY, ORDER BY and LIMIT</title>
  <status>Confirmed</status>
  <importance>High</importance>
  <created>2012-05-03 04:03:32.564835+00:00</created>
  <description>
<![CDATA[The following sequence of commands gives a wrong result set:

CREATE TABLE t1 (
  id BIGINT(20) , member_id_to INT(11) , r_date DATE , 
  PRIMARY KEY (id,r_date), KEY r_date_idx (r_date), KEY t1_idx01 (member_id_to)
 ) ENGINE=InnoDB;

INSERT INTO t1 VALUES
(107924526,518491,'2011-05-01'), (107924527,518491,'2011-05-01'), (107924528,518491,'2011-05-01'), 
(107924529,518491,'2011-05-01'), (107924530,518491,'2011-05-01'), (107924531,518491,'2011-05-01'),
(107924532,518491,'2011-05-01'), (107924534,518491,'2011-06-21'), (107924535,518491,'2011-06-21'), (107924536,518491,'2011-06-21'), (107924537,518491,'2011-06-21'), (107924538,518491,'2011-06-21'),
(107924542,1601319,'2011-06-21'), (107924543,1601319,'2011-06-21'), (107924544,1601319,'2011-06-21'),
(107924545,1601319,'2011-06-21'), (107924546,1601319,'2011-06-21'), (107924547,1601319,'2011-06-21'),
(107924548,1601319,'2011-06-21'), (107924549,1601319,'2011-06-21'), (107924550,1601319,'2011-06-21');

SELECT member_id_to, COUNT(*) FROM t1 
    WHERE r_date =   '2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT;

MariaDB [test]> SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =   '2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1;
+--------------+----------+
| member_id_to | COUNT(*) |
+--------------+----------+
|         NULL |        2 |
+--------------+----------+

(see also bug #12713907 reported for mysql-5.1)]]>  </description>
  <activities>
    <activity datechanged="2012-05-03T04:03:32.564835+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Igor Babaev</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2012-05-03T04:03:42.877247+00:00">
      <oldvalue>
<![CDATA[New]]>      </oldvalue>
      <newvalue>
<![CDATA[Confirmed]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2012-05-03T04:03:48.691766+00:00">
      <oldvalue>
<![CDATA[Undecided]]>      </oldvalue>
      <newvalue>
<![CDATA[High]]>      </newvalue>
      <whatchanged>maria: importance</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2012-05-03T04:04:07.495577+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[Vladislav Vaintroub (wlad-montyprogram)]]>      </newvalue>
      <whatchanged>maria: assignee</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2012-05-03T04:04:13.431102+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[5.2]]>      </newvalue>
      <whatchanged>maria: milestone</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2012-05-10T23:03:42.311345+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[wrong-result]]>      </newvalue>
      <whatchanged>tags</whatchanged>
      <person>Elena Stepanova</person>
      <message></message>
    </activity>
  </activities>
</launchpad-bug>
