Subject | Re: slow query fixed after backup |
---|---|
Author | Sergio |
Post date | 2011-06-22T11:48:36Z |
--- Svein Erling Tysvær wrote:
I was told (some time ago) that using things like "or (:in_id = -2)" in where clauses was not too bad. But, of course, I undestand that with an "or" like that, index can not be used. Anyway I will follow your advice, as usual!!!
By the other hand, when I do a backup-restore, the same query runs whithout any problem, the report takes few second to show up in the preview tool I'm using...
If it was a problem with bad plan selection, wouldn't it persist after the backup-restore?
THANKS!!!!
-s
>Hi Set! As usual, your help is invaluable!
> Regarding NATURAL, I'd recommend you to consider changing:
>
> join clientes_seleccion
> on ((clientes.id = clientes_seleccion.id)
> or (:in_id = -2))
>
> to
>
> join clientes_seleccion
> on clientes_seleccion.id =
> case when (:in_id = -2) then
> clientes_seleccion.id
> else
> clientes.id
> end
>
> This will not work if clients_seleccion.id can be NULL, but id columns tend to be NOT NULL. It would probably be a bit slower when (:in_id = -2), but it should be considerably faster if it isn't. So, do you typically run with :in_id = -2? This change would typically make an index for clientes_seleccion.id available to the query.
>
> HTH,
> Set
I was told (some time ago) that using things like "or (:in_id = -2)" in where clauses was not too bad. But, of course, I undestand that with an "or" like that, index can not be used. Anyway I will follow your advice, as usual!!!
By the other hand, when I do a backup-restore, the same query runs whithout any problem, the report takes few second to show up in the preview tool I'm using...
If it was a problem with bad plan selection, wouldn't it persist after the backup-restore?
THANKS!!!!
-s