From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Fernando Schapachnik <fernando(at)mecon(dot)gov(dot)ar> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Optimizer problem in 8.1.6 |
Date: | 2007-06-22 18:14:34 |
Message-ID: | 24860.1182536074@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Fernando Schapachnik <fernando(at)mecon(dot)gov(dot)ar> writes:
> A rewritten query still exhibits the same behavior:
> EXPLAIN ANALYZE SELECT DISTINCT p.id
> FROM partes_tecnicos p
> WHERE
> p.id IN
> (SELECT r.id_parte_tecnico FROM
> rel_usr_sector_parte_tecnico r, active_users u
> WHERE (r.id_usr=u.id AND u.login='xxx' AND
> r.id_sector=p.id_sector_actual AND
> p.id_cola_por_ambito=1)
> OR p.id_cola_por_ambito=1)
> AND p.id_situacion!=6;
[ shrug... ] This is still telling the system to perform a
Cartesian-product join when p.id_cola_por_ambito=1.
A sane formulation of the query might look like
EXPLAIN ANALYZE SELECT DISTINCT p.id
FROM partes_tecnicos p
WHERE
(p.id_cola_por_ambito=1 OR
p.id IN
(SELECT r.id_parte_tecnico FROM
rel_usr_sector_parte_tecnico r, active_users u
WHERE (r.id_usr=u.id AND u.login='xxx' AND
r.id_sector=p.id_sector_actual)))
AND p.id_situacion!=6;
ie, get the constant term out of the sub-select. This is not exactly
the same thing though --- in particular, what do you intend should
happen if p.id has no matches whatsoever in r.id_parte_tecnico,
yet p.id_cola_por_ambito=1?
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Bob Pawley | 2007-06-22 18:15:20 | Establishing a primary key |
Previous Message | Fernando Schapachnik | 2007-06-22 17:59:36 | Re: Optimizer problem in 8.1.6 |