fix: refs #6421 worker_getHierarchy infinite loop
This commit is contained in:
parent
4dd70ccc69
commit
e3c92c3644
|
@ -1,5 +1,7 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`worker_getHierarchy`(vUserFk INT)
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`worker_getHierarchy`(
|
||||
vUserFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Retorna una tabla temporal con los trabajadores que tiene
|
||||
|
@ -12,15 +14,16 @@ BEGIN
|
|||
(PRIMARY KEY (workerFk))
|
||||
ENGINE = MEMORY
|
||||
WITH RECURSIVE workerHierarchy AS (
|
||||
SELECT id workerFk, bossFk, 0 depth
|
||||
SELECT id workerFk, bossFk, 0 `depth`, CAST(id AS CHAR(255)) `path`
|
||||
FROM vn.worker
|
||||
WHERE id = vUserFk
|
||||
UNION ALL
|
||||
SELECT w.id, w.bossFk, wh.depth + 1
|
||||
SELECT w.id, w.bossFk, wh.`depth` + 1, CONCAT(wh.`path`, ',', w.id)
|
||||
FROM vn.worker w
|
||||
JOIN workerHierarchy wh ON w.bossFk = wh.workerFk
|
||||
WHERE NOT FIND_IN_SET(w.id, wh.`path`)
|
||||
)
|
||||
SELECT *
|
||||
SELECT *
|
||||
FROM workerHierarchy
|
||||
ORDER BY depth, workerFk;
|
||||
END$$
|
||||
|
|
Loading…
Reference in New Issue