fix: refs #7126 Slow update
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-07-19 14:29:20 +02:00
parent ca48c64163
commit 05598b3371
1 changed files with 15 additions and 2 deletions

View File

@ -1,8 +1,21 @@
ALTER TABLE bs.waste ADD buyerFk int(10) unsigned NOT NULL;
CREATE OR REPLACE TEMPORARY TABLE tBuyers
ENGINE = MEMORY
WITH tDistinctBuyers AS (
SELECT DISTINCT buyer
FROM bs.waste w
)
SELECT buyer, u.id
FROM tDistinctBuyers tdb
JOIN account.`user` u ON u.name = tdb.buyer COLLATE utf8mb3_unicode_ci
UPDATE bs.waste w
JOIN account.`user` u ON u.name = w.buyer COLLATE utf8mb3_unicode_ci
SET w.buyerFk = u.id;
JOIN tBuyers tb ON tb.buyer = w.buyer
SET w.buyerFk = tb.id;
DROP TEMPORARY TABLE tBuyers;
ALTER TABLE bs.waste
DROP PRIMARY KEY,