Bug #71409 [Fbk->NoF]: [Performance] include build in types in get_field_name()
Edit report at https://bugs.php.net/bug.php?id=71409&edit=1
ID: 71409
Updated by: php-bugs@lists.php.net
Reported by: php at sdiz dot net
Summary: [Performance] include build in types in
get_field_name()
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: PostgreSQL related
Operating System: Linux
PHP Version: 5.6.17
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2016-04-15 10:26:07] ab@php.net
Please provide some test code to illustrate the issue.
Thanks.
------------------------------------------------------------------------
[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
Thread (3 messages)