Subject | Re: [firebird-support] Index usage in update statement |
---|---|
Author | unordained |
Post date | 2012-02-10T17:39:01Z |
---------- Original Message -----------
From: Marcin Bury <marcin.bury@...>
Try something like
merge into table_a using (select id_a from table_b where field_b =
some_condition) z on table_a.id_a = z.id_a
when matched then update set field_a = some_value;
I think I remember that it gets optimized differently, but I'm not sure.
-Philip
From: Marcin Bury <marcin.bury@...>
> TABLE_A------- End of Original Message -------
> ID_A - primary key
> FIELD_A - some field
>
> TABLE_B
> ID_B - primary key
> ID_A - reference to TABLE_A - indexed
> FIELD_B - some field - also indexed
>
> UPDATE TABLE_A
> SET FIELD_A = some_value
> WHERE ID_A IN (SELECT ID_A FROM TABLE_B FIELD_B = some_condition)
>
> When I prepare the statement, Firebird 2.5.1.26166 returns NATURAL
> plan for TABLE_A and proper index usage for TABLE_B Is it correct or
> am I missing something? Is there a way to avoid iterating records in
> some EXECUTE BLOCK statement?
Try something like
merge into table_a using (select id_a from table_b where field_b =
some_condition) z on table_a.id_a = z.id_a
when matched then update set field_a = some_value;
I think I remember that it gets optimized differently, but I'm not sure.
-Philip