 
 system echo "=========================== DONE ==========================="
 
-
+***/
+
+

CALL getFullNodeInfo( "mostRecentCommonAncestor_ids", "mostRecentCommonAncestor_info" );
SELECT * FROM mostRecentCommonAncestor_info;

***/



system echo "=========================== TREE DEFINITION ==========================="

SET @calibrationID = 104;  /* 106 */
DROP TEMPORARY TABLE IF EXISTS testHints;
CREATE TEMPORARY TABLE testHints ENGINE=memory AS (SELECT * FROM node_definitions WHERE calibration_id = @calibrationID);



CREATE TEMPORARY TABLE tmp ENGINE=memory SELECT * FROM hier;

the_loop:WHILE NOT v_done DO

    -- SELECT v_depth, (SELECT COUNT(*) FROM hier), (SELECT COUNT(*) FROM tmp);

    SET v_depth = v_depth + 1;          

    IF limitDepth IS NOT NULL THEN
        IF v_depth > limitDepth THEN
	    SET v_done = 1;
	    LEAVE the_loop;
        END IF;
    END IF;

    IF EXISTS( SELECT 1 FROM multitree p INNER JOIN hier ON p.parent_node_id = hier.node_id AND hier.depth = (v_depth - 1)) THEN

        INSERT INTO hier 
            SELECT p.node_id, p.parent_node_id, v_depth FROM multitree p 
            INNER JOIN tmp ON p.parent_node_id = tmp.node_id AND tmp.depth = v_depth - 1;

	-- stash this depth's results into tmp, for comparison next time
        TRUNCATE TABLE tmp;
        INSERT INTO tmp SELECT * FROM hier WHERE depth = v_depth;

    ELSE
        SET v_done = 1;
    END IF;

END WHILE;
 
-- SELECT '======== FINAL COUNTS ========';
-- SELECT v_depth, (SELECT COUNT(*) FROM hier), (SELECT COUNT(*) FROM tmp);

-- put resulting values into 'tmp' so we can rename+preserve them
TRUNCATE TABLE tmp;
INSERT INTO tmp SELECT DISTINCT
 p.node_id,
 b.node_id AS parent_node_id,
