[MDEV-32729] look at SET FOREIGN_KEY_CHECK=0 Created: 2023-11-08 Updated: 2023-11-19 Resolved: 2023-11-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table |
| Affects Version/s: | None |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | mark f edwards | Assignee: | Marko Mäkelä |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Comments |
| Comment by mark f edwards [ 2023-11-08 ] | |||||||
|
i have a procedure i run quite regularly that uses this syntax: SET FOREIGN_KEY_CHECKS=0; but today when i upgraded from 10.5.13 to Server version: 10.5.22-MariaDB MariaDB Server suddenly i keep getting this error: ERROR 1833 (HY000) at line 9: Cannot change column 'xx': used in a foreign key constraint 'xx' of table 'xx.xx' this is how i solved the issue several years ago as per stackexchange so today i tried this stackoverflow suggestion instead: SET FOREIGN_KEY_CHECKS = 0; and that did not fix it. any thoughts or suggestions? has anybody else experienced that FOREIGN_KEY_CHECKS does not appear to disable anymore? | |||||||
| Comment by Marko Mäkelä [ 2023-11-08 ] | |||||||
|
MariaDB Server 10.5.22 includes a fix of | |||||||
| Comment by Marko Mäkelä [ 2023-11-09 ] | |||||||
|
Does the approach that is described in | |||||||
| Comment by mark f edwards [ 2023-11-09 ] | |||||||
|
hi - thanks for following up. i am currrently on the road and have not studied the solution. however, i am not really altering the key at all, but rather just "moving" the column around with the BEFORE or AFTER suffix: ALTER TABLE MODIFY COLUMN...... *AFTER *column-name; so, i am wondering it it would be better for me to just move one of the non-key columns instead. side-note: i am surprised there is not a much easier way to move an index column. but maybe this is a stack-overflow question (except they keep down-voting me) | |||||||
| Comment by Marko Mäkelä [ 2023-11-09 ] | |||||||
|
Once you have a chance to post a self-contained test case (starting with CREATE TABLE), I should be able to help with an alternative solution. For the record, | |||||||
| Comment by mark f edwards [ 2023-11-16 ] | |||||||
|
hello - first off, THANK YOU for your patience with me. it appears when switching from 10.5.13 to 10.5.22, there is a new rule being enforced that was not previously enforced. i have switched back & forth between 5.13 and 5.22, and somehow the error does not show up in 5.13. the error of course is pure carelessness on my part, but i am still surprised this error was not caught *much *earlier. my installation instructions: /home/mark/mariadb_repo_setup --mariadb-server-version="mariadb-10.5.22" ; dnf -y install mariadb-server ; systemctl start mariadb.service ; mariadb --verbose < ./myTestScript.sql ; ## shows error systemctl stop mariadb.service ; dnf --assumeyes remove mariadb-server ; /home/mark/mariadb_repo_setup --mariadb-server-version="mariadb-10.5.13" ; dnf -y install mariadb-server ; systemctl start mariadb.service ; ./myTestScript.sql below: DROP DATABASE IF EXISTS comptonTransAnlys ; – MariaDB dump 10.19 Distrib 10.5.13-MariaDB, for Linux (x86_64) /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; – DROP TABLE IF EXISTS `stimwordPosition`; CREATE TABLE `stimwordPosition` ( DROP TABLE IF EXISTS `clientStimword`; `stimwordPositionAutoIncr` mediumint(10) NOT NULL, `clientStimwordAutoIncr` int(10) unsigned NOT NULL AUTO_INCREMENT, KEY `stimwordPositionAutoIncr_2_clientStimword` (`stimwordPositionAutoIncr`), ) ENGINE=InnoDB AUTO_INCREMENT=8288165 DEFAULT CHARSET=latin1; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; – Dump completed on 2023-11-16 15:25:55 SET FOREIGN_KEY_CHECKS=0; /*this can be fixed by changing UNSIGNED to SIGNED! */ SET FOREIGN_KEY_CHECKS=1 ; | |||||||
| Comment by Marko Mäkelä [ 2023-11-17 ] | |||||||
|
edwardsmarkf, thank you for the clarification. The last ALTER TABLE statement in your comment is not only moving the position of the column in the table definition (for things like SELECT * FROM clientStimword) but also changing the data type from MEDIUMINT (signed by default) to MEDIUMINT UNSIGNED. This would never be allowed via the native ALTER TABLE of InnoDB, because it does not implement any data format conversions, apart from adding or removing NOT NULL, extending VARCHAR or changing some character set encodings to compatible ones. It would use ALGORITHM=COPY a.k.a. copy_data_between_tables(). Before the fix of | |||||||
| Comment by Marko Mäkelä [ 2023-11-17 ] | |||||||
|
I remember from my time at Oracle when implementing online ALTER TABLE for InnoDB in MySQL 5.6 that people (including myself) would complain that the ALTER TABLE…CHANGE COLUMN and ALTER TABLE…MODIFY COLUMN are error-prone because they force the entire data type definition to be duplicated. Even a small difference, such as forgetting or adding NOT NULL or UNSIGNED would cause the column data type to be changed, if the intention was to only rename the column. I think that CHANGE COLUMN differs from MODIFY only by the need to specify a possibly new name for the column. MariaDB got RENAME COLUMN ( serg, since you are familiar with the SQL standard, maybe you could comment on whether it would make sense to introduce ALTER TABLE…MOVE COLUMN name ⟦AS new_name⟧ ⟮FIRST|AFTER col_name⟯ syntax. | |||||||
| Comment by Sergei Golubchik [ 2023-11-19 ] | |||||||
|
There is no "MOVE COLUMN" in the standard, there are (reverse-engineered from BNF, omitting features we don't have):
So, MOVE doesn't exist, although if we'd wanted to add it, a standard-alike syntax could've been
|