@@ -128,55 +128,53 @@ BEGIN
128128 FROM (
129129 -- direct term references
130130 ( SELECT cd .depth AS depth
131- FROM component_depth cd
132- JOIN term_local_component_references cr
133- ON cd .component_hash_id = cr .component_hash_id
131+ FROM namespace_terms nt
134132 JOIN terms t
135- ON cr .term_id = t .id
136- JOIN namespace_terms nt
137- ON t .id = nt . term_id
133+ ON nt .term_id = t .id
134+ JOIN component_depth cd
135+ ON t .component_hash_id = cd . component_hash_id
138136 WHERE nt .namespace_hash_id = the_namespace_hash_id
139137 ) UNION
140138 -- term metadata references
141139 ( SELECT cd .depth AS depth
142- FROM component_depth cd
143- JOIN terms t
144- ON cd .component_hash_id = t .component_hash_id
140+ FROM namespace_terms nt
145141 JOIN namespace_term_metadata ntm
146- ON ntm .metadata_term_id = t .id
147- JOIN namespace_terms nt
148142 ON ntm .named_term = nt .id
143+ JOIN terms t
144+ ON ntm .metadata_term_id = t .id
145+ JOIN component_depth cd
146+ ON t .component_hash_id = cd .component_hash_id
149147 WHERE nt .namespace_hash_id = the_namespace_hash_id
150148 ) UNION
151149 -- direct constructor references
152150 ( SELECT cd .depth AS depth
153- FROM component_depth cd
151+ FROM namespace_terms nt
154152 JOIN constructors c
155- ON cd .component_hash_id = c .constructor_type_component_hash_id
156- JOIN namespace_terms nt
157153 ON c .id = nt .constructor_id
154+ JOIN types t
155+ ON c .type_id = t .id
156+ JOIN component_depth cd
157+ ON t .component_hash_id = cd .component_hash_id
158158 WHERE nt .namespace_hash_id = the_namespace_hash_id
159159 ) UNION
160160 -- direct type references
161161 ( SELECT cd .depth AS depth
162- FROM component_depth cd
163- JOIN type_local_component_references cr
164- ON cd .component_hash_id = cr .component_hash_id
162+ FROM namespace_types nt
165163 JOIN types t
166- ON cr .type_id = t .id
167- JOIN namespace_types nt
168- ON t .id = nt . type_id
164+ ON nt .type_id = t .id
165+ JOIN component_depth cd
166+ ON t .component_hash_id = cd . component_hash_id
169167 WHERE nt .namespace_hash_id = the_namespace_hash_id
170168 ) UNION
171169 -- type metadata references
172170 ( SELECT cd .depth AS depth
173- FROM component_depth cd
174- JOIN terms t
175- ON cd .component_hash_id = t .component_hash_id
171+ FROM namespace_types nt
176172 JOIN namespace_type_metadata ntm
177- ON ntm .metadata_term_id = t .id
178- JOIN namespace_types nt
179173 ON ntm .named_type = nt .id
174+ JOIN terms t
175+ ON ntm .metadata_term_id = t .id
176+ JOIN component_depth cd
177+ ON t .component_hash_id = cd .component_hash_id
180178 WHERE nt .namespace_hash_id = the_namespace_hash_id
181179 )
182180 ) AS refs;
@@ -202,19 +200,27 @@ BEGIN
202200 SELECT COALESCE(MAX (cd .depth ), - 1 ) INTO max_referenced_component_depth
203201 FROM (
204202 -- term references
205- ( SELECT from_term_component_hash_id AS component_hash_id
206- FROM patch_term_mappings
207- WHERE patch_id = the_patch_id
203+ ( SELECT t .component_hash_id AS component_hash_id
204+ FROM patch_term_mappings ptm
205+ JOIN terms t
206+ ON ptm .to_term_id = t .id
207+ WHERE ptm .patch_id = the_patch_id
208208 ) UNION
209209 -- constructor mappings
210- ( SELECT from_constructor_component_hash_id AS component_hash_id
211- FROM patch_constructor_mappings
212- WHERE patch_id = the_patch_id
210+ ( SELECT t .component_hash_id AS component_hash_id
211+ FROM patch_constructor_mappings pcm
212+ JOIN constructors c
213+ ON pcm .to_constructor_id = c .id
214+ JOIN types t
215+ ON c .type_id = t .id
216+ WHERE pcm .patch_id = the_patch_id
213217 ) UNION
214218 -- type references
215- ( SELECT from_type_component_hash_id AS component_hash_id
216- FROM patch_type_mappings
217- WHERE patch_id = the_patch_id
219+ ( SELECT t .component_hash_id AS component_hash_id
220+ FROM patch_type_mappings ptm
221+ JOIN types t
222+ ON ptm .to_type_id = t .id
223+ WHERE ptm .patch_id = the_patch_id
218224 )
219225 ) AS refs JOIN component_depth cd
220226 ON cd .component_hash_id = refs .component_hash_id ;
0 commit comments