[MDEV-19831] Need to clean up temporarry table in select handler. Optimize the way select handler search for tables and rewrites the query. Created: 2019-06-21  Updated: 2019-08-28  Resolved: 2019-08-28

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.4.6
Fix Version/s: 10.4.8

Type: Bug Priority: Critical
Reporter: Roman Assignee: Roman
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MCOL-2178 Run CS with vanilla 10.4 Closed

 Description   

There are number of defficiences that should be addressed in 10.4.

  • Pushdown_select instance doesn't clean up the temporary table created for Select_handler
  • The loop in SELECT_LEX::find_select_handler() should iterater of TABLE_LIST from next_global and not next_local. Then subquery tables' handlertons could be searched for select handler capabilities
  • JOIN::optimize_inner() should be called before Select_handler::init() in JOIN::optimize(). If Select_handler::init() is called before JOIN::optimize() then processing of statements like the one is broken since Server doesn't rewrite one of outter JOINs with inner JOIN.

    select j1_key, j6_key, j11_key from j1 right join j6 on j1_key=j6_key right join j11 on j6_key = j11_key where j6_key > 0;
    



 Comments   
Comment by Igor Babaev [ 2019-08-21 ]

Review:

Roman,

The following chages are ok (more than this the first one fixes a bug)

1.
@@ -45,6 +45,8 @@ Pushdown_select::Pushdown_select(SELECT_LEX *sel, select_handler *h)

Pushdown_select::~Pushdown_select()

{ + if (handler->table) + free_tmp_table(handler->thd, handler->table); delete handler; select->select_h= NULL; }

2.
-28551,7 +28553,7 @@ select_handler *SELECT_LEX::find_select_handler(THD *thd)

  • for (TABLE_LIST *tbl= join->tables_list; tbl; tbl= tbl->next_local)
    + for (TABLE_LIST *tbl= join->tables_list; tbl; tbl= tbl->next_global)

The change concerning replacement of the call of select_lex->pushdown_select->init() is not ok
You need only rewrites. Which ones? If all of them then the above call should be placed after the last re-write which is performed before this code:
if (optimize_constant_subqueries())
DBUG_RETURN(1);
Yet in this case you have to be able to work with the query tree after all re-writes have been done.
If you won't be able work with this tree, but you still need some rewrites then situation becomes more complicated.
In this case the call select_lex->pushdown_select->init() is not moved but it returns in bitmap of re-writes you need (in some member of the select_handler class that has to be added). Then immediately after this call you have to call select_lex->pushdown_select->optimize() that has to take care of all re-writes you needed (now it does not do it of course).
It's a big change.
So would suggest first to push in one commit 1&2 that are approved.

Comment by Roman [ 2019-08-24 ]

I removed the questionable change and made a pull request for the patch. Plz merge it.

Comment by Roman [ 2019-08-28 ]

Review has been done by igor

Comment by Roman [ 2019-08-28 ]

The patch has been merged into 10.4

Generated at Thu Feb 08 08:54:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.