[SalesForce] What Does Cardinality Mean in the Query Plan Tool

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:

Query Plan

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:

The approximate record count for the queried object.

So you seem to have approximately 20 records in that object.

The two notes mean

  1. The field IsDeleted is not indexed and thus the query cannot be optimized by leveraging this filter field.
  2. The same applies to the other note: The field "Name" on the related User object is not indexed either.

The article I mentioned above explains a lot more about indexing and performance.

Related Topic