pooleleven
Benutzer
- Beiträge
- 8
Hallo,
ich habe da eine StoredProceduer, mit der wir aus einer ParentChild-Liste eine NestedSet Liste zaubern. Diese funktioniert seit vielen Jährchen auf MySQL-Servern. Nun jedoch wurden wir mit einer MariaDB zwangsbeglückt und haben da ein letztes Problem. Die SP wird zwar ohne Probleme bei Speichern akzeptiert, benötigt aber über 10 Minuten (wenn Maria das überhaupt schafft), während es bei MySQL ca. 15-25Sekunden waren. Bei gleichem Datenumfang und vergleichbaren ServerKonfigurationen.
DECLARE currentId, currentParentId CHAR(36);
DECLARE currentLeft INT;
DECLARE startId INT DEFAULT 1;
SET max_heap_table_size = 1024 * 1024 * 512;
START TRANSACTION;
DROP TABLE IF EXISTS `tmp_tree_webcat`;
SET @rownum=0;
CREATE TABLE `tmp_tree_webcat` (
`id_kategorie` BIGINT(36) NOT NULL DEFAULT '0',
`mutter_id` CHAR(36) DEFAULT NULL,
`left_m` INT(11) UNSIGNED DEFAULT NULL,
`right_m` INT(11) UNSIGNED DEFAULT NULL,
`row_number` INT(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`id_kategorie`),
INDEX USING HASH (`mutter_id`),
INDEX USING HASH (`left_m`),
INDEX USING HASH (`right_m`)
) ENGINE=MEMORY
SELECT `fashop2_web_platformkategorie`.`id_kategorie`,
`fashop2_web_platformkategorie`.`mutter_id`,
`fashop2_web_platformkategorie`.`left_m`,
`fashop2_web_platformkategorie`.`right_m`,
@rownum := @rownum + 1 AS ROW_NUMBER
FROM `fashop2_web_platformkategorie`
WHERE fashop2_web_platformkategorie.kategorie_art = 'kategorie'
ORDER BY fashop2_web_platformkategorie.kategoriegruppe_id, fashop2_web_platformkategorie.reihenfolge
;
UPDATE `tmp_tree_webcat`
SET `left_m` = NULL,
`right_m` = NULL;
WHILE EXISTS (SELECT * FROM `tmp_tree_webcat` WHERE `mutter_id` = 0 AND `left_m` IS NULL AND `right_m` IS NULL ORDER BY `row_number` LIMIT 1) DO
UPDATE `tmp_tree_webcat`
SET `left_m` = startId,
`right_m` = startId + 1
WHERE `mutter_id` = 0
AND `left_m` IS NULL
AND `right_m` IS NULL
ORDER BY `row_number` ASC
LIMIT 1;
SET startId = startId + 2;
END WHILE;
DROP INDEX `left_m` ON `tmp_tree_webcat`;
DROP INDEX `right_m` ON `tmp_tree_webcat`;
CREATE INDEX `left_m` USING BTREE ON `tmp_tree_webcat` (`left_m`);
CREATE INDEX `right_m` USING BTREE ON `tmp_tree_webcat` (`right_m`);
WHILE EXISTS (SELECT * FROM `tmp_tree_webcat` WHERE `left_m` IS NULL ORDER BY `row_number` LIMIT 1) DO
SELECT `tmp_tree_webcat`.`id_kategorie`
INTO currentId
FROM `tmp_tree_webcat`
INNER JOIN `tmp_tree_webcat` AS `parents`
ON `tmp_tree_webcat`.`mutter_id` = `parents`.`id_kategorie`
WHERE `tmp_tree_webcat`.`left_m` IS NULL
AND `parents`.`left_m` IS NOT NULL
ORDER BY `tmp_tree_webcat`.`row_number` DESC
LIMIT 1;
SELECT `mutter_id`
INTO currentParentId
FROM `tmp_tree_webcat`
WHERE `id_kategorie` = currentId;
SELECT `left_m`
INTO currentLeft
FROM `tmp_tree_webcat`
WHERE `id_kategorie` = currentParentId;
UPDATE `tmp_tree_webcat`
SET `right_m` = `right_m` + 2
WHERE `right_m` > currentLeft;
UPDATE `tmp_tree_webcat`
SET `left_m` = `left_m` + 2
WHERE `left_m` > currentLeft;
UPDATE `tmp_tree_webcat`
SET `left_m` = currentLeft + 1,
`right_m` = currentLeft + 2
WHERE `id_kategorie` = currentId;
END WHILE;
UPDATE `fashop2_web_platformkategorie`, `tmp_tree_webcat`
SET `fashop2_web_platformkategorie`.`left_m` = `tmp_tree_webcat`.`left_m`,
`fashop2_web_platformkategorie`.`right_m` = `tmp_tree_webcat`.`right_m`
WHERE `fashop2_web_platformkategorie`.`id_kategorie` = `tmp_tree_webcat`.`id_kategorie`;
COMMIT;
DROP TABLE IF EXISTS `tmp_tree_webcat`;
MariaDB-Version:
10.2.18-MariaDB-cll-lve - MariaDB Server
Hat jemand einen Ansatz, warum es hier so eklatante Unterschiede gibt? Ich bin am Ende meines Lateins.
LG
ich habe da eine StoredProceduer, mit der wir aus einer ParentChild-Liste eine NestedSet Liste zaubern. Diese funktioniert seit vielen Jährchen auf MySQL-Servern. Nun jedoch wurden wir mit einer MariaDB zwangsbeglückt und haben da ein letztes Problem. Die SP wird zwar ohne Probleme bei Speichern akzeptiert, benötigt aber über 10 Minuten (wenn Maria das überhaupt schafft), während es bei MySQL ca. 15-25Sekunden waren. Bei gleichem Datenumfang und vergleichbaren ServerKonfigurationen.
DECLARE currentId, currentParentId CHAR(36);
DECLARE currentLeft INT;
DECLARE startId INT DEFAULT 1;
SET max_heap_table_size = 1024 * 1024 * 512;
START TRANSACTION;
DROP TABLE IF EXISTS `tmp_tree_webcat`;
SET @rownum=0;
CREATE TABLE `tmp_tree_webcat` (
`id_kategorie` BIGINT(36) NOT NULL DEFAULT '0',
`mutter_id` CHAR(36) DEFAULT NULL,
`left_m` INT(11) UNSIGNED DEFAULT NULL,
`right_m` INT(11) UNSIGNED DEFAULT NULL,
`row_number` INT(11) UNSIGNED DEFAULT NULL,
PRIMARY KEY (`id_kategorie`),
INDEX USING HASH (`mutter_id`),
INDEX USING HASH (`left_m`),
INDEX USING HASH (`right_m`)
) ENGINE=MEMORY
SELECT `fashop2_web_platformkategorie`.`id_kategorie`,
`fashop2_web_platformkategorie`.`mutter_id`,
`fashop2_web_platformkategorie`.`left_m`,
`fashop2_web_platformkategorie`.`right_m`,
@rownum := @rownum + 1 AS ROW_NUMBER
FROM `fashop2_web_platformkategorie`
WHERE fashop2_web_platformkategorie.kategorie_art = 'kategorie'
ORDER BY fashop2_web_platformkategorie.kategoriegruppe_id, fashop2_web_platformkategorie.reihenfolge
;
UPDATE `tmp_tree_webcat`
SET `left_m` = NULL,
`right_m` = NULL;
WHILE EXISTS (SELECT * FROM `tmp_tree_webcat` WHERE `mutter_id` = 0 AND `left_m` IS NULL AND `right_m` IS NULL ORDER BY `row_number` LIMIT 1) DO
UPDATE `tmp_tree_webcat`
SET `left_m` = startId,
`right_m` = startId + 1
WHERE `mutter_id` = 0
AND `left_m` IS NULL
AND `right_m` IS NULL
ORDER BY `row_number` ASC
LIMIT 1;
SET startId = startId + 2;
END WHILE;
DROP INDEX `left_m` ON `tmp_tree_webcat`;
DROP INDEX `right_m` ON `tmp_tree_webcat`;
CREATE INDEX `left_m` USING BTREE ON `tmp_tree_webcat` (`left_m`);
CREATE INDEX `right_m` USING BTREE ON `tmp_tree_webcat` (`right_m`);
WHILE EXISTS (SELECT * FROM `tmp_tree_webcat` WHERE `left_m` IS NULL ORDER BY `row_number` LIMIT 1) DO
SELECT `tmp_tree_webcat`.`id_kategorie`
INTO currentId
FROM `tmp_tree_webcat`
INNER JOIN `tmp_tree_webcat` AS `parents`
ON `tmp_tree_webcat`.`mutter_id` = `parents`.`id_kategorie`
WHERE `tmp_tree_webcat`.`left_m` IS NULL
AND `parents`.`left_m` IS NOT NULL
ORDER BY `tmp_tree_webcat`.`row_number` DESC
LIMIT 1;
SELECT `mutter_id`
INTO currentParentId
FROM `tmp_tree_webcat`
WHERE `id_kategorie` = currentId;
SELECT `left_m`
INTO currentLeft
FROM `tmp_tree_webcat`
WHERE `id_kategorie` = currentParentId;
UPDATE `tmp_tree_webcat`
SET `right_m` = `right_m` + 2
WHERE `right_m` > currentLeft;
UPDATE `tmp_tree_webcat`
SET `left_m` = `left_m` + 2
WHERE `left_m` > currentLeft;
UPDATE `tmp_tree_webcat`
SET `left_m` = currentLeft + 1,
`right_m` = currentLeft + 2
WHERE `id_kategorie` = currentId;
END WHILE;
UPDATE `fashop2_web_platformkategorie`, `tmp_tree_webcat`
SET `fashop2_web_platformkategorie`.`left_m` = `tmp_tree_webcat`.`left_m`,
`fashop2_web_platformkategorie`.`right_m` = `tmp_tree_webcat`.`right_m`
WHERE `fashop2_web_platformkategorie`.`id_kategorie` = `tmp_tree_webcat`.`id_kategorie`;
COMMIT;
DROP TABLE IF EXISTS `tmp_tree_webcat`;
MariaDB-Version:
10.2.18-MariaDB-cll-lve - MariaDB Server
Hat jemand einen Ansatz, warum es hier so eklatante Unterschiede gibt? Ich bin am Ende meines Lateins.
LG