mysql [localhost:8035] {msandbox} (test) > tee /tmp/bug113587-test2-2-condition-2.txt Logging to file '/tmp/bug113587-test2-2-condition-2.txt' mysql [localhost:8035] {msandbox} (test) > TRUNCATE TABLE a2; INSERT INTO a2(order_revision_id) SELECT NULL FROM t2 LIMIT 606397; -- OK Query OK, 0 rows affected (0.13 sec) Query OK, 606397 rows affected (2.12 sec) Records: 606397 Duplicates: 0 Warnings: 0 mysql [localhost:8035] {msandbox} (test) > EXPLAIN SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ | 1 | SIMPLE | t1 | NULL | index | PRIMARY,order_revision_id | PRIMARY | 4 | NULL | 290999 | 100.00 | Using where; Backward index scan; Using temporary | | 1 | SIMPLE | t2 | NULL | eq_ref | PRIMARY | PRIMARY | 4 | test.t1.order_revision_id | 1 | 100.00 | Using index; Distinct | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec) mysql [localhost:8035] {msandbox} (test) > SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | 555000003 | | 555000002 | | 555000001 | | 555000000 | +-----------+ 181894 rows in set (1.18 sec) mysql [localhost:8035] {msandbox} (test) > INSERT INTO a2(order_revision_id) SELECT NULL FROM t2 LIMIT 1; Query OK, 1 row affected (0.01 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql [localhost:8035] {msandbox} (test) > EXPLAIN SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ | 1 | SIMPLE | t1 | NULL | index | PRIMARY,order_revision_id | PRIMARY | 4 | NULL | 290999 | 100.00 | Using where; Backward index scan; Using temporary | | 1 | SIMPLE | t2 | NULL | eq_ref | PRIMARY | PRIMARY | 4 | test.t1.order_revision_id | 1 | 100.00 | Using index; Distinct | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec) mysql [localhost:8035] {msandbox} (test) > SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | 555000003 | | 555000002 | | 555000001 | | 555000000 | +-----------+ 181894 rows in set (0.84 sec) mysql [localhost:8035] {msandbox} (test) > DELETE FROM a2 LIMIT 1; Query OK, 1 row affected (0.02 sec) mysql [localhost:8035] {msandbox} (test) > EXPLAIN SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ | 1 | SIMPLE | t1 | NULL | index | PRIMARY,order_revision_id | PRIMARY | 4 | NULL | 290999 | 100.00 | Using where; Backward index scan; Using temporary | | 1 | SIMPLE | t2 | NULL | eq_ref | PRIMARY | PRIMARY | 4 | test.t1.order_revision_id | 1 | 100.00 | Using index; Distinct | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec) mysql [localhost:8035] {msandbox} (test) > SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | 555000003 | | 555000002 | | 555000001 | | 555000000 | +-----------+ 181894 rows in set (0.86 sec) mysql [localhost:8035] {msandbox} (test) > TRUNCATE TABLE a2; INSERT INTO a2(order_revision_id) SELECT NULL FROM t2 LIMIT 606498; -- Bug113587 Query OK, 0 rows affected (0.90 sec) Query OK, 606498 rows affected (1.96 sec) Records: 606498 Duplicates: 0 Warnings: 0 mysql [localhost:8035] {msandbox} (test) > EXPLAIN SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ | 1 | SIMPLE | t1 | NULL | index | PRIMARY,order_revision_id | PRIMARY | 4 | NULL | 290999 | 100.00 | Using where; Backward index scan; Using temporary | | 1 | SIMPLE | t2 | NULL | eq_ref | PRIMARY | PRIMARY | 4 | test.t1.order_revision_id | 1 | 100.00 | Using index; Distinct | +----+-------------+-------+------------+--------+---------------------------+---------+---------+---------------------------+--------+----------+---------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec) mysql [localhost:8035] {msandbox} (test) > SELECT DISTINCT t1.order_id FROM t1 INNER JOIN a2 t2 USING (order_revision_id) ORDER BY t1.order_id DESC; | 555184513 | | 555184520 | | 555184521 | | 555184525 | +-----------+ 181977 rows in set (0.69 sec) mysql [localhost:8035] {msandbox} (test) > notee Outfile disabled.