I don't currently have an org with sufficient data to test this, and I've not been able to find a definitive answer so far.
Would a with sharing
declaration on an Apex class affect the selectivity of a SOQL query contained within it?
For example, let's say that you have a custom index on a text field - let's call it Test_Value__c
- on Opportunity, and you have 5 million records in there, where 4.5 million have the same value - Example
- for this field.
If the Opportunity trigger contains the query:
SELECT Id FROM Opportunity WHERE Test_Value__c = 'Example'
then this looks like it is going to be non-selective. However would the platform still regard it as such if there were a private sharing model, the class had a with sharing
declaration and as a result the executing user could only see 100 of the 5 million original records?