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: -
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:
Status: Open Package: PostgreSQL related
PHP Version: 7.2.0 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 13:01:24 2019 UTC