[php-src] Issue #9692: pg_field_type first call is very slow
| From: | vicreal | Date: | Sat, 08 Oct 2022 13:51:25 +0000 |
| Subject: | [php-src] Issue #9692: pg_field_type first call is very slow | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242544@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9692
Author: vicreal
### Description
Problem: function **pg_field_type** first call (after run php script) is very slow.
The following code:
```php
$connection = pg_connect("host='".vp::REMOTE_HOST."'
password='".vp::PASSWORD."'
port='".vp::POSTGRESQL['port']."'
user='".vp::POSTGRESQL['user']."'
dbname='".vp::POSTGRESQL['dbname']."'") 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 100');
$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
[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)