-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Optimise query where with injective dictionary #7968
Description
(you don't have to strictly follow this form)
Use case
When a dictionary field is used as filter in where clause, if the field is injective the query can be optimised.
Instead of doing dictGet on every line, invert de dictGet and make it constant to juste have to compare values.
For exemple
Query A:
´SELECT * FROM Table where dictGet(‘dict’, ´dictField’ , tableField) = ‘a value’´
Could be optimized into
´SELECT * FROM Table WHERE tableField = (SELECT dictId FROM dict.dict WHERE dictField = ‘a value ‘)´
Query B:
´SELECT * FROM Table WHERE (dictGet(‘dictName’, ‘dictField’, tableField) , anotherTableField ) in (
(‘Value1’,’ValueX’),
(‘Value2’,’ValueX’),
(‘Value3’,’ValueY’))’
Into :
´SELECT * FROM Table WHERE (tableField , anotherTableField ) in (
((SELECT dictId FROM dict.dict WHERE dictField = ‘Value1‘),’ValueX’),
((SELECT dictId FROM dict.dict WHERE dictField = ‘Value2‘),’ValueX’),
((SELECT dictId FROM dict.dict WHERE dictField = ‘Value3’),’ValueY’))´.
In my own trials queries time are divide by four.