Repository navigation
Conversation
| }; | ||
| let selection_clause = build_dml_selection_clause( | ||
| update.selection.as_ref(), | ||
| &update.order_by, |
There was a problem hiding this comment.
If the table has a column named __upd_id, UPDATE t SET id = id + 100 ORDER BY __upd_id LIMIT 1 sorts by the generated SET alias. I tried this with (id, __upd_id) values (1, 20) and (2, 10). Both paths updated row 1, but row 2 has the smaller __upd_id. Can we select the target rows before projecting the SET expressions?
| // Selection clauses are rendered from the sqlparser AST. | ||
| let query_sql = format!( | ||
| "SELECT \"__paimon_file_idx\", \"__paimon_row_offset\" FROM {cow_table_name}{where_clause}" | ||
| "SELECT \"__paimon_file_idx\", \"__paimon_row_offset\" FROM {cow_table_name}{selection_clause}" |
There was a problem hiding this comment.
DELETE FROM t ORDER BY t.id DESC LIMIT 1 fails on CoW because the query now reads from __cow_target_* and t.id no longer resolves. I hit the same error with UPDATE. Can we preserve the target table qualifier when querying the temp table?
| ); | ||
|
|
||
| let query_sql = format!("SELECT {select_clause} FROM {table_ref}{where_clause}"); | ||
| let query_sql = format!("SELECT {select_clause} FROM {table_ref}{selection_clause}"); |
There was a problem hiding this comment.
With IDs 1 and 2, UPDATE t SET id = 12 / (2 - id) ORDER BY id LIMIT 1 fails with divide by zero on both paths. Only row 1 is selected, but SET is also evaluated for row 2. Moving the SET projection after ORDER BY and LIMIT would fix this too.
Purpose
Linked issue: close #1396
Paimon's DataFusion
SQLContextignoresORDER BYandLIMITwhen selecting rows for UPDATE and DELETE, which can modify more rows than requested. This change honors these clauses for both Copy-on-Write and Data Evolution tables.Brief change log
Preserve
WHERE,ORDER BYandLIMITin Copy-on-Write and Data Evolution selection queries, applying sorting and limiting before writing.Tests
test_update_with_order_by_and_limitandtest_delete_with_order_by_and_limitcover ordered selection and LIMIT on both paths.API and Format
No public API or storage format changes.
Documentation
No documentation changes; this fixes execution of already parsed clauses.