postgresql - PostgreSQL 中的性能问题
问题描述
我们正在处理从 SQL Server 到 Aurora PostgreSQL 的数据库转换。对于数据库中的某些函数,我们看到 PG 中的执行时间(30 多秒)与 SQL Server(0.5-2 秒)相比非常高。
我们已经将数据库参数设置为最佳性能所需的值。
其中许多函数使用外部表视图从另一个数据库引用表。
客户的期望是功能的性能至少应该比我们目前在 SQL Server 中的性能更好。
有哪些方法可以提高 PG 的性能?
以下是各自的配置详细信息:
SQL server config: Microsoft SQL Server 2012 (SP4) (KB4018073) – 11.0.7001.0 (X64). RAM: 16GB. Inter Xeon
Aurora RDS config: 4 vCPU, 30.5 GB RAM.
示例代码:
代码示例:// 这个花费不到一秒钟。
insert into temptable(
column1 ,column2,column3 ,
column4 ,column5, column6 ,
column7
)
SELECT --DISTINCT
t.col AS column1, d.column1,null as column3 ,
null as column4 ,null as column5,null as column6 ,
null as column7
FROM
view1 AS d
INNER JOIN table2 AS t
ON t.column2= d.column1
LEFT OUTER JOIN table2 AS i
ON i.col1 = t.col AND i.col = t.col2 AND i.col = var1 AND i.svc_type = var2
AND i.col2= var3 AND i.col1 = var4
WHERE
(i.col3 = 'XXX' OR d.col3 = 'XX')
AND i.col4 IN (var5, var6)
;
// This update query only taking 27 seconds and result 39 rows
update temptable set
column3=function1(column2, v1, v2, v3), -- this is single execution it took 412ms
column4=function2(column2, v3),-- this is single execution it took 350ms
column5=function3(column2, v3),
column6=function4(column2),
column7=function5(column2);
// this one taking less then one seconds.
OPEN rs1 FOR
select column1 ,column2,column3 ,
column4 ,column5, column6 ,
column7 from temptable;
RETURN NEXT rs1;
解决方案
推荐阅读
- flutter - 标签栏颤动错误在页面之间切换
- jpa - 通过 JPA 存储库在运行时通过 And 或 Or 创建条件
- regex - 如何修改此正则表达式以允许在电子邮件的用户名中使用点 (.)
- python - 你如何用一组子集的平均值填充 NaN?
- python - 如何测试包含不同日期的 datetime.now() 的 python 方法?
- time-complexity - 在某些位置应用 if 语句生成所有可能序列的复杂性是什么
- c# - 尝试使用 autofac 在测试类中注入模拟实例,但容器在其他测试类中注入相同的实例
- xml - 使用 xslt 编码查找具有值的所有元素名称
- c# - 如何从特征提取中找到匹配的数量?
- ios - Swift 4 - NSURLComponents 使用正斜杠设置密码