[MDEV-27879] SELECT STRAIGHT_JOIN is ignored for views Created: 2022-02-18  Updated: 2022-02-22  Resolved: 2022-02-22

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.4.11, 10.1.48, 10.6.5
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Roy Bellingan Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: optimizer
Environment:

Suse 15.3 and Tumbleweed


Attachments: File create.sql    

 Description   

When using SELECT STRAIGHT_JOIN the optimizer will NOT follow the order of the JOIN as expressed in the sql when accessed as a VIEW.

I tried to look in the documentation but there is not mention about if is ok or not.
I would totally expect such optimization switch to be kept like all the other (force index ecc)

(see attached code to prepare)
 
analyze select * from noCondition;
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
| id   | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | r_rows | filtered | r_filtered | Extra       |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
|    1 | SIMPLE      | a     | const | PRIMARY       | PRIMARY | 4       | const | 1    | NULL   |   100.00 |       NULL | Using index |
|    1 | SIMPLE      | b     | ALL   | NULL          | NULL    | NULL    | NULL  | 1    | 1.00   |   100.00 |     100.00 | Using where |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
 
analyze select * from forceConditionU;
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
| id   | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | r_rows | filtered | r_filtered | Extra       |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
|    1 | SIMPLE      | a     | const | PRIMARY       | PRIMARY | 4       | const | 1    | NULL   |   100.00 |       NULL | Using index |
|    1 | SIMPLE      | b     | ALL   | NULL          | NULL    | NULL    | NULL  | 1    | 1.00   |   100.00 |     100.00 | Using where |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
 
analyze select * from forceConditionM;
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
| id   | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | r_rows | filtered | r_filtered | Extra       |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
|    1 | SIMPLE      | a     | const | PRIMARY       | PRIMARY | 4       | const | 1    | NULL   |   100.00 |       NULL | Using index |
|    1 | SIMPLE      | b     | ALL   | NULL          | NULL    | NULL    | NULL  | 1    | 1.00   |   100.00 |     100.00 | Using where |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
 
analyze select straight_join `a`.`id` AS `id` from (`b` join `a` on(`b`.`notIndexed` = `a`.`id`)) where `a`.`id` = 1;
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
| id   | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | r_rows | filtered | r_filtered | Extra       |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+
|    1 | SIMPLE      | b     | ALL   | NULL          | NULL    | NULL    | NULL  | 1    | 1.00   |   100.00 |     100.00 | Using where |
|    1 | SIMPLE      | a     | const | PRIMARY       | PRIMARY | 4       | const | 1    | 1.00   |   100.00 |     100.00 | Using index |
+------+-------------+-------+-------+---------------+---------+---------+-------+------+--------+----------+------------+-------------+

I will try to dig a bit in the code if I can figure out something about that.



 Comments   
Comment by Roy Bellingan [ 2022-02-19 ]

Looks like in 10.8.1 is working, I will now try to bisect to identify when the fix has been introduced.

I rechecked in 10.4.11 and 10.6.5 and... is now working also on them!

I confirm is NOT working only in the 10.1.48.

So I would say the bug can be closed. I have no idea what error I did during the test, but now is working fine.

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