Enhance the efficiency of Glide queries in deletion strategy scripts that target the 'Comment' fieldOverview Some of the Azure and AWS deletion strategy scripts are taking long time which are using the comment field in Glide queries and causing slow query execution. Addressed slow query issue in below scripts: #PatternCIDeletion Strategy Script1Amazon AWS - Executable Template (LP)cmdb_ci_os_templateExecutableTemplateAwsGetCi2Amazon AWS - Owned Template (LP)cmdb_ci_os_templateOwnedTemplateAwsGetCi3Amazon AWS - Virtual Server (LP)cmdb_ci_os_templateVirtualServerAwsGetCi4Amazon AWS - Virtual Server (LP)cmdb_ci_dns_nameVirtualServerAwsGetCi5Amazon AWS - Classic LB (LP)cmdb_ci_dns_nameClassicLbAwsGetCi6Amazon AWS - Classic LB (LP)cmdb_ci_cloud_load_balancerClassicLbAwsGetCi7Amazon AWS - Classic LB (LP)cmdb_ci_cloud_lb_ipaddressClassicLbAwsGetCi8Amazon AWS - Classic LB (LP)cmdb_ci_lb_poolClassicLbAwsGetCi9Amazon AWS - Classic LB (LP)cmdb_ci_lb_serviceClassicLbAwsGetCi10Amazon AWS - Application and Network LB (LP)cmdb_ci_dns_nameAppAndNetLbAwsGetCi11Amazon AWS - Application and Network LB (LP)cmdb_ci_cloud_load_balancerAppAndNetLbAwsGetCi12Amazon AWS - LB Pool (LP)cmdb_ci_lb_poolPoolAppAndNetLbAwsGetCi13Amazon AWS - LB Service (LP)cmdb_ci_lb_serviceServiceAppAndNetLbAwsGetCi14Amazon AWS - NIC (LP)cmdb_ci_cloud_lb_ipaddressNicAwsGetCi15Azure - Virtual Machine (LP) cmdb_ci_os_templateVmAzureGetCi16Azure - Virtual Machine (LP)cmdb_ci_storage_volumeVmAzureGetCi17Azure - Storage Blobs(LP)cmdb_ci_storage_volumeBlobsAzureGetCi18Azure - Storage Volume (LP)cmdb_ci_storage_volumeStorageAzureGetCi19Azure - Image (LP) cmdb_ci_os_templateImageAzureGetCi20Azure - Classic LB (LP)cmdb_ci_cloud_load_balancerClassicLbAzureGetCi21Azure - Classic LB (LP)cmdb_ci_lb_serviceClassicLbAzureGetCi22Azure - Classic LB (LP)cmdb_ci_lb_poolClassicLbAzureGetCi23Azure - Classic LB (LP)cmdb_ci_cloud_lb_ipaddressClassicLbAzureGetCi24Azure - Route Table (LP)cmdb_ci_route_tableRouteTableAzureGetCi25Azure - Local Network Gateway (LP)cmdb_ci_virtual_pvt_gatewayLocalGatewayAzureGetCi26Azure - Private Gateway (LP)cmdb_ci_virtual_pvt_gatewayPrivateGatewayAzureGetCi Release This feature is available in the following release. "Discovery and Service Mapping Patterns(sn_itom_pattern)" version 1.13.0 - May 2024 or later Implementation Before Fix Executing the following Glide query within Deletion strategy scripts on a resource class (for example: cmdb_ci_cloud_load_balancer). var relGr = new GlideRecord(ciClass); relGr.addQuery('comments', comment); relGr.addQuery('sys_updated_on', '<=', scheduleStartTime); relGr.addQuery('operational_status', 'NOT IN', this._deleteLayerExcludes()); relGr.addQuery('discovery_source', 'IN', this._deleteLayerSources()); relGr.query(); while (relGr.next()) { CiSysId.push(relGr.getUniqueValue()); } In the above query inputs: ciClassresource table namescheduleStartTimeDiscovery schedules start timecommentConstruct comment filed valuethis._deleteLayerExcludes()['2','7']this._deleteLayerSources()['ServiceNow'] Output: CiSysIdList of CI Sys Ids potentially applicable for Deletion Strategy Details about query Resource table Class has indexes on 'sys_class_name' , 'sys_updated_on' columns.Initially, the Query Optimizer filter records based on these indexed fields. However Index fields, filter out only Cis that are updated in current discovery. For instance, If table contains 1M CIs, after applying index field queries(assume updated CIs in current discovery are 1K), the table subset still contains approximately 1M CIs (Total number of CIs in the table minus updated Cis in the current discovery). After applying the index field conditions, the table subset still contains ~1M records to which the remaining query conditions(Non-Index fields) must be applied.This process is inefficient and can lead to performance issues. After Fix Executing the following Glide query within Deletion strategy scripts on a CI Relationship (cmdb_rel_ci) class. var relGr = new GlideRecord('cmdb_rel_ci'); relGr.addQuery('child', 'IN', childSysIds); relGr.addQuery('parent.sys_class_name', this.ciClass); relGr.addQuery('parent.sys_updated_on', '<=', this.scheduleStartTime); relGr.addQuery('parent.operational_status', 'NOT IN', this.deleteLayerExcludes); relGr.addQuery('parent.discovery_source', 'IN', this.deleteLayerSources); if (this.isCommentIncludeInQuery) { relGr.addQuery('parent.comments', 'IN', comments); } relGr.setLimit(this._limit); relGr.query(); while (relGr.next()) { ciSysId.push(relGr.parent.sys_id + ''); } In the above query inputs: childSysIdsInput datacentersthis.ciClassresource table namethis.scheduleStartTimeDiscovery schedules start timecommentConstruct comment filed valuethis.deleteLayerExcludes['2','7']this.deleteLayerSources['ServiceNow'] Output: CiSysIdList of CI Sys Ids potentially applicable for Deletion Strategy Details about query The CI Relationship Table has indexes on 'child' , 'parent' columns.Initially, the Query Optimizer filter records based on these indexed fields. However Index fields, filter out CIs where the Child is in the input datacenter, the Parent class is a resource Class and updated in current discovery. For instance, If table contains 1M CIs, after applying index field queries(assume input datacenter has 10K with resource class and current discovery 1K records are updated in current discovery), the table subset contains approximately 9K CIs (Total number of resource types CIs having a relationship with input datacenters minus updated Cis in the current discovery). After applying the index field conditions, the table subset contains 9K records to which the remaining query conditions(Non-Index fields) will be applied.This process is efficient and resolves the performance issues. **** END of TOI ****