[MDEV-650] LP:886146 - crash if JOIN::optimize fails in INSERT IGNORE Created: 2011-11-04  Updated: 2015-01-28  Resolved: 2014-10-20

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Sergei Golubchik Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug886146.xml    

 Description   

See MySQL's Bug#34660.
The fix isn't quite complete, the crash can occur even without subqueries. Doing
INSERT IGNORE ... SELECT ...
and imitating a failure in JOIN::optimize (forcing table->file->print_error() in make_join_statistics),
the error status is properly returned all the way up to mysql_parse, but the error packet is not sent
(see my_message_sql() in 5.3) because of the IGNORE clause.



 Comments   
Comment by Sergei Golubchik [ 2011-11-04 ]

Re: crash if JOIN::optimize fails in INSERT IGNORE
Monty thinks that my_message_sql should not check for select_lex->no_errors and always send an error packet.
Trying it, mysql-test fails in three different ways (because of errors that were not happening before):

1. INSERT IGNORE ... SELECT: ERROR 1048: Column 'c1' cannot be null

This can be fixed with

=== modified file 'sql/sql_insert.cc'
--- sql/sql_insert.cc   2011-09-26 20:54:00 +0000
+++ sql/sql_insert.cc   2011-11-04 14:02:57 +0000
@@ -3271,7 +3271,8 @@ int select_insert::send_data(List<Item>
 
   thd->count_cuted_fields= CHECK_FIELD_WARN;   // Calculate cuted fields
   store_values(values);
-  thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
+  if (!info.ignore)
+    thd->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
   if (thd->is_error())
   {
     table->auto_increment_field_not_null= FALSE;

2. UPDATE IGNORE T1 SET B=(SELECT ...) ERROR 1242: Subquery returns more than 1 row

In my opinion this needs no fix. It correctly fails as it should. This error
should not be ignored.

3. DELETE IGNORE ... ERROR 1451: Cannot delete or update a parent row: a foreign key constraint fails

This one is a bit more difficult to fix.

Comment by Rasmus Johansson (Inactive) [ 2011-11-04 ]

Launchpad bug id: 886146

Comment by Elena Stepanova [ 2014-10-20 ]

Apparently the bug was fixed back in 5.3.3 by the following commit:

    ------------------------------------------------------------
    revno: 3327.1.3
    revision-id: monty@askmonty.org-20111211163933-rmsxvnwrmd2xpe1m
    parent: monty@askmonty.org-20111211093444-dat95bd5h1e5dgmy
    committer: Michael Widenius <monty@askmonty.org>
    branch nick: maria-5.3-new
    timestamp: Sun 2011-12-11 18:39:33 +0200
    message:
      Rewrite IGNORE handling:
      - Instead of supressing all errors, only suppress safe ones like:
      ER_DUP_KEY, ER_BAD_NULL_ERROR, ER_SUBQUERY_NO_1_ROW, ER_ROW_IS_REFERENCED_2

At least I am getting the crash using bug11747970 injection and the test case below on 5.3 tree up to revno: 3327.1.2, but the since the revision above the same test case only produces a regular error.

use test;
create table t1 (c1 int, unique key (c1)) engine=myisam;
insert into t1 values (1),(2);
 
SET @@debug="d,bug11747970_raise_error";
insert ignore into t1 select * from t1;

Generated at Thu Feb 08 06:30:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.