Browse Source

MDEV-37195:

For all degenerate select queries having sub-queries in them,
the field rows_examined in the slow query log is always being set to 0.

The problem is that, although sub-queries increment the rows_examined field
of the thd object correctly, the degenerate outer select query is resetting
the rows_examined to zero after it has finished execution, by
invoking thd->set_examined_row_count(0).

The solution is to remove the thd->set_examined_row_count(0) in the
degenerate select queries.
10.11-MDEV-37195-fix
bsrikanth-mariadb 4 months ago
parent
commit
0790427a88
  1. 51
      mysql-test/main/log_state.result
  2. 51
      mysql-test/main/log_state.test
  3. 1
      sql/sql_select.cc

51
mysql-test/main/log_state.result

@ -392,6 +392,57 @@ disconnect con2;
connection default;
DROP TABLE t1;
TRUNCATE TABLE mysql.slow_log;
#
# MDEV-37195 Rows_examined is always 0 in the slow query log
# for queries with a subquery and degenerate select
#
SET GLOBAL log_output = "TABLE";
SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 0.0;
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (id INT);
INSERT INTO t1(id) SELECT seq FROM seq_1_to_10;
connect con2,localhost,root,,;
SELECT 100 in (SELECT id FROM t1) AS res;
res
0
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
rows_examined sql_text
10 SELECT 100 in (SELECT id FROM t1) AS res
TRUNCATE TABLE mysql.slow_log;
SELECT 100 in (
SELECT id FROM t1
UNION
SELECT id FROM t1
) AS res;
res
0
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
rows_examined sql_text
20 SELECT 100 in (
SELECT id FROM t1
UNION
SELECT id FROM t1
) AS res
TRUNCATE TABLE mysql.slow_log;
SELECT 100 in (
SELECT id FROM t1
UNION ALL
SELECT id FROM t1
) AS res;
res
0
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
rows_examined sql_text
20 SELECT 100 in (
SELECT id FROM t1
UNION ALL
SELECT id FROM t1
) AS res
disconnect con2;
connection default;
DROP TABLE t1;
TRUNCATE TABLE mysql.slow_log;
End of 10.11 tests
SET GLOBAL long_query_time = @save_long_query_time;
SET GLOBAL log_output = @old_log_output;

51
mysql-test/main/log_state.test

@ -441,6 +441,57 @@ DROP TABLE t1;
TRUNCATE TABLE mysql.slow_log;
###########################################################################
--echo #
--echo # MDEV-37195 Rows_examined is always 0 in the slow query log
--echo # for queries with a subquery and degenerate select
--echo #
SET GLOBAL log_output = "TABLE";
SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 0.0;
# clear slow_log of any residual slow queries
TRUNCATE TABLE mysql.slow_log;
CREATE TABLE t1 (id INT);
INSERT INTO t1(id) SELECT seq FROM seq_1_to_10;
connect (con2,localhost,root,,);
--disable_ps_protocol
SELECT 100 in (SELECT id FROM t1) AS res;
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
TRUNCATE TABLE mysql.slow_log;
SELECT 100 in (
SELECT id FROM t1
UNION
SELECT id FROM t1
) AS res;
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
TRUNCATE TABLE mysql.slow_log;
SELECT 100 in (
SELECT id FROM t1
UNION ALL
SELECT id FROM t1
) AS res;
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
disconnect con2;
connection default;
DROP TABLE t1;
TRUNCATE TABLE mysql.slow_log;
--echo End of 10.11 tests
###########################################################################

1
sql/sql_select.cc

@ -4865,7 +4865,6 @@ void JOIN::exec_inner()
}
/* Single select (without union) always returns 0 or 1 row */
thd->limit_found_rows= send_records;
thd->set_examined_row_count(0);
DBUG_VOID_RETURN;
}

Loading…
Cancel
Save