WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 7 months 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 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.8
Component: Database Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

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:
wp-includes/post.php:4867

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)) {
                                $pidx[$p->ID]=true;
                                $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
7 months ago

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