Bug #46237 Slow query log is logging unions
Submitted: 16 Jul 2009 17:48 Modified: 17 Jul 2009 5:37
Reporter: Eric St-Georges Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.1.32 OS:Windows
Assigned to: CPU Architecture:Any

[16 Jul 2009 17:48] Eric St-Georges
Description:
Unions are written to the slow query log if log-queries-not-using-indexes is specified, even if both sides are using indexes.

Might be as designed, but I could not find any mention of this in the documentation.

How to repeat:
CREATE TABLE  `test`.`test` (
  `I` int(10) unsigned NOT NULL,
  PRIMARY KEY (`I`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `test`.`test` (I) VALUES (1), (2), (3), (4), (5), (6), (7) ,(8) ,(9) ,(10)

The following query will appear in the slow query log if log-queries-not-using-indexes is on :

SELECT * FROM `test`.`test` where i = 1
UNION
SELECT * FROM `test`.`test` where i = 2
[17 Jul 2009 5:37] Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

If I run explain on the UNION provided I get:

id      1
select_type     PRIMARY
...
id      NULL
select_type     UNION RESULT
table   <union1,2>
type    ALL
possible_keys   NULL
key     NULL
key_len NULL
ref     NULL
rows    NULL

So it really does not use indexes when creates result.