Skip to content

Commit

Permalink
MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to …
Browse files Browse the repository at this point in the history
…I_S and processlist

MDEV-32441 SENT_ROWS shows random wrong values when stored function
           is selected.
MDEV-32281 EXAMINED_ROWS is not populated in
           information_schema.processlist upon SELECT.

Added ROWS_SENT to information_schema.processlist
This is to have the same information as Percona server (SENT_ROWS)

To ensure that information_schema.processlist has correct values for
sent_rows and examined_rows I introduced two new variables to hold the
total counts so far. This was needed as stored functions and stored
procedures will reset the normal counters to be able to count rows for
each statement individually for slow query log.

Other things:
- Selects with functions shows in processlist the total examined_rows
  and sent_rows by the main statement and all functions.
- Stored procedures shows in processlist examined_rows and sent_rows
  per stored procedure statement.
- Fixed some double accounting for sent_rows and examined_rows.
- HANDLER operations now also supports send_rows and examined_rows.
- Display sizes for MEMORY_USED, MAX_MEMORY_USED, EXAMINED_ROWS and
  QUERY_ID in information_schema.processlist changed to 10 characters.
- EXAMINED_ROWS and SENT_ROWS changed to bigint.
- INSERT RETURNING and DELETE RETURNING now updates SENT_ROWS.
- As thd is always up to date with examined_rows, we do not need
  to handle examined row counting for unions or filesort.
- I renamed SORT_INFO::examined_rows to m_examined_rows to ensure that
  we don't get bugs in merges that tries to use examined_rows.
- Removed calls of type "thd->set_examined_row_count(0)" as they are
  not needed anymore.
- Removed JOIN::join_examined_rows
- Removed not used functions:
  THD::set_examined_row_count()
- Made inline some functions that where called for each row.
  • Loading branch information
montywi committed Nov 1, 2023
1 parent 3e50b4e commit f132fc0
Show file tree
Hide file tree
Showing 30 changed files with 689 additions and 342 deletions.
22 changes: 12 additions & 10 deletions mysql-test/main/create.result
Original file line number Diff line number Diff line change
Expand Up @@ -1083,12 +1083,13 @@ t1 CREATE TABLE `t1` (
`STAGE` tinyint(2) NOT NULL,
`MAX_STAGE` tinyint(2) NOT NULL,
`PROGRESS` decimal(7,3) NOT NULL,
`MEMORY_USED` bigint(7) NOT NULL,
`MAX_MEMORY_USED` bigint(7) NOT NULL,
`EXAMINED_ROWS` int(7) NOT NULL,
`QUERY_ID` bigint(4) NOT NULL,
`MEMORY_USED` bigint(10) NOT NULL,
`MAX_MEMORY_USED` bigint(10) NOT NULL,
`EXAMINED_ROWS` bigint(10) NOT NULL,
`SENT_ROWS` bigint(10) NOT NULL,
`QUERY_ID` bigint(10) NOT NULL,
`INFO_BINARY` blob,
`TID` bigint(4) NOT NULL
`TID` bigint(10) NOT NULL
) DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
drop table t1;
create temporary table t1 like information_schema.processlist;
Expand All @@ -1107,12 +1108,13 @@ t1 CREATE TEMPORARY TABLE `t1` (
`STAGE` tinyint(2) NOT NULL,
`MAX_STAGE` tinyint(2) NOT NULL,
`PROGRESS` decimal(7,3) NOT NULL,
`MEMORY_USED` bigint(7) NOT NULL,
`MAX_MEMORY_USED` bigint(7) NOT NULL,
`EXAMINED_ROWS` int(7) NOT NULL,
`QUERY_ID` bigint(4) NOT NULL,
`MEMORY_USED` bigint(10) NOT NULL,
`MAX_MEMORY_USED` bigint(10) NOT NULL,
`EXAMINED_ROWS` bigint(10) NOT NULL,
`SENT_ROWS` bigint(10) NOT NULL,
`QUERY_ID` bigint(10) NOT NULL,
`INFO_BINARY` blob,
`TID` bigint(4) NOT NULL
`TID` bigint(10) NOT NULL
) DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
drop table t1;
create table t1 like information_schema.character_sets;
Expand Down
16 changes: 16 additions & 0 deletions mysql-test/main/delete_returning.result
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,19 @@ id
3
set sql_mode=@sql_mode_save;
DROP TABLE t1;
#
# MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to I_S and
# processlist
#
create table t1 (a int primary key, b int);
insert into t1 select seq,seq+1 from seq_1_to_10;
flush status;
delete from t1 where a between 1 and 3 returning a,b;
a b
1 2
2 3
3 4
show status like "Rows_sent";
Variable_name Value
Rows_sent 3
drop table t1;
13 changes: 13 additions & 0 deletions mysql-test/main/delete_returning.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--source include/have_sequence.inc
#
# Tests for DELETE FROM <table> ... RETURNING <expr>,...
#
Expand Down Expand Up @@ -170,3 +171,15 @@ DELETE FROM t1 WHERE id > 2 RETURNING *;
set sql_mode=@sql_mode_save;

DROP TABLE t1;

--echo #
--echo # MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to I_S and
--echo # processlist
--echo #

create table t1 (a int primary key, b int);
insert into t1 select seq,seq+1 from seq_1_to_10;
flush status;
delete from t1 where a between 1 and 3 returning a,b;
show status like "Rows_sent";
drop table t1;
20 changes: 20 additions & 0 deletions mysql-test/main/insert_returning.result
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,23 @@ INSERT t WITH cte AS (SELECT 1) SELECT * FROM cte RETURNING *;
a
1
DROP TABLE t;
#
# MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to I_S and
# processlist
#
create table t1 (a int primary key, b int);
flush status;
insert into t1 values (1,2),(2,4) returning a,b;
a b
1 2
2 4
insert into t1 select seq,seq from seq_10_to_13 returning a,b;
a b
10 10
11 11
12 12
13 13
show status like "Rows_sent";
Variable_name Value
Rows_sent 6
drop table t1;
14 changes: 14 additions & 0 deletions mysql-test/main/insert_returning.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--source include/have_sequence.inc

--echo # Test for INSERT...RETURNING

CREATE TABLE t1(id1 INT PRIMARY KEY AUTO_INCREMENT, val1 VARCHAR(1));
Expand Down Expand Up @@ -396,3 +398,15 @@ CREATE TABLE t (a INT);
INSERT t WITH cte AS (SELECT 1) SELECT * FROM cte RETURNING *;

DROP TABLE t;

--echo #
--echo # MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to I_S and
--echo # processlist
--echo #

create table t1 (a int primary key, b int);
flush status;
insert into t1 values (1,2),(2,4) returning a,b;
insert into t1 select seq,seq from seq_10_to_13 returning a,b;
show status like "Rows_sent";
drop table t1;
118 changes: 118 additions & 0 deletions mysql-test/main/status2.result
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,121 @@ variable_value < 1024*1024*1024
#
# End of 10.2 tests
#
#
# MDEV-32441 SENT_ROWS shows random wrong values when stored function
# is selected
#
create table t1 (a int) engine=aria;
insert into t1 values (1),(2),(3),(4),(5),(6),(7);
flush status;
create function if not exists f() returns int return
(
select sum(a) > 0 from t1
);
select f() from seq_1_to_10 where seq%5 = 0;
f()
1
1
show status like "rows_sent";
Variable_name Value
Rows_sent 2
# Test simple query
set debug_sync='RESET';
connect con1,localhost,root,,;
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go';
select f() from seq_1_to_10 where seq%5 = 0;
connection default;
set debug_sync='now WAIT_FOR parked';
# Result should be 2, 10+7*2=24
select sent_rows, examined_rows from information_schema.processlist where id=#;
sent_rows examined_rows
2 24
set debug_sync='now signal go';
connection con1;
f()
1
1
# Test union
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go';
select a from t1 where a not in (1,2,3,4) union select a from t1 where a not in (4,5,6,7);
connection default;
set debug_sync='now WAIT_FOR parked';
# Result should be 6, 7+7+6=20 (2 scans of 7 rows + 6 rows in union)
select sent_rows, examined_rows from information_schema.processlist where id=#;
sent_rows examined_rows
6 20
set debug_sync='now signal go';
connection con1;
a
5
6
7
1
2
3
# Test handler calls
handler t1 open;
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go';
handler t1 read NEXT LIMIT 2,4;
connection default;
set debug_sync='now WAIT_FOR parked';
# Result should be 2, 10+7*2=24
select sent_rows, examined_rows from information_schema.processlist where id=#;
sent_rows examined_rows
4 6
set debug_sync='now signal go';
connection con1;
a
3
4
5
6
handler t1 close;
connection default;
drop function f;
drop table t1;
# Test Stored procedures
create or replace table t (a int primary key);
insert into t select seq from seq_1_to_100;
create procedure pr()
begin
select * from t where a between 1 and 2 ;
select * from t where a between 4 and 6 ;
end $
connection con1;
flush status;
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go EXECUTE 2';
call pr();
connection default;
set debug_sync='now WAIT_FOR parked';
select examined_rows, sent_rows, info from information_schema.processlist where id=#;
examined_rows sent_rows info
2 2 select * from t where a between 1 and 2
set debug_sync='now signal go';
select examined_rows, sent_rows, info from information_schema.processlist where id=#;
examined_rows sent_rows info
3 3 select * from t where a between 4 and 6
set debug_sync='now signal go';
connection con1;
a
1
2
a
4
5
6
show status like '%rows%';
Variable_name Value
Not_flushed_delayed_rows 0
Rows_read 8
Rows_sent 5
Rows_tmp_read 0
Sort_rows 0
connection default;
drop table t;
drop procedure pr;
disconnect con1;
set debug_sync= RESET;
#
# End of 11.3 tests
#
112 changes: 112 additions & 0 deletions mysql-test/main/status2.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
--source include/not_embedded.inc
--source include/have_sequence.inc
--source include/have_debug_sync.inc
--source include/have_sequence.inc

--echo #
--echo # Bug#24289 Status Variable "Questions" gets wrong values with Stored Routines
Expand Down Expand Up @@ -77,3 +80,112 @@ select variable_value < 1024*1024*1024 from information_schema.global_status whe
--echo # End of 10.2 tests
--echo #

--echo #
--echo # MDEV-32441 SENT_ROWS shows random wrong values when stored function
--echo # is selected
--echo #

create table t1 (a int) engine=aria;
insert into t1 values (1),(2),(3),(4),(5),(6),(7);
flush status;
create function if not exists f() returns int return
(
select sum(a) > 0 from t1
);

--disable_ps_protocol
select f() from seq_1_to_10 where seq%5 = 0;
show status like "rows_sent";
--enable_ps_protocol

--echo # Test simple query

set debug_sync='RESET';
--connect(con1,localhost,root,,)
--let $conid= `select connection_id()`
--let $replace_conid=id=$conid
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go';
--send select f() from seq_1_to_10 where seq%5 = 0

--connection default
set debug_sync='now WAIT_FOR parked';
--echo # Result should be 2, 10+7*2=24
--replace_result $replace_conid id=#
eval select sent_rows, examined_rows from information_schema.processlist where id=$conid;
set debug_sync='now signal go';
--connection con1
--reap

--echo # Test union

set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go';
--send select a from t1 where a not in (1,2,3,4) union select a from t1 where a not in (4,5,6,7)
--connection default
set debug_sync='now WAIT_FOR parked';
--echo # Result should be 6, 7+7+6=20 (2 scans of 7 rows + 6 rows in union)
--replace_result $replace_conid id=#
eval select sent_rows, examined_rows from information_schema.processlist where id=$conid;
set debug_sync='now signal go';
--connection con1
--reap

--echo # Test handler calls
handler t1 open;
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go';
--send handler t1 read NEXT LIMIT 2,4
--connection default
set debug_sync='now WAIT_FOR parked';
--echo # Result should be 2, 10+7*2=24
--replace_result $replace_conid id=#
eval select sent_rows, examined_rows from information_schema.processlist where id=$conid;
set debug_sync='now signal go';
--connection con1
--reap
handler t1 close;

--connection default
drop function f;
drop table t1;

--echo # Test Stored procedures

create or replace table t (a int primary key);
insert into t select seq from seq_1_to_100;
--delimiter $
create procedure pr()
begin
select * from t where a between 1 and 2 ;
select * from t where a between 4 and 6 ;
end $
--delimiter ;

--connection con1
flush status;
set debug_sync='end_of_statement SIGNAL parked WAIT_FOR go EXECUTE 2';

--send call pr()

--connection default
set debug_sync='now WAIT_FOR parked';
--replace_result $replace_conid id=#
eval select examined_rows, sent_rows, info from information_schema.processlist where id=$conid;
set debug_sync='now signal go';
--replace_result $replace_conid id=#
eval select examined_rows, sent_rows, info from information_schema.processlist where id=$conid;
set debug_sync='now signal go';

--connection con1
--reap
show status like '%rows%';

connection default;
# Cleanup
drop table t;
drop procedure pr;

--disconnect con1
set debug_sync= RESET;

--echo #
--echo # End of 11.3 tests
--echo #

0 comments on commit f132fc0

Please sign in to comment.