fix: refs #6421 worker_getHierarchy infinite loop
This commit is contained in:
parent
4dd70ccc69
commit
e3c92c3644
|
@ -1,5 +1,7 @@
|
||||||
DELIMITER $$
|
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
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Retorna una tabla temporal con los trabajadores que tiene
|
* Retorna una tabla temporal con los trabajadores que tiene
|
||||||
|
@ -12,13 +14,14 @@ BEGIN
|
||||||
(PRIMARY KEY (workerFk))
|
(PRIMARY KEY (workerFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH RECURSIVE workerHierarchy AS (
|
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
|
FROM vn.worker
|
||||||
WHERE id = vUserFk
|
WHERE id = vUserFk
|
||||||
UNION ALL
|
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
|
FROM vn.worker w
|
||||||
JOIN workerHierarchy wh ON w.bossFk = wh.workerFk
|
JOIN workerHierarchy wh ON w.bossFk = wh.workerFk
|
||||||
|
WHERE NOT FIND_IN_SET(w.id, wh.`path`)
|
||||||
)
|
)
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM workerHierarchy
|
FROM workerHierarchy
|
||||||
|
|
Loading…
Reference in New Issue