php.net |  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: 2022-10-10 08:06 UTC
Votes:2
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: cmb (profile)
Status: Duplicate Package: PostgreSQL related
PHP Version: 7.2.0 OS:
Private report: No CVE-ID: None
 [2017-12-19 13:01 UTC] dmitry dot kunilov at gmail dot com
Description:
------------
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.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2022-10-10 08:06 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-10-10 08:06 UTC] cmb@php.net
Closing as duplicate of https://github.com/php/php-src/issues/9692.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 11:05:53 2022 UTC