/*postgresql OMOP CDM Indices

  There are no unique indices created because it is assumed that the primary key constraints have been run prior to
  implementing indices.
*/

/**************************

Standardized vocabularies

***************************/

CREATE INDEX idx_concept_concept_id  ON {{ schema }}.concept  (concept_id ASC);
CLUSTER {{ schema }}.concept  USING idx_concept_concept_id ;
CREATE INDEX idx_concept_code ON {{ schema }}.concept (concept_code ASC);
CREATE INDEX idx_concept_vocabluary_id ON {{ schema }}.concept (vocabulary_id ASC);
CREATE INDEX idx_concept_domain_id ON {{ schema }}.concept (domain_id ASC);
CREATE INDEX idx_concept_class_id ON {{ schema }}.concept (concept_class_id ASC);

CREATE INDEX idx_vocabulary_vocabulary_id  ON {{ schema }}.vocabulary  (vocabulary_id ASC);
CLUSTER {{ schema }}.vocabulary  USING idx_vocabulary_vocabulary_id ;

CREATE INDEX idx_domain_domain_id  ON {{ schema }}.domain  (domain_id ASC);
CLUSTER {{ schema }}.domain  USING idx_domain_domain_id ;

CREATE INDEX idx_concept_class_class_id  ON {{ schema }}.concept_class  (concept_class_id ASC);
CLUSTER {{ schema }}.concept_class  USING idx_concept_class_class_id ;

CREATE INDEX idx_concept_relationship_id_1  ON {{ schema }}.concept_relationship  (concept_id_1 ASC);
CLUSTER {{ schema }}.concept_relationship  USING idx_concept_relationship_id_1 ;
CREATE INDEX idx_concept_relationship_id_2 ON {{ schema }}.concept_relationship (concept_id_2 ASC);
CREATE INDEX idx_concept_relationship_id_3 ON {{ schema }}.concept_relationship (relationship_id ASC);

CREATE INDEX idx_relationship_rel_id  ON {{ schema }}.relationship  (relationship_id ASC);
CLUSTER {{ schema }}.relationship  USING idx_relationship_rel_id ;

CREATE INDEX idx_concept_synonym_id  ON {{ schema }}.concept_synonym  (concept_id ASC);
CLUSTER {{ schema }}.concept_synonym  USING idx_concept_synonym_id ;

CREATE INDEX idx_concept_ancestor_id_1  ON {{ schema }}.concept_ancestor  (ancestor_concept_id ASC);
CLUSTER {{ schema }}.concept_ancestor  USING idx_concept_ancestor_id_1 ;
CREATE INDEX idx_concept_ancestor_id_2 ON {{ schema }}.concept_ancestor (descendant_concept_id ASC);

CREATE INDEX idx_drug_strength_id_1  ON {{ schema }}.drug_strength  (drug_concept_id ASC);
CLUSTER {{ schema }}.drug_strength  USING idx_drug_strength_id_1 ;
CREATE INDEX idx_drug_strength_id_2 ON {{ schema }}.drug_strength (ingredient_concept_id ASC);


--Additional v6.0 indices

--CREATE CLUSTERED INDEX idx_survey_person_id_1 ON {{ schema }}.survey_conduct (person_id ASC);


--CREATE CLUSTERED INDEX idx_episode_person_id_1 ON {{ schema }}.episode (person_id ASC);
--CREATE INDEX idx_episode_concept_id_1 ON {{ schema }}.episode (episode_concept_id ASC);

--CREATE CLUSTERED INDEX idx_episode_event_id_1 ON {{ schema }}.episode_event (episode_id ASC);
--CREATE INDEX idx_ee_field_concept_id_1 ON {{ schema }}.episode_event (event_field_concept_id ASC);
