java - 我可以使用 JOOQ 对查询运行“解释分析”吗?
问题描述
我可以explain analyze
在 JOOQ 中运行查询吗?喜欢:
explain analyse select some, columns from some_table
但是在 PostgreSQL 数据库上使用 JOOQ 吗?
我找到了一个org.jooq.Explain
带有方法的接口DSLContext.explain(Query query)
- 但它似乎只是用于EXPLAIN
查询:
@Support({AURORA_MYSQL,AURORA_POSTGRES,H2,HSQLDB,MARIADB,MEMSQL,MYSQL,ORACLE,POSTGRES,SQLITE})
Explain explain(Query query)
Run an EXPLAIN statement in the database to estimate the cardinality of the query.
是否有任何明智的方法可以EXPLAIN ANALYZE
从代码端在数据库上运行?
解决方案
是的,你可以运行解释。例子
SelectWhereStep<ModuldefRecord> where = dsl.selectFrom(MODULDEF);
Explain explain = dsl().explain(where);
System.out.println(explain);
输出如下所示(对于 Oracle)
+------------------------------------------------------------------------------+
|PLAN_TABLE_OUTPUT |
+------------------------------------------------------------------------------+
|Plan hash value: 3871168833 |
| |
|------------------------------------------------------------------------------|
|| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time ||
|------------------------------------------------------------------------------|
|| 0 | SELECT STATEMENT | | 61303 | 30M| 1305 (1)| 00:00:01 ||
|| 1 | TABLE ACCESS FULL| MODULDEF | 61303 | 30M| 1305 (1)| 00:00:01 ||
|------------------------------------------------------------------------------|
+------------------------------------------------------------------------------+
解释还包含行和成本
/**
* The number of rows (cardinality) that is estimated to be returned by the query.
* <p>
* This returns {@link Double#NaN} if rows could not be estimated.
*/
double rows();
/**
* The cost the database associated with the execution of the query.
* <p>
* This returns {@link Double#NaN} if cost could not be retrieved.
*/
double cost();
推荐阅读
- python - 列表python的排列
- python - Python中的隐含字符串连接
- python - 图上实现算法的输出
- nginx - FastCGI中的“多路复用”是什么意思?
- javascript - 发送 POST 请求以启动 FLASK 功能
- vue.js - 如何使用 Nuxt 和 Strapi 显示图片库?
- python - 如何使用bs4从div内的锚标记获取文本
- c# - 合并(将值加在一起,减少为单个元素)列表中的所有对(第一对和最后一对除外)
- wordpress - 如何使用 mysql 命令更改 wordpress 标题
- amazon-web-services - 由于 python 版本,AWS 版本返回错误的解释器错误