Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-650

LP:886146 - crash if JOIN::optimize fails in INSERT IGNORE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: N/A
    • Component/s: Optimizer
    • Labels:

      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.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            serg Sergei Golubchik added a comment - - edited

            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.

            Show
            serg Sergei Golubchik added a comment - - edited 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.
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 886146

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 886146
            Hide
            elenst Elena Stepanova added a comment -

            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;
            
            Show
            elenst Elena Stepanova added a comment - 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;

              People

              • Assignee:
                Unassigned
                Reporter:
                serg Sergei Golubchik
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: