Bug #71409 [Opn->Fbk]: [Performance] include build in types in get_field_name()
| From: | ab@php.net | Date: | Fri, 15 Apr 2016 10:26:08 +0000 |
| Subject: | Bug #71409 [Opn->Fbk]: [Performance] include build in types in get_field_name() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200563@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71409&edit=1
ID: 71409
Updated by: ab@php.net
Reported by: php at sdiz dot net
Summary: [Performance] include build in types in
get_field_name()
-Status: Open
+Status: Feedback
Type: Bug
Package: PostgreSQL related
Operating System: Linux
PHP Version: 5.6.17
Block user comment: N
Private report: N
New Comment:
Please provide some test code to illustrate the issue.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2016-01-18 17:15:26] php at sdiz dot net
Description:
------------
Oid of PostgreSQL buildin types (those defined in src/include/catalog/pg_type.h) should be hardcoded
for performance.
Reason:
Currently, PHP do a "SELECT oid,typename FROM pg_type" on the first time get_field_name()
is called. Results are cached.
In most case, it is called for build-in types, which can use hardcoded value in pg_type.h. The
pg_type query is needed only if it miss.
I have some (non-PHP) application that create/drop lots of tables dynamically, pg_type is very
bloated and a simple select all take ~1 second. If you can cut it down, it will be a great
performance gain for me.
---
The related code is at: https://github.com/php/php-src/blob/master/ext/pgsql/pgsql.c#L2389
if ((field_type = zend_hash_find_ptr(list, str.s)) != NULL) {
ret = estrdup((char *)field_type->ptr);
} else { /* hash all oid's */
int i, num_rows;
int oid_offset,name_offset;
char *tmp_oid, *end_ptr, *tmp_name;
zend_resource new_oid_entry;
if ((result = PQexec(pgsql, "select oid,typname from pg_type")) == NULL ||
PQresultStatus(result) != PGRES_TUPLES_OK) {
if (result) {
PQclear(result);
}
Expected result:
----------------
The pg_type query is run only if I query on custom type.
Actual result:
--------------
The pg_type query is run always.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71409&edit=1