[MDEV-11107] Use table check constraints in optimizer Created: 2016-10-22  Updated: 2020-11-25

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

Type: Task Priority: Major
Reporter: Galina Shalygina (Inactive) Assignee: Igor Babaev
Resolution: Unresolved Votes: 1
Labels: None

Sprint: 10.3.6-1, 10.4.0-1

 Description   

Consider two tables defined as

create table t1 (a int primary key, b int, check b < 5); 
create table t2 (a int primary key);

and a query

select * from t1, t2 where t1.b=t2.a and t2.a > 2;

If to take into account the check constraint on t1.b then the query will be looking as

select * from t1, t2 where t1.b=t2.a and t2.a > 2 and t1.b < 5;

As t1.b is equal to t2.a a much better condition on the column t2.a can be deduced:
t2.a > 2 and t2.a < 5

Consider another query

select * from t1, t2 where t1.a=t2.b and t2.a > 10;

As in the previous one, a new condition for t2.a can be deduced: t2.a > 10 and t2.a < 5
This condition is always false, so there is no need to evaluate the query.


Generated at Thu Feb 08 07:47:22 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.