2

This is a minimal example that triggers the error

CREATE TABLE A (
  id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY
);

CREATE TABLE B (
  what tinyint NOT NULL,

  a bigint NOT NULL,

  CONSTRAINT x FOREIGN KEY (a) REFERENCES A(id),
  CONSTRAINT y CHECK (what > 0)
);


SELECT b.a FROM B b;

ALTER TABLE B DROP CONSTRAINT x;

When i run this in a fresh MariaDB instance (docker mariadb:10.3.28) everything works fine.

When MariaDB 10.3.29 was released the query suddenly broke. So, when i run this in a fresh MariaDB instance (docker mariadb:10.3.29) i get the following error message for the last statement:

[42S22][1054] (conn=8) Unknown column '`db`.`b`.`what`' in 'CHECK'

Some weird observations:

  • if i delete the y check and add it after dropping x everything works
  • if i remove the SELECT everything works
  • the b from the error message changes with the table alias from the SELECT statement
  • running the last statement again shows the same error
  • the error message makes no sense at all

So my question: what's wrong with my SQL?

5
  • sorry, yes, the error message also contains what
    – Wombatz
    Commented May 19, 2021 at 12:41
  • Reproduced. dbfiddle.uk/… If uncomment then the error dissapears. Seems to be a bug.
    – Akina
    Commented May 19, 2021 at 12:49
  • @Akina but this works: dbfiddle.uk/… Weird Commented May 19, 2021 at 13:12
  • @ypercubeᵀᴹ In my fiddle the insertion fixes the issue too. Even errorneous insertion (with incorrect what) or insertion into non-existent table fixes (insertion into A - not fixes).
    – Akina
    Commented May 19, 2021 at 13:15
  • 2
    this shoulb be a bug report
    – nbk
    Commented May 19, 2021 at 13:30

1 Answer 1

1

This is actually a bug in MariaDB. See the bugtracker.

They recommended to do FLUSH TABLES; before the ALTER statement.

I can confirm that this "hides the bug".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.