@@ -1237,8 +1237,6 @@ MYSQLND_METHOD(mysqlnd_res, fetch_row)(MYSQLND_RES * result, void * param, const
1237
1237
/* }}} */
1238
1238
1239
1239
1240
- #define STORE_RESULT_PREALLOCATED_SET_IF_NOT_EMPTY 2
1241
-
1242
1240
/* {{{ mysqlnd_res::store_result_fetch_data */
1243
1241
enum_func_status
1244
1242
MYSQLND_METHOD (mysqlnd_res , store_result_fetch_data )(MYSQLND_CONN_DATA * const conn , MYSQLND_RES * result ,
@@ -1247,7 +1245,8 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
1247
1245
zend_bool binary_protocol )
1248
1246
{
1249
1247
enum_func_status ret ;
1250
- unsigned int next_extend = STORE_RESULT_PREALLOCATED_SET_IF_NOT_EMPTY , free_rows = 1 ;
1248
+ uint64_t total_allocated_rows = 0 ;
1249
+ unsigned int free_rows = 0 ;
1251
1250
MYSQLND_RES_BUFFERED * set = result -> stored_data ;
1252
1251
MYSQLND_PACKET_ROW row_packet ;
1253
1252
@@ -1256,14 +1255,8 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
1256
1255
ret = FAIL ;
1257
1256
goto end ;
1258
1257
}
1259
- if (free_rows ) {
1260
- * row_buffers = mnd_emalloc ((size_t )(free_rows * sizeof (MYSQLND_MEMORY_POOL_CHUNK * )));
1261
- if (!* row_buffers ) {
1262
- SET_OOM_ERROR (conn -> error_info );
1263
- ret = FAIL ;
1264
- goto end ;
1265
- }
1266
- }
1258
+
1259
+ * row_buffers = NULL ;
1267
1260
1268
1261
conn -> payload_decoder_factory -> m .init_row_packet (& row_packet );
1269
1262
set -> references = 1 ;
@@ -1277,17 +1270,33 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
1277
1270
1278
1271
while (FAIL != (ret = PACKET_READ (conn , & row_packet )) && !row_packet .eof ) {
1279
1272
if (!free_rows ) {
1280
- uint64_t total_allocated_rows = free_rows = next_extend = next_extend * 11 / 10 ; /* extend with 10% */
1281
1273
MYSQLND_MEMORY_POOL_CHUNK * * new_row_buffers ;
1282
1274
total_allocated_rows += set -> row_count ;
1283
1275
1276
+ if (total_allocated_rows < 1024 ) {
1277
+ if (total_allocated_rows == 0 ) {
1278
+ free_rows = 1 ;
1279
+ total_allocated_rows = 1 ;
1280
+ } else {
1281
+ free_rows = total_allocated_rows ;
1282
+ total_allocated_rows *= 2 ;
1283
+ }
1284
+ } else {
1285
+ free_rows = 1024 ;
1286
+ total_allocated_rows += 1024 ;
1287
+ }
1288
+
1284
1289
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
1285
1290
if (total_allocated_rows * sizeof (MYSQLND_MEMORY_POOL_CHUNK * ) > SIZE_MAX ) {
1286
1291
SET_OOM_ERROR (conn -> error_info );
1287
1292
ret = FAIL ;
1288
1293
goto free_end ;
1289
1294
}
1290
- new_row_buffers = mnd_erealloc (* row_buffers , (size_t )(total_allocated_rows * sizeof (MYSQLND_MEMORY_POOL_CHUNK * )));
1295
+ if (* row_buffers ) {
1296
+ new_row_buffers = mnd_erealloc (* row_buffers , (size_t )(total_allocated_rows * sizeof (MYSQLND_MEMORY_POOL_CHUNK * )));
1297
+ } else {
1298
+ new_row_buffers = mnd_emalloc ((size_t )(total_allocated_rows * sizeof (MYSQLND_MEMORY_POOL_CHUNK * )));
1299
+ }
1291
1300
if (!new_row_buffers ) {
1292
1301
SET_OOM_ERROR (conn -> error_info );
1293
1302
ret = FAIL ;
@@ -1323,6 +1332,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
1323
1332
UPSERT_STATUS_SET_WARNINGS (conn -> upsert_status , row_packet .warning_count );
1324
1333
UPSERT_STATUS_SET_SERVER_STATUS (conn -> upsert_status , row_packet .server_status );
1325
1334
}
1335
+
1326
1336
/* save some memory */
1327
1337
if (free_rows ) {
1328
1338
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
0 commit comments