Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#46565 new enhancement

Mixed engine in tables, could bring to major WP failure! Also there is a small fix that could avoid that.

Reported by: nokao's profile Nokao Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.8
Component: Database Keywords: needs-patch
Focuses: Cc:


First of all ... after MySQL decided to make InnoDB the default engine ... many of us have mixed database with both InnoDB and MyisAM labeled tables.

If a plugin add a new table now (it happened to us with both WPML and Woocommerce) the new table will be mostly InnoDB but old table could be MyIsAM.

That can bring to JOIN failures, that in our case made us lost primary key or foreign key links, but will definitely cause also tables permanent locks (due to plugin/software crash), and that took finally to the main problem:
data (rows) inserted with ID = 0

THAT alone should be advertised a lot around plugin developers, that should check if their plugin tables are equal to the current-default-engine and if they are not, they should:
"alter TABLENAME engine = current-default-engine".

Straight to the point:
Data with ID = 0 actually can make crash WordPress because of this:

Please note that this code will make WordPress go into a recursive infinite loop (causing "fatal error memory exhausted") if the ID = 0.
I know that ID = 0 is an abnormal situation, but believe me, if having locked tables makes this happen, you want to add a handbreak to that.

This is a small fix, but you surely can do better:

        // Start the search by looking at immediate children.
        if ( isset( $children[ $page_id ] ) ) {
                // Always start at the end of the stack in order to preserve original `$pages` order.
                $to_look = array_reverse( $children[ $page_id ] );

                while ( $to_look ) {
                        $p = array_pop( $to_look );
                        if (!array_key_exists($p->ID,$pidx)) {
                                $page_list[] = $p;
                                if ( isset( $children[ $p->ID ] ) ) {
                                        foreach ( array_reverse( $children[ $p->ID ] ) as $child ) {
                                                // Append to the `$to_look` stack to descend the tree.
                                                $to_look[] = $child;

Change History (1)

#1 @swissspidy
5 years ago

  • Component changed from General to Database
  • Focuses coding-standards removed
Note: See TracTickets for help on using tickets.