[MDEV-20468] Allocating more space than required for JOIN_TAB array for a query with SJM table Created: 2019-09-02  Updated: 2023-12-20  Resolved: 2019-09-25

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.5.0

Type: Bug Priority: Major
Reporter: Varun Gupta (Inactive) Assignee: Varun Gupta (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-20014 Assertion failure: thd->mdl_context.i... Closed
relates to MDEV-33100 Backport MDEV-20468 to 10.4 Closed

 Description   

An example

EXPLAIN SELECT * FROM one_k
WHERE  a IN (SELECT t10.b 
                           FROM t10, t11, t12, t13, t14
                           WHERE t11.a=t10.b+1 AND t12.a=t10.b AND
                                           t13.a=t10.b AND t14.a=t10.b);

this case uses Semi Join Materializaion and the subquery is added to the table list of select #1.
The total number of tables for select #1 is 1(one_k)+ 5(inner_tables) + 1(SJM_TABLE). But for the top level we are only considered about 2 and should only have two JOIN_TAB structures.

In the function JOIN::get_best_combination
we allocate space for JOIN_TAB array like

  if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*
                                        (top_join_tab_count + aggr_tables))))

In the debugger
(gdb) p top_join_tab_count
$8 = 6

So in this issue we would like to correct the value of top_join_tab_count, to only consider the tables that would be present at the top level. In this case
the value of top_join_tab_count should be 2.



 Comments   
Comment by Varun Gupta (Inactive) [ 2019-09-02 ]

Patch:
http://lists.askmonty.org/pipermail/commits/2019-September/013965.html

This patch also fixes the crash in MDEV-20014

Comment by Sergei Petrunia [ 2019-09-19 ]

Ok to push

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