refactor: refs #7486 engine memory and primary key sales_merge
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-06-11 07:59:53 +02:00
parent 75a529830c
commit bd13ecd464
1 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,5 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sales_merge`(vTicketFk INT) CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sales_merge`(vTicketFk INT)
BEGIN BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN BEGIN
@ -8,19 +8,21 @@ BEGIN
END; END;
CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity SELECT s.id, s.itemFk, SUM(s.quantity) newQuantity
FROM sale s FROM sale s
JOIN item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN itemType it ON it.id = i.typeFk JOIN itemType it ON it.id = i.typeFk
WHERE s.ticketFk = vTicketFk WHERE s.ticketFk = vTicketFk
AND it.isMergeable AND it.isMergeable
GROUP BY s.itemFk, s.price, s.discount; GROUP BY s.itemFk, s.price, s.discount;
START TRANSACTION; START TRANSACTION;
UPDATE sale s UPDATE sale s
JOIN tSalesToPreserve stp ON stp.id = s.id JOIN tSalesToPreserve stp ON stp.id = s.id
SET quantity = newQuantity SET s.quantity = newQuantity
WHERE s.ticketFk = vTicketFk; WHERE s.ticketFk = vTicketFk;
DELETE s.* DELETE s.*
@ -35,5 +37,5 @@ BEGIN
COMMIT; COMMIT;
DROP TEMPORARY TABLE tSalesToPreserve; DROP TEMPORARY TABLE tSalesToPreserve;
END$$ END$$
DELIMITER ; DELIMITER ;