Subject | Re: Firebird Plan Analyzer |
---|---|
Author | kick_tisho |
Post date | 2005-05-13T11:09:08Z |
> Hello Stanislav,for
>
> The problem your plan has is that P_IMPORTID is checked for null
> every record, so you pretty much force Firebird to do a table scan.evaluate
> The Firebird optimiser can't (or maybe it can but it doesn't)
> expressions like this.Stored
>
> 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
> procedure. Try something like this (see release notes, p20):i try to run some DSQL, but the problem was that you have to write
>
> ...
> 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.
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.