mysql:1498
From: 奥田 典子 <奥田 典子 <okud_no@xxxxxxxxxx>>
Date: Mon, 17 Jan 2000 18:39:11 +0900
Subject: [mysql 01498] 3.22.26a で order by が効かない
奥田と申します。
先日、MySQLのバージョンを3.21.30→3.22.26aにアップしたところ、
以前は正常に動作していたクエリーで、order by の指定が
正しく働かなくなるケースがみつかりました。
テーブル定義、サンプルデータ、クエリーは以下のとおりです。
create table s (
s00 char( 6) NOT NULL,
s01 char( 4) NOT NULL,
index (s00),
index (s01)
);
create table h (
h00 char( 6) NOT NULL,
h01 char( 18) NOT NULL,
h02 char( 8) NOT NULL,
unique (h00),
index (h01),
index (h02)
);
create table z (
z00 char( 8) NOT NULL,
z01 char( 6) NOT NULL,
unique (z00),
index (z01)
);
mysql> select * from s;
+--------+------+
| s00 | s01 |
+--------+------+
| 839889 | JKSB |
| 820240 | JKSB |
| 820240 | JKSQ |
| 839890 | JKSB |
| 847653 | JKSC |
| 839927 | JKSC |
+--------+------+
6 rows in set (0.01 sec)
mysql> select * from h;
+--------+----------+----------+
| h00 | h01 | h02 |
+--------+----------+----------+
| 839889 | kamiya | 00968801 |
| 820240 | hori | 00803603 |
| 839890 | yamada | 00975701 |
| 847653 | take | 00977003 |
| 839927 | hayakawa | 00975702 |
+--------+----------+----------+
5 rows in set (0.01 sec)
mysql> select * from z;
+----------+--------+
| z00 | z01 |
+----------+--------+
| 00803603 | 502030 |
| 00968801 | 051010 |
| 00975701 | 552010 |
| 00975702 | 552020 |
| 00977003 | 551020 |
+----------+--------+
5 rows in set (0.01 sec)
mysql> SELECT s00,s01,h01,h02,z01
-> from s left join h on s.s00 = h.h00
-> left join z on h.h02 = z.z00
-> order by z01, s00
-> ;
◆2 ◆1
+--------+------+----------+----------+--------+
| s00 | s01 | h01 | h02 | z01 |
+--------+------+----------+----------+--------+
| 820240 | JKSB | hori | 00803603 | 502030 |
| 820240 | JKSQ | hori | 00803603 | 502030 |
| 839889 | JKSB | kamiya | 00968801 | 051010 |
| 839890 | JKSB | yamada | 00975701 | 552010 |
| 839927 | JKSC | hayakawa | 00975702 | 552020 |
| 847653 | JKSC | take | 00977003 | 551020 |
+--------+------+----------+----------+--------+
6 rows in set (0.02 sec)
◆1,◆2の順になっていない。
ちなみに、order by の2番目をs00からs01に変えてみると、
正しくソートされます。
mysql> SELECT s00,s01,h01,h02,z01
-> from s left join h on s.s00 = h.h00
-> left join z on h.h02 = z.z00
-> order by z01, s01
-> ;
◆2 ◆1
+--------+------+----------+----------+--------+
| s00 | s01 | h01 | h02 | z01 |
+--------+------+----------+----------+--------+
| 839889 | JKSB | kamiya | 00968801 | 051010 |
| 820240 | JKSB | hori | 00803603 | 502030 |
| 820240 | JKSQ | hori | 00803603 | 502030 |
| 847653 | JKSC | take | 00977003 | 551020 |
| 839890 | JKSB | yamada | 00975701 | 552010 |
| 839927 | JKSC | hayakawa | 00975702 | 552020 |
+--------+------+----------+----------+--------+
6 rows in set (0.03 sec)
left joinの使い方が悪いとか、何か理由がありますでしょうか。
EXPLAINをかけると、以下のように表示されます。
mysql> EXPLAIN SELECT s00,s01,h01,h02,z01
-> from s left join h on s.s00 = h.h00
-> left join z on h.h02 = z.z00
-> order by z01, s00
-> ;
+-------+--------+---------------+------+---------+-------+------+-------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+-------+--------+---------------+------+---------+-------+------+-------+
| s | ALL | NULL | NULL | NULL | NULL | 6 | |
| h | eq_ref | h00 | h00 | 6 | s.s00 | 1 | |
| z | eq_ref | z00 | z00 | 8 | h.h02 | 1 | |
+-------+--------+---------------+------+---------+-------+------+-------+
3 rows in set (0.34 sec)
参考まで、load data infile 用のテキストを添付します。<sample.lzh>
どなたか、よろしくお願いします。
-----------------------------------------------------------------
奥田 典子 <okud_no@xxxxxxxxxx>
-> @ 1498 2000-01-17 18:39 [奥田 典子 <okud_no@] 3.22.26a で order by が効かない 1499 2000-01-17 19:09 ┗[<takeshi@xxxxxxxxxx>] 1500 2000-01-18 10:24 ┗[奥田 典子 <okud_no@]