diff --git a/schema/config.hcl b/schema/config.hcl index d39440d0..e4143072 100644 --- a/schema/config.hcl +++ b/schema/config.hcl @@ -393,6 +393,9 @@ table "config_items" { columns = [column.scraper_id] where = "deleted_at IS NULL" } + index "idx_config_items_path" { + columns = [column.path] + } check "config_item_name_type_not_empty" { expr = "LENGTH(name) > 0 AND LENGTH(type) > 0" } diff --git a/views/005_component_views.sql b/views/005_component_views.sql index a98a01eb..f2d8f1ea 100644 --- a/views/005_component_views.sql +++ b/views/005_component_views.sql @@ -155,7 +155,7 @@ BEGIN WITH config_id_paths AS ( SELECT config_items.id FROM config_items - WHERE path LIKE '%' || (SELECT config_id FROM components WHERE components.id = $1::UUID) || '%' + WHERE starts_with(path, (SELECT path FROM config_items WHERE id IN (SELECT config_id FROM components WHERE components.id = $1::UUID))) ) SELECT components.id FROM components