Introduce `settings` function for queries
Loriowar opened this issue · comments
You know, ClickHouse allow to specify custom settings for each query. This allow to tweak queries and achieve a good performance in some cases. So, will be geed to have such function in ruby. Example:
ClickHouse::MyModel.where(column1: 42).settings("optimize_read_in_order=1").to_sql
=> "SELECT my_table.* FROM my_table WHERE my_table.column1 = 42 SETTINGS optimize_read_in_order=1"
In case of multiple calls of settings
we just redefine a settings value. I.e. last settings
call will win.
Technically, here might be two ways of implementation: simple and more fancy. In simple case we just pass a string into settings
function and than string directly passing into the query (see previous example). In more fancy scenarion we have to build a list of available settings together with allowed values and build a resulted settings string from that hash. Example:
ClickHouse::MyModel.where(column1: 42).settings(optimize_read_in_order: 1, cast_keep_nullable: 1).to_sql
=> "SELECT my_table.* FROM my_table WHERE my_table.column1 = 42 SETTINGS optimize_read_in_order=1, cast_keep_nullable=1"
In than case we have to handle redefining of different settings across multiple calls.