-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Error occurs when using --innodb-optimize-keys and there is a column having a foreign key and part of a generated column #395
Comments
(Other than this minor issue, kudos for the |
Hi @Zombaya, Thanks for file this bug as --innodb-optimize-keys is one of the latest and most important feature, but it is also the one that has receive a lot of changes. Can you check/compile the master version? as v0.10.7 was an earlier release with this feature and v0.10.9 we slightly change it to fix several issues. |
I was able to compile the master-version (a330520) and reproduce the issue. Log
|
@davidducos, as a heads-up, I'm using MariaDB, not mysql. I forgot to mention it before. I've edited the original post as well. Version: mysql Ver 15.1 Distrib 10.4.20-MariaDB, for Linux (x86_64) |
Hi @Zombaya, This is my test case:
Then I'm exporting and exporting the database:
I see no error on PS 5.7. It might be affecting only to MariaDB. I will be installing a MariaDB and test again. |
@davidducos , with your script I'm unable to reproduce the issue so something is different. I'll try to modify the script to see what I need to change to make it fail and post my findings. |
@davidducos , the script you provided, used a virtual generated column. When using this, the problem also did not occur on my end. I was using a stored generated column, meaning the data about it will be stored on disk instead of calculated every time the data is requested. DROP DATABASE `issues_395`;
CREATE DATABASE IF NOT EXISTS `issues_395` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `issues_395`;
CREATE TABLE `offices` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`office_id` int(11) DEFAULT NULL,
`slogan` varchar(64) GENERATED ALWAYS AS (concat('Hello office #',`office_id`)) STORED,
CONSTRAINT `users_FK` FOREIGN KEY (`office_id`) REFERENCES `offices` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `offices` (`id`) VALUES
(1),
(2);
INSERT INTO `users` (`office_id`) VALUES
(1),
(1),
(1),
(2);
SELECT * FROM offices;
+----+
| id |
+----+
| 1 |
| 2 |
+----+
SELECT * FROM users;
+----+-----------+-----------------+
| id | office_id | slogan |
+----+-----------+-----------------+
| 1 | 1 | Hello office #1 |
| 2 | 1 | Hello office #1 |
| 3 | 1 | Hello office #1 |
| 4 | 2 | Hello office #2 |
+----+-----------+-----------------+ Exporting and importing
|
I checked with MariaDB 10.4.21 and it is not failing. Can you execute myloader with general_log = ON and upload the file? Thanks! |
I added the The mariadb-general.log as requested. |
Hi @Zombaya, I installed MariaDB 10.4.20, as I thought that it might be a version related issue, but it is working too. Can you share the configuration file of the server? |
As requested, mariadb-server.cnf.txt. For as for as I'm aware, the only thing that is non-default is the I'll try to toy around with docker to see if I'm able to reproduce it that way and see what influences the reproducibility. No idea when I will be able to work on this so I'm not able to specify a timespan for when you would be receiving more info from my end. Thanks for taking the time to look into it and super that it at least lead to fixing/finding another bug :-) |
I can reproduce this on a default installation of mariadb-10.3 on centos 8 following the database in this comment. Adding the constraint manually with: |
It fails due to FOREIGN_KEY_CHECKS=0 . If FOREIGN_KEY_CHECKS=1 then the ADD CONSTRAINT works correctly |
@fredricj @Zombaya Ooohhhhh!!!
and this is happening on Percona Server too. |
I found why my tests are working. |
I can offer 2 workarounds: or, you can wait until we implement #389 |
I created a bash-function for workaround 2. Functionfunction dontOptimizeInnoDBKeysForTablesWithStoredColumns()
{
DIRNAME="$1"
if [ -z "$DIRNAME" ]; then
echo "Please provide dirname of export to fix"
return 1
fi
if [ ! -d "$DIRNAME" ]; then
echo "Directory '$DIRNAME' does not exist"
return 1
fi
FILES=$(grep --with-filename --fixed-strings "STORED" -l "$DIRNAME"/*-schema.sql)
for FILE in $FILES
do
# echo "Fixing $FILE"
sed -i 's/^ CONSTRAINT/CONSTRAINT/g' "$FILE"
done
} Usage
🎉 for being able to continue for now and enjoying the speedboost for almost all tables. |
Describe the bug
There is a column, which has a foreign key relation to another table. It is also used in a generated column.
When importing the database using
--innodb-optimize-keys
, it will trigger an error:Error restoring database.table from file (null): Cannot add foreign key on the base column of stored column
.To Reproduce
Command executed:
mydumper -u root -a -B mydumper_bug_foreign_key_autogenerated
myloader -d export-20210812-092600/ -u root -a -B test_mydumper_import_3 --innodb-optimize-keys
Summary of database-structure
offices
users
offices.id
CONCAT('Hello world #',office_id)
Expected behavior
I expect the import to finish successfully.
When omitting the flag
--innodb-optimize-keys
, the import will be successful.Log
log.txt
Backup
mydumper-export.tar.gz
Environment
Additional information
For as far as I can see, all the data is actually imported, only the indexes are not applied for tables experiencing this kind of problem.
The text was updated successfully, but these errors were encountered: