Commit ee3c555a authored by mithun's avatar mithun

Bug #17059925: UNIONS COMPUTES ROWS_EXAMINED INCORRECTLY

ISSUE:
------
For UNION of selects, rows examined by the query will be sum
of rows examined by individual select operations and rows
examined for union operation. The value of session level
global counter that is used to count the rows examined by a
select statement should be accumulated and reset before it
is used for next select statement. But we have missed to
reset the same. Because of this examined row count of a
select query is accounted more than once.

SOLUTION:
---------
In union reset the session level global counter used to
accumulate count of examined rows after its value is saved.

mysql-test/r/union.result:
  Expected output of testcase added.
mysql-test/t/union.test:
  Test to verify examined row count of Union operations.
sql/sql_union.cc:
  Reset the value of thd->examined_row_count after
  accumulating the value.
parent 858e5626
......@@ -1826,3 +1826,37 @@ dev
SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
dev
1
#
# Bug #17059925 : UNIONS COMPUTES ROWS_EXAMINED INCORRECTLY
#
SET @old_slow_query_log= @@global.slow_query_log;
SET @old_log_output= @@global.log_output;
SET @old_long_query_time= @@long_query_time;
SET GLOBAL log_output= "TABLE";
SET GLOBAL slow_query_log= ON;
SET SESSION long_query_time= 0;
CREATE TABLE t17059925 (a INT);
CREATE TABLE t2 (b INT);
CREATE TABLE t3 (c INT);
INSERT INTO t17059925 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (4), (5), (6);
INSERT INTO t3 VALUES (7), (8), (9);
TRUNCATE table mysql.slow_log;
SELECT * FROM t17059925 UNION SELECT * FROM t2 UNION SELECT * FROM t3;
a
1
2
3
4
5
6
7
8
9
SELECT sql_text, rows_examined FROM mysql.slow_log WHERE sql_text LIKE '%SELECT%t17059925%';
sql_text rows_examined
SELECT * FROM t17059925 UNION SELECT * FROM t2 UNION SELECT * FROM t3 18
DROP TABLE t17059925, t2, t3;
SET @@long_query_time= @old_long_query_time;
SET @@global.log_output= @old_log_output;
SET @@global.slow_query_log= @old_slow_query_log;
......@@ -1225,3 +1225,34 @@ SELECT(SELECT 0 AS a FROM dual UNION SELECT 1 AS a FROM dual ORDER BY a DESC LIM
SELECT(SELECT 1 AS a ORDER BY a) AS dev;
SELECT(SELECT 1 AS a LIMIT 1) AS dev;
SELECT(SELECT 1 AS a FROM dual ORDER BY a DESC LIMIT 1) AS dev;
--echo #
--echo # Bug #17059925 : UNIONS COMPUTES ROWS_EXAMINED INCORRECTLY
--echo #
## Save current state of slow log variables
SET @old_slow_query_log= @@global.slow_query_log;
SET @old_log_output= @@global.log_output;
SET @old_long_query_time= @@long_query_time;
SET GLOBAL log_output= "TABLE";
SET GLOBAL slow_query_log= ON;
SET SESSION long_query_time= 0;
CREATE TABLE t17059925 (a INT);
CREATE TABLE t2 (b INT);
CREATE TABLE t3 (c INT);
INSERT INTO t17059925 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (4), (5), (6);
INSERT INTO t3 VALUES (7), (8), (9);
TRUNCATE table mysql.slow_log;
--sorted_result
SELECT * FROM t17059925 UNION SELECT * FROM t2 UNION SELECT * FROM t3;
SELECT sql_text, rows_examined FROM mysql.slow_log WHERE sql_text LIKE '%SELECT%t17059925%';
DROP TABLE t17059925, t2, t3;
## Reset to initial values
SET @@long_query_time= @old_long_query_time;
SET @@global.log_output= @old_log_output;
SET @@global.slow_query_log= @old_slow_query_log;
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -557,7 +557,13 @@ bool st_select_lex_unit::exec()
0);
if (!saved_error)
{
/*
Save the current examined row count locally and clear the global
counter, so that we can accumulate the number of evaluated rows for
the current query block.
*/
examined_rows+= thd->examined_row_count;
thd->examined_row_count= 0;
if (union_result->flush())
{
thd->lex->current_select= lex_select_save;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment