function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andy Norman 3Andy Norman 3 

Why does the Query Plan tool always decide that a table scan is needed because of IsDeleted

I'm trying to use the Query Plan tool in the developer console for the first time.

Every single query that I try ends up with a table scan, because of the IsDeleted field not being indexed. The notes always have this for every table in the query:
Not considering filter for optimization because unindexed.
Table: Opportunity Fields: ["IsDeleted"]
Even if the query is as basic as:
select Id from Opportunity
where id = 'xxxxxxxxxxxxxxx'
Am I doing something wrong or is something broken ?
 
NagendraNagendra (Salesforce Developers) 
Hi Andy,

It only uses the lowest cost plan. Anything below that is irrelevant and can be safely ignored. So since your Index query has a Cost of 0.00001, that's what the Query Optimizer will use at runtime.

Note from Query Plan Tool (How To & FAQ): https://help.salesforce.com/articleView?id=000199003&type=1

What does it all mean?

The Query Plan tool will show a list of available plans that our Query Optimizer can utilize for the query provided and will be arranged by cost ascending. Each Plan will contain information on Cardinality, Operation Type, Cost, sObject Type, and more. Each plan has a “Leading Operation Type”, for example, Field Index or Full Table Scan. The plan with the lowest cost is the plan that is used for driving the query execution.

Thanks,
Nagendra