Subject | RE: [firebird-support] Re: Optimizing a query |
---|---|
Author | Alan McDonald |
Post date | 2006-11-28T20:45:47Z |
> > no - you need to pass the paging parameters into the procedureOK - using those classes means you will still call the first skip of the
> > and let the
> > queries in the procedure handle this paging. Don't use FIRST
> > skip on a
> > proceure output since you will be processing all records the
> > most expensive
> > way everytime you call it. I have used it sometimes but only
> > when performace
> > is acceptable and therefore only on small tables with
> > inexpensive queries -
> > (and when I'm feeling really lazy)
>
> Ah! That's interesting. Unfortunately something I wasn't aware of (until
> now). I can do that, but I have to restructure the entire PHP class that
> I'm using for Page display (I'm using EZResults for this, with
> EZSql as the
> DB class). They have a simple way (based on how MySQL does this)
> to show a
> page of data, handle next/previous, first/last, etc. But of course it
> doesn't take into consideration the way that Firebird works for this.
>
> So if I understand you correctly, rather than using FIRST x SKIP y in the
> query that is used to call the stored procedure, I should use
> this technique
> but only INSIDE the stored procedure. Is that correct and the
> most optimal
> way to do this?
>
> Regards,
> Myles
procedure but the proc parameters will include those same page constants so
the proc is returning only the bracket being called for anyway.
The parameters inside the SP are used to like this (taken from a helen
Borrie post:
The way to emulate Firebird's SELECT FIRST m SKIP n in a sub-v.6.5
InterBase database, is to write a stored procedure to do the job - one
procedure for each query from which you want some rows:
create procedure GetFirst (Set_size integer, Start_row integer)
as
declare variable size_counter integer;
declare variable skip_counter integer;
declare variable..
declare variable..
(variables for all the cols you want in the output set)
;
begin
size_counter = 0;
skip_counter = 0;
for select blah from atable
order by blah
into :variable1, :variable2,.... do
begin
if (skip_counter <= :start_row) then
skip_counter = :skipcounter + 1;
else
begin
suspend;
counter = :counter + 1;
if (counter = :Set_size) then Exit;
end
end
Alan