diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-12-22 00:28:04 +0530 |
---|---|---|
committer | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-12-24 11:25:37 +0530 |
commit | 1190e2edbe4dd48ec2309449663d8a92b4ab1b63 (patch) | |
tree | 07c70573244faaa576875cdb1b9c0621082a6530 | |
parent | 1b8f0d4b674dd7f9414778054ef714f0fed71ccc (diff) | |
download | mariadb-git-bb-10.7-MDEV-26698.tar.gz |
Fixed.bb-10.7-MDEV-26698
Todo: Add comment and commit message
-rw-r--r-- | mysql-test/main/get_diagnostics.result | 21 | ||||
-rw-r--r-- | mysql-test/main/get_diagnostics.test | 16 | ||||
-rw-r--r-- | sql/sql_select.cc | 18 |
3 files changed, 46 insertions, 9 deletions
diff --git a/mysql-test/main/get_diagnostics.result b/mysql-test/main/get_diagnostics.result index 2e749fa21d7..2606f6a90e0 100644 --- a/mysql-test/main/get_diagnostics.result +++ b/mysql-test/main/get_diagnostics.result @@ -1811,3 +1811,24 @@ SELECT @n; @n 4 DROP TABLE t; +# +# MDEV-26698: Incorrect row number upon INSERT .. SELECT from the same +# table: rows are counted twice +# +CREATE OR REPLACE TABLE t (a TINYINT); +INSERT INTO t VALUES (1),(100); +INSERT INTO t SELECT a*2 FROM t; +Warnings: +Warning 1264 Out of range value for column 'a' at row 2 +GET DIAGNOSTICS CONDITION 1 @err1 = ROW_NUMBER; +SELECT @err1; +@err1 +2 +GET DIAGNOSTICS CONDITION 2 @err2 = ROW_NUMBER; +Warnings: +Warning 1264 Out of range value for column 'a' at row 2 +Error 1758 Invalid condition number +SELECT @err2; +@err2 +NULL +DROP TABLE t; diff --git a/mysql-test/main/get_diagnostics.test b/mysql-test/main/get_diagnostics.test index e8d81dca1e6..3dbe72ec55c 100644 --- a/mysql-test/main/get_diagnostics.test +++ b/mysql-test/main/get_diagnostics.test @@ -1687,3 +1687,19 @@ GET DIAGNOSTICS CONDITION 3 @n = ROW_NUMBER; SELECT @n; DROP TABLE t; + +-- echo # +-- echo # MDEV-26698: Incorrect row number upon INSERT .. SELECT from the same +-- echo # table: rows are counted twice +-- echo # + +CREATE OR REPLACE TABLE t (a TINYINT); +INSERT INTO t VALUES (1),(100); + +INSERT INTO t SELECT a*2 FROM t; +GET DIAGNOSTICS CONDITION 1 @err1 = ROW_NUMBER; +SELECT @err1; +GET DIAGNOSTICS CONDITION 2 @err2 = ROW_NUMBER; +SELECT @err2; + +DROP TABLE t; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ba141222168..2b674ad220c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -21145,7 +21145,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, bool shortcut_for_distinct= join_tab->shortcut_for_distinct; ha_rows found_records=join->found_records; COND *select_cond= join_tab->select_cond; - bool select_cond_result= TRUE; + bool select_cond_result= TRUE, unlock_rows= true; DBUG_ENTER("evaluate_join_record"); DBUG_PRINT("enter", @@ -21297,10 +21297,10 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab, if (found) { + unlock_rows= false; enum enum_nested_loop_state rc; /* A match from join_tab is found for the current partial join. */ rc= (*join_tab->next_select)(join, join_tab+1, 0); - join->thd->get_stmt_da()->inc_current_row_for_warning(); if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS) DBUG_RETURN(rc); if (return_tab < join->return_tab) @@ -21320,11 +21320,6 @@ 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); - } } else { @@ -21333,9 +21328,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(); + if (unlock_rows) + join_tab->read_record.unlock_row(join_tab); + DBUG_RETURN(NESTED_LOOP_OK); } @@ -22587,6 +22584,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), join->unit->lim.set_unlimited(); } } + join->thd->get_stmt_da()->inc_current_row_for_warning(); } end: if (unlikely(join->thd->check_killed())) @@ -29504,6 +29502,7 @@ AGGR_OP::end_send() table->reginfo.lock_type= TL_UNLOCK; bool in_first_read= true; + join_tab->join->thd->get_stmt_da()->reset_current_row_for_warning(1); while (rc == NESTED_LOOP_OK) { int error; @@ -29527,6 +29526,7 @@ AGGR_OP::end_send() else { rc= evaluate_join_record(join, join_tab, 0); + join_tab->join->thd->get_stmt_da()->inc_current_row_for_warning(); } } |