Skip to content

Commit 5aed56d

Browse files
committed
Remove unique constraint from relations table.
This aligns with the removal of the unique constraint in the assets table. This will likely improve performance and avoid some deadlocks faced in production as shown below from the innodb status. *** (2) TRANSACTION: TRANSACTION 13224836, ACTIVE 2 sec inserting mysql tables in use 1, locked 1 908 lock struct(s), heap size 106616, 943 row lock(s), undo log entries 1951 MySQL thread id 4405, OS thread handle 140199291565824, query id 676173554 10.236.102.30 svc-criteokb Update INSERT INTO relations (id, from_id, to_id, type) VALUES (?, ?, ?, ?) *** (2) HOLDS THE LOCK(S): RECORD LOCKS space id 41 page no 34334 n bits 528 index unique_relation of table `criteokb`.`relations` trx id 13224836 lock_mode X locks rec but not gap Record lock, heap no 455 PHYSICAL RECORD: n_fields 4; compact format; info bits 0 0: len 8; hex e74f2e13ed67611d; asc O. ga ;; 1: len 8; hex 7a9f7cd5e9f8c4c0; asc z | ;; 2: len 3; hex 686173; asc has;; 3: len 8; hex 74af2536c993d1f2; asc t %6 ;;
1 parent db8440e commit 5aed56d

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

internal/database/mariadb.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ func (m *MariaDB) InitializeSchema() error {
8383
CONSTRAINT fk_from FOREIGN KEY (from_id) REFERENCES assets (id),
8484
CONSTRAINT fk_to FOREIGN KEY (to_id) REFERENCES assets (id),
8585
86-
UNIQUE unique_relation (from_id, to_id, type),
87-
8886
INDEX full_relation_type_from_to_idx (type, from_id, to_id),
8987
INDEX full_relation_type_to_from_idx (type, to_id, from_id),
9088
INDEX full_relation_from_type_to_idx (from_id, type, to_id),

0 commit comments

Comments
 (0)