简体   繁体   English

jooq是否比Java中的简单sql有任何性能领先优势

[英]Does jooq has any performance lead over simple sql in java

我想为我的Java Web项目使用jooq,因为从它的规范来看,它看起来像是简单而又好的查询生成器,但是相对于Java中的简单查询或预备语句,它没有任何性能提升。

There are ongoing (unpublished) benchmarks checking for bottlenecks and general performance issues in jOOQ. 正在进行(未发布)的基准测试可检查jOOQ中的瓶颈和一般性能问题。 An example of a recently discovered issue can be seen here: 可以在这里看到最近发现的问题的示例:

https://github.com/jOOQ/jOOQ/issues/1625 https://github.com/jOOQ/jOOQ/issues/1625

As Mikko stated as well , jOOQ cannot beat static SQL strings passed to JDBC directly, as you will always have the overhead of: 正如Mikko所说 ,jOOQ无法击败直接传递给JDBC的静态SQL字符串,因为您总是会产生以下开销:

  1. Constructing the jOOQ objects 构造jOOQ对象
  2. Traversing the jOOQ objects for rendering SQL 遍历jOOQ对象以呈现SQL
  3. Creating a PreparedStatement with that SQL 使用该SQL创建PreparedStatement
  4. Traversing the jOOQ objects for bind variables, binding them to the PreparedStatement 遍历jOOQ对象以获取绑定变量,并将其绑定到PreparedStatement

If performance is critical in your environment, I suggest you do not let jOOQ perform these steps for every query execution. 如果性能在您的环境中至关重要,建议您不要让jOOQ每次执行查询都执行这些步骤。 Instead, let jOOQ render SQL once and cache the SQL string yourself, as well as a reference to the reusable PreparedStatement . 相反,让jOOQ一次渲染SQL并自己缓存SQL字符串,以及对可重用PreparedStatement的引用。 However, if you're not using an in-memory database, such as H2, we're talking about micro-optimisation here, as shown in the benchmark. 但是,如果您不使用内存数据库(例如H2),那么我们将在这里讨论微优化,如基准测试所示。 We're talking about gaining < 1ms per query. 我们正在谈论的是每个查询的时间少于1毫秒。

No, it does not offer performance gain. 不,它不会提高性能。 JOOQ itself communicates with database over JDBC (and uses prepared statements) and does not contain cache, so it simply cannot be faster than executing queries over JDBC directly. JOOQ本身通过JDBC与数据库通信(并使用准备好的语句),并且不包含缓存,因此,它不能比直接通过JDBC执行查询更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM