Details
-
New Feature
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
A storage engine that executes query subtrees itself gets a hook to rewrite a SELECT before its names are resolved, and server-side primitives to move tables into a new materialized derived table that the engine's create_derived then receives.
Hook (sql/handler.h)
int (*rewrite_select)(THD *thd, SELECT_LEX *select_lex);
- called at the top of JOIN::prepare, for the engine of the first base table of the FROM clause
- returns 1 when the select was changed (the server re-reads its table list, WHERE and HAVING), 0 when untouched, -1 with an error set
- st_select_lex::rewritten_by_engine keeps later prepares of a prepared statement or stored routine off the already rewritten tree
Primitives (st_select_lex, sql/sql_derived.cc)
- wrap_tables_into_derived(...) - moves top-level FROM tables, with the conjuncts, select list and GROUP BY built by the engine, into a new derived table at the end of FROM (modelled on wrap_tvc); subqueries whose conjuncts moved are re-parented under the new select (move_as_slave, outer name-resolution context, nesting level); the name-resolution chain is rebuilt
- wrap_table_in_place(...) - one table, possibly the inner table of an outer join; the derived table takes its place in the join list with its nesting and outer-join flags, the caller sets the ON expression
- left_join_table(...) - moves the only table of a subquery into a derived table nested as the outer-joined side of a LEFT JOIN with this select's single table; ON and removal of the subquery are the caller's
- carve_table_into_derived(...) - the shared part of the two above
Other
- TABLE_LIST::engine_carved marks a table carved by the engine
- Item_in_subselect::set_left_expr() lets a rewrite re-home the left operand of IN, also for re-execution
Commits (branch orthus/derived-late-decline, MariaDBEnterprise)
- 8db0ee859af rewrite_select: an engine carves a derived table out of a SELECT
- f62be099074 rewrite_select: subqueries move with the carved derived table
- 24226163d2a Add st_select_lex::wrap_table_in_place
- b29dfc1cba7 Add st_select_lex::left_join_table; share the carving with wrap_table_in_place