-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
背景:现在Doris在某些场景中需要对特殊的查询进行查询级别的Session Variable设置。
场景1:某些查询exec_mem_limit需要设置为8g大小才跑得动,否则会直接报错。
场景2:某些特殊的大查询query_timeout需要设置>20s。其它查询<10s。
但是某些查询用默认的2g就足够,这时候我在写代码的时候就需要写成这样。
for (int i = 1; i <= 3; i++) {
try {
LOGGER.info("RUN SQL:\n{}", querySQL);
boolean res = getInstance().update("set exec_mem_limit=8589934592;");
if(!res){
LOGGER.error("SET出错:{}次,重试", i);
continue;
}
resultList = getInstance().query(querySQL);
if (resultList.size() == 0) {
return resultList;
}
} catch (Exception ex) {
LOGGER.info("查询失败", ex);
}
if (resultList.size() == 0) {
continue;
}
这是由于JDBC不支持一次执行2条语句的形式,例如:
set exec_mem_limit=8589934592;select * from table where aa=bb;
所以代码中不得不进行2次通信,我担心会有一定的性能开销。
那我能不能改一定这个默认配置都为4G呢?我发现这个配置是在FE上的,并且如果改了以后所有的查询都是8g的话会不会对某些查询来讲其实有一定的浪费?
因此我希望能进行一次通信就可以满足设置环境变量,同时应用环境变量进行查询。
这个问题和#3023 可能类似,本质是在select查询中可以设置环境变量。
Describe the solution you'd like
A clear and concise description of what you want to happen.
我最开始的想法其实是在JDBC的连接字符串上做手脚,但是发现jdbc的连接字符串似乎并不支持我主要需要的2个Session Variable,他们是exec_mem_limit、query_timeout。
后来我发现Mysql 8.0是这样解决的:
https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html#optimizer-hints-set-var
他支持SELECT的SET_VAR
SELECT /*+ SET_VAR(sort_buffer_size = 16M) */ name FROM people ORDER BY name;
INSERT /*+ SET_VAR(foreign_key_checks=OFF) */ INTO t2 VALUES(2);
SELECT /*+ SET_VAR(optimizer_switch = 'mrr_cost_based=off') */ 1;
所以我觉得SET_VAR这种形式应该会比较通用,同时也能支持mysql 5.7中提到的MAX_EXECUTION_TIME这种形式。
https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
SELECT /*+ MAX_EXECUTION_TIME(1000) */ * FROM t1 INNER JOIN t2 WHERE ...
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
其它的方式我们都考虑过,似乎不符合标准,例如在连接字符串上去做,或者是支持set+select的语句。
Additional context
Add any other context or screenshots about the feature request here.
后面我会提一个PR,以我认为的方式改了一下,可能代码不是很优雅,也变动了一些主干部分,需要Doris这边儿看看怎么改一下比较好,看看会不会影响什么。