@@ -147,18 +147,12 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, free_last_data)(MYSQLND_RES_UNBUFFERED
147
147
}
148
148
149
149
DBG_INF_FMT ("field_count=%u" , unbuf -> field_count );
150
- if (unbuf -> last_row_data ) {
151
- unsigned int i ;
152
- for (i = 0 ; i < unbuf -> field_count ; i ++ ) {
153
- zval_ptr_dtor_nogc (& (unbuf -> last_row_data [i ]));
154
- }
155
-
156
- /* Free last row's zvals */
157
- mnd_efree (unbuf -> last_row_data );
158
- unbuf -> last_row_data = NULL ;
159
- }
160
150
if (unbuf -> last_row_buffer .ptr ) {
161
151
DBG_INF ("Freeing last row buffer" );
152
+ for (unsigned i = 0 ; i < unbuf -> field_count ; i ++ ) {
153
+ zval_ptr_dtor_nogc (& unbuf -> last_row_data [i ]);
154
+ }
155
+
162
156
/* Nothing points to this buffer now, free it */
163
157
unbuf -> result_set_memory_pool -> free_chunk (
164
158
unbuf -> result_set_memory_pool , unbuf -> last_row_buffer .ptr );
@@ -612,7 +606,7 @@ static const size_t *
612
606
MYSQLND_METHOD (mysqlnd_result_unbuffered , fetch_lengths )(const MYSQLND_RES_UNBUFFERED * const result )
613
607
{
614
608
/* simulate output of libmysql */
615
- return (result -> last_row_data || result -> eof_reached )? result -> lengths : NULL ;
609
+ return (result -> last_row_buffer . ptr || result -> eof_reached )? result -> lengths : NULL ;
616
610
}
617
611
/* }}} */
618
612
@@ -660,8 +654,6 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
660
654
/* Not fully initialized object that is being cleaned up */
661
655
DBG_RETURN (FAIL );
662
656
}
663
- /* Let the row packet fill our buffer and skip additional mnd_malloc + memcpy */
664
- row_packet -> skip_extraction = FALSE;
665
657
666
658
checkpoint = result -> memory_pool -> checkpoint ;
667
659
mysqlnd_mempool_save_state (result -> memory_pool );
@@ -673,52 +665,48 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
673
665
if (PASS == (ret = PACKET_READ (conn , row_packet )) && !row_packet -> eof ) {
674
666
result -> unbuf -> m .free_last_data (result -> unbuf , conn -> stats );
675
667
676
- result -> unbuf -> last_row_data = row_packet -> fields ;
677
668
result -> unbuf -> last_row_buffer = row_packet -> row_buffer ;
678
- row_packet -> fields = NULL ;
679
669
row_packet -> row_buffer .ptr = NULL ;
680
670
681
671
MYSQLND_INC_CONN_STATISTIC (conn -> stats , STAT_ROWS_FETCHED_FROM_CLIENT_NORMAL_UNBUF );
682
672
683
- if (!row_packet -> skip_extraction ) {
684
- unsigned int i , field_count = meta -> field_count ;
673
+ unsigned int i , field_count = meta -> field_count ;
674
+
675
+ enum_func_status rc = result -> unbuf -> m .row_decoder (& result -> unbuf -> last_row_buffer ,
676
+ result -> unbuf -> last_row_data ,
677
+ field_count ,
678
+ row_packet -> fields_metadata ,
679
+ conn -> options -> int_and_float_native ,
680
+ conn -> stats );
681
+ if (PASS != rc ) {
682
+ mysqlnd_mempool_restore_state (result -> memory_pool );
683
+ result -> memory_pool -> checkpoint = checkpoint ;
684
+ DBG_RETURN (FAIL );
685
+ }
686
+ {
687
+ * row = mnd_emalloc (field_count * sizeof (char * ));
688
+ MYSQLND_FIELD * field = meta -> fields ;
689
+ size_t * lengths = result -> unbuf -> lengths ;
685
690
686
- enum_func_status rc = result -> unbuf -> m .row_decoder (& result -> unbuf -> last_row_buffer ,
687
- result -> unbuf -> last_row_data ,
688
- field_count ,
689
- row_packet -> fields_metadata ,
690
- conn -> options -> int_and_float_native ,
691
- conn -> stats );
692
- if (PASS != rc ) {
693
- mysqlnd_mempool_restore_state (result -> memory_pool );
694
- result -> memory_pool -> checkpoint = checkpoint ;
695
- DBG_RETURN (FAIL );
696
- }
697
- {
698
- * row = mnd_emalloc (field_count * sizeof (char * ));
699
- MYSQLND_FIELD * field = meta -> fields ;
700
- size_t * lengths = result -> unbuf -> lengths ;
701
-
702
- for (i = 0 ; i < field_count ; i ++ , field ++ ) {
703
- zval * data = & result -> unbuf -> last_row_data [i ];
704
- const size_t len = (Z_TYPE_P (data ) == IS_STRING )? Z_STRLEN_P (data ) : 0 ;
691
+ for (i = 0 ; i < field_count ; i ++ , field ++ ) {
692
+ zval * data = & result -> unbuf -> last_row_data [i ];
693
+ const size_t len = (Z_TYPE_P (data ) == IS_STRING )? Z_STRLEN_P (data ) : 0 ;
705
694
706
695
/* BEGIN difference between normal normal fetch and _c */
707
- if (Z_TYPE_P (data ) != IS_NULL ) {
708
- convert_to_string (data );
709
- (* row )[i ] = Z_STRVAL_P (data );
710
- } else {
711
- (* row )[i ] = NULL ;
712
- }
696
+ if (Z_TYPE_P (data ) != IS_NULL ) {
697
+ convert_to_string (data );
698
+ (* row )[i ] = Z_STRVAL_P (data );
699
+ } else {
700
+ (* row )[i ] = NULL ;
701
+ }
713
702
/* END difference between normal normal fetch and _c */
714
703
715
- if (lengths ) {
716
- lengths [i ] = len ;
717
- }
704
+ if (lengths ) {
705
+ lengths [i ] = len ;
706
+ }
718
707
719
- if (field -> max_length < len ) {
720
- field -> max_length = len ;
721
- }
708
+ if (field -> max_length < len ) {
709
+ field -> max_length = len ;
722
710
}
723
711
}
724
712
}
@@ -788,8 +776,6 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row)(MYSQLND_RES * result, void
788
776
/* Not fully initialized object that is being cleaned up */
789
777
DBG_RETURN (FAIL );
790
778
}
791
- /* Let the row packet fill our buffer and skip additional mnd_malloc + memcpy */
792
- row_packet -> skip_extraction = row ? FALSE:TRUE;
793
779
794
780
checkpoint = result -> memory_pool -> checkpoint ;
795
781
mysqlnd_mempool_save_state (result -> memory_pool );
@@ -801,14 +787,12 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row)(MYSQLND_RES * result, void
801
787
if (PASS == (ret = PACKET_READ (conn , row_packet )) && !row_packet -> eof ) {
802
788
result -> unbuf -> m .free_last_data (result -> unbuf , conn -> stats );
803
789
804
- result -> unbuf -> last_row_data = row_packet -> fields ;
805
790
result -> unbuf -> last_row_buffer = row_packet -> row_buffer ;
806
- row_packet -> fields = NULL ;
807
791
row_packet -> row_buffer .ptr = NULL ;
808
792
809
793
MYSQLND_INC_CONN_STATISTIC (conn -> stats , STAT_ROWS_FETCHED_FROM_CLIENT_NORMAL_UNBUF );
810
794
811
- if (! row_packet -> skip_extraction ) {
795
+ if (row ) {
812
796
unsigned int i , field_count = meta -> field_count ;
813
797
814
798
enum_func_status rc = result -> unbuf -> m .row_decoder (& result -> unbuf -> last_row_buffer ,
@@ -1263,8 +1247,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
1263
1247
row_packet .binary_protocol = binary_protocol ;
1264
1248
row_packet .fields_metadata = meta -> fields ;
1265
1249
1266
- row_packet .skip_extraction = TRUE; /* let php_mysqlnd_rowp_read() not allocate row_packet.fields, we will do it */
1267
-
1268
1250
while (FAIL != (ret = PACKET_READ (conn , & row_packet )) && !row_packet .eof ) {
1269
1251
if (!free_rows ) {
1270
1252
MYSQLND_ROW_BUFFER * new_row_buffers ;
@@ -1301,7 +1283,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
1301
1283
set -> row_count ++ ;
1302
1284
1303
1285
/* So row_packet's destructor function won't efree() it */
1304
- row_packet .fields = NULL ;
1305
1286
row_packet .row_buffer .ptr = NULL ;
1306
1287
1307
1288
/*
@@ -1459,7 +1440,9 @@ MYSQLND_METHOD(mysqlnd_res, skip_result)(MYSQLND_RES * const result)
1459
1440
STAT_FLUSHED_PS_SETS );
1460
1441
1461
1442
while ((PASS == result -> m .fetch_row (result , NULL , 0 , & fetched_anything )) && fetched_anything == TRUE) {
1462
- /* do nothing */ ;
1443
+ MYSQLND_INC_CONN_STATISTIC (conn -> stats ,
1444
+ result -> type == MYSQLND_RES_NORMAL
1445
+ ? STAT_ROWS_SKIPPED_NORMAL : STAT_ROWS_SKIPPED_PS );
1463
1446
}
1464
1447
}
1465
1448
DBG_RETURN (PASS );
@@ -1880,6 +1863,9 @@ mysqlnd_result_unbuffered_init(MYSQLND_RES *result, const unsigned int field_cou
1880
1863
ret -> lengths = pool -> get_chunk (pool , field_count * sizeof (size_t ));
1881
1864
memset (ret -> lengths , 0 , field_count * sizeof (size_t ));
1882
1865
1866
+ ret -> last_row_data = pool -> get_chunk (pool , field_count * sizeof (zval ));
1867
+ memset (ret -> last_row_data , 0 , field_count * sizeof (zval ));
1868
+
1883
1869
ret -> result_set_memory_pool = pool ;
1884
1870
ret -> field_count = field_count ;
1885
1871
ret -> ps = ps ;
0 commit comments