Subject Re: Firebird Plan Analyzer
Author kick_tisho
> Hello Stanislav,
>
> The problem your plan has is that P_IMPORTID is checked for null
for
> every record, so you pretty much force Firebird to do a table scan.
> The Firebird optimiser can't (or maybe it can but it doesn't)
evaluate
> expressions like this.
>
> select id
> from contact
> where 1 = 0
>
> will also do a full table scan, same problem.
>
> Firebird 1.5 allows you to dynamically build the SQL inside the
Stored
> procedure. Try something like this (see release notes, p20):
>
> ...
> DECLARE VARIABLE sql varchar(100);
> BEGIN
> SQL = 'SELECT C.ID FROM CONTACTS';
> IF (:P_IMPORTID IS NOT NULL) THEN
> BEGIN
> SQL = SQL || ' WHERE C.IMPORTID = :P_IMPORTID';
> END
>
> FOR EXECUTE STATEMENT :SQL INTO :ID
> DO
> BEGIN
> SUSPEND;
> END
> END
> ^
>
> Hope that helps
>
> Adam.

i try to run some DSQL, but the problem was that you have to write
SQL = SQL || ' WHERE C.IMPORTID = ' || :P_IMPORTID;

and it gets more nasty when i have to contact stings or dates
SQL = SQL || ' WHERE C.NAME= ''' || :P_NAME || '''';

and i'm not sure when it comes to Dates, or BLOBS what will be the
result.

Also isn't it a way with some prepare stmt to have
WHERE C.IMPORTID = :P_IMPORTID';
and then to prepare so it can replace the params for me.
there is some PREPARE STMT in the docs but i cannot run it.