citusdata / citus

Distributed PostgreSQL as an extension
https://www.citusdata.com
GNU Affero General Public License v3.0
10.57k stars 670 forks source link

bad rewriting of query involving targetList indirection: "UPDATE SET (col2, col1, col3)" #7674

Open c2main opened 2 months ago

c2main commented 2 months ago

A customer reported a bug from development team affecting queries with UPDATE SET (col2, col1, col3) = (.....) The columns are reordered following their physical ordering in pg_attribute, leading to for example UPDATE SET (col1, col2, col3) = (.....) with the right part, after = unchanged, as a results wrong columns are updated...

I have a complete test case, and a PR which I'm going to link in a moment. I think the issue may affect silently many applications, even more because the behavior can change over time based on the DDL applied on the updated tables.

There are several issue, I'm going to collect what I fond and link here so maybe we can close several at once...

Please see https://github.com/citusdata/citus/actions/runs/10527721147#summary-29171656391 for some examples of the problem.

c2main commented 2 months ago

Similar to https://github.com/citusdata/citus/issues/4092 which focus on reference table.

c2main commented 2 months ago

Yes I will update with patch for pg14 and pg15.