Skip to content

MDEV-41862: Syntax error with DELETE and IN in FederatedX pushdown - #6050

Open
bsrikanth-mariadb wants to merge 1 commit into
13.2-MDEV-39226-direct-multi_table-update-deletefrom
13.2-MDEV-41862-syntax-err-with-delete-and-in-op-when-pushdown-1
Open

bsrikanth-mariadb wants to merge 1 commit into
13.2-MDEV-39226-direct-multi_table-update-deletefrom
13.2-MDEV-41862-syntax-err-with-delete-and-in-op-when-pushdown-1

Conversation

@bsrikanth-mariadb

Copy link
Copy Markdown
Contributor

A single-table DELETE with an IN subquery on the same table, pushed down to FederatedX, failed on the remote server with a syntax error:

DELETE FROM t3 WHERE a IN (SELECT a FROM t3 WHERE a < 3);

The target table of a single-table DELETE is not in top_join_list, so the list is empty. st_select_lex::print() printed it as "delete from using dual where ...".

Fix: in st_select_lex::print() use top_join_list only when it is not empty, and otherwise print the tables from leaf_tables. For DELETE that branch emits the "from " keyword. UPDATE is unchanged.

As a side effect, EXPLAIN EXTENDED of a single-table DELETE no longer shows the dummy "using dual" and prints "delete from t where ...". A DELETE through a view now prints the view instead of its base table. Update the affected results (explain_non_select,
myisam_explain_non_select_all, opt_hints, opt_hints_index, opt_trace, versioning.delete_history).

Add a test to federatedx_pushdown_upd_del that pushes down DELETE (also with ORDER BY ... LIMIT and as a prepared statement) and UPDATE with an IN subquery on the same table, and checks both the resulting data and the statements received by the remote server in its general log.

@bsrikanth-mariadb

Copy link
Copy Markdown
Contributor Author

Moved the suggested changes from #6036 to here (as the main merge created a lot of merge conflicts)

A single-table DELETE with an IN subquery on the same table, pushed
down to FederatedX, failed on the remote server with a syntax error:

  DELETE FROM t3 WHERE a IN (SELECT a FROM t3 WHERE a < 3);

The target table of a single-table DELETE is not in top_join_list, so
the list is empty. st_select_lex::print() printed it as
"delete  from  using dual where ...".

Fix: in st_select_lex::print() use top_join_list only when it is not
empty, and otherwise print the tables from leaf_tables. For DELETE that
branch emits the "from " keyword. UPDATE is unchanged.

As a side effect, EXPLAIN EXTENDED of a single-table DELETE no longer
shows the dummy "using dual" and prints "delete from `t` where ...".
A DELETE through a view now prints the view instead of its base table.
Update the affected results (explain_non_select,
myisam_explain_non_select_all, opt_hints, opt_hints_index, opt_trace,
versioning.delete_history).

Add a test to federatedx_pushdown_upd_del that pushes down DELETE (also
with ORDER BY ... LIMIT and as a prepared statement) and UPDATE with an
IN subquery on the same table, and checks both the resulting data and
the statements received by the remote server in its general log.
@spetrunia
spetrunia force-pushed the 13.2-MDEV-41862-syntax-err-with-delete-and-in-op-when-pushdown-1 branch from b9b5449 to 746a3d1 Compare November 2, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant