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

sql_mode NO_ZERO_DATE conflicts with versioned tables

Details

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

    Description

      The sql_mode variable NO_ZERO_DATE specifies to reject any INSERT and UPDATE queries where a date value is submitted as '0000-00-00'. Though if a new column is added to a table, then the value '0000-00-00' is still inserted for all rows. It is a session variable and not an attribute of the table column, which causes problems if the sql mode is entered after a table has been created. For example:

      1:

      CREATE TABLE abc (a DATE NOT NULL DEFAULT '0000-00-00');
      

      Now the following ALTER TABLE will fail, despite that it does not touch column 'a'.

      SET SESSION sql_mode='NO_ZERO_DATE';
      ALTER TABLE abc ADD b INT NOT NULL;
      

      This is especially apparent in versioned tables. Both these situations will cause error code 1067:

      2:

      SET SESSION sql_mode='NO_ZERO_DATE';
      CREATE TABLE abc (a INT NOT NULL) WITH SYSTEM VERSIONING;
      

      3:

      CREATE TABLE abc (a INT NOT NULL) WITH SYSTEM VERSIONING;
      SET SESSION system_versioning_alter_history=KEEP, SESSION sql_mode='NO_ZERO_DATE';
      ALTER TABLE abc ADD b INT NOT NULL;
      

      Given that '0000-00-00' values can still occur in a table, despite that NO_ZERO_DATE may at one point in time become configured, I think that a column's default value should not be validated against this restriction, especially when a table alteration does not even affect that column. Perhaps an even better solution would be to make NO_ZERO_DATE an attribute of the column, rather than a session variable.

      Attachments

        Issue Links

          Activity

            Which server version are you using?
            It should have been fixed in the scope of MDEV-16937 in 10.3.24 / 10.4.14 / 10.5.4.

            elenst Elena Stepanova added a comment - Which server version are you using? It should have been fixed in the scope of MDEV-16937 in 10.3.24 / 10.4.14 / 10.5.4.
            user2180613 Remy Fox added a comment - - edited

            I tested on 10.4.10 and 10.5.8.

            It turns out that the first error happens on both version, while the second and third example no longer exist in 10.5.8.

            user2180613 Remy Fox added a comment - - edited I tested on 10.4.10 and 10.5.8. It turns out that the first error happens on both version, while the second and third example no longer exist in 10.5.8.

            Right, MDEV-16937 fixes the part related to versioning tables, which was indeed a bug.

            The behavior with CREATE/ALTER table is expected. It is a documentation bug if you point out at the documentation page which you refer to as "The sql_mode variable NO_ZERO_DATE specifies to reject any INSERT and UPDATE queries where a date value is submitted as '0000-00-00'."

            I can't find it either in MariaDB KB or in MySQL manual. Both do say that INSERT/UPDATE IGNORE allow to bypass the restriction, but it doesn't mean that the restriction only applies to INSERT/UPDATE.

            elenst Elena Stepanova added a comment - Right, MDEV-16937 fixes the part related to versioning tables, which was indeed a bug. The behavior with CREATE/ALTER table is expected. It is a documentation bug if you point out at the documentation page which you refer to as "The sql_mode variable NO_ZERO_DATE specifies to reject any INSERT and UPDATE queries where a date value is submitted as '0000-00-00'." I can't find it either in MariaDB KB or in MySQL manual. Both do say that INSERT/UPDATE IGNORE allow to bypass the restriction, but it doesn't mean that the restriction only applies to INSERT/UPDATE.
            user2180613 Remy Fox added a comment -

            Why is the ALTER TABLE expected to fail when I add a totally unrelated column to an empty table under this configuration?

            user2180613 Remy Fox added a comment - Why is the ALTER TABLE expected to fail when I add a totally unrelated column to an empty table under this configuration?

            People

              Unassigned Unassigned
              user2180613 Remy Fox
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.