I have a query that I'm using to export data:
SELECT c.Id, c.SystemModstamp, ... FROM Contact c WHERE c.SystemModstamp > start AND c.SystemModstamp < end AND c.Id > string ORDER BY c.Id ASC LIMIT 100000
...where 'start' and 'end' are valid timestamps and 'string' is an 18-digit Id. This query runs multiple times, each time setting the 'string' to the highest-value Id from the previous batch.
Most of the time this is fine. However, for a certain (large) slice of data, this query instead returned 99994 records with 0 errors. I know that it didn't simply reach the end of the filtered list, because when I run the next batch (with a new and higher 'string'), that query returns the full 100000.
What could be causing this? I've been running this query in Data Loader while researching, and the results are the same when using Export or Export All. I've been able to reproduce the 99994 records even with slightly-altered queries. It almost seems like there is somehow 'broken' data on this table that's not returned and doesn't throw an error.
Has anyone seen this before?
UPDATE: After a lot of trial-and-error, I've found that excluding all custom fields from this query returns the expected 100000 records. However, including even one custom field (I tested with a simple checkbox, Inactive__c) causes the query to return 99994 records instead. Unfortunately, I have no idea why that is or what it means.
UPDATE 2: I was able to compare the 100000 records with the 99994 records and found the 6 records that make up the difference. Despite being an Admin, I get the 'Insufficient Privileges' message when trying to access the records in UI. However, I can query them in Dev Console (SELECT Id FROM Contact WHERE Id='x'). What could be wrong with these six records that would cause this sort of behavior?
UPDATE 3: Neither of the posted answers match up with what I'm seeing, but since both have received a score of 2, the bounty will be awarded anyway. Unless a better answer comes along before the bounty expires, I'm abandoning this question.