[MDEV-28749] restore_prev_nj_state() doesn't update cur_sj_inner_tables correctly Created: 2022-06-05  Updated: 2022-06-07  Resolved: 2022-06-07

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.3.36, 10.4.26, 10.5.17, 10.6.9, 10.7.5, 10.8.4

Type: Bug Priority: Major
Reporter: Sergei Petrunia Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: None

Attachments: File psergey-mdev28749-findcrash.diff    

 Description   

Discovered this while reviewing the patch

Author: Michael Widenius <monty@mariadb.org>
Date:   Sun May 15 15:46:29 2022 +0300
 
    greedy_search() and best_extension_by_limited_search() scrambled table order
    
    best_extension_by_limited_search() assumes that tables should be sorted
    according to size to be able to quickly disregard bad plans. However the
    current usage of swap_variables() will change the table order to a not

The patch changes which join orders are considered, and potentially the order the join orders are enumerated.

One of the .result changes in the patch:

@@ -596,8 +596,8 @@ limit 10;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
 1	PRIMARY	nation	ALL	PRIMARY	NULL	NULL	NULL	25	4.00	Using where; Using temporary; Using filesort
 1	PRIMARY	supplier	ref	PRIMARY,i_s_nationkey	i_s_nationkey	5	dbt3_s001.nation.n_nationkey	1	100.00	
-1	PRIMARY	part	ALL	PRIMARY	NULL	NULL	NULL	200	7.03	Using where
-1	PRIMARY	partsupp	eq_ref	PRIMARY,i_ps_partkey,i_ps_suppkey	PRIMARY	8	dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey	1	100.00	Using where; FirstMatch(supplier)
+1	PRIMARY	part	ALL	PRIMARY	NULL	NULL	NULL	200	7.03	Using where; Start temporary; Using join buffer (flat, BNL join)
+1	PRIMARY	partsupp	eq_ref	PRIMARY,i_ps_partkey,i_ps_suppkey	PRIMARY	8	dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey	1	100.00	Using where; End temporary

That is

-1  PRIMARY	part	... Using where
+1  PRIMARY	part	... Using where; Start temporary; Using join buffer (flat, BNL join)
 
-1  PRIMARY	partsupp ... Using where; FirstMatch(supplier)
+1  PRIMARY	partsupp ... Using where; End temporary

The join order is NOT changed while the semi-join strategy IS changed. This should not happen.



 Comments   
Comment by Sergei Petrunia [ 2022-06-06 ]

https://github.com/MariaDB/server/commit/161e8c5b7132212d5884865e67c50657854f1b63

Comment by Sergei Petrunia [ 2022-06-07 ]

Attaching a patch (against 10.3) which just adds state verification.

Attempting to run subselect*test causes failures:

Failing test(s): main.subselect_sj2 main.subselect_sj2_jcl6 main.subselect main.subselect3 main.subselect_sj2_mat main.subselect_mat main.subselect4 main.subselect3_jcl6 main.subselect_no_exists_to_in main.subselect_sj

Generated at Thu Feb 08 10:03:11 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.