17 lines
507 B
MySQL
17 lines
507 B
MySQL
|
-- Place your SQL code here
|
||
|
USE vn;
|
||
|
CREATE INDEX IF NOT EXISTS ticketLog_creationDate_IDX
|
||
|
USING BTREE ON vn.ticketLog (creationDate); -- 10m
|
||
|
|
||
|
DELETE tl
|
||
|
FROM vn.ticketLog tl
|
||
|
JOIN vn.ticket t ON t.id = tl.originFk
|
||
|
WHERE tl.creationDate <= util.VN_CURDATE() + INTERVAL -5 YEAR
|
||
|
AND t.shipped IS NOT NULL; -- 400000 rows
|
||
|
|
||
|
DELETE tl
|
||
|
FROM vn.ticketLog tl
|
||
|
JOIN vn.ticket t ON t.id = tl.originFk
|
||
|
WHERE t.isDeleted; -- 113574 rows
|
||
|
|
||
|
OPTIMIZE TABLE vn.ticketLog; -- 17m 35s
|