Subject | RE: [firebird-support] starting with and like in FB 1.5 |
---|---|
Author | Svein Erling Tysvær |
Post date | 2011-02-02T12:09:59Z |
>Thanks for that thorough information.No, that is not what I said. I said there can be a difference if you use parameters as opposed to constants. So, to use Delphi syntax (at least if used with IBO):
>So if I get you right no difference in normal direct SQL, but there can be a
>difference in stored procedures?
MyCursor.SQL.Add('select * from MyTable where field1 starting ''Z''');
MyCursor.Prepare;
Should get the same plan as:
MyCursor.SQL.Add('select * from MyTable where field1 like ''Z%''');
MyCursor.Prepare;
Whereas
MyCursor.SQL.Add('select * from MyTable where field1 starting :Param1');
MyCursor.Prepare;
MyCursor.ParamByName(Param1).AsString:='Z'
Is very different from
MyCursor.SQL.Add('select * from MyTable where field1 like :Param1');
MyCursor.Prepare;
MyCursor.ParamByName(Param1).AsString:='Z%'
The point is that the plan is generated at prepare time, and at that point in time, the last SQL doesn't know whether it can use an index or not (i.e. it doesn't know whether the parameter will be Z% (which can use an index) or %Z (which cannot)). LIKE gives the programmer more freedom than STARTING WITH, but at the cost of limiting the choices available to the optimizer.
HTH,
Set