[MDEV-23450] Move subquery rewrites from JOIN::prepare into JOIN::optimize Created: 2020-08-11  Updated: 2023-11-09

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Fix Version/s: 11.5

Type: Task Priority: Critical
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: refactoring

Issue Links:
Duplicate
is duplicated by MDEV-23860 Move all optimization query re-writes... Closed

 Description   

Currently some of the subquery rewrites are done in check_and_do_in_subquery_rewrites().

This function is called from

  • JOIN::prepare() // the "primary" call
  • Item_exists_subselect::exists2in_processor // the secondary

This task is about moving subquery rewrites from JOIN::prepare() phase into JOIN::optimize().

check_and_do_in_subquery_rewrites() does several rewrites:

 - Convert subquery predicate into semi-join, or
 - Mark the subquery for execution using materialization, or
 - Perform IN->EXISTS transformation, or
 - Perform more/less ALL/ANY -> MIN/MAX rewrite
 - Substitute trivial scalar-context subquery with its value

Note that for semi-joins, check_and_do_in_subquery_rewrites() doesn't actually do the rewrites. It checks the condition and adds the subquery into SELECT_LEX::sj_subselects.

The actual conversion happens in JOIN::optimize_inner():

  if (select_lex->first_cond_optimization)
  {
    /* dump_TABLE_LIST_graph(select_lex, select_lex->leaf_tables); */
    if (convert_join_subqueries_to_semijoins(this))
      DBUG_RETURN(1); /* purecov: inspected */
    /* dump_TABLE_LIST_graph(select_lex, select_lex->leaf_tables); */
    select_lex->update_used_tables();
  }



 Comments   
Comment by Sergei Petrunia [ 2020-08-11 ]

... the "remove redundant ORDER BY clause" rewrite should be moved from fix_fields into JOIN::optimize, too.

Generated at Thu Feb 08 09:22:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.