Is there a good way to tell how long the query in a batch apex job is taking? I don't find anything in the debug logs. I can see each batch and how long it takes, but not how long the initial query to get the first batch is taking.
Here's why I ask: I have a managed package with a batch job that works everywhere we've installed it. It iterates over Campaign Member records. Except last week it failed multiple times in an org that had 14 million CM records. The err looks like this:
First error: SQLException [common.exception.SfdcSqlException: ORA-01013: user requested cancel of current operation
Which based on this, seems to be a query timeout: http://help.salesforce.com/HTViewSolution?id=000175555&language=en_US
I suspect the problem is in the ORDER BY, which is why I want to see how long it's taking to get the first batch.
The problem is that since then this has started working again, in the same org. Code hasn't changed. Some CM records have been deleted (in an unrelated process), so they're now at about 13 million. I don't know if SF is just executing faster today, or if it can handle 13 million but not 14 million.
I know I may need to optimize my query and make it more "selective", and I have some ideas for how to go about that. But if I can't get it to fail with regularity now, I won't know when I've optimized it enough. Unless I can profile how long it's taking, and then I can just try to get it under a particular execution time.
Anyone got advice here?