[MDEV-32840] Drop PK issues FK error (poorly), but is still is doing an alter table Created: 2023-11-19  Updated: 2023-12-01

Status: Open
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 11.1.2
Fix Version/s: 10.4, 10.6

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Nikita Malyavin
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Windows 10 22H2
Docker version 24.0.5, build ced0996
Docker Compose version v2.20.2-desktop.1
Docker-Compose-File: see Attachments

using MariaDB v. 11.1.2 with docker compose

Image information (uname -a):
Linux 23b7ba3f4fbc 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


Attachments: File docker-compose.yml     Text File docker.log     File dump.sql    
Issue Links:
Relates
relates to MDEV-32814 ALTER TABLE DROP PK crashes on WSL Open

 Description   

Hi everyone,

I am encountering the following problem:
I have a database which consists of three tables: users, abonnements, and user_abonnements. users and abonnements have unique IDs and user_abonnements is used to model the relation between users and abonnements (see attachment dump.sql). Until each abonnement should now have a starting date (validFrom) and an end date (validTo), I add two columns using the following queries to the table:

alter table user_abonnements
    add validFrom date not null;
 
alter table user_abonnements
    add validTo date null;

This works just fine. As a user can also subscribe to the same abonnement multiple times (after the first subscription has ended), I want to add "validFrom" to the primary key such that the columns userID, abonnementID, and validFrom are considered as the primary key. However, when trying to drop the current primary key (userID, abonnementID) of the table, the MariaDB-Server crashes (see docker.log) while executing the following query:

alter table user_abonnements
    drop primary key;

I think the server should return an error, stating that the primary key not be dropped because it is used for foreign keys instead of letting the server crash.



 Comments   
Comment by Daniel Black [ 2023-11-19 ]

nikitamalyavin fyi keeping this cloned task as the ALTER TABLE problem and using the original reporters one to extract what is wrong under WSL to generate assertion.

On the alter removing the PK.

Thread 2 hit Breakpoint 6, fk_check_column_changes (thd=<optimized out>, alter_info=alter_info@entry=0x7f796809fb50, 
 
fk_prepare_copy_alter_table (thd=thd@entry=0x7f7938001618, table=table@entry=0x7f79380644e8, alter_info=0x7f796809fb50, alter_ctx=alter_ctx@entry=0x7f796809dd60)
    at /home/dan/repos/mariadb-server-10.6/sql/sql_table.cc:9113
9113	    switch(changes)
(rr) p changes
$1 = FK_COLUMN_NO_CHANGE

Generated at Thu Feb 08 10:34:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.