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

Check Constraints with binary logging makes insert inconsistent

Details

    Description

      CREATE TABLE Employees (
        EmployeeID SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
      , FirstName VARCHAR(30) NOT NULL CHECK (CHAR_LENGTH(FirstName > 2))
      , LastName VARCHAR(40) NOT NULL
      , Title VARCHAR(50) NOT NULL CHECK (Title != 'God')
      , DeptID SMALLINT UNSIGNED NOT NULL
      , ManagerID INT UNSIGNED NULL
      , Salary DECIMAL(38) DEFAULT 0.0 CHECK (Salary < 10000.0)
      , CONSTRAINT c_deptid CHECK (DeptID > 0)
      );
      

      root@ma-102-master [test] SQL> INSERT INTO Employees VALUES   
          ->  (1,   'Ken', 'Sánchez', 'Chief Executive Officer',16,NULL, 9999)  
          -> ,(273, 'Brian', 'Welcker', 'Vice President of Sales',3,1, 8000)
          -> ;
      ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'Ken'
      root@ma-102-master [test] SQL> INSERT INTO Employees VALUES   (1,   'Ken', 'Sánchez', 'Chief Executive Officer',16,NULL, 9999)  ;
      Query OK, 1 row affected, 1 warning (0.00 sec)
       
      root@ma-102-master [test] SQL> show warnings;
      +-------+------+-----------------------------------------+
      | Level | Code | Message                                 |
      +-------+------+-----------------------------------------+
      | Error | 1292 | Truncated incorrect DOUBLE value: 'Ken' |
      +-------+------+-----------------------------------------+
      1 row in set (0.00 sec)
      

      This works without check constraints and I do not see why the insert should fail. And IF, at least the error message is nonsense...
      Docu states that most deterministic functions work.

      Attachments

        Activity

          oli Oli Sennhauser created issue -
          elenst Elena Stepanova made changes -
          Field Original Value New Value
          Description CREATE TABLE Employees (
            EmployeeID SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
          , FirstName VARCHAR(30) NOT NULL CHECK (CHAR_LENGTH(FirstName > 2))
          , LastName VARCHAR(40) NOT NULL
          , Title VARCHAR(50) NOT NULL CHECK (Title != 'God')
          , DeptID SMALLINT UNSIGNED NOT NULL
          , ManagerID INT UNSIGNED NULL
          , Salary DECIMAL(38) DEFAULT 0.0 CHECK (Salary < 10000.0)
          , CONSTRAINT c_deptid CHECK (DeptID > 0)
          );

          root@ma-102-master [test] SQL> INSERT INTO Employees VALUES
              -> (1, 'Ken', 'Sánchez', 'Chief Executive Officer',16,NULL, 9999)
              -> ,(273, 'Brian', 'Welcker', 'Vice President of Sales',3,1, 8000)
              -> ;
          ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'Ken'
          root@ma-102-master [test] SQL> INSERT INTO Employees VALUES (1, 'Ken', 'Sánchez', 'Chief Executive Officer',16,NULL, 9999) ;
          Query OK, 1 row affected, 1 warning (0.00 sec)

          root@ma-102-master [test] SQL> show warnings;
          +-------+------+-----------------------------------------+
          | Level | Code | Message |
          +-------+------+-----------------------------------------+
          | Error | 1292 | Truncated incorrect DOUBLE value: 'Ken' |
          +-------+------+-----------------------------------------+
          1 row in set (0.00 sec)

          This works without check constraints and I do not see why the insert should fail. And IF, at least the error message is nonsense...
          Docu states that most deterministic functions work.
          {code:sql}
          CREATE TABLE Employees (
            EmployeeID SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
          , FirstName VARCHAR(30) NOT NULL CHECK (CHAR_LENGTH(FirstName > 2))
          , LastName VARCHAR(40) NOT NULL
          , Title VARCHAR(50) NOT NULL CHECK (Title != 'God')
          , DeptID SMALLINT UNSIGNED NOT NULL
          , ManagerID INT UNSIGNED NULL
          , Salary DECIMAL(38) DEFAULT 0.0 CHECK (Salary < 10000.0)
          , CONSTRAINT c_deptid CHECK (DeptID > 0)
          );
          {code}
          {code:sql}
          root@ma-102-master [test] SQL> INSERT INTO Employees VALUES
              -> (1, 'Ken', 'Sánchez', 'Chief Executive Officer',16,NULL, 9999)
              -> ,(273, 'Brian', 'Welcker', 'Vice President of Sales',3,1, 8000)
              -> ;
          ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'Ken'
          root@ma-102-master [test] SQL> INSERT INTO Employees VALUES (1, 'Ken', 'Sánchez', 'Chief Executive Officer',16,NULL, 9999) ;
          Query OK, 1 row affected, 1 warning (0.00 sec)

          root@ma-102-master [test] SQL> show warnings;
          +-------+------+-----------------------------------------+
          | Level | Code | Message |
          +-------+------+-----------------------------------------+
          | Error | 1292 | Truncated incorrect DOUBLE value: 'Ken' |
          +-------+------+-----------------------------------------+
          1 row in set (0.00 sec)
          {code}

          This works without check constraints and I do not see why the insert should fail. And IF, at least the error message is nonsense...
          Docu states that most deterministic functions work.
          elenst Elena Stepanova made changes -
          Labels need_feedback
          elenst Elena Stepanova made changes -
          Labels need_feedback
          elenst Elena Stepanova made changes -
          Labels need_feedback
          elenst Elena Stepanova made changes -
          Labels need_feedback
          elenst Elena Stepanova made changes -
          Status Open [ 1 ] Confirmed [ 10101 ]
          elenst Elena Stepanova made changes -
          Fix Version/s 10.2 [ 14601 ]
          Fix Version/s 10.3 [ 22126 ]
          Affects Version/s 10.2 [ 14601 ]
          Affects Version/s 10.3 [ 22126 ]
          Assignee Michael Widenius [ monty ]
          elenst Elena Stepanova made changes -
          Summary Check Constraints makes insert invalid Check Constraints with binary logging makes insert inconsistent
          monty Michael Widenius made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]
          monty Michael Widenius made changes -
          issue.field.resolutiondate 2018-05-15 14:14:09.0 2018-05-15 14:14:09.83
          monty Michael Widenius made changes -
          Component/s Data Manipulation - Insert [ 10101 ]
          Component/s Data Definition - Alter Table [ 10114 ]
          Fix Version/s 10.2.15 [ 23006 ]
          Fix Version/s 10.3.7 [ 23005 ]
          Fix Version/s 10.2 [ 14601 ]
          Fix Version/s 10.3 [ 22126 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 85817 ] MariaDB v4 [ 153893 ]

          People

            monty Michael Widenius
            oli Oli Sennhauser
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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