[MDEV-30226] Allow USE / FORCE on an index the optimizer would never consider using Created: 2022-12-14  Updated: 2023-05-09

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Hartmut Holzgraefe Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

For a query like

SELECT * FROM t1  WHERE val1 < val2;

an index on (val1,val2) is never considered as a candidate, and so USE or FORCE can't be used on it, and a full table scan is done instead unless there's a covering index over all result columns.

There are edge cases though where only a small minority of rows actually fulfill the "val1 < val2" condition, I tested this with only 0.1% of rows matching. In that case an index scan with following random row lookups of the matching rows turns out to be faster than a full table scan.

The optimizer itself can't decide on this as it does not have statistics on the "less than" relationship between val1 and val2, and so will never consider using an index scan here.

A user may know about the data distribution, and so be able to decide that a FORCE INDEX may make sense here, but as the index is not even considered as a candidate it is also not available for FORCE


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