我有一大堆标识符,我想像这样添加到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&中优化了数组吗? PostgreSQL的?
发布评论