简单查询,在VF页面控制器中占用1分钟,在Developer Console中执行时间不到1秒。查询正在搜索的记录超过50,000条。为什么在查询运行时出现如此显着的差异?
String s = '123456';
List<Registration__c> regs =
[select id, name
from Registration__c
where name =: s or speical_number__c =: s limit 1];
以下是调试日志的摘录:
开发者控制台:
12:22:39.063 (63557000)| SOQL_EXECUTE_BEGIN | [2] |聚合:0 |选择id,来自Registration__c的名称where(name =:tmpVar1或speical_number__c =:tmpVar2)limit 1 < / p>
12:22:39.263 (263582000)| SOQL_EXECUTE_END | [2] |行数:0
VF页面控制器:
12:17:08.148 (3148592000)| SOQL_EXECUTE_BEGIN | [633] |聚合:0 |选择id,来自Registration__c的名称,其中(name =:tmpVar1或speical_number__c =:tmpVar2)limit 1 < / p>
12:18:07.350 (62350264000)| SOQL_EXECUTE_END | [633] |行:0
答案 0 :(得分:0)
我怀疑这与VF / Apex批量回复的方式有关。虽然,限制1似乎表明情况并非如此。但是,只是为了踢...试试这个......
String s = '123456';
List<Registration__c> regs = new List<Registration__c>();
for ( Registration__c reg :
[select id, name
from Registration__c
where name =: s or speical_number__c =: s
limit 1
] ) {
regs.add(reg);
}
speical_number__c是外部ID的合适人选吗?我问,因为将该字段设置为外部ID将保证Salesforce.com将为您的字段创建索引。如果没有索引,查询将执行全表扫描。