Skip to content

pg_field_type first call is very slow #9692

Open
@vicreal

Description

@vicreal

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions