在jOOQ&中优化了数组吗? PostgreSQL的? [英] Are arrays optimized in jOOQ & PostgreSQL?

查看:79
本文介绍了在jOOQ&中优化了数组吗? PostgreSQL的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆标识符,我想像这样添加到WHERE子句中:

I have a large list of identifiers which I would like to add to the WHERE clause like this:

identifier IN (..., ..., ..., ...)

但是,这非常慢,因为它必须分别绑定每个值.请记住,该列表很长(几乎1000个值).在这种情况下,最好使用:

However, that is pretty slow, because it has to bind each value individually. Remember, the list is pretty long (almost 1000 values). In such case, it is better to use:

identifier = ANY({..., ..., ..., ...})

现在,我们只绑定一次数组.

Now, we are only binding the array, just once.

我尝试在jOOQ中这样做:

I tried doing that in jOOQ:

Integer[] values = {..., ..., ..., ...}
DSL.any(DSL.array(values))

生成以下SQL:

"identifier" = any (array[?, ?, ?, ...])
TRACE | 2017-08-24 10:02:08,914 | JooqLogger.java | 187 | Binding variable 1       : ...
TRACE | 2017-08-24 10:02:08,947 | JooqLogger.java | 187 | Binding variable 2       : ...
TRACE | 2017-08-24 10:02:08,958 | JooqLogger.java | 187 | Binding variable 3       : ...
...

那么,这使我得出结论,我们仍在分别绑定每个值?有没有办法对此进行优化?

So, this makes me conclude that we are still binding each value separately? Is there a way to optimize this?

推荐答案

替换:

DSL.any(DSL.array(values));

使用:

DSL.any(values);

创建单个绑定变量.

或者,您可以显式创建该绑定变量:

Alternatively, you could create that bind variable explicitly:

Field<Integer[]> array = DSL.val(values);
DSL.any(array);

这篇关于在jOOQ&amp;中优化了数组吗? PostgreSQL的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆