function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kirill_YunussovKirill_Yunussov 

Same SOQL Query taking a long time in a “VF page controller” VS in the “Developer Console”

Simple query, taking 1 minute in the VF page controller, and less than 1 second when executed in the Developer Console. There are more than 50,000 records that the query is searching through. Why such a dramatic difference in the query run time?

 

String s = '123456';
List<Registration__c> regs = 
    [select id, name 
     from Registration__c 
     where name =: s or speical_number__c =: s limit 1];

 

Here are the excerpts from the debug logs:

 

Developer Console:

12:22:39.063 (63557000)|SOQL_EXECUTE_BEGIN|[2]|Aggregations:0|select id, name from Registration__c where (name = :tmpVar1 or speical_number__c = :tmpVar2) limit 1

12:22:39.263 (263582000)|SOQL_EXECUTE_END|[2]|Rows:0

 

VF Page Controller:

12:17:08.148 (3148592000)|SOQL_EXECUTE_BEGIN|[633]|Aggregations:0|select id, name from Registration__c where (name = :tmpVar1 or speical_number__c = :tmpVar2) limit 1

12:18:07.350 (62350264000)|SOQL_EXECUTE_END|[633]|Rows:0

Thomas DvornikThomas Dvornik

That's curious. Couple questions.

- Is this consistantly reproducible?
- Does it matter the order? i.e. VF then DC or DC than VF.
- Is VF tracing on in your log levels?
- I'm assuming you are running the query as an Sys Admin with view all data?

Kirill_YunussovKirill_Yunussov

It's not consistently reproducible, but when it happens, the delay is always on the same query.

 

I can't check if the order matters b/c of inconsistency of the issue.   (I'm guessing it might be going over the prefetched results in subsequent runs?)

 

VF logging is set to INFO, which includes "VF_SERIALIZE_VIEWSTATE_BEGIN; VF_SERIALIZE_VIEWSTATE_END; VF_DESERIALIZE_VIEWSTATE_BEGIN; VF_DESERIALIZE_VIEWSTATE_END;"

 

Running the query as Sys Admin with View All.

Thomas DvornikThomas Dvornik
Weird. My thought was it was the prefetched results as well, but I don't know for sure. Let me know if you find out anything more.
IspitaIspita
I too agree with Thomas .. The behaviour seems queer more so if its not consistent. Trying switching objects and check, if its still similar behaviour. Also you say that in developer console its faster - its supposed to be - but the difference in execution you point out is curious. Also are there any modification/ update happening in your page as you query? Also since you say its inconsistent - is it a possibility that a Batch job may be running when you got the statistics mentioned by you.
Just check that may be...