@@ -300,20 +300,20 @@ pub unsafe extern "C" fn cass_session_execute(
300
300
// Since `query.query` is consumed, we cannot match the statement
301
301
// after execution, to retrieve the cached metadata in case
302
302
// of prepared statements.
303
- Option < Arc < Vec < Arc < CassDataType > > > > ,
303
+ Option < Arc < CassResultData > > ,
304
304
) ,
305
305
QueryError ,
306
306
> ;
307
307
let query_res: QueryRes = match statement {
308
308
Statement :: Simple ( query) => {
309
309
// We don't store result metadata for Queries - return None.
310
- let maybe_result_col_data_types = None ;
310
+ let maybe_result_metadata = None ;
311
311
312
312
if paging_enabled {
313
313
session
314
314
. query_single_page ( query. query , bound_values, paging_state)
315
315
. await
316
- . map ( |( qr, psr) | ( qr, psr, maybe_result_col_data_types ) )
316
+ . map ( |( qr, psr) | ( qr, psr, maybe_result_metadata ) )
317
317
} else {
318
318
session
319
319
. query_unpaged ( query. query , bound_values)
@@ -322,21 +322,21 @@ pub unsafe extern "C" fn cass_session_execute(
322
322
(
323
323
result,
324
324
PagingStateResponse :: NoMorePages ,
325
- maybe_result_col_data_types ,
325
+ maybe_result_metadata ,
326
326
)
327
327
} )
328
328
}
329
329
}
330
330
Statement :: Prepared ( prepared) => {
331
- // Clone vector of the Arc<CassDataType> , so we don't do additional allocations when constructing
332
- // CassDataTypes in `CassResultData::from_result_payload` .
333
- let maybe_result_col_data_types = Some ( prepared . result_col_data_types . clone ( ) ) ;
331
+ // Clone result metadata , so we don't need to construct it from scratch in
332
+ // `CassResultData::from_column_specs` - it requires a lot of allocations for complex types .
333
+ let maybe_result_metadata = Some ( Arc :: clone ( & prepared . result_metadata ) ) ;
334
334
335
335
if paging_enabled {
336
336
session
337
337
. execute_single_page ( & prepared. statement , bound_values, paging_state)
338
338
. await
339
- . map ( |( qr, psr) | ( qr, psr, maybe_result_col_data_types ) )
339
+ . map ( |( qr, psr) | ( qr, psr, maybe_result_metadata ) )
340
340
} else {
341
341
session
342
342
. execute_unpaged ( & prepared. statement , bound_values)
@@ -345,16 +345,21 @@ pub unsafe extern "C" fn cass_session_execute(
345
345
(
346
346
result,
347
347
PagingStateResponse :: NoMorePages ,
348
- maybe_result_col_data_types ,
348
+ maybe_result_metadata ,
349
349
)
350
350
} )
351
351
}
352
352
}
353
353
} ;
354
354
355
355
match query_res {
356
- Ok ( ( result, paging_state_response, _maybe_col_data_types) ) => {
357
- let metadata = Arc :: new ( CassResultData :: from_column_specs ( result. col_specs ( ) ) ) ;
356
+ Ok ( ( result, paging_state_response, maybe_result_metadata) ) => {
357
+ // maybe_result_metadata is:
358
+ // - Some(_) for prepared statements
359
+ // - None for unprepared statements
360
+ let metadata = maybe_result_metadata. unwrap_or_else ( || {
361
+ Arc :: new ( CassResultData :: from_column_specs ( result. col_specs ( ) ) )
362
+ } ) ;
358
363
let cass_rows = result
359
364
. rows
360
365
. map ( |rows| create_cass_rows_from_rows ( rows, & metadata) ) ;
0 commit comments