1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-23 08:45:18 +03:00
Files
mariadb/mysql-test/main/delete_returning.test
Monty f132fc0049 MDEV-3953 Add columns for ROWS_EXAMINED, ROWS_SENT, and ROWS_READ to 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.
2023-11-01 13:02:19 +02:00

186 lines
4.1 KiB
Plaintext

--source include/have_sequence.inc
#
# Tests for DELETE FROM <table> ... RETURNING <expr>,...
#
--disable_warnings
drop table if exists t1,t2;
drop view if exists v1;
drop procedure if exists p1;
--enable_warnings
CREATE TABLE t1 (a int, b varchar(32));
INSERT INTO t1 VALUES
(7,'ggggggg'), (1,'a'), (3,'ccc'),
(4,'dddd'), (1,'A'), (2,'BB'), (4,'DDDD'),
(5,'EEEEE'), (7,'GGGGGGG'), (2,'bb');
CREATE TABLE t1c SELECT * FROM t1;
CREATE TABLE t2 (c int);
INSERT INTO t2 VALUES
(4), (5), (7), (1);
CREATE TABLE t2c SELECT * FROM t2;
CREATE VIEW v1 AS SELECT a, UPPER(b) FROM t1;
# DELETE FROM <table> ... RETURNING *
DELETE FROM t1 WHERE a=2 RETURNING * ;
SELECT * FROM t1;
INSERT INTO t1 VALUES (2,'BB'), (2,'bb');
# DELETE FROM <table> ... RETURNING <col>
DELETE FROM t1 WHERE a=2 RETURNING b;
SELECT * FROM t1;
# DELETE FROM <table> ... RETURNING <not existing col>
--error ER_BAD_FIELD_ERROR
DELETE FROM t1 WHERE a=2 RETURNING c;
INSERT INTO t1 VALUES (2,'BB'), (2,'bb');
# DELETE FROM <table> ... RETURNING <col>, <expr>
DELETE FROM t1 WHERE a=2 RETURNING a, UPPER(b);
SELECT * FROM t1;
INSERT INTO t1 VALUES (2,'BB'), (2,'bb');
# DELETE FROM <table> ... RETURNING <col> with no rows to be deleted
DELETE FROM t1 WHERE a=6 RETURNING b;
SELECT * FROM t1;
# DELETE FROM <table> ... RETURNING <expr with aggr function>
--error ER_INVALID_GROUP_FUNC_USE
DELETE FROM t1 WHERE a=2 RETURNING MAX(b);
# DELETE FROM <table> ... RETURNING <expr with subquery>
DELETE FROM t1 WHERE a < 5 RETURNING a, (SELECT MIN(c) FROM t2 WHERE c=a+1);
SELECT * FROM t1;
DELETE FROM t1;
INSERT INTO t1 SELECT * FROM t1c;
DELETE FROM t2 WHERE c < 5
RETURNING (SELECT GROUP_CONCAT(b) FROM t1 GROUP BY a HAVING a=c);
SELECT * FROM t2;
DELETE FROM t2;
INSERT INTO t2 SELECT * FROM t2c;
# DELETE FROM <table> ... RETURNING <expr with function invocation>
DELIMITER |;
CREATE FUNCTION f(arg INT) RETURNS TEXT
BEGIN
RETURN (SELECT GROUP_CONCAT(b) FROM t1 WHERE a=arg);
END|
DELIMITER ;|
DELETE FROM t2 WHERE c < 5 RETURNING f(c);
SELECT * FROM t2;
DELETE FROM t2;
INSERT INTO t2 SELECT * FROM t2c;
DROP FUNCTION f;
# DELETE FROM <view> ... RETURNING <col>, <col>
DELETE FROM v1 WHERE a < 5 RETURNING * ;
SELECT * FROM t1;
DELETE FROM t1;
INSERT INTO t1 SELECT * FROM t1c;
# DELETE FROM <view> ... RETURNING <expr>
CREATE VIEW v11(a,c) AS SELECT a, COUNT(b) FROM t1 GROUP BY a;
-- error ER_NON_UPDATABLE_TABLE
DELETE FROM v11 WHERE a < 5 RETURNING * ;
DROP VIEW v11;
# prepared DELETE FROM <table> ... RETURNING <expr>
PREPARE stmt FROM
"DELETE FROM t1 WHERE a=2 ORDER BY b LIMIT 1 RETURNING a, UPPER(b)";
EXECUTE stmt;
SELECT * FROM t1;
EXECUTE stmt;
SELECT * FROM t1;
DEALLOCATE PREPARE stmt;
# Cleanup
DROP VIEW v1;
DROP TABLE t1,t2;
DROP TABLE t1c,t2c;
--echo #
--echo # Bug mdev-4918: DELETE ... RETURNING subquery with more than 1 row
--echo #
CREATE TABLE t1 (i1 int);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (i2 int);
INSERT INTO t2 VALUES (1),(2);
--error ER_SUBQUERY_NO_1_ROW
DELETE FROM t1 ORDER BY i1 RETURNING ( SELECT i2 FROM t2 );
DROP TABLE t1,t2;
--echo #
--echo # MDEV-4919: Packets out of order on a SELECT after calling a procedure with DELETE .. RETURNING
--echo #
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
--delimiter |
CREATE PROCEDURE p1 (a INT)
BEGIN
DELETE FROM t1 WHERE i = a RETURNING *;
INSERT INTO t1 VALUES (a);
END |
--delimiter ;
CALL p1(1);
SELECT * FROM t1;
DROP PROCEDURE p1;
DROP TABLE t1;
--echo #
--echo # MDEV-13776: DELETE ... RETURNING with sql_mode='ONLY_FULL_GROUP_BY'
--echo #
set @sql_mode_save= @@sql_mode;
set sql_mode='ONLY_FULL_GROUP_BY';
CREATE TABLE t1 (id INT);
INSERT INTO t1 VALUE(1),(2),(3);
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;