Unit db.pas
contains implementation of TParam
class, which represents a parameter in database query.
While testing queries with lots of params I noticed that function TParam.ParamRef: TParam
takes a lot of time, since it calls ParamByName
which does an unindexed search of params.
The implementation is simple:
function TParam.ParamRef: TParam;
begin
if not Assigned(FParamRef) then
if Assigned(Collection) and (Name <> '') then
FParamRef := TParams(Collection).ParamByName(Name) else
FParamRef := Self;
Result := FParamRef;
end;
It can return self
or ParamRef
, so the idea is to allow some sort of redirection.
But it does a slow ParamByName
, is called a lot and I don't understand the purpose. In fact, if I modify it to just returns self
everything seems to work correctly.
The only use I see for it would be to have several params of same name all redirect to same instance. If that's the case, surely the performance penalty of ParamByName
overweights the benefit of this feature.
ParamRef
is undocumented and private
so only relevant within the db.pas unit. Also, there is no significant discussion about it online.
Has anyone encountered the same problem ?