efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

ExecuteUpdate: handle queries failing due to invalid references to main table

Open roji opened this issue 3 years ago • 2 comments
trafficstars

Tests Update_with_cross_join_cross_apply_set_constant, Update_with_cross_join_left_join_set_constant, Update_with_cross_join_outer_apply_set_constant.

Make these work by introducing an additional subquery join, see https://github.com/dotnet/efcore/pull/28834#pullrequestreview-1082059936.

See conversation in https://github.com/npgsql/efcore.pg/pull/2476#discussion_r952034688

roji avatar Aug 23 '22 12:08 roji

This will require changing IsValidSelectExpressionForExecuteUpdate method.

  • By default relational converts APPLY to JOIN if there are no outer references (or they can be lifted in join predicate), so APPLY should cause it in all cases.
  • For predicate joins, need to check join condition
    • LEFT join would cause subquery join
    • INNER join can lift predicate to outer level and convert it to cross join

Look at SelectExpressionCorrelationFindingExpressionVisitor and write similar visitor to verify the outer references from the table which is being updated.

smitpatel avatar Aug 23 '22 17:08 smitpatel

Thanks @smitpatel, will follow these instructions.

roji avatar Aug 23 '22 17:08 roji