From 51a42062a7000825fc248258c778f65ffda089bc Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Fri, 2 Jun 2023 20:37:46 +0200 Subject: [PATCH] MT#56693 fix 15766.up improve parent_chain aggregation * use char based aggregation instead of JSON_ARRAY accumulation + REPLACE Change-Id: I5deb748637d2becc6d5aa6f598ba5a858b09b74b --- db_scripts/diff/15766.up | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/db_scripts/diff/15766.up b/db_scripts/diff/15766.up index c3a95b75..6e6fb7de 100644 --- a/db_scripts/diff/15766.up +++ b/db_scripts/diff/15766.up @@ -54,7 +54,7 @@ BEGIN WITH RECURSIVE cte as ( SELECT v.id AS set_id, v.handle_id, v.id AS data_set_id, - JSON_ARRAY(v.id) AS parent_chain + CAST('' AS CHAR(4096)) AS parent_chain FROM (SELECT s.*, h.id as handle_id FROM (voip_sound_sets s, voip_sound_handles h) ) AS v @@ -77,18 +77,16 @@ BEGIN UNION SELECT v.id AS set_id, v.handle_id, IF(f.use_parent = 0, v.id, cte.data_set_id) AS data_set_id, - JSON_ARRAY_INSERT(cte.parent_chain, "$[0]", v.id) AS parent_chain + CONCAT(v.parent_id, IF(cte.parent_chain, ':', ''), cte.parent_chain) as parent_chain FROM (SELECT s.*, h.id as handle_id, h.name as handle_name FROM (voip_sound_sets s, voip_sound_handles h) ) AS v LEFT JOIN voip_sound_files f ON f.handle_id = v.handle_id AND f.set_id = v.id JOIN cte ON cte.set_id = v.parent_id AND cte.handle_id = v.handle_id ) - SELECT set_id, handle_id, IF(data_set_id = set_id, NULL, data_set_id) as data_set_id, - REPLACE(REPLACE(REPLACE( - JSON_REMOVE(cte.parent_chain, "$[0]"), - "[", ""), "]", ""), ", ", ":" - ) AS parent_chain + SELECT set_id, handle_id, + IF(data_set_id = set_id, NULL, data_set_id) as data_set_id, + parent_chain FROM cte; ELSE IF u_handle_id IS NOT NULL THEN @@ -101,7 +99,7 @@ BEGIN WITH RECURSIVE cte as ( SELECT v.id AS set_id, v.handle_id, v.id AS data_set_id, - JSON_ARRAY(v.id) AS parent_chain + CAST('' AS CHAR(4096)) AS parent_chain FROM (SELECT s.*, h.id as handle_id FROM (voip_sound_sets s, voip_sound_handles h) ) AS v @@ -111,18 +109,16 @@ BEGIN UNION SELECT v.id AS set_id, v.handle_id, IF(f.use_parent = 0, v.id, cte.data_set_id) AS data_set_id, - JSON_ARRAY_INSERT(cte.parent_chain, "$[0]", v.id) AS parent_chain + CONCAT(v.parent_id, IF(cte.parent_chain, ':', ''), cte.parent_chain) as parent_chain FROM (SELECT s.*, h.id as handle_id, h.name as handle_name FROM (voip_sound_sets s, voip_sound_handles h) ) AS v LEFT JOIN voip_sound_files f ON f.handle_id = v.handle_id AND f.set_id = v.id JOIN cte ON cte.set_id = v.parent_id AND cte.handle_id = v.handle_id ) - SELECT set_id, handle_id, IF(data_set_id = set_id, NULL, data_set_id) as data_set_id, - REPLACE(REPLACE(REPLACE( - JSON_REMOVE(cte.parent_chain, "$[0]"), - "[", ""), "]", ""), ", ", ":" - ) AS parent_chain + SELECT set_id, handle_id, + IF(data_set_id = set_id, NULL, data_set_id) as data_set_id, + parent_chain FROM cte; END IF;