[Pgsql-ayuda] update exists
Xavi Puig
personal@xavihost.com
Thu, 24 Oct 2002 17:15:5 +0100
Perd=F3n, se me habia olvidado la query:
UPDATE tab1 SET col20=3Dfalse WHERE exists (select * from (select *=
from tab1 where col20=3Dtrue) as alias0,tab2,tab3 where=
(tab2.col2=3Dtab3.col1 and tab3.col2=3Dalias0.col1) and (=
tab2.col2=3D20500))
Result (cost=3D0.00..5705.67 rows=3D267967 width=3D60)
One-Time Filter: $0
InitPlan
-> Nested Loop (cost=3D0.00..9739.17 rows=3D214 width=3D91)
-> Nested Loop (cost=3D0.00..8464.72 rows=3D214 width=3D36)=
-> Index Scan using col2_btrre_col2 on tab2 =
(cost=3D0.00..7.10 rows=3D1 width=3D28)
Index Cond: (col2 =3D 20500::character=
varying)
-> Index Scan using col2_pkey on tab3 =
(cost=3D0.00..6560.53 rows=3D3035 width=3D8)
Index Cond: ("outer".id_word =3D tab3.col1)
-> Index Scan using col1_pkey on tab1 =
(cost=3D0.00..5.95 rows=3D1 width=3D55)
Index Cond: ("outer".col2 =3D tab1.col1)
Filter: (col20 =3D true)
-> Seq Scan on tab1 (cost=3D0.00..5705.67 rows=3D267967 width=3D60)=
Los campos tienen indices, la subquery funciona bien (rapido)=
pero al actualizar todo el resultado....
En el ejemplo de ahora el coste es mucho menor pero se cuelga=
igual
Gracias otra vez.
>On Thu, Oct 24, 2002 at 10:25:21AM +0100, Xavi Puig wrote:
>> Os adjunto explain con query ejemplo:
>
>Falt=F3 adjuntar la consulta. Pero lo que sospecho es que tab1 no=
tiene
>un =EDndice apropiado en la columna que est=E1 devolviendo la=
subconsulta...
>
>Dej=E9 mi bola de cristal en la casa, de manera que tendr=E1s que=
indicar
>las definiciones de las tablas y la consulta que est=E1s=
ejecutando.
>
>> QUERY PLAN
>> Seq Scan on tab1 (cost=3D0.00..22726480.50 rows=3D133984=
width=3D57)
>> Filter: (subplan)
>> SubPlan
>> -> Hash Join (cost=3D6.45..84.68 rows=3D1 width=3D16)
>> Hash Cond: ("outer".tab2 =3D "inner".col2)
>> -> Nested Loop (cost=3D0.00..78.09 rows=3D29=
width=3D12)
>> -> Index Scan using tab1_col1 on tab1 =
(cost=3D0.00..2.01 rows=3D1 width=3D4)
>> Index Cond: (col1 =3D true)
>> -> Index Scan using btree_tab3_col2 on tab3 =
(cost=3D0.00..75.65 rows=3D34 width=3D8)
>> Index Cond: (tab3.col2 =3D "outer".col2)
>> -> Hash (cost=3D6.45..6.45 rows=3D1 width=3D4)
>> -> Index Scan using btree_tab2_col2 on tab2 =
(cost=3D0.00..6.45 rows=3D1 width=3D4)
>> Index Cond: (col2 =3D=
'keyword1'::character varying)
>
>--
>Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
>"El que vive para el futuro es un iluso, y el que vive para el=
pasado,
>un imb=E9cil" (Luis Adler, "Los tripulantes de la noche")