在jOOQ&中优化了数组吗? PostgreSQL的?

编程入门 行业动态 更新时间:2024-10-26 10:33:02
本文介绍了在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的?

本文发布于:2023-10-19 20:27:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508678.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   jOOQ   amp   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!