MT#56693 fix 15766.up improve parent_chain aggregation

* use char based aggregation instead of JSON_ARRAY accumulation +
  REPLACE

Change-Id: I5deb748637d2becc6d5aa6f598ba5a858b09b74b
mr11.4
Kirill Solomko 3 years ago committed by Marco Capetta
parent da8defc504
commit 51a42062a7

@ -54,7 +54,7 @@ BEGIN
WITH RECURSIVE cte as ( WITH RECURSIVE cte as (
SELECT v.id AS set_id, v.handle_id, SELECT v.id AS set_id, v.handle_id,
v.id AS data_set_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 (SELECT s.*, h.id as handle_id
FROM (voip_sound_sets s, voip_sound_handles h) FROM (voip_sound_sets s, voip_sound_handles h)
) AS v ) AS v
@ -77,18 +77,16 @@ BEGIN
UNION UNION
SELECT v.id AS set_id, v.handle_id, SELECT v.id AS set_id, v.handle_id,
IF(f.use_parent = 0, v.id, cte.data_set_id) AS data_set_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 (SELECT s.*, h.id as handle_id, h.name as handle_name
FROM (voip_sound_sets s, voip_sound_handles h) FROM (voip_sound_sets s, voip_sound_handles h)
) AS v ) AS v
LEFT JOIN voip_sound_files f ON f.handle_id = v.handle_id AND f.set_id = v.id 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 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, SELECT set_id, handle_id,
REPLACE(REPLACE(REPLACE( IF(data_set_id = set_id, NULL, data_set_id) as data_set_id,
JSON_REMOVE(cte.parent_chain, "$[0]"), parent_chain
"[", ""), "]", ""), ", ", ":"
) AS parent_chain
FROM cte; FROM cte;
ELSE ELSE
IF u_handle_id IS NOT NULL THEN IF u_handle_id IS NOT NULL THEN
@ -101,7 +99,7 @@ BEGIN
WITH RECURSIVE cte as ( WITH RECURSIVE cte as (
SELECT v.id AS set_id, v.handle_id, SELECT v.id AS set_id, v.handle_id,
v.id AS data_set_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 (SELECT s.*, h.id as handle_id
FROM (voip_sound_sets s, voip_sound_handles h) FROM (voip_sound_sets s, voip_sound_handles h)
) AS v ) AS v
@ -111,18 +109,16 @@ BEGIN
UNION UNION
SELECT v.id AS set_id, v.handle_id, SELECT v.id AS set_id, v.handle_id,
IF(f.use_parent = 0, v.id, cte.data_set_id) AS data_set_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 (SELECT s.*, h.id as handle_id, h.name as handle_name
FROM (voip_sound_sets s, voip_sound_handles h) FROM (voip_sound_sets s, voip_sound_handles h)
) AS v ) AS v
LEFT JOIN voip_sound_files f ON f.handle_id = v.handle_id AND f.set_id = v.id 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 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, SELECT set_id, handle_id,
REPLACE(REPLACE(REPLACE( IF(data_set_id = set_id, NULL, data_set_id) as data_set_id,
JSON_REMOVE(cte.parent_chain, "$[0]"), parent_chain
"[", ""), "]", ""), ", ", ":"
) AS parent_chain
FROM cte; FROM cte;
END IF; END IF;

Loading…
Cancel
Save