Bug #84060 Use std::is_trivially_destructible in Mem_root_array
Submitted: 5 Dec 2016 12:59 Modified: 6 Dec 2016 18:27
Reporter: Knut Anders Hatlen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.1 OS:Any
Assigned to: CPU Architecture:Any

[5 Dec 2016 12:59] Knut Anders Hatlen
Description:
Mem_root_array takes a template argument that tells if the elements have trivial destructors, in which case it optimizes away the destruction of the elements when they are removed from the array or when the array is destroyed.

In C++11 we can instead use std::is_trivially_destructible to check if the elements have trivial destructors.

Currently, there are three cases where Mem_root_array is instantiated with has_trivial_destructor == false and std::is_trivially_destructible tells the destructor is not trivial:

- in_string::base_objects is a Mem_root_array of String objects. Mem_root_array's destructor does not destroy the String objects, instead in_string's destructor does it manually.

- in_row::base_objects is a Mem_root_array of cmp_item_row objects. Mem_root_array's destructor does not destroy the cmp_item_row objects, instead in_row's destructor does it manually.

- in_decimal::base is a Mem_root_array of my_decimal objects. my_decimal has a destructor which does some sanity checking in debug builds. It is a no-op in optimized builds, but it is still considered non-trivial by std::is_trivially_destructible.

These cases need to be handled if we change Mem_root_array to use std::is_trivially_destructible to determine if the destructors should be invoked. One possible approach:

- in_string and in_row can stop destroying the objects in the Mem_root_array manually, and instead leave the memory management to Mem_root_array.

- my_decimal's destructor can be disabled in optimized builds with #ifndef DBUG_OFF. Then in_decimal will still skip the destruction in optimized builds. In debug builds, it will invoke the destructors via Mem_root_array's destructor, so that we get additional sanity checks.

How to repeat:
N/A
[6 Dec 2016 18:27] Paul DuBois
Posted by developer:
 
Fixed in 8.0.1.

Code cleanup. No changelog entry needed.