[MDEV-24298] SELECT_LEX::find_select_handler() fails to find MCS table running INSERT..SELECT with a single derived at top level in SELECT Created: 2020-11-27  Updated: 2022-05-06  Resolved: 2021-01-26

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.5, 10.6
Fix Version/s: 10.5.9

Type: Bug Priority: Major
Reporter: Roman Assignee: Roman
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Problem/Incident
causes MCOL-3890 insert.. select * from (subselect) th... Closed
Relates
relates to MCOL-4222 Import from Table fails or writing em... Closed

 Description   

As of now MDB doesn't use Select Handler for queries like:

INSERT INTO t1 SELECT * FROM (SELECT * FROM mcs1) d;

but Select Handler works for the SELECT part of the query.

The reason why this happens is that join->tables_list doesn't have TABLE_LIST* for a real table but for a derived one. Here is the gdb snippet taken in the first iteration of the loop in SELECT_LEX::find_select_handler():

(gdb) p tbl->table_name   
$2 = {
  str = 0x55907a9f76c8 <internal_table_name> "*",
  length = 1
}

It doesn't matter if derived_merged is on or off.

(gdb) p thd->variables->optimizer_switch & OPTIMIZER_SWITCH_DERIVED_MERGE
$8 = 128
(gdb) p join->tables_list->table_name
$9 = {
  str = 0x55bee4acaa28 <internal_table_name> "*", 
  length = 1
}
(gdb) p join->tables_list->next_global
$10 = (TABLE_LIST *) 0x0
(gdb) 

Here is the code of the mentioned find_select_handler():

select_handler *SELECT_LEX::find_select_handler(THD *thd)                                                                                                                                                                                     
{
  if (next_select())
      return 0;
  if (master_unit()->outer_select())
    return 0;
  for (TABLE_LIST *tbl= join->tables_list; tbl; tbl= tbl->next_global)
  {
    if (!tbl->table)
      continue;
    handlerton *ht= tbl->table->file->partition_ht();
    if (!ht->create_select)
      continue;
    select_handler *sh= ht->create_select(thd, this);
    return sh;
  }
  return 0;
}



 Comments   
Comment by Roman [ 2021-01-11 ]

Closing an issue trying to address it from a different direction.

Comment by Chris Calender (Inactive) [ 2021-01-11 ]

Alternative direction, if interested: MCOL-4490

Comment by Roman [ 2021-01-22 ]

The issue is caused by the fact that Smart Engines: MCS and Xpand can't handle derived_merge optimization thus disabling it in the very beginning of the query processing so that SELECT_LEX::join->tables_list has no leaf table at the moment where SELECT_LEX::find_select_handler() is called.

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