3

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"]

0

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.

| improve this answer | |
  • Thank you chris for your answer but I am not using isDeleted field in where caluse then why this note is coming at the query plan tool and also cardinality is never equal to number records query return Sometimes the difference is in 100s , could you please suggest? – gs650x Feb 19 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.