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

CREATE TABLE AS SELECT produces warnings, not errors

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • 11.2
    • Optimizer
    • None

    Description

      CREATE TABLE ... SELECT should treat datatype conversion warnings as errors.

      create table t10 (a int);
      insert into t10 values (1),(2);
      

      Normally, it does that:

      MariaDB [test]> create table tmp1 as SELECT * FROM t10 where "x"=0;
      ERROR 1292 (22007): Truncated incorrect DECIMAL value: 'x'
      

      But if the item producing the warning is a basic constant inside AND/OR, a warning is produced instead:

      MariaDB [test]> create table tmp2 as SELECT * FROM t10 where (a<10 and "x"=0);
      Query OK, 2 rows affected, 1 warning (0.009 sec)
      Records: 2  Duplicates: 0  Warnings: 1
       
      MariaDB [test]> show warnings;
      +---------+------+----------------------------------------+
      | Level   | Code | Message                                |
      +---------+------+----------------------------------------+
      | Warning | 1292 | Truncated incorrect DECIMAL value: 'x' |
      +---------+------+----------------------------------------+
      1 row in set (0.000 sec)
      

      The problem is that the warning here is produced inside Item_cond::fix_fields|eval_not_null_cond:

       
      (gdb) wher 
        #0  THD::really_abort_on_warning 
        #1  0x0000555555f3e15e in THD::raise_condition 
        ...
        #20 0x0000555555e3f3ce in Item::val_bool 
        #21 0x00005555560952ab in Item::eval_const_cond 
        #22 0x000055555643f096 in Item_cond::eval_not_null_tables 
        #23 0x000055555643edb2 in Item_cond::fix_fields 
        #24 0x0000555555e9e590 in Item::fix_fields_if_needed 
        #25 0x0000555555e9e5bd in Item::fix_fields_if_needed_for_scalar 
        #26 0x0000555555f26fdb in Item::fix_fields_if_needed_for_bool 
        #27 0x0000555555f23463 in setup_conds 
        #28 0x0000555556032971 in setup_without_group 
        #29 0x0000555556035b7c in JOIN::prepare 
      

      while THD::abort_on_warning is set to true at the end of JOIN::prepare():

        Thread 14 "one_connection" hit Hardware watchpoint 3: -location thd->abort_on_warning
        Old value = false
        New value = true
        select_create::prepare (...)  at sql_insert.cc:5011
      (gdb) wher 20
        #0  select_create::prepare 
        #1  0x0000555556036dd6 in JOIN::prepare 
      

      it's this line:

        if (!procedure && result && result->prepare(fields_list, unit_arg))
          goto err;					/* purecov: inspected */
      

      Should we set thd->abort_on_warning earlier?

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              psergei Sergei Petrunia
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.