 
 CREATE INDEX idx_domain_cc
    ON domain_snomed (concept_code);
+   
 
 UPDATE concept_stage c
    SET c.domain_id =

                          WHERE     a.ancestor_concept_code = p.peak_code
                                AND p.ranked = A.ranked) child
                  WHERE child.concept_code = d.concept_code)
       WHERE d.concept_code IN (SELECT a.descendant_concept_code
                                  FROM peak p, snomed_ancestor a
                                 WHERE     a.ancestor_concept_code = p.peak_code);
   END LOOP;

   COMMIT;
END;

-- Check orphans whether they contain mixed children with different multiple concept_class_ids or domains. 
-- If they have mixed children, the concept_class_id-based heuristic might create problems



-- 5. Start building domains, preassign all them with "Not assigned"
DROP TABLE domain_snomed purge;

CREATE TABLE domain_snomed
AS
   SELECT concept_code, CAST ('Not assigned' AS VARCHAR2 (20)) AS domain_id
