"Name" is a table with more or less 1 million rows. I've tried this request but it never ends. Is there an issue to avoid the "in" ?
update name
set name_val = true
where name_pk in (select max (name_pk)
from name
group by foreign_key_pk);
I'm not against triggers if it's necessary.
Query plan :
"Nested Loop (cost=26073.59..26310.38 rows=200 width=54)"
" -> HashAggregate (cost=26073.59..26075.59 rows=200 width=4)"
" -> HashAggregate (cost=23122.82..24598.20 rows=118031 width=12)"
" -> Seq Scan on name (cost=0.00..19956.21 rows=633321 width=12)"
" -> Index Scan using name_pk on name (cost=0.00..1.16 rows=1 width=54)"
" Index Cond: (public.name.name_pk = (max(public.name.name_pk)))"
2 indexes :
CREATE INDEX link_name_foreign_key_pk
ON name
USING btree
(foreign_key_pk);
CREATE UNIQUE INDEX name_pk
ON name
USING btree
(name_pk);
Thanks.
name_pkrepresent, and could the query be rewritten like this? postgres.cz/wiki/…(foreign_key_pk, name_pk)especially with Postgres 9.2 this might help.NOT NULLconstraints ...