|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75705 pg_field_type() slow and consumes CPU on a large database
Submitted: 2017-12-19 13:01 UTC Modified: -
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: dmitry dot kunilov at gmail dot com Assigned:
Status: Open Package: PostgreSQL related
PHP Version: 7.2.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
49 - 29 = ?
Subscribe to this entry?

 [2017-12-19 13:01 UTC] dmitry dot kunilov at gmail dot com
Our database has around 25K tables. Whenever a PHP script does a first call to pg_field_type(), it consumes a lot of CPU, memory and network traffic.
This is reproducible with all PHP versions from 5 to 7.2

The problem was narrowed down to the following query performed from ext/pgsql/pgsql.c get_field_name():

select oid,typname from pg_type

As postgresql defines several types for each table in the database, the above query produces over 76K rows on our system. All of those are put into a hashmap by get_field_name().

Obviously, rowset types present in pg_type table cannot be used as field types, and have to be excluded from the query.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 15:01:23 2020 UTC