Subject | Re: Does SP use indexes? |
---|---|
Author | Adam |
Post date | 2006-07-31T04:25:07Z |
--- In firebird-support@yahoogroups.com, chand0s
<chand0s.lazy.inbox@...> wrote:
If you want to use an index on ID, you can do it from within the
stored procedure.
eg:
create procedure test_sp()
returns(name varchar(32), id integer)
as
begin
for select name, id from test_table order by ID into :name, :id
do suspend;
end
combined with:
select * from test_sp()
Will return the records ordered by ID possibly using the index on ID
if the optimiser thinks that is beneficial.
Just a note about sorting on indexed fields. It is often slower to
use an index to sort a recordset than to read the records in the
order they occur on disk and sort in memory. Sorting using an index
is extremely beneficial when you are selecting the first n.
Adam
<chand0s.lazy.inbox@...> wrote:
>No, see Dimitry's post for details.
> I have a test table like this -
> create table test_table(name varchar(32), id integer);
> where id field is primary key
>
> and I have a simple SP -
> create procedure test_sp()
> returns(name varchar(32), id integer)
> as
> begin
> for select name, id from test_table into :name, :id
> do suspend;
> end
>
> Question -
> if I will execute my SP with query
> select * from test_sp() order by id
>
> Will SP use indexes?
If you want to use an index on ID, you can do it from within the
stored procedure.
eg:
create procedure test_sp()
returns(name varchar(32), id integer)
as
begin
for select name, id from test_table order by ID into :name, :id
do suspend;
end
combined with:
select * from test_sp()
Will return the records ordered by ID possibly using the index on ID
if the optimiser thinks that is beneficial.
Just a note about sorting on indexed fields. It is often slower to
use an index to sort a recordset than to read the records in the
order they occur on disk and sort in memory. Sorting using an index
is extremely beneficial when you are selecting the first n.
Adam