DWS JDBC调用同一条sql,performance计划毫秒级,实际执行却需要几分钟
生产中经常遇到一条简单的SQL performance计划毫秒级,实际执行却需要几分钟。
经过分析主要慢在jdbc查询结果集元数据上面,会产生类似下面的sql
元数据查询sql如下
SELECT c.oid, a.attnum, a.attname, c.relname, n.nspname, a.attnotnull OR (t.typtype = 'd' AND t.typnotnull), pg_catalog.pg_get_expr(d.adbin, d.adrelid) LIKE '%nextval(%' FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (c.relnamespace = n.oid) JOIN pg_catalog.pg_attribute a ON (c.oid = a.attrelid) JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) LEFT JOIN pg_catalog.pg_attrdef d ON (d.adrelid = a.attrelid AND d.adnum = a.attnum) JOIN (SELECT 52267 AS oid , 1 AS attnum UNION ALL SELECT 52267, 2 UNION ALL SELECT 52267, 3 UNION ALL SELECT 52267, 4 UNION ALL SELECT 52267, 5 UNION ALL SELECT 52267, 6 UNION ALL SELECT 52267, 7 UNION ALL SELECT 52267, 8 UNION ALL SELECT 52267, 9 UNION ALL SELECT 52267, 10 UNION ALL SELECT 52267, 11 UNION ALL SELECT 52267, 12 UNION ALL SELECT 52267, 13 UNION ALL SELECT 52267, 14 UNION ALL SELECT 52267, 15 UNION ALL SELECT 52267, 16 UNION ALL SELECT 52267, 17 UNION ALL SELECT 52267, 18 UNION ALL SELECT 52267, 19 UNION ALL SELECT 52267, 20 UNION ALL SELECT 52267, 21 UNION ALL SELECT 52267, 22 UNION ALL SELECT 52267, 23 UNION ALL SELECT 52267, 24) vals ON (c.oid = vals.oid AND a.attnum = vals.attnum)
通过计划分析,join_collapse_limit参数过小为4没有生成最优执行计划,导致执行时间变长,修改为8后毫秒级返回
调整方式如下:
1.如果该参数对已有业务影响不大,可以全局修改
2.如果只针对特定sql调整可以使用session级别修改
4.如果上述两种都不行,可以使用hint方式修改
- 点赞
- 收藏
- 关注作者
评论(0)