Subject | Re: [firebird-support] Several SP parameters requested only |
---|---|
Author | Adomas Urbanavicius |
Post date | 2005-11-15T16:44:44Z |
About, SP :
The point is , that to handle this in SP, is up to developer : this is
exactly what I mean :
...
MyProc returns (a integer, b integer, c integer) as
if <a Param is Requested> ///// THIS IS NEEDED
then <Calculate a>
About view : joins, sure will be done anyway, but subselects no:
create view V_CUSTOMERS (CUSTOMER,TOTAL_SUM_OF_PROFIT,COUNTRY)
as select NAME,
(SELECT SUM(PROFIT) FROM ORDERS WHERE CUST_ID =
TB_CUSTOMERS.CUST_ID).
COUNTRY
TB_CUSTOMERS
,so select V_CUSTOMERS.CUSTOMER,V_CUSTOMERS.TOTAL_SUM_OF_PROFIT from
V_CUSTOMERS.
and
select V_CUSTOMERS.CUSTOMER from V_CUSTOMERS
will differ in execution time.
Adomas
The point is , that to handle this in SP, is up to developer : this is
exactly what I mean :
...
MyProc returns (a integer, b integer, c integer) as
if <a Param is Requested> ///// THIS IS NEEDED
then <Calculate a>
About view : joins, sure will be done anyway, but subselects no:
create view V_CUSTOMERS (CUSTOMER,TOTAL_SUM_OF_PROFIT,COUNTRY)
as select NAME,
(SELECT SUM(PROFIT) FROM ORDERS WHERE CUST_ID =
TB_CUSTOMERS.CUST_ID).
COUNTRY
TB_CUSTOMERS
,so select V_CUSTOMERS.CUSTOMER,V_CUSTOMERS.TOTAL_SUM_OF_PROFIT from
V_CUSTOMERS.
and
select V_CUSTOMERS.CUSTOMER from V_CUSTOMERS
will differ in execution time.
Adomas
>if I doAlexandre Benson Smith wrote:
>select a, b, c from MyProc the procedure should be executed entirely
>if I do
>select B from MyProc the If should not be execute neither column A and C
>Adomas Urbanavicius wrote:
>
>
>
>>Yes, in fact this is how it done now, but as far, as engine knows what
>>is requested : why should app client about passing aditional args.
>>And by the way, I think, VIEWS work in this way.
>>
>>
>>
>>
>Adomas,
>
>In an ideal world maybe :-)
>
>But I think will be hard to the engine to know what parameters is
>requested and transmogrify the code to handle this, and even harder to
>know what parts of the calc should be performed beacuse other parts
>depend on it.
>
>Lets examie this pseudo-code
>
>create procedure MyProc returns (a integer, b integer, c integer) as
>begin
> for
> select
> a, b, c
> from
> MyTable
> into
> :a, :b, :c
> do begin
>
> if (a > c) then
> c = a;
>
> Suspend;
> end
>end;
>
>if I do
>
>select a, b, c from MyProc the procedure should be executed entirely
>
>if I do
>
>select B from MyProc the If should not be execute neither column A and C
>should be read from the table and the SP would be transmogrified to:
>create procedure MyProc returns (a integer, b integer, c integer) as
>begin
> for
> select
> b
> from
> MyTable
> into
> :b
> do begin
> Suspend;
> end
>end;
>
>I think it is a hard work don't you think ?
>
>and what about this one:
>create procedure MyProc returns (a integer, b integer, c integer) as
>begin
> for
> select
> a.a, b.b, c.c
> from
> MyTableA a join
> MyTableB b on (a.id = b.id) join
> MyTableC c on (c.id = b.id)
> into
> :a, :b, :c
> do begin
>
> if (a > c) then
> c = a;
>
> Suspend;
> end
>end;
>
>if I do
>
>select B from MyProc
>
>should it be modified to:
>
>create procedure MyProc returns (a integer, b integer, c integer) as
>begin
> for
> select
> b.b
> from
> MyTableB b
> into
> :b
> do begin
> Suspend;
> end
>end;
>
>?
>
>If so, the result coud not be the same since the joins are removed it
>will retrieve records from MyTableB that has no correspondece on
>MyTableA and MyTableC
>
>I think it is to dificult to in run time modify a compiled code and even
>don't know if the BLR will contain enough data to make those assumptions.
>
>Have you looked at Execute Statement ? Maybe it can help you...
>
>
>About the views:
>The view has a pre-define select statement that is executed by the
>engine so if you have a view like:
>
>Create MyView (A, B, C) as
>select
> A.A, B.B, C.C
>from
> MyTableA A join
> MyTableB B on (B.ID = A.ID) join
> MyTableC C on (C.ID = B.ID)
>
>and issue
>
>select B from MyView, the join will be performed in any way, take a look
>at the execution plan to confirm it.
>
>see you !
>
>
>