Skip to content

Commit 0b16d78

Browse files
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.
1 parent 16190d2 commit 0b16d78

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

mysql-test/main/log_state.result

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,57 @@ disconnect con2;
392392
connection default;
393393
DROP TABLE t1;
394394
TRUNCATE TABLE mysql.slow_log;
395+
#
396+
# MDEV-37195 Rows_examined is always 0 in the slow query log
397+
# for queries with a subquery and degenerate select
398+
#
399+
SET GLOBAL log_output = "TABLE";
400+
SET GLOBAL slow_query_log = ON;
401+
SET GLOBAL long_query_time = 0.0;
402+
TRUNCATE TABLE mysql.slow_log;
403+
CREATE TABLE t1 (id INT);
404+
INSERT INTO t1(id) SELECT seq FROM seq_1_to_10;
405+
connect con2,localhost,root,,;
406+
SELECT 100 in (SELECT id FROM t1) AS res;
407+
res
408+
0
409+
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
410+
rows_examined sql_text
411+
10 SELECT 100 in (SELECT id FROM t1) AS res
412+
TRUNCATE TABLE mysql.slow_log;
413+
SELECT 100 in (
414+
SELECT id FROM t1
415+
UNION
416+
SELECT id FROM t1
417+
) AS res;
418+
res
419+
0
420+
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
421+
rows_examined sql_text
422+
20 SELECT 100 in (
423+
SELECT id FROM t1
424+
UNION
425+
SELECT id FROM t1
426+
) AS res
427+
TRUNCATE TABLE mysql.slow_log;
428+
SELECT 100 in (
429+
SELECT id FROM t1
430+
UNION ALL
431+
SELECT id FROM t1
432+
) AS res;
433+
res
434+
0
435+
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
436+
rows_examined sql_text
437+
20 SELECT 100 in (
438+
SELECT id FROM t1
439+
UNION ALL
440+
SELECT id FROM t1
441+
) AS res
442+
disconnect con2;
443+
connection default;
444+
DROP TABLE t1;
445+
TRUNCATE TABLE mysql.slow_log;
395446
End of 10.11 tests
396447
SET GLOBAL long_query_time = @save_long_query_time;
397448
SET GLOBAL log_output = @old_log_output;

mysql-test/main/log_state.test

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,57 @@ DROP TABLE t1;
441441

442442
TRUNCATE TABLE mysql.slow_log;
443443

444+
###########################################################################
445+
446+
--echo #
447+
--echo # MDEV-37195 Rows_examined is always 0 in the slow query log
448+
--echo # for queries with a subquery and degenerate select
449+
--echo #
450+
451+
SET GLOBAL log_output = "TABLE";
452+
SET GLOBAL slow_query_log = ON;
453+
SET GLOBAL long_query_time = 0.0;
454+
455+
# clear slow_log of any residual slow queries
456+
TRUNCATE TABLE mysql.slow_log;
457+
458+
CREATE TABLE t1 (id INT);
459+
460+
INSERT INTO t1(id) SELECT seq FROM seq_1_to_10;
461+
462+
connect (con2,localhost,root,,);
463+
--disable_ps_protocol
464+
465+
SELECT 100 in (SELECT id FROM t1) AS res;
466+
467+
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
468+
469+
TRUNCATE TABLE mysql.slow_log;
470+
471+
SELECT 100 in (
472+
SELECT id FROM t1
473+
UNION
474+
SELECT id FROM t1
475+
) AS res;
476+
477+
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
478+
479+
TRUNCATE TABLE mysql.slow_log;
480+
481+
SELECT 100 in (
482+
SELECT id FROM t1
483+
UNION ALL
484+
SELECT id FROM t1
485+
) AS res;
486+
487+
SELECT rows_examined,sql_text FROM mysql.slow_log WHERE sql_text LIKE '%SELECT 100%';
488+
489+
disconnect con2;
490+
connection default;
491+
DROP TABLE t1;
492+
493+
TRUNCATE TABLE mysql.slow_log;
494+
444495
--echo End of 10.11 tests
445496
###########################################################################
446497

sql/sql_select.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4865,7 +4865,6 @@ void JOIN::exec_inner()
48654865
}
48664866
/* Single select (without union) always returns 0 or 1 row */
48674867
thd->limit_found_rows= send_records;
4868-
thd->set_examined_row_count(0);
48694868
DBUG_VOID_RETURN;
48704869
}
48714870

0 commit comments

Comments
 (0)