Subject | RE: [Firebird-Java] PreparedStatement with LIKE ? extremly slow |
---|---|
Author | Steffen Heil |
Post date | 2007-02-05T17:04:42Z |
Hi
of LIKE and this simpilfies the query to:
(In this case the prepared statement is a gotcha. Using a non-prepared
statement would enable the optimizier to do the same in the first case, but
prepared statements are optimized earlier.)
One way to speed up things would be to use = instead of LIKE if possible:
example as long as you don't use wildcards.
Regards,
Steffen
[Non-text portions of this message have been removed]
> SELECT DISTINCT * FROM t_apos JOIN t_auftrag on f_id_auftragHere, the optimizer doen't know anything about the parameter.
> = id_auftrag WHERE f_liefer_nr LIKE ?
> This code is extremly slow.
> SELECTHere, the optimizer sees that there is no wildcard in the right-hand operand
> DISTINCT * FROM t_apos JOIN t_auftrag on f_id_auftrag =
> id_auftrag WHERE f_liefer_nr LIKE '2005-0119849-8'
> It is fast (about 50 ms),
of LIKE and this simpilfies the query to:
> SELECTSo that query can use the index very efficiently.
> DISTINCT * FROM t_apos JOIN t_auftrag on f_id_auftrag =
> id_auftrag WHERE f_liefer_nr = '2005-0119849-8'
(In this case the prepared statement is a gotcha. Using a non-prepared
statement would enable the optimizier to do the same in the first case, but
prepared statements are optimized earlier.)
One way to speed up things would be to use = instead of LIKE if possible:
> SELECT DISTINCT * FROM t_apos JOIN t_auftrag on f_id_auftragThis should be as fast as your second example and as flexible as your first
> = id_auftrag WHERE f_liefer_nr = ?
example as long as you don't use wildcards.
Regards,
Steffen
[Non-text portions of this message have been removed]