From 8f6bc97a3601996db3e88a111cd19c2176710ebb Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Mon, 21 Apr 2025 13:43:44 +0100 Subject: [PATCH] ext/pgsql: pg_fetch_all_columns/pg_copy_to arrays optimisations. (#18374) changes to packed arrays for output userland values. --- ext/pgsql/pgsql.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index c53bf8ed9a3..745b247c661 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2186,17 +2186,18 @@ PHP_FUNCTION(pg_fetch_all_columns) RETURN_THROWS(); } - array_init(return_value); - if ((pg_numrows = PQntuples(pgsql_result)) <= 0) { - return; + RETURN_EMPTY_ARRAY(); } + array_init_size(return_value, pg_numrows); + zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); + for (pg_row = 0; pg_row < pg_numrows; pg_row++) { if (PQgetisnull(pgsql_result, pg_row, (int)colno)) { - add_next_index_null(return_value); + add_index_null(return_value, pg_row); } else { - add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, (int)colno)); + add_index_string(return_value, pg_row, PQgetvalue(pgsql_result, pg_row, (int)colno)); } } } @@ -3363,6 +3364,7 @@ PHP_FUNCTION(pg_copy_to) PQclear(pgsql_result); array_init(return_value); + zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); while (!copydone) { int ret = PQgetCopyData(pgsql, &csv, 0);