Skip to content

Optimise query where with injective dictionary #7968

@crakjie

Description

@crakjie

(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.

Metadata

Metadata

Assignees

Labels

comp-dictionaryDictionaries (in-memory key-value, periodically refreshed from sources).feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions