pg_field_type first call is very slow
未关闭
还没有人认领这个 Issue。
Bug
Extension: pgsql
Status: Needs Triage
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
Problem: function pg_field_type first call (after run php script) is very slow.
The following code:
$connection = pg_connect("...") or die('Cannot connect db');
$res = pg_query($connection, 'SELECT 100');
$time0 = microtime(true); pg_field_name($res, 0);
$out[] = '(query 1) pg_field_name() first call = '.number_format((microtime(true) - $time0) * 1000, 4).' мс';
$time0 = microtime(true); pg_field_size($res, 0);
$out[] = '(query 1) pg_field_size() first call = '.number_format((microtime(true) - $time0) * 1000, 4).' мс';
$time0 = microtime(true); pg_field_type($res, 0);
$out[] = '(query 1) pg_field_type() first call = '.number_format((microtime(true) - $time0) * 1000, 4).' мс';
$time0 = microtime(true); pg_field_type($res, 0);
$out[] = '(query 1) pg_field_type() second call = '.number_format((microtime(true) - $time0) * 1000, 4).' мс';
$res = pg_query($connection, 'SELECT 200');
$time0 = microtime(true); pg_field_type($res, 0);
$out[] = '(query 2) pg_field_type() first call = '.number_format((microtime(true) - $time0) * 1000, 4).' мс';
$time0 = microtime(true); pg_field_type($res, 0);
$out[] = '(query 2) pg_field_type() second call = '.number_format((microtime(true) - $time0) * 1000, 4).' мс';
print_r($out);
<?php
Resulted in this output:
Array (
[0] => "(query 1) pg_field_name() first call = 0.0069 мс"
[1] => "(query 1) pg_field_size() first call = 0.0031 мс"
[2] => "(query 1) pg_field_type() first call = 46.6821 мс" // FIRST CALL IS VERY SLOW (pg_field_type)
[3] => "(query 1) pg_field_type() second call = 0.0050 мс"
[4] => "(query 2) pg_field_type() first call = 0.0069 мс"
[5] => "(query 2) pg_field_type() second call = 0.0029 мс"
)
But I expected this output instead:
Array (
[0] => "(query 1) pg_field_name() first call = 0.0069 мс"
[1] => "(query 1) pg_field_size() first call = 0.0031 мс"
[2] => "(query 1) pg_field_type() first call = 0.0050-0.0069 мс" // MUST BE
[3] => "(query 1) pg_field_type() second call = 0.0050 мс"
[4] => "(query 2) pg_field_type() first call = 0.0069 мс"
[5] => "(query 2) pg_field_type() second call = 0.0029 мс"
)
PHP Version
PHP 8.1
Operating System
Debian 11 (bullseye)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用提供的 PHP 复现代码,在 PHP 8.1 和 PostgreSQL 上调用 pg_connect()、pg_query() 和 pg_field_type(),比较第一次调用与后续调用。跟踪 PostgreSQL 的字段类型查找路径,以确定为什么第一次调用需要约 46 ms;完成的标准是第一次调用不再存在无法解释的延迟,并且观测到的耗时已由回归检查覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php, postgresql
- 领域
- backend, databases
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100