Subject | Re: [firebird-support] Slow select with variable in SP |
---|---|
Author | Pavel Menshchikov |
Post date | 2005-09-23T19:30:10Z |
Hello Eric,
ES> Stored procedure with parameter
ES> CREATE PROCEDURE "COMMENCE_PAR"
ES> (
ES> "DEBUT" VARCHAR(8)
ES> )
ES> RETURNS
ES> (
ES> "ID_WP" INTEGER
ES> )
ES> AS
ES> begin
ES> FOR
ES> SELECT ID_WAYPOINT
ES> FROM WAYPOINTS
ES> WHERE WP_NOM LIKE :DEBUT
ES> INTO :ID_WP
ES> DO
ES> BEGIN
ES> SUSPEND;
ES> END
ES> end
ES> select * from "COMMENCE_PAR"('CHAMBER%');
ES> prepare time 0.0031 s
ES> execution time 2mn59 s
ES> PLAN (WAYPOINTS NATURAL)
ES> As you can see, the last version is very slow ... and do not use
ES> indexes. How to get better performances?
Use STARTING WITH instead of LIKE with parameter (in case you always
use LIKE 'SOMETHING%', and not another kind of patterns). In the first
two cases FB internally converts your LIKEs to STARTINGs, and with the
parameter FB can't do it.
--
Best regards,
Pavel Menshchikov
http://www.ls-software.com/
ES> Stored procedure with parameter
ES> CREATE PROCEDURE "COMMENCE_PAR"
ES> (
ES> "DEBUT" VARCHAR(8)
ES> )
ES> RETURNS
ES> (
ES> "ID_WP" INTEGER
ES> )
ES> AS
ES> begin
ES> FOR
ES> SELECT ID_WAYPOINT
ES> FROM WAYPOINTS
ES> WHERE WP_NOM LIKE :DEBUT
ES> INTO :ID_WP
ES> DO
ES> BEGIN
ES> SUSPEND;
ES> END
ES> end
ES> select * from "COMMENCE_PAR"('CHAMBER%');
ES> prepare time 0.0031 s
ES> execution time 2mn59 s
ES> PLAN (WAYPOINTS NATURAL)
ES> As you can see, the last version is very slow ... and do not use
ES> indexes. How to get better performances?
Use STARTING WITH instead of LIKE with parameter (in case you always
use LIKE 'SOMETHING%', and not another kind of patterns). In the first
two cases FB internally converts your LIKEs to STARTINGs, and with the
parameter FB can't do it.
--
Best regards,
Pavel Menshchikov
http://www.ls-software.com/