MDEV-31742 incorrect examined rows in case of stored function usage

The counter is global so we do not need add backup to it
if we do not zero it after taking the backup.
This commit is contained in:
Oleksandr Byelkin 2023-07-19 16:14:39 +02:00
parent 2bf291ba59
commit 89a493d64c
5 changed files with 128 additions and 13 deletions

View file

@ -133,3 +133,54 @@ drop table t;
#
# End of 10.3 tests
#
#
# MDEV-31742: incorrect examined rows in case of stored function usage
#
CREATE TABLE `tab_MDEV_30820` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`NAME_F` varchar(50) DEFAULT NULL,
PRIMARY KEY (`ID`)
);
CREATE TABLE `tab2` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`TAB1_ID` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE FUNCTION `get_zero`() RETURNS int(11)
BEGIN
RETURN(0) ;
END
//
for i in 1..100 do insert into tab_MDEV_30820 values (i,'qwerty'); end for ; //
for i in 1..1000 do insert into tab2 values (i,i+300); end for ; //
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 slow_query_log=ON;
SET SESSION long_query_time= 0;
SELECT 0 as zero, (SELECT ID FROM tab2 where tab2.TAB1_ID =
tab_MDEV_30820.ID ORDER BY 1 LIMIT 1 ) AS F1 FROM tab_MDEV_30820 ORDER BY 2 DESC LIMIT 2;
zero F1
0 NULL
0 NULL
SELECT get_zero() as zero, (SELECT ID FROM tab2 where tab2.TAB1_ID =
tab_MDEV_30820.ID ORDER BY 1 LIMIT 1) AS F1 FROM tab_MDEV_30820 ORDER BY 2 DESC LIMIT 2;
zero F1
0 NULL
0 NULL
# should be the same rows_examined
SELECT rows_examined FROM mysql.slow_log WHERE sql_text LIKE '%SELECT%tab_MDEV_30820%';
rows_examined
100202
100202
SET @@long_query_time= @old_long_query_time;
SET @@global.log_output= @old_log_output;
SET @@global.slow_query_log= @old_slow_query_log;
SET SESSION slow_query_log=default;
drop table tab_MDEV_30820, tab2;
drop function get_zero;
#
# End of 10.4 tests
#

View file

@ -121,3 +121,68 @@ drop table t;
--echo #
--echo # End of 10.3 tests
--echo #
--echo #
--echo # MDEV-31742: incorrect examined rows in case of stored function usage
--echo #
CREATE TABLE `tab_MDEV_30820` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`NAME_F` varchar(50) DEFAULT NULL,
PRIMARY KEY (`ID`)
);
CREATE TABLE `tab2` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`TAB1_ID` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
--disable_ps2_protocol
--delimiter //
CREATE FUNCTION `get_zero`() RETURNS int(11)
BEGIN
RETURN(0) ;
END
//
for i in 1..100 do insert into tab_MDEV_30820 values (i,'qwerty'); end for ; //
for i in 1..1000 do insert into tab2 values (i,i+300); end for ; //
--delimiter ;
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 slow_query_log=ON;
SET SESSION long_query_time= 0;
SELECT 0 as zero, (SELECT ID FROM tab2 where tab2.TAB1_ID =
tab_MDEV_30820.ID ORDER BY 1 LIMIT 1 ) AS F1 FROM tab_MDEV_30820 ORDER BY 2 DESC LIMIT 2;
SELECT get_zero() as zero, (SELECT ID FROM tab2 where tab2.TAB1_ID =
tab_MDEV_30820.ID ORDER BY 1 LIMIT 1) AS F1 FROM tab_MDEV_30820 ORDER BY 2 DESC LIMIT 2;
--echo # should be the same rows_examined
SELECT rows_examined FROM mysql.slow_log WHERE sql_text LIKE '%SELECT%tab_MDEV_30820%';
## 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;
SET SESSION slow_query_log=default;
drop table tab_MDEV_30820, tab2;
drop function get_zero;
--enable_ps2_protocol
--echo #
--echo # End of 10.4 tests
--echo #

View file

@ -287,15 +287,15 @@ ON UPDATE CURRENT_TIMESTAMP,
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,
`rows_sent` int(11) NOT NULL,
`rows_examined` int(11) NOT NULL,
`rows_sent` bigint(20) unsigned NOT NULL,
`rows_examined` bigint(20) unsigned NOT NULL,
`db` varchar(512) NOT NULL,
`last_insert_id` int(11) NOT NULL,
`insert_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL,
`thread_id` BIGINT(21) UNSIGNED NOT NULL,
`rows_affected` int(11) NOT NULL
`rows_affected` bigint(20) unsigned NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log';
set global general_log='ON';
set global slow_query_log='ON';
@ -580,15 +580,15 @@ CREATE TABLE `db_17876.slow_log_data` (
`user_host` mediumtext ,
`query_time` time(6) ,
`lock_time` time(6) ,
`rows_sent` int(11) ,
`rows_examined` int(11) ,
`rows_sent` bigint(20) unsigned,
`rows_examined` bigint(20) unsigned,
`db` varchar(512) default NULL,
`last_insert_id` int(11) default NULL,
`insert_id` int(11) default NULL,
`server_id` int(11) default NULL,
`sql_text` mediumtext,
`thread_id` bigint(21) unsigned default NULL,
`rows_affected` int(11) default NULL
`rows_affected` bigint(20) unsigned default NULL
);
CREATE TABLE `db_17876.general_log_data` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

View file

@ -307,15 +307,15 @@ CREATE TABLE `slow_log` (
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,
`rows_sent` int(11) NOT NULL,
`rows_examined` int(11) NOT NULL,
`rows_sent` bigint(20) unsigned NOT NULL,
`rows_examined` bigint(20) unsigned NOT NULL,
`db` varchar(512) NOT NULL,
`last_insert_id` int(11) NOT NULL,
`insert_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL,
`thread_id` BIGINT(21) UNSIGNED NOT NULL,
`rows_affected` int(11) NOT NULL
`rows_affected` bigint(20) unsigned NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log';
set global general_log='ON';
@ -743,15 +743,15 @@ CREATE TABLE `db_17876.slow_log_data` (
`user_host` mediumtext ,
`query_time` time(6) ,
`lock_time` time(6) ,
`rows_sent` int(11) ,
`rows_examined` int(11) ,
`rows_sent` bigint(20) unsigned,
`rows_examined` bigint(20) unsigned,
`db` varchar(512) default NULL,
`last_insert_id` int(11) default NULL,
`insert_id` int(11) default NULL,
`server_id` int(11) default NULL,
`sql_text` mediumtext,
`thread_id` bigint(21) unsigned default NULL,
`rows_affected` int(11) default NULL
`rows_affected` bigint(20) unsigned default NULL
);
CREATE TABLE `db_17876.general_log_data` (

View file

@ -5603,7 +5603,6 @@ void THD::restore_sub_statement_state(Sub_statement_state *backup)
The following is added to the old values as we are interested in the
total complexity of the query
*/
inc_examined_row_count(backup->examined_row_count);
cuted_fields+= backup->cuted_fields;
DBUG_VOID_RETURN;
}