[MDEV-32030] Error in restoring SQL dump with virtual columns after upgrade to version 10.6.15 Created: 2023-08-28 Updated: 2023-08-29 Resolved: 2023-08-29 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Virtual Columns |
| Affects Version/s: | 10.6.15 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Matteo Tassinari | Assignee: | Sergei Golubchik |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Ubuntu 22.04 |
||
| Issue Links: |
|
||||||||
| Description |
|
After upgrading to MariaDB 10.6.15 from 10.6.10, I tried restoring an SQL dump which worked on the previous version, but now fails with errors like:
Here is the table which generated the error:
if I change "STORED" to "VIRTUAL", I can then restore the SQL dump; however, I do not understand why a minor upgrade causes this problem. |
| Comments |
| Comment by Elena Stepanova [ 2023-08-28 ] | |||||||
|
Is it the exact statement you extracted from the dump line 512844? | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
Yes, it is the exact statement; there are also other similar statements (about 7-8) that failed like this. If I execute it manually on the client after failure, the behaviour is inconsistent: for some tables it still fails, for other it works. For example, I just tried executing the following statement from the client: CREATE TABLE `lin_98_68_persone_TEST` ( and it worked, even though the generated column is marked as "STORED" and refers columns later in the definition | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
I have also noticed that other statements previously working, now fail, for example: ALTER TABLE lin_98_67_cartelle_cliniche This is a statement taken from our software update procedure; when applied on version 10.6.10 it works correctly, now that I have update to 10.6.15 it no longer works unless I change the computed columns from PERSISTENT to VIRTUAL. While from a functional perspective I think VIRTUAL and STORED are almost equivalent for our use case, from a performance perspective I think it'd be much better to have the computed value stored instead of it being re-computed each and every time. | |||||||
| Comment by Elena Stepanova [ 2023-08-29 ] | |||||||
We cannot comment on statements or on tables which we cannot see. So, back to the statement from the description, do you mean it works for you when you execute it manually, but fails when you run it in the dump? | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
That SQL dump does not contain sensitive data per-se, however it is a backup with the full database structure of our application, and as such I really cannot upload it to a public bug tracker. Would it be ok if I sent it to you by direct e-mail instead? I would really need this file not to be available on the public web. | |||||||
| Comment by Elena Stepanova [ 2023-08-29 ] | |||||||
|
You can upload it to the private section of MariaDB FTP server: If you don't feel comfortable to do it however, please don't send it to me by email either, it's the liability I can't take upon myself. An even better option would be if you could extract a minimal part of the dump which you can share and which still fails when it's executed as a whole. As we apparently established, the single statement doesn't fail, so there must be something in that dump which causes the error, possibly some system variables (mysqldump sets quite a lot of them), either by themselves or in combination with the configuration of your server. | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
I am uploading a 7z archive on the FTP server which contains:
I have just tested the restore again: root@TMA-21 ~ root@TMA-21 ~ The upload should be completed in ~10 minutes. | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
I would like to add, this is the exact version I have installed: mysql Ver 15.1 Distrib 10.6.15-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
Finally (and sorry for the many comments), I just downgraded to mysql Ver 15.1 Distrib 10.6.13-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper and now the dump loads correctly with the exact same settings. | |||||||
| Comment by Elena Stepanova [ 2023-08-29 ] | |||||||
|
Thank you, the dump was very helpful. The change was made in the scope of
Before the change, the structures were allowed in MariaDB, but as | |||||||
| Comment by Matteo Tassinari [ 2023-08-29 ] | |||||||
|
So, the end result is, if I understand correctly, that you cannot have a STORED computed column based on a field part of a foreign key defined with ON UPDATE CASCADE, right? I guess that, if this is intended, we'd need to re-define all those virtual columns.... | |||||||
| Comment by Elena Stepanova [ 2023-08-29 ] | |||||||
|
Sorry I pasted a wrong sample before, fixed now. I do suppose that it was intentional, because the assumption is, if a user defines the virtual column and the foreign key this way, they expect them to work properly; so, if it's not possible, then the definition shouldn't be allowed. It is very unfortunate that it breaks the backward compatibility, we of course try to avoid it, but it's still better than to allow it produce erroneous results silently. | |||||||
| Comment by Sergei Golubchik [ 2023-08-29 ] | |||||||
|
If it's due to foreign keys then yes, indeed, it is intentional. The way MariaDB works, and always did, foreign key cascading actions are applied to child tables on a very low level where the server cannot update STORED generated column values anymore. In other words, if a STORED generated column depends on a column that can be modified via a cascade action, this STORED column can become out of sync with other columns. Basically, it'll have an incorrect value. That's why such a table structure is no longer allowed. We're planning to lift this restriction. MDEV-31942 (or MDEV-22361) when implemented, will allow us to recalculate STORED generated columns on UPDATE CASCADE and SET NULL actions. Note that ON DELETE CASCADE is fine, it's allowed, because it doesn't modify individual columns, but deletes the complete row. |