Commit 452c9a4d authored by Rucha Deodhar's avatar Rucha Deodhar

MDEV-26698: Incorrect row number upon INSERT .. SELECT from the same

table: rows are counted twice

Analysis: When the table we are trying to insert into and the SELECT table
are same for INSERT ... SELECT, rows from the SELECT table are copied into
internal temporary table and then to the INSERT table. We only want to
count the rows when we start inserting into the table.
Fix: Reset the counter to 1 before starting to copy from internal temporary
table to select table and then increment the counter.
parent 5d57e04b
......@@ -865,3 +865,22 @@ t2 CREATE TABLE `t2` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2;
End of 5.5 tests
#
# Beginning of 10.2 test
#
# MDEV-26698: Incorrect row number upon INSERT .. SELECT from the same
# table: rows are counted twice
#
CREATE TABLE t1(a TINYINT);
INSERT INTO t1 VALUES (1), (100);
INSERT INTO t1 SELECT a*2 FROM t1;
Warnings:
Warning 1264 Out of range value for column 'a' at row 2
TRUNCATE TABLE t1;
# using ORDER BY
INSERT INTO t1 VALUES(1), (2), (100), (3);
INSERT INTO t1 SELECT a*2 FROM t1 ORDER BY a;
Warnings:
Warning 1264 Out of range value for column 'a' at row 4
DROP TABLE t1;
# End of 10.2 test
......@@ -435,3 +435,28 @@ show create table t2;
drop table t1, t2;
--echo End of 5.5 tests
--echo #
--echo # Beginning of 10.2 test
--echo #
--echo # MDEV-26698: Incorrect row number upon INSERT .. SELECT from the same
--echo # table: rows are counted twice
--echo #
CREATE TABLE t1(a TINYINT);
INSERT INTO t1 VALUES (1), (100);
INSERT INTO t1 SELECT a*2 FROM t1;
TRUNCATE TABLE t1;
--echo # using ORDER BY
INSERT INTO t1 VALUES(1), (2), (100), (3);
INSERT INTO t1 SELECT a*2 FROM t1 ORDER BY a;
DROP TABLE t1;
--echo # End of 10.2 test
......@@ -19146,11 +19146,8 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
*/
if (shortcut_for_distinct && found_records != join->found_records)
DBUG_RETURN(NESTED_LOOP_NO_MORE_ROWS);
}
else
{
join->thd->get_stmt_da()->inc_current_row_for_warning();
join_tab->read_record.unlock_row(join_tab);
DBUG_RETURN(NESTED_LOOP_OK);
}
}
else
......@@ -19160,9 +19157,11 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
with the beginning coinciding with the current partial join.
*/
join->join_examined_rows++;
join->thd->get_stmt_da()->inc_current_row_for_warning();
join_tab->read_record.unlock_row(join_tab);
}
join->thd->get_stmt_da()->inc_current_row_for_warning();
join_tab->read_record.unlock_row(join_tab);
DBUG_RETURN(NESTED_LOOP_OK);
}
......@@ -26945,6 +26944,12 @@ AGGR_OP::end_send()
table->reginfo.lock_type= TL_UNLOCK;
bool in_first_read= true;
/*
Reset the counter before copying rows from internal temporary table to
INSERT table.
*/
join_tab->join->thd->get_stmt_da()->reset_current_row_for_warning();
while (rc == NESTED_LOOP_OK)
{
int error;
......
......@@ -656,54 +656,54 @@ Warning 1264 Out of range value for column 'b1' at row 1
Warning 1264 Out of range value for column 'b20' at row 1
INSERT INTO t1 (i,i0,i1,i20,t,t0,t1,t20,s,s0,s1,s20,m,m0,m1,m20,b,b0,b1,b20) SELECT b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b FROM t1 WHERE b IN (-9223372036854775808,9223372036854775807,18446744073709551615);
Warnings:
Warning 1264 Out of range value for column 'i' at row 8
Warning 1264 Out of range value for column 'i0' at row 8
Warning 1264 Out of range value for column 'i1' at row 8
Warning 1264 Out of range value for column 'i20' at row 8
Warning 1264 Out of range value for column 't' at row 8
Warning 1264 Out of range value for column 't0' at row 8
Warning 1264 Out of range value for column 't1' at row 8
Warning 1264 Out of range value for column 't20' at row 8
Warning 1264 Out of range value for column 's' at row 8
Warning 1264 Out of range value for column 's0' at row 8
Warning 1264 Out of range value for column 's1' at row 8
Warning 1264 Out of range value for column 's20' at row 8
Warning 1264 Out of range value for column 'm' at row 8
Warning 1264 Out of range value for column 'm0' at row 8
Warning 1264 Out of range value for column 'm1' at row 8
Warning 1264 Out of range value for column 'm20' at row 8
Warning 1264 Out of range value for column 'i' at row 9
Warning 1264 Out of range value for column 'i0' at row 9
Warning 1264 Out of range value for column 'i1' at row 9
Warning 1264 Out of range value for column 'i20' at row 9
Warning 1264 Out of range value for column 't' at row 9
Warning 1264 Out of range value for column 't0' at row 9
Warning 1264 Out of range value for column 't1' at row 9
Warning 1264 Out of range value for column 't20' at row 9
Warning 1264 Out of range value for column 's' at row 9
Warning 1264 Out of range value for column 's0' at row 9
Warning 1264 Out of range value for column 's1' at row 9
Warning 1264 Out of range value for column 's20' at row 9
Warning 1264 Out of range value for column 'm' at row 9
Warning 1264 Out of range value for column 'm0' at row 9
Warning 1264 Out of range value for column 'm1' at row 9
Warning 1264 Out of range value for column 'm20' at row 9
Warning 1264 Out of range value for column 'i' at row 10
Warning 1264 Out of range value for column 'i0' at row 10
Warning 1264 Out of range value for column 'i1' at row 10
Warning 1264 Out of range value for column 'i20' at row 10
Warning 1264 Out of range value for column 't' at row 10
Warning 1264 Out of range value for column 't0' at row 10
Warning 1264 Out of range value for column 't1' at row 10
Warning 1264 Out of range value for column 't20' at row 10
Warning 1264 Out of range value for column 's' at row 10
Warning 1264 Out of range value for column 's0' at row 10
Warning 1264 Out of range value for column 's1' at row 10
Warning 1264 Out of range value for column 's20' at row 10
Warning 1264 Out of range value for column 'm' at row 10
Warning 1264 Out of range value for column 'm0' at row 10
Warning 1264 Out of range value for column 'm1' at row 10
Warning 1264 Out of range value for column 'm20' at row 10
Warning 1264 Out of range value for column 'i' at row 1
Warning 1264 Out of range value for column 'i0' at row 1
Warning 1264 Out of range value for column 'i1' at row 1
Warning 1264 Out of range value for column 'i20' at row 1
Warning 1264 Out of range value for column 't' at row 1
Warning 1264 Out of range value for column 't0' at row 1
Warning 1264 Out of range value for column 't1' at row 1
Warning 1264 Out of range value for column 't20' at row 1
Warning 1264 Out of range value for column 's' at row 1
Warning 1264 Out of range value for column 's0' at row 1
Warning 1264 Out of range value for column 's1' at row 1
Warning 1264 Out of range value for column 's20' at row 1
Warning 1264 Out of range value for column 'm' at row 1
Warning 1264 Out of range value for column 'm0' at row 1
Warning 1264 Out of range value for column 'm1' at row 1
Warning 1264 Out of range value for column 'm20' at row 1
Warning 1264 Out of range value for column 'i' at row 2
Warning 1264 Out of range value for column 'i0' at row 2
Warning 1264 Out of range value for column 'i1' at row 2
Warning 1264 Out of range value for column 'i20' at row 2
Warning 1264 Out of range value for column 't' at row 2
Warning 1264 Out of range value for column 't0' at row 2
Warning 1264 Out of range value for column 't1' at row 2
Warning 1264 Out of range value for column 't20' at row 2
Warning 1264 Out of range value for column 's' at row 2
Warning 1264 Out of range value for column 's0' at row 2
Warning 1264 Out of range value for column 's1' at row 2
Warning 1264 Out of range value for column 's20' at row 2
Warning 1264 Out of range value for column 'm' at row 2
Warning 1264 Out of range value for column 'm0' at row 2
Warning 1264 Out of range value for column 'm1' at row 2
Warning 1264 Out of range value for column 'm20' at row 2
Warning 1264 Out of range value for column 'i' at row 3
Warning 1264 Out of range value for column 'i0' at row 3
Warning 1264 Out of range value for column 'i1' at row 3
Warning 1264 Out of range value for column 'i20' at row 3
Warning 1264 Out of range value for column 't' at row 3
Warning 1264 Out of range value for column 't0' at row 3
Warning 1264 Out of range value for column 't1' at row 3
Warning 1264 Out of range value for column 't20' at row 3
Warning 1264 Out of range value for column 's' at row 3
Warning 1264 Out of range value for column 's0' at row 3
Warning 1264 Out of range value for column 's1' at row 3
Warning 1264 Out of range value for column 's20' at row 3
Warning 1264 Out of range value for column 'm' at row 3
Warning 1264 Out of range value for column 'm0' at row 3
Warning 1264 Out of range value for column 'm1' at row 3
Warning 1264 Out of range value for column 'm20' at row 3
SELECT i,i0,i1,i20,t,t0,t1,t20,s,s0,s1,s20,m,m0,m1,m20,b,b0,b1,b20 FROM t1;
i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
......
......@@ -29,15 +29,15 @@ Warning 1265 Data truncated for column 'c20' at row 1
Warning 1265 Data truncated for column 'c255' at row 1
INSERT INTO t1 (c,c0,c1,c20,c255) SELECT c255, c255, c255, c255, CONCAT('a',c255,c1) FROM t1;
Warnings:
Warning 1265 Data truncated for column 'c' at row 5
Warning 1265 Data truncated for column 'c0' at row 5
Warning 1265 Data truncated for column 'c1' at row 5
Warning 1265 Data truncated for column 'c20' at row 5
Warning 1265 Data truncated for column 'c' at row 6
Warning 1265 Data truncated for column 'c0' at row 6
Warning 1265 Data truncated for column 'c1' at row 6
Warning 1265 Data truncated for column 'c20' at row 6
Warning 1265 Data truncated for column 'c255' at row 6
Warning 1265 Data truncated for column 'c' at row 2
Warning 1265 Data truncated for column 'c0' at row 2
Warning 1265 Data truncated for column 'c1' at row 2
Warning 1265 Data truncated for column 'c20' at row 2
Warning 1265 Data truncated for column 'c' at row 3
Warning 1265 Data truncated for column 'c0' at row 3
Warning 1265 Data truncated for column 'c1' at row 3
Warning 1265 Data truncated for column 'c20' at row 3
Warning 1265 Data truncated for column 'c255' at row 3
SELECT c,c0,c1,c20,c255 FROM t1;
c c0 c1 c20 c255
......
......@@ -129,70 +129,70 @@ Warning 1264 Out of range value for column 'b1' at row 1
Warning 1264 Out of range value for column 'b20' at row 1
INSERT INTO t1 (i,i0,i1,i20,t,t0,t1,t20,s,s0,s1,s20,m,m0,m1,m20,b,b0,b1,b20) SELECT b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b,b FROM t1 WHERE b IN (-9223372036854775808,9223372036854775807,18446744073709551615);
Warnings:
Warning 1264 Out of range value for column 'i' at row 8
Warning 1264 Out of range value for column 'i0' at row 8
Warning 1264 Out of range value for column 'i1' at row 8
Warning 1264 Out of range value for column 'i20' at row 8
Warning 1264 Out of range value for column 't' at row 8
Warning 1264 Out of range value for column 't0' at row 8
Warning 1264 Out of range value for column 't1' at row 8
Warning 1264 Out of range value for column 't20' at row 8
Warning 1264 Out of range value for column 's' at row 8
Warning 1264 Out of range value for column 's0' at row 8
Warning 1264 Out of range value for column 's1' at row 8
Warning 1264 Out of range value for column 's20' at row 8
Warning 1264 Out of range value for column 'm' at row 8
Warning 1264 Out of range value for column 'm0' at row 8
Warning 1264 Out of range value for column 'm1' at row 8
Warning 1264 Out of range value for column 'm20' at row 8
Warning 1264 Out of range value for column 'i' at row 9
Warning 1264 Out of range value for column 'i0' at row 9
Warning 1264 Out of range value for column 'i1' at row 9
Warning 1264 Out of range value for column 'i20' at row 9
Warning 1264 Out of range value for column 't' at row 9
Warning 1264 Out of range value for column 't0' at row 9
Warning 1264 Out of range value for column 't1' at row 9
Warning 1264 Out of range value for column 't20' at row 9
Warning 1264 Out of range value for column 's' at row 9
Warning 1264 Out of range value for column 's0' at row 9
Warning 1264 Out of range value for column 's1' at row 9
Warning 1264 Out of range value for column 's20' at row 9
Warning 1264 Out of range value for column 'm' at row 9
Warning 1264 Out of range value for column 'm0' at row 9
Warning 1264 Out of range value for column 'm1' at row 9
Warning 1264 Out of range value for column 'm20' at row 9
Warning 1264 Out of range value for column 'i' at row 10
Warning 1264 Out of range value for column 'i0' at row 10
Warning 1264 Out of range value for column 'i1' at row 10
Warning 1264 Out of range value for column 'i20' at row 10
Warning 1264 Out of range value for column 't' at row 10
Warning 1264 Out of range value for column 't0' at row 10
Warning 1264 Out of range value for column 't1' at row 10
Warning 1264 Out of range value for column 't20' at row 10
Warning 1264 Out of range value for column 's' at row 10
Warning 1264 Out of range value for column 's0' at row 10
Warning 1264 Out of range value for column 's1' at row 10
Warning 1264 Out of range value for column 's20' at row 10
Warning 1264 Out of range value for column 'm' at row 10
Warning 1264 Out of range value for column 'm0' at row 10
Warning 1264 Out of range value for column 'm1' at row 10
Warning 1264 Out of range value for column 'm20' at row 10
Warning 1264 Out of range value for column 'i' at row 11
Warning 1264 Out of range value for column 'i0' at row 11
Warning 1264 Out of range value for column 'i1' at row 11
Warning 1264 Out of range value for column 'i20' at row 11
Warning 1264 Out of range value for column 't' at row 11
Warning 1264 Out of range value for column 't0' at row 11
Warning 1264 Out of range value for column 't1' at row 11
Warning 1264 Out of range value for column 't20' at row 11
Warning 1264 Out of range value for column 's' at row 11
Warning 1264 Out of range value for column 's0' at row 11
Warning 1264 Out of range value for column 's1' at row 11
Warning 1264 Out of range value for column 's20' at row 11
Warning 1264 Out of range value for column 'm' at row 11
Warning 1264 Out of range value for column 'm0' at row 11
Warning 1264 Out of range value for column 'm1' at row 11
Warning 1264 Out of range value for column 'm20' at row 11
Warning 1264 Out of range value for column 'i' at row 1
Warning 1264 Out of range value for column 'i0' at row 1
Warning 1264 Out of range value for column 'i1' at row 1
Warning 1264 Out of range value for column 'i20' at row 1
Warning 1264 Out of range value for column 't' at row 1
Warning 1264 Out of range value for column 't0' at row 1
Warning 1264 Out of range value for column 't1' at row 1
Warning 1264 Out of range value for column 't20' at row 1
Warning 1264 Out of range value for column 's' at row 1
Warning 1264 Out of range value for column 's0' at row 1
Warning 1264 Out of range value for column 's1' at row 1
Warning 1264 Out of range value for column 's20' at row 1
Warning 1264 Out of range value for column 'm' at row 1
Warning 1264 Out of range value for column 'm0' at row 1
Warning 1264 Out of range value for column 'm1' at row 1
Warning 1264 Out of range value for column 'm20' at row 1
Warning 1264 Out of range value for column 'i' at row 2
Warning 1264 Out of range value for column 'i0' at row 2
Warning 1264 Out of range value for column 'i1' at row 2
Warning 1264 Out of range value for column 'i20' at row 2
Warning 1264 Out of range value for column 't' at row 2
Warning 1264 Out of range value for column 't0' at row 2
Warning 1264 Out of range value for column 't1' at row 2
Warning 1264 Out of range value for column 't20' at row 2
Warning 1264 Out of range value for column 's' at row 2
Warning 1264 Out of range value for column 's0' at row 2
Warning 1264 Out of range value for column 's1' at row 2
Warning 1264 Out of range value for column 's20' at row 2
Warning 1264 Out of range value for column 'm' at row 2
Warning 1264 Out of range value for column 'm0' at row 2
Warning 1264 Out of range value for column 'm1' at row 2
Warning 1264 Out of range value for column 'm20' at row 2
Warning 1264 Out of range value for column 'i' at row 3
Warning 1264 Out of range value for column 'i0' at row 3
Warning 1264 Out of range value for column 'i1' at row 3
Warning 1264 Out of range value for column 'i20' at row 3
Warning 1264 Out of range value for column 't' at row 3
Warning 1264 Out of range value for column 't0' at row 3
Warning 1264 Out of range value for column 't1' at row 3
Warning 1264 Out of range value for column 't20' at row 3
Warning 1264 Out of range value for column 's' at row 3
Warning 1264 Out of range value for column 's0' at row 3
Warning 1264 Out of range value for column 's1' at row 3
Warning 1264 Out of range value for column 's20' at row 3
Warning 1264 Out of range value for column 'm' at row 3
Warning 1264 Out of range value for column 'm0' at row 3
Warning 1264 Out of range value for column 'm1' at row 3
Warning 1264 Out of range value for column 'm20' at row 3
Warning 1264 Out of range value for column 'i' at row 4
Warning 1264 Out of range value for column 'i0' at row 4
Warning 1264 Out of range value for column 'i1' at row 4
Warning 1264 Out of range value for column 'i20' at row 4
Warning 1264 Out of range value for column 't' at row 4
Warning 1264 Out of range value for column 't0' at row 4
Warning 1264 Out of range value for column 't1' at row 4
Warning 1264 Out of range value for column 't20' at row 4
Warning 1264 Out of range value for column 's' at row 4
Warning 1264 Out of range value for column 's0' at row 4
Warning 1264 Out of range value for column 's1' at row 4
Warning 1264 Out of range value for column 's20' at row 4
Warning 1264 Out of range value for column 'm' at row 4
Warning 1264 Out of range value for column 'm0' at row 4
Warning 1264 Out of range value for column 'm1' at row 4
Warning 1264 Out of range value for column 'm20' at row 4
SELECT i,i0,i1,i20,t,t0,t1,t20,s,s0,s1,s20,m,m0,m1,m20,b,b0,b1,b20 FROM t1;
i i0 i1 i20 t t0 t1 t20 s s0 s1 s20 m m0 m1 m20 b b0 b1 b20
-2147483648 -2147483648 -2147483648 -2147483648 -128 -128 -128 -128 -32768 -32768 -32768 -32768 -8388608 -8388608 -8388608 -8388608 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808
......
......@@ -65,13 +65,13 @@ Warning 1265 Data truncated for column 'v64' at row 1
Warning 1265 Data truncated for column 'v65000' at row 1
INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, CONCAT('a',v65000), CONCAT(v65000,v1) FROM t1;
Warnings:
Warning 1265 Data truncated for column 'v0' at row 5
Warning 1265 Data truncated for column 'v1' at row 5
Warning 1265 Data truncated for column 'v64' at row 5
Warning 1265 Data truncated for column 'v0' at row 6
Warning 1265 Data truncated for column 'v1' at row 6
Warning 1265 Data truncated for column 'v64' at row 6
Warning 1265 Data truncated for column 'v65000' at row 6
Warning 1265 Data truncated for column 'v0' at row 2
Warning 1265 Data truncated for column 'v1' at row 2
Warning 1265 Data truncated for column 'v64' at row 2
Warning 1265 Data truncated for column 'v0' at row 3
Warning 1265 Data truncated for column 'v1' at row 3
Warning 1265 Data truncated for column 'v64' at row 3
Warning 1265 Data truncated for column 'v65000' at row 3
SELECT HEX(v0), HEX(v1), HEX(v64), LENGTH(HEX(v65000)) FROM t1;
HEX(v0) HEX(v1) HEX(v64) LENGTH(HEX(v65000))
0
......
......@@ -110,13 +110,13 @@ Warning 1265 Data truncated for column 'v64' at row 1
Warning 1265 Data truncated for column 'v65000' at row 1
INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, CONCAT('a',v65000), CONCAT(v65000,v1) FROM t1;
Warnings:
Warning 1265 Data truncated for column 'v0' at row 5
Warning 1265 Data truncated for column 'v1' at row 5
Warning 1265 Data truncated for column 'v64' at row 5
Warning 1265 Data truncated for column 'v65000' at row 5
Warning 1265 Data truncated for column 'v0' at row 6
Warning 1265 Data truncated for column 'v1' at row 6
Warning 1265 Data truncated for column 'v64' at row 6
Warning 1265 Data truncated for column 'v0' at row 2
Warning 1265 Data truncated for column 'v1' at row 2
Warning 1265 Data truncated for column 'v64' at row 2
Warning 1265 Data truncated for column 'v65000' at row 2
Warning 1265 Data truncated for column 'v0' at row 3
Warning 1265 Data truncated for column 'v1' at row 3
Warning 1265 Data truncated for column 'v64' at row 3
SELECT v0, v1, v64, LENGTH(v65000) FROM t1;
v0 v1 v64 LENGTH(v65000)
0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment