OllieJones / index-wp-mysql-for-speed

A plugin to add useful indexes to your WordPress installation's MySQL database.
GNU General Public License v2.0
125 stars 10 forks source link

PHP Fatal error: Uncaught ImfsException: [0]: Duplicate entry '0' for key 'option_id' in ALTER TABLE [...] #80

Open Znuff opened 4 months ago

Znuff commented 4 months ago

Hello,

While running

wp index-mysql enable --all --dry-run

This attempts to create a unique key on option_id:

Index WP MySQL For Speed 1.4.18
Versions  Plugin:1.4.18 MySQL:10.11.7-MariaDB-1:10.11.7+maria~ubu2204 WordPress:6.5.4 WordPress database:57155 php:8.0.30
WordPress database error Duplicate entry '0' for key 'option_id' for query ALTER TABLE `zs_options` ADD UNIQUE KEY option_id (option_id), ADD PRIMARY KEY (option_name), DROP KEY option_name, DROP KEY autoload_2, DROP KEY autoload_3, DROP KEY autoload_4/**imfs-query-tag*394371712*/ made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->run_command_and_exit, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, ImsfCli->enable, ImsfCli->doRekeying, ImfsDb->rekeyTables, ImfsDb->rekeyTable, ImfsDb->query
PHP Fatal error:  Uncaught ImfsException: [0]: Duplicate entry '0' for key 'option_id' in ALTER TABLE `zs_options` ADD UNIQUE KEY option_id (option_id), ADD PRIMARY KEY (option_name), DROP KEY option_name, DROP KEY autoload_2, DROP KEY autoload_3, DROP KEY autoload_4/**imfs-query-tag*394371712*/

Looking at my database structure, there seems to be A LOT of options with the option_id=0:

MariaDB > select count(*) from zs_options where option_id=0 \G
*************************** 1. row ***************************
count(*): 922
1 row in set (0.001 sec)

Looking at the entries in zs_options, there seem so be A LOT of different plugins that, over the years, have inserted an option with id=0.

This is a very very old Wordpress install (originating from 19-ish years ago?) .

I'm assuming that somewhere along the lines the _options table has received a auto_increment on the option_id column, but the damage was probably already done so that the schema alteration never took place on this table (because there were always duplicate keys).