[php-src] master: ext/pdo: Size PDO::FETCH_BOTH rows for both keys of each column (#24565)

From: Date: Fri, 23 Oct 2026 21:20:00 +0000
Subject: [php-src] master: ext/pdo: Size PDO::FETCH_BOTH rows for both keys of each column (#24565)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142643@lists.php.net to get a copy of this message
Author: Matthias Dötsch (brainexe) Committer: GitHub (web-flow) Pusher: iliaal Date: 2026-10-23T17:19:57-04:00 Commit: https://github.com/php/php-src/commit/14c65d1c284fe094689be0cefd23360960c72272 Raw diff: https://github.com/php/php-src/commit/14c65d1c284fe094689be0cefd23360960c72272.diff ext/pdo: Size PDO::FETCH_BOTH rows for both keys of each column (#24565) PDO::FETCH_BOTH, the default fetch mode, stores each value under its column name and its index, but the row array was sized for one entry per column. Rows with more than 4 columns were therefore resized and rehashed once per fetched row. The final array size is unchanged. 50x fetchAll(PDO::FETCH_BOTH) of 10k rows with 11 columns (pdo_pgsql): -4.9% instructions, -9% cycles Changed paths: M UPGRADING M ext/pdo/pdo_stmt.c Diff: diff --git a/UPGRADING b/UPGRADING index 39f8d9bbc0ba..baa930594bd9 100644 --- a/UPGRADING +++ b/UPGRADING @@ -183,6 +183,10 @@ PHP 8.7 UPGRADE NOTES - MBString: . Improved performance of mb_strlen for UTF-8 strings. +- PDO: + . Improved performance of fetching rows with PDO::FETCH_BOTH, the default + fetch mode, for results with more than 4 columns. + - PDO_PGSQL: . Improved performance of the SQL parser that handles placeholders in PDO::prepare() and, with emulated prepares, PDOStatement::execute(). diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index eab4398a0d5e..2a84d7ae2e98 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -735,7 +735,8 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h case PDO_FETCH_NUM: case PDO_FETCH_NAMED: if (!group_key) { - array_init_size(return_value, stmt->column_count); + /* PDO::FETCH_BOTH stores every value under its name and its index */ + array_init_size(return_value, how == PDO_FETCH_BOTH ? 2 * stmt->column_count : stmt->column_count); } else { array_init(return_value); }

« previous php.cvs (#142643) next »