Bug #32426 FEDERATED query returns corrupt results for ORDER BY on a TEXT field
Submitted: 16 Nov 2007 4:04 Modified: 18 Sep 2008 8:21
Reporter: Sean Pringle
Status: Need Doc Info
Category:Server: Federated Severity:S2 (Serious)
Version:5.0.50 OS:Any
Assigned to: Ramil Kalimullin Target Version:
Tags: federated, order by, text
Triage: D2 (Serious)

[16 Nov 2007 4:04] Sean Pringle
Description:
A simple SELECT * from a FEDERATED table gives corrupt results when you ORDER BY a TEXT
field.

How to repeat:
On the Server:

mysql> create table t1 (c1 text);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values ('abc'),('gh'),('f'),('ijk'),('de');
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select * from t1;
+------+
| c1   |
+------+
| abc  | 
| gh   | 
| f    | 
| ijk  | 
| de   | 
+------+
5 rows in set (0.00 sec)

mysql> select * from t1 order by c1;
+------+
| c1   |
+------+
| abc  | 
| de   | 
| f    | 
| gh   | 
| ijk  | 
+------+
5 rows in set (0.00 sec)

On the Client:

mysql> create table t1 (c1 text) engine=federated
connection='mysql://root@127.0.0.1:3307/test/t1';
Query OK, 0 rows affected (0.01 sec)

mysql> select * from t1;
+------+
| c1   |
+------+
| abc  | 
| gh   | 
| f    | 
| ijk  | 
| de   | 
+------+
5 rows in set (0.00 sec)

mysql> select * from t1 order by c1;
+------+
| c1   |
+------+
| dek  | 
| de   | 
| d    | 
| de   | 
| dek  | 
+------+
5 rows in set (0.00 sec)

On the Client again:

If you change the FEDERATED table definition to use CHAR instead of TEXT, everything is
fine.

mysql> create table t2 (c1 char(10)) engine=federated
connection='mysql://root@127.0.0.1:3307/test/t1';
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t2;
+------+
| c1   |
+------+
| abc  | 
| gh   | 
| f    | 
| ijk  | 
| de   | 
+------+
5 rows in set (0.00 sec)

mysql> select * from t2 order by c1;
+------+
| c1   |
+------+
| abc  | 
| de   | 
| f    | 
| gh   | 
| ijk  | 
+------+
5 rows in set (0.00 sec)

Suggested fix:
Seems to be broken Client side in the FEDERATED engine.  General Query Log on the Server
show only "SELECT * FROM t1" queries being issued; ie, ORDER BY happens locally.
[14 Dec 2007 7:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/39966

ChangeSet@1.2602, 2007-12-14 10:50:56+04:00, ramil@mysql.com +4 -0
  Fix for bug #32426: "FEDERATED query returns corrupt results for
  ORDER BY on a TEXT field"
  
  Problem: storing a reference to a row which is used in fielsort 
  we miss BLOB/TEXT data.
  
  Fix: store a reference as current result set address and data 
  cursor position.
[26 Mar 2008 11:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/44438

ChangeSet@1.2600, 2008-03-26 14:37:47+04:00, ramil@mysql.com +4 -0
  Fix for bug #32426: "FEDERATED query returns corrupt results for
  ORDER BY on a TEXT field"
  
  Problem: storing a reference to a row which is used in fielsort 
  we miss BLOB/TEXT data.
  
  Fix: store a reference as current result set address and data 
  cursor position.
[15 Aug 2008 14:18] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/51725

2767 Ramil Kalimullin	2008-08-15
        Fix for bug #32426: "FEDERATED query returns corrupt results for
        ORDER BY on a TEXT field"
        
        Problem: storing a reference to a row which is used in fielsort 
        we miss BLOB/TEXT data.
        
        Fix: store a reference as current result set address and data 
        cursor position.
[15 Aug 2008 14:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/51727

2768 Ramil Kalimullin	2008-08-15
        Fix for bug #33702: accessing a federated table with a non existing server 
        returns random error code
        
        Problem: accessing a federated table through a non existing server leads to
        wrong error number returned.
        
        Fix: return a proper error.
[13 Sep 2008 22:21] Bugs System
Pushed into 6.0.6-alpha  (revid:ramil@mysql.com-20080815121806-r07gbqrl29hezjjh) (version
source revid:sergefp@mysql.com-20080611231653-nmuqmw6dedjra79i) (pib:3)
[18 Sep 2008 8:21] Paul DuBois
Noted in 6.0.6 chanagelog.

Query results from a FEDERATED table were corrupt if the query
included an ORDER BY on a TEXT column.