Last friday i was optimizing a form with a lof of display fields with an implementation like the following:
display EmplName emplName()
{
return EmplTable::find(this.EmplID).Name;
}
The one of sources to increase performance of such code is to select only fields which will be used lately. So I have replaced this code with the following:
display EmplName emplName()
{
return this.EmplID ?
(select Name from EmplTable
where EmplTable.emplID==this.EmplID).Name
:
"";
}
but when I enabled SQL tracing, I found, that this code producess select with ALL fields of EmplTable.
It was strange... With a great help of my co worker, i've found the following:
- when there is only fields of any unique index in the where condition, all fields are fetched
- when there is an extra field in the condition, only required fields is selected (and the extra fields in where)
- So I converted previously mentioned methods to the following:
display EmplName emplName()
{
return this.EmplID ?
(select Name from EmplTable
where EmplTable.emplID==this.EmplID
&&
EmplTable.recID
).Name
:
"";
}