Debuggging a few basic examples:

{code:sql}
create table t10 (a int, b int);
insert into t10 values (1,1),(2,2);
create table t11 as select * from t10;
{code}

{code}
explain select 1 in (select t10.b+T.b from t10, (select * from t11 limit 2) T where t10.a=T.a);
+------+-------------+------------+------+---------------+------+---------+------------+------+----------------+
| id   | select_type | table      | type | possible_keys | key  | key_len | ref        | rows | Extra          |
+------+-------------+------------+------+---------------+------+---------+------------+------+----------------+
|    1 | PRIMARY     | NULL       | NULL | NULL          | NULL | NULL    | NULL       | NULL | No tables used |
|    2 | SUBQUERY    | t10        | ALL  | NULL          | NULL | NULL    | NULL       | 2    | Using where    |
|    2 | SUBQUERY    | <derived3> | ref  | key0          | key0 | 5       | test.t10.a | 2    | Using where    |
|    3 | DERIVED     | t11        | ALL  | NULL          | NULL | NULL    | NULL       | 2    |                |
+------+-------------+------------+------+---------------+------+---------+------------+------+----------------+
{code}

{code}
  Thread 12 "mysqld" hit Breakpoint 1, free_tmp_table (thd=0x62b00016c288, entry=0x62000001a128) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:20942
  $156 = 0x62900004df98 "T" 
  $157 = (TABLE *) 0x62000001a128
  $158 = (ha_heap *) 0x61b000053328
(gdb) wher
  #0  free_tmp_table (thd=0x62b00016c288, entry=0x62000001a128) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:20942
  #1  0x0000555556ff79cd in close_thread_tables (thd=0x62b00016c288) at /home/psergey/dev-git2/10.9/sql/sql_base.cc:880
  #2  0x0000555556ff707c in close_thread_tables_for_query (thd=0x62b00016c288) at /home/psergey/dev-git2/10.9/sql/sql_base.cc:790
  #3  0x00005555571c51b2 in mysql_execute_command (thd=0x62b00016c288, is_called_from_prepared_stmt=false) at /home/psergey/dev-git2/10.9/sql/sql_parse.cc:6080
  #4  0x00005555571d1ef4 in mysql_parse (thd=0x62b00016c288, rawbuf=0x62900004b2a8 "explain select 1 in (select t10.b+T.b from t10, (select * from t11 limit 2)
  #5  0x00005555571a7de0 in dispatch_command (command=COM_QUERY, thd=0x62b00016c288, packet=0x6290000eb289 "", packet_length=94, blocking=true) 
{code}

Now, lets try a semi-join table:

explain select 1 in (select a from t10 where b in (select max(b) from t11 group by c));
+------+--------------+-------------+--------+---------------+--------------+---------+------------+------+-----------------+
| id   | select_type  | table       | type   | possible_keys | key          | key_len | ref        | rows | Extra           |
+------+--------------+-------------+--------+---------------+--------------+---------+------------+------+-----------------+
|    1 | PRIMARY      | NULL        | NULL   | NULL          | NULL         | NULL    | NULL       | NULL | No tables used  |
|    2 | SUBQUERY     | t10         | ALL    | NULL          | NULL         | NULL    | NULL       | 2    | Using where     |
|    2 | SUBQUERY     | <subquery3> | eq_ref | distinct_key  | distinct_key | 4       | test.t10.b | 1    |                 |
|    3 | MATERIALIZED | t11         | ALL    | NULL          | NULL         | NULL    | NULL       | 2    | Using temporary |
+------+--------------+-------------+--------+---------------+--------------+---------+------------+------+-----------------+


{code}
  Thread 12 "mysqld" hit Breakpoint 1, free_tmp_table (thd=0x62b00016c288, entry=0x620000021128) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:20942
  $171 = 0x629000247da0 "<subquery3>"
  $172 = (TABLE *) 0x620000021128
  $173 = (ha_heap *) 0x61b000078628
(gdb) wher
  #0  free_tmp_table (thd=0x62b00016c288, entry=0x620000021128) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:20942
  #1  0x0000555557d444fc in subselect_hash_sj_engine::cleanup (this=0x629000247bc8) at /home/psergey/dev-git2/10.9/sql/item_subselect.cc:5438
  #2  0x0000555557d10dcb in Item_subselect::cleanup (this=0x62900004e0c8) at /home/psergey/dev-git2/10.9/sql/item_subselect.cc:159
  #3  0x0000555557d1155c in Item_in_subselect::cleanup (this=0x62900004e0c8) at /home/psergey/dev-git2/10.9/sql/item_subselect.cc:200
  #4  0x000055555731646f in st_join_table::cleanup (this=0x629000250580) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:14379
  #5  0x000055555731931b in JOIN::cleanup (this=0x6290002458f0, full=true) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:14789
  #6  0x00005555572d2606 in JOIN::destroy (this=0x6290002458f0) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:4878
  #7  0x0000555557504d04 in st_select_lex::cleanup (this=0x62900004b918) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2802
  #8  0x00005555575036b5 in st_select_lex_unit::cleanup (this=0x62900004e360) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2608
  #9  0x0000555557504edb in st_select_lex::cleanup (this=0x62900004b3c0) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2813
  #10 0x00005555575036b5 in st_select_lex_unit::cleanup (this=0x62b0001706b0) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2608
  #11 0x00005555571c4ec1 in mysql_execute_command (thd=0x62b00016c288, is_called_from_prepared_stmt=false) at /home/psergey/dev-git2/10.9/sql/sql_parse.cc:6043
{code}

Together with JOIN::cleanup():

{code}
  Thread 12 "mysqld" hit Breakpoint 1, free_tmp_table (thd=0x62b00016c288, entry=0x620000022128) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:20942
  $174 = 0x5555591caf40 ""
  $175 = (TABLE *) 0x620000022128
  $176 = (ha_heap *) 0x61b000078d28
(gdb) wher
  #0  free_tmp_table (thd=0x62b00016c288, entry=0x620000022128) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:20942
  #1  0x00005555573195be in JOIN::cleanup (this=0x629000246040, full=true) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:14802
  #2  0x00005555572d2606 in JOIN::destroy (this=0x629000246040) at /home/psergey/dev-git2/10.9/sql/sql_select.cc:4878
  #3  0x0000555557504d04 in st_select_lex::cleanup (this=0x62900004c7e8) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2802
  #4  0x00005555575036b5 in st_select_lex_unit::cleanup (this=0x62900004d898) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2608
  #5  0x0000555557504edb in st_select_lex::cleanup (this=0x62900004b918) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2813
  #6  0x00005555575036b5 in st_select_lex_unit::cleanup (this=0x62900004e360) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2608
  #7  0x0000555557504edb in st_select_lex::cleanup (this=0x62900004b3c0) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2813
  #8  0x00005555575036b5 in st_select_lex_unit::cleanup (this=0x62b0001706b0) at /home/psergey/dev-git2/10.9/sql/sql_union.cc:2608
  #9  0x00005555571c4ec1 in mysql_execute_command (thd=0x62b00016c288, is_called_from_prepared_stmt=false) at /home/psergey/dev-git2/10.9/sql/sql_parse.cc:6043
{code}


