+ protected function nativeInsertSelect(
+ $destTable, $srcTable, $varMap, $conds,
+ $fname = __METHOD__, $insertOptions = [], $selectOptions = [], $selectJoinConds = []
+ ) {
+ $isSafe = in_array( 'NO_AUTO_COLUMNS', $insertOptions, true );
+ if ( !$isSafe && $this->insertSelectIsSafe === null ) {
+ // In MySQL, an INSERT SELECT is only replication safe with row-based
+ // replication or if innodb_autoinc_lock_mode is 0. When those
+ // conditions aren't met, use non-native mode.
+ // While we could try to determine if the insert is safe anyway by
+ // checking if the target table has an auto-increment column that
+ // isn't set in $varMap, that seems unlikely to be worth the extra
+ // complexity.
+ $row = $this->selectRow(
+ false,
+ [
+ 'innodb_autoinc_lock_mode' => '@@innodb_autoinc_lock_mode',
+ 'binlog_format' => '@@binlog_format',
+ ],
+ [],
+ __METHOD__
+ );
+ $this->insertSelectIsSafe = $row->binlog_format === 'ROW' ||
+ (int)$row->innodb_autoinc_lock_mode === 0;
+ }
+
+ if ( !$isSafe && !$this->insertSelectIsSafe ) {
+ return $this->nonNativeInsertSelect(
+ $destTable,
+ $srcTable,
+ $varMap,
+ $conds,
+ $fname,
+ $insertOptions,
+ $selectOptions,
+ $selectJoinConds
+ );
+ } else {
+ return parent::nativeInsertSelect(
+ $destTable,
+ $srcTable,
+ $varMap,
+ $conds,
+ $fname,
+ $insertOptions,
+ $selectOptions,
+ $selectJoinConds
+ );
+ }
+ }
+