Bug #71409 [NEW]: [Performance] include build in types in get_field_name()

From: Date: Mon, 18 Jan 2016 17:15:29 +0000
Subject: Bug #71409 [NEW]: [Performance] include build in types in get_field_name()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198761@lists.php.net to get a copy of this message
From:             php at sdiz dot net
Operating system: Linux
PHP version:      5.6.17
Package:          PostgreSQL related
Bug Type:         Bug
Bug description:[Performance] include build in types in get_field_name()

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 bug report at https://bugs.php.net/bug.php?id=71409&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71409&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71409&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71409&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71409&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71409&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71409&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71409&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71409&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71409&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71409&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71409&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71409&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71409&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71409&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71409&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71409&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71409&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71409&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71409&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71409&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#198761) next »