postgresql - EXPLAIN ANALYZE QUERY 如何用于测量查询性能?

标签 postgresql performance psycopg2 psql execution-time

今天我尝试使用 explain analyze 来提取查询的执行时间。我希望在不受查询延迟影响的情况下正确计算它们的执行时间,但是在 documentation 中它指出存在分析开销:

In order to measure the run-time cost of each node in the execution plan, the current implementation of EXPLAIN ANALYZE adds profiling overhead to query execution. As a result, running EXPLAIN ANALYZE on a query can sometimes take significantly longer than executing the query normally. The amount of overhead depends on the nature of the query, as well as the platform being used. The worst case occurs for plan nodes that in themselves require very little time per execution, and on machines that have relatively slow operating system calls for obtaining the time of day.

因此,我质疑 explain analyze 的有用性,因为您似乎只是用分析开销来交换延迟。更令人惊讶的是,在代码中计时我的数据库查询(在我的例子中是 Python,使用 psycopg2 库)导致查询执行时间更短。

最佳答案

EXPLAIN (ANALYZE) 很有用,不是因为它测量执行时间的准确性,而是因为它告诉您大部分执行时间花在了哪里以及 PostgreSQL 的估计在哪里。

关于postgresql - EXPLAIN ANALYZE QUERY 如何用于测量查询性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51773140/

相关文章:

sql - 在更新表 A 后触发更新表 A 中的特定列

macos - Docker fatal error : could not write lock file "postmaster.pid": No space left on device

PHP 准备的 postgres 查询失败,返回 :"could not determine data type of parameter $1"

c# - 找出 C# 中的对象使用了多少内存?

linux - 如何在 Linux 上以编程方式获取网络接口(interface)速度?

psycopg2 - 插入整数数组

php - laravel(lumen) 查询中的 Postgis ST_DWithin 函数

c# - 正则表达式匹配需要很长时间才能执行

installation - OSX Lion 上的 psycopg2 安装问题

python - 在 SQLAlchemy : could not translate host name to address: Name or service not known 中创建引擎