Re: Optimizer problem in 8.1.6 - Mailing list pgsql-general

From Fernando Schapachnik
Subject Re: Optimizer problem in 8.1.6
Date
Msg-id 20070622174852.GT5964@bal740r0.mecon.gov.ar
Whole thread Raw
In response to Re: Optimizer problem in 8.1.6  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Optimizer problem in 8.1.6  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
En un mensaje anterior, Tom Lane escribió:
> Fernando Schapachnik <fernando@mecon.gov.ar> writes:
> > Now, combined (sorry for the convoluted query, it is build
> > automatically by an app).
>
> > EXPLAIN SELECT DISTINCT p.id
> > FROM partes_tecnicos p,
> > rel_usr_sector_parte_tecnico r, active_users u
> > WHERE ((r.id_parte_tecnico=p.id AND 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;
>
> Is this query really what you want to do?  Because the OR overrides all
> the join conditions, meaning that rows having p.id_cola_por_ambito=1
> AND p.id_situacion!=6 must produce Cartesian products against every
> row in each of the other tables.
>
> I think your SQL-building app is broken.

Yes, yes, we found this while working on improving the query. I just
wanted to point out that the optimizer was doing a sequential scan
in a situation it could unfould de active_users definition, add the
login='xxx' clause, and use the index on the users table.

Thanks.

Fernando.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How determine a Views dependents
Next
From: "Harpreet Dhaliwal"
Date:
Subject: writing debug output in perl