[MDEV-29890] Update with inner join false row count result Created: 2022-10-26  Updated: 2023-01-09  Resolved: 2023-01-09

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Update
Affects Version/s: 10.4.25
Fix Version/s: 10.11.2, 10.4.28, 10.5.19, 10.6.12, 10.7.8, 10.8.7, 10.9.5, 10.10.3

Type: Bug Priority: Major
Reporter: Marc Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None
Environment:

Red Hat Enterprise Linux release 8.6 (Ootpa)

sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

optimizer_switch = index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on


Attachments: File update_bug_example_1.sql     File update_bug_example_2.sql     File update_bug_example_3.sql    

 Description   

In “update_bug_example_1.sql”, we have a situation where an UPDATE with INNER JOIN triggers an unwarranted warning. Although the update is successful, with two rows modified, the subsequent call to ROW_COUNT() returns 0.

The warning is:
Code: 1264 — Out of range value for column 'start_date' at row 1

In “update_bug_example_2.sql”, we have removed the NOT NULL option on the start_date field. Having done so, no more warning is issued, and the ROW_COUNT() function returns the correct value 2.

In “update_bug_example_3.sql”, the start_date field is back to NOT NULL, but we have removed the INNER JOIN portion of the UPDATE statement. Again, we have no warning and ROW_COUNT() returns 2 as expected.



 Comments   
Comment by Alice Sherepa [ 2022-11-17 ]

I could not repeat it, I am getting the warning and row_count shows 2(expected) or -1 in case warnings are switched on (which is expected, -1 for statements which return a result set: as show warnings)

Comment by Marc [ 2022-11-17 ]

ok, strange, but why is the warning occurring? I assume you are talking about the scripts in file update_bug_example_1.sql

Comment by Sergei Golubchik [ 2022-11-17 ]

the warning is a bug. it's caused by internal reasons and shouldn't be shown to a user. We'll fix it

Comment by Marc [ 2022-11-17 ]

Thank you for the information Sergei.

Comment by Alexander Barkov [ 2023-01-09 ]

Hello serg,

https://github.com/MariaDB/server/commit/4212c890962e2d81318a91fd46090b70ef2a2169

I'm afraid this patch has some flaws:

  • It's too specific to a certain data type (DATE/DATETIME).
  • It's fixing the consequences by masking errors in field_copy(). I prefer the source of the problem to be fixed: the original column does not have a DEFAULT, therefore create_tmp_table() should not even try to copy the default from the original field to the temporary field.

This patch seems to fix the reason of the problem (and is not data type specific):

diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f313d571b5b..4cf02cfefad 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -18241,7 +18241,8 @@ Field *Item_field::create_tmp_field_ex(TABLE *table,
   src->set_field(field);
   if (!(result= create_tmp_field_from_item_field(table, NULL, param)))
     return NULL;
-  if (field->eq_def(result))
+  if (!(field->flags & NO_DEFAULT_VALUE_FLAG) &&
+      field->eq_def(result))
     src->set_default_field(field);
   return result;
 }

olap.test failed for me with this patch. I think it should be recorded.

Comment by Alexander Barkov [ 2023-01-09 ]

Ok to push.

As discussed on slack, the fix should actually mix both:

Comment by Sergei Golubchik [ 2023-01-09 ]

Note: The fix only fixes the warning, as explained above.

Generated at Thu Feb 08 10:12:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.