Skip to content

Commit

Permalink
Adding Rows_examined and Rows_sent implementation from 5.6
Browse files Browse the repository at this point in the history
Summary:
These two fields were added to 5.6 but missing in 8.0.  I noticed
previous implementation was buggy so added a new implementation which is
capturing more rows_examine operations.
There were also no MTR tests so I added new tests to cover these fields.

Differential Revision: D15999862
  • Loading branch information
bertanari authored and inikep committed Jul 2, 2024
1 parent f006c54 commit af816d8
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mysql-test/include/counter_rows.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Executes sql command and validates the values of Rows_examined and Rows_sent
# values from status table.
# The following variables should be set before invoking this inc file

# Start counters
--let $start_rows_examined = query_get_value(show status like "Rows_examined", Value, 1)
--let $start_rows_sent = query_get_value(show status like "Rows_sent", Value, 1)

--eval $sql

# Get counters
--let $end_rows_examined = query_get_value(show status like "Rows_examined", Value, 1)
--let $end_rows_sent = query_get_value(show status like "Rows_sent", Value, 1)

# Check sanity
--let $assert_text= Rows_examined should be increased by $expected_rows_examined.
--let $assert_cond= $end_rows_examined - $start_rows_examined = $expected_rows_examined
--source include/assert.inc

--let $assert_text= Rows_sent should be increased by $expected_rows_sent.
--let $assert_cond= $end_rows_sent - $start_rows_sent = $expected_rows_sent
--source include/assert.inc
45 changes: 45 additions & 0 deletions mysql-test/r/counter_rows.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
flush status;
Variation 0: Return constant value.
select 1;;
1
1
include/assert.inc [Rows_examined should be increased by 1.]
include/assert.inc [Rows_sent should be increased by 1.]
Variation 1: Create Table.
CREATE TABLE t1 (a INT) ENGINE=InnoDB;;
include/assert.inc [Rows_examined should be increased by 0.]
include/assert.inc [Rows_sent should be increased by 0.]
Variation 2: Insert one row into Table.
INSERT INTO t1 VALUES (1);;
include/assert.inc [Rows_examined should be increased by 0.]
include/assert.inc [Rows_sent should be increased by 0.]
Variation 3: Select one row from Table.
SELECT * FROM t1;;
a
1
include/assert.inc [Rows_examined should be increased by 1.]
include/assert.inc [Rows_sent should be increased by 1.]
Variation 4: Update one row.
UPDATE t1 SET a = 1;;
include/assert.inc [Rows_examined should be increased by 1.]
include/assert.inc [Rows_sent should be increased by 0.]
Variation 5: SELECT with JOIN
SELECT * FROM t1 AS a1 JOIN t1 AS a2 ON a1.a = a2.a;;
a a
1 1
include/assert.inc [Rows_examined should be increased by 2.]
include/assert.inc [Rows_sent should be increased by 1.]
Variation 6: UNION
SELECT * FROM t1 AS a1 LEFT JOIN t1 AS a2 ON a1.a = a2.a UNION SELECT * FROM t1 AS a1 RIGHT JOIN t1 AS a2 ON a1.a = a2.a;;
a a
1 1
include/assert.inc [Rows_examined should be increased by 5.]
include/assert.inc [Rows_sent should be increased by 1.]
Variation 7: DELETE rows from Table.
DELETE FROM t1;;
include/assert.inc [Rows_examined should be increased by 1.]
include/assert.inc [Rows_sent should be increased by 0.]
Variation 8: Drop Table.
DROP TABLE t1;;
include/assert.inc [Rows_examined should be increased by 0.]
include/assert.inc [Rows_sent should be increased by 0.]
90 changes: 90 additions & 0 deletions mysql-test/t/counter_rows.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#Set all to zero
flush status;

#
--echo Variation 0: Return constant value.
#

--let $sql = select 1;
--let $expected_rows_examined = 1
--let $expected_rows_sent = 1
--source include/counter_rows.inc


#
--echo Variation 1: Create Table.
#

--let $sql = CREATE TABLE t1 (a INT) ENGINE=InnoDB;
--let $expected_rows_examined = 0
--let $expected_rows_sent = 0
--source include/counter_rows.inc


#
--echo Variation 2: Insert one row into Table.
#

--let $sql = INSERT INTO t1 VALUES (1);
--let $expected_rows_examined = 0
--let $expected_rows_sent = 0
--source include/counter_rows.inc


#
--echo Variation 3: Select one row from Table.
#

--let $sql = SELECT * FROM t1;
--let $expected_rows_examined = 1
--let $expected_rows_sent = 1
--source include/counter_rows.inc


#
--echo Variation 4: Update one row.
#

--let $sql = UPDATE t1 SET a = 1;
--let $expected_rows_examined = 1
--let $expected_rows_sent = 0
--source include/counter_rows.inc


#
--echo Variation 5: SELECT with JOIN
#

--let $sql = SELECT * FROM t1 AS a1 JOIN t1 AS a2 ON a1.a = a2.a;
--let $expected_rows_examined = 2
--let $expected_rows_sent = 1
--source include/counter_rows.inc

#
--echo Variation 6: UNION
#

--let $sql = SELECT * FROM t1 AS a1 LEFT JOIN t1 AS a2 ON a1.a = a2.a UNION SELECT * FROM t1 AS a1 RIGHT JOIN t1 AS a2 ON a1.a = a2.a;
--let $expected_rows_examined = 5
--let $expected_rows_sent = 1
--source include/counter_rows.inc


#
--echo Variation 7: DELETE rows from Table.
#

--let $sql = DELETE FROM t1;
--let $expected_rows_examined = 1
--let $expected_rows_sent = 0
--source include/counter_rows.inc


#
--echo Variation 8: Drop Table.
#

--let $sql = DROP TABLE t1;
--let $expected_rows_examined = 0
--let $expected_rows_sent = 0
--source include/counter_rows.inc
4 changes: 4 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12010,6 +12010,10 @@ SHOW_VAR status_vars[] = {
SHOW_SCOPE_GLOBAL},
{"Relay_log_sql_wait_seconds", (char *)&relay_sql_wait_time, SHOW_TIMER,
SHOW_SCOPE_GLOBAL},
{"Rows_examined", (char *)offsetof(System_status_var, rows_examined),
SHOW_LONGLONG_STATUS, SHOW_SCOPE_GLOBAL},
{"Rows_sent", (char *)offsetof(System_status_var, rows_sent),
SHOW_LONGLONG_STATUS, SHOW_SCOPE_GLOBAL},
{"Secondary_engine_execution_count",
(char *)offsetof(System_status_var, secondary_engine_execution_count),
SHOW_LONGLONG_STATUS, SHOW_SCOPE_ALL},
Expand Down
2 changes: 2 additions & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2496,11 +2496,13 @@ void THD::set_sent_row_count(ha_rows count) {

void THD::inc_sent_row_count(ha_rows count) {
m_sent_row_count += count;
status_var.rows_sent += count;
MYSQL_SET_STATEMENT_ROWS_SENT(m_statement_psi, m_sent_row_count);
}

void THD::inc_examined_row_count(ha_rows count) {
m_examined_row_count += count;
status_var.rows_examined += count;
MYSQL_SET_STATEMENT_ROWS_EXAMINED(m_statement_psi, m_examined_row_count);
}

Expand Down
2 changes: 2 additions & 0 deletions sql/system_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ struct System_status_var {
ulonglong com_stmt_fetch;
ulonglong com_stmt_reset;
ulonglong com_stmt_close;
ulonglong rows_examined;
ulonglong rows_sent;

ulonglong bytes_received;
ulonglong bytes_sent;
Expand Down

0 comments on commit af816d8

Please sign in to comment.