Subject Stored Procedure vs View for derived/calculated data
Author sugi
Dear all,

I apologize if this is considered RTFM, but I ran into the following
item on the knowledgeBase at ibphoenix.com:
...
Question:
How do I create a static query that exists and is permanently optimized
on the server for repeated use?

Answer:
You need to create a Stored Procedure.
...

I have several questions about the above QA....
1. I always thought that in relational databases, 'server side queries'
are synonimous with views, and that Selectable SPs are a feature

unique to IB/FB only. Is the 'recommendation' above still
correct,
in the sense that Selectable SPs are the recommended way in
IB/FB
to create 'server side queries' ?
2. There was a post recently mentioning the (bad) performance of joining

selectable SPs with a table or view. I believe the message said
something about the result set of SPs not using index so join
operations will be slow. Is there any definitive documentation
the developers on this subject ?

Another question popped up recently, still related to the above subject.
Suppose I'd need to calculate some value for every record in
a table. There are at least two ways to write the sp for this:
...
create procedure calc_one( record_id integer )
returns ( somevalue numeric(18,4) )
as begin
...
end;
...
as opposed to
...
create procedure calc_two
returns ( record_id integer, somevalue numeric(18,4) )
as begin
...
end;
...

CALC_ONE is like a function, you give it a record_id (primary key) and
it
will return just one value for the calculation. Normally I'd use the
following construct to retrieve the data.
...
select record_id, (select somevalue from
calc_one(mytable.record_id)
from mytable;
...
CALC_TWO is a more typical select procedure, returning a result set
containing two fields, so it can be treated like a table. Calling this
one is a bit simpler.
...
select record_id, somevalue
from calc_two;
...

Now the main question I have at this point is which approach is the
recommended practice in FB? I suppose there must be some difference
in performance, but my limited testing did not reveal any, probably
because my test dataset is not big enough. Please advise.

TIA,
sugi.