<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="1002508">
  <date_last_updated>2012-05-21 21:08:20.591135+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/1002508</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.5</milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/1002508/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/1002508/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/1002508</bug_web_link>
  <owner>Igor Babaev</owner>
  <assignee>Igor Babaev</assignee>
  <milestone_title>Maria 5.5</milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>The number of expected rows to be examined is off for a query with ORDER BY</title>
  <status>Confirmed</status>
  <importance>Medium</importance>
  <created>2012-05-21 20:56:52.985267+00:00</created>
  <description>
<![CDATA[If to create  and populate tables t1,t2 with the commands  

CREATE TABLE t1(a int PRIMARY KEY, b int) ENGINE=myisam;
INSERT INTO t1 VALUES
  (5, 10), (2, 70), (7, 80), (6, 20), (1, 50), (9, 40), (8, 30), (3, 60);
CREATE TABLE t2 (p int, a int, INDEX i_a(a)) ENGINE=myisam;
INSERT INTO t2 VALUES
  (103, 7), (109, 3), (102, 3), (108, 1), (106, 3),
  (107, 7), (105, 1), (101, 3), (100, 7), (110, 1);

then Mariadb 5.5 will return the following  explain output for the query
SELECT t1.a FROM t1 LEFT JOIN t2 ON t1.a=t2.a ORDER BY t1.a

MariaDB [test]> EXPLAIN
    -> SELECT t1.a FROM t1 LEFT JOIN t2 ON t1.a=t2.a ORDER BY t1.a;
+------+-------------+-------+-------+---------------+---------+---------+-----------+------+-------------+
| id   | select_type | table | type  | possible_keys | key     | key_len | ref       | rows | Extra       |
+------+-------------+-------+-------+---------------+---------+---------+-----------+------+-------------+
|    1 | SIMPLE      | t1    | index | NULL          | PRIMARY | 4       | NULL      |    4 | Using index |
|    1 | SIMPLE      | t2    | ref   | i_a           | i_a     | 5       | test.t1.a |    2 | Using index |
+------+-------------+-------+-------+---------------+---------+---------+-----------+------+-------------+

The expected number of the examined rows from t1 is 4 though it should be 8 as for the following query:

MariaDB [test]> EXPLAIN
    -> SELECT t1.a FROM t1 LEFT JOIN t2 ON t1.a=t2.a ORDER BY t1.a;
+------+-------------+-------+-------+---------------+---------+---------+-----------+------+-------------+
| id   | select_type | table | type  | possible_keys | key     | key_len | ref       | rows | Extra       |
+------+-------------+-------+-------+---------------+---------+---------+-----------+------+-------------+
|    1 | SIMPLE      | t1    | index | NULL          | PRIMARY | 4       | NULL      |    4 | Using index |
|    1 | SIMPLE      | t2    | ref   | i_a           | i_a     | 5       | test.t1.a |    2 | Using index |
+------+-------------+-------+-------+---------------+---------+---------+-----------+------+-------------+]]>  </description>
  <activities>
    <activity datechanged="2012-05-21T20:56:52.985267+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Igor Babaev</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2012-05-21T20:57:02.988943+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-21T20:57:10.665360+00:00">
      <oldvalue>
<![CDATA[Undecided]]>      </oldvalue>
      <newvalue>
<![CDATA[Medium]]>      </newvalue>
      <whatchanged>maria: importance</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2012-05-21T20:57:19.758033+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[Igor Babaev (igorb-seattle)]]>      </newvalue>
      <whatchanged>maria: assignee</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2012-05-21T20:57:25.030776+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[5.5]]>      </newvalue>
      <whatchanged>maria: milestone</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
  </activities>
  <comments>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/1002508/comments/1" datecreated="2012-05-21T21:08:20.194166+00:00">
      <person>Igor Babaev</person>
      <subject>
<![CDATA[Re: The number of expected rows to be examined is off for a query with ORDER BY]]>      </subject>
      <content>
<![CDATA[See also bug #13528826 from mysql-trunk.]]>      </content>
    </comment>
  </comments>
</launchpad-bug>
