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

sql_safe_updates blocks queries that actually do use a key column in WHERE

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Not a Bug
    • Affects Version/s: 10.5.12, 10.6.4
    • Fix Version/s: N/A
    • Component/s: Optimizer
    • Labels:
      None

      Description

      Create a simple test table, and enable sql_safe_updates:

      create table t1(id int primary key, val int);
      insert into t1 values(1,1),(2,2),(3,3);
      set session sql_safe_updates=ON;
      

      DELETE without WHERE fails now, as expected:

      delete from t1;
      -- ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
      

      DELETE with a simple WHERE 1=1 also fails as expected:

      delete from t1 where 1=1;
      -- ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
      

      Now the following two queries fail, too, even though the primary key column is clearly referenced in them:

      delete from t1 where id = id;
      -- ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
       
      delete from t1 where id is not null;
      ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
      

      This one does work as expected though:

      delete from t1 where id > 0;
      -- Query OK, 3 rows affected (0.001 sec)
      

      What I assume happening here is that the optimizer already optimized "id = id" and "id IS NOT NULL" away, knowing that these will always return "true" anyway, before the SQL_SAFE_UPDATES does even kick in?

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              serg Sergei Golubchik
              Reporter:
              hholzgra Hartmut Holzgraefe
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration