I am running below query in query editor in the free developer edition
SELECT count() FROM contact WHERE createdby.Name = 'gs650x'
I am getting 17 records but when I click query plan tool I get below result:
As per my understanding
cardinality = number of records query will return
and sObject Cardinality
= total number of records in the org (here in this case is 20)
I can understand sObject Cardinality is total number of records in org, which is 20. But in my plan, the Cardinaltiy should be 17 instead of 20, as I understand it. In some cases I have seen cardinality is lesser number, but I am getting higher value when I execute query.
I also tried the below in executed anonymous window but still I got 17 not 20.
SELECT count() FROM Contact WHERE CreatedBy.Name = 'gs650x' ALL ROWS
What should I expect from cardinality? Also, what do the 2 notes mentioned on the query plan tool mean?
Not considering filter for optimization because unindexed. Table:
Contact Fields: ["IsDeleted"] Not considering filter for optimization
because query table is not optimizable. Table: User Fields: ["Name"]
Best Answer
This Salesforce help article explains all the info from the query plan tool.
For sObject cardinality it says:
So you seem to have approximately 20 records in that object.
The two notes mean
IsDeleted
is not indexed and thus the query cannot be optimized by leveraging this filter field.The article I mentioned above explains a lot more about indexing and performance.