Re: Slow update with simple query - Mailing list pgsql-performance

From Arnaud Lesauvage
Subject Re: Slow update with simple query
Date
Msg-id 457FF0CD.4050606@freesurf.fr
Whole thread Raw
In response to Re: Slow update with simple query  ("Jens Schipkowski" <jens.schipkowski@apus.co.at>)
Responses Re: Slow update with simple query
List pgsql-performance
Jens Schipkowski a écrit :
> the problem is a combination of bad formed SQL and maybe missing indexes.
> try this:
> UPDATE t1
> SET booleanfield = foo.bar
>  FROM (SELECT uid,(field IN ('some','other') AND field2 = 'Y') AS bar FROM
> t2) AS foo
> WHERE t1.uid=foo.uid;


Hi Jens,
Why is this query better than the other one ? Because it runs the
"(field IN ('some','other') AND field2 = 'Y')" once and then executes
the join with the resulting set ?

> and index t1.uid, t2.uid, t2.field, t2.field2

t1.field can only take 3 or 4 values (don't remember exactly), and
field2 only 2 ('Y' or 'N'). So this fields have a very low cardinality.
Won't the planner chose to do a table scan in such a case ?

Thanks for your advices !

--
Arnaud

pgsql-performance by date:

Previous
From: "Jens Schipkowski"
Date:
Subject: Re: Slow update with simple query
Next
From: "Jens Schipkowski"
Date:
Subject: Re: Slow update with simple query