Skip to content

Commit 8f6bc97

Browse files
authored
ext/pgsql: pg_fetch_all_columns/pg_copy_to arrays optimisations. (#18374)
changes to packed arrays for output userland values.
1 parent 23e9d8b commit 8f6bc97

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ext/pgsql/pgsql.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -2186,17 +2186,18 @@ PHP_FUNCTION(pg_fetch_all_columns)
21862186
RETURN_THROWS();
21872187
}
21882188

2189-
array_init(return_value);
2190-
21912189
if ((pg_numrows = PQntuples(pgsql_result)) <= 0) {
2192-
return;
2190+
RETURN_EMPTY_ARRAY();
21932191
}
21942192

2193+
array_init_size(return_value, pg_numrows);
2194+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
2195+
21952196
for (pg_row = 0; pg_row < pg_numrows; pg_row++) {
21962197
if (PQgetisnull(pgsql_result, pg_row, (int)colno)) {
2197-
add_next_index_null(return_value);
2198+
add_index_null(return_value, pg_row);
21982199
} else {
2199-
add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, (int)colno));
2200+
add_index_string(return_value, pg_row, PQgetvalue(pgsql_result, pg_row, (int)colno));
22002201
}
22012202
}
22022203
}
@@ -3363,6 +3364,7 @@ PHP_FUNCTION(pg_copy_to)
33633364

33643365
PQclear(pgsql_result);
33653366
array_init(return_value);
3367+
zend_hash_real_init_packed(Z_ARRVAL_P(return_value));
33663368
while (!copydone)
33673369
{
33683370
int ret = PQgetCopyData(pgsql, &csv, 0);

0 commit comments

Comments
 (0)