Skip to content
/ server Public

MDEV-31255: Crash with fulltext search subquery in explain delete#4523

Merged
bsrikanth-mariadb merged 1 commit into10.11from
10.11-MDEV-31255-explain-delete-failure-with-fulltext-search-subquery
Jan 27, 2026
Merged

MDEV-31255: Crash with fulltext search subquery in explain delete#4523
bsrikanth-mariadb merged 1 commit into10.11from
10.11-MDEV-31255-explain-delete-failure-with-fulltext-search-subquery

Conversation

@bsrikanth-mariadb
Copy link
Contributor

@bsrikanth-mariadb bsrikanth-mariadb commented Jan 9, 2026

ft_handler isn't getting initialized for subqueries inside explain
delete/update queries. However, ft_handler is accessed inside ha_ft_read(),
and is the reason for NULL pointer exception.
This is not the case with non-explain delete/update queries, as
well as explain/non-explain select queries.

Follow the approach the SELECT statements are using in
JOIN::optimize_constant_subqueries(): remove SELECT_DESCRIBE
flag when invoking optimization of constant subqueries.

Single-table UPDATE/DELETEs have SELECT_LEX but don't have JOIN.
So, we make optimize_constant_subqueries() not to be a member
of JOIN class, and instead move it to SELECT_LEX, and then
invoke it from single-table UPDATE/DELETE as well as for SELECT queries.

@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 10.11-MDEV-31255-explain-delete-failure-with-fulltext-search-subquery branch from bd69d0f to ce070d1 Compare January 21, 2026 10:59
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 10.11-MDEV-31255-explain-delete-failure-with-fulltext-search-subquery branch 2 times, most recently from 65b276c to 5fcae12 Compare January 27, 2026 09:55
@spetrunia
Copy link
Member

After the patch, the reader will see this in both sql_update and sql_delete:

  if (select_lex->optimize_constant_subqueries())
    DBUG_RETURN(TRUE);

  /* Apply the IN=>EXISTS transformation to all subqueries and optimize them. */
  if (select_lex->optimize_unflattened_subqueries(false))
    DBUG_RETURN(TRUE);

The comment in the middle looks mis-placed.

In both files, make it be

  /* 
    Apply the IN=>EXISTS and other transformations to all subqueries and
    optimize them.

    Constant subqueries are treated in a special way here: they can be
    evaluated even in EXPLAIN statement, so their query plan must be
    fully initialized for computation.
  */
  if (select_lex->optimize_constant_subqueries())
    DBUG_RETURN(TRUE);

  if (select_lex->optimize_unflattened_subqueries(false))
    DBUG_RETURN(TRUE);

Copy link
Member

@spetrunia spetrunia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to push after the above is addressed.

ft_handler isn't getting initialized for subqueries inside explain
delete/update queries. However, ft_handler is accessed inside ha_ft_read(),
and is the reason for NULL pointer exception.
This is not the case with non-explain delete/update queries, as
well as explain/non-explain select queries.

Follow the approach the SELECT statements are using in
JOIN::optimize_constant_subqueries(): remove SELECT_DESCRIBE
flag when invoking optimization of constant subqueries.

Single-table UPDATE/DELETEs have SELECT_LEX but don't have JOIN.
So, we make optimize_constant_subqueries() not to be a member
of JOIN class, and instead move it to SELECT_LEX, and then
invoke it from single-table UPDATE/DELETE as well as for SELECT queries.
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 10.11-MDEV-31255-explain-delete-failure-with-fulltext-search-subquery branch from 5fcae12 to dc28140 Compare January 27, 2026 11:13
@bsrikanth-mariadb bsrikanth-mariadb merged commit dc28140 into 10.11 Jan 27, 2026
16 of 17 checks passed
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.

2 participants