As I mentioned above, the cleanup went well on my testsystem. But it failed on the db with my provider =:-o.
Reason: on my test system runs a MySQL, my provider runs a MariaDB, wich do not support deletion with cte (common table expression) as I posted above. So some new SQL-statements had to be written and I'm posting them here if someone else runs into the same problems as i did.
SQL-Statements:
<pre>[code]
-- you have to replace pref in the table names with your table prefix (about 20 times)
-- create a first temporary table
drop table if exists pref_dpl;
create table pref_dpl
(
dpl_namek varchar(95) not null
, dpl_min_id int unsigned not null
, dpl_max_id int unsigned not null
, dpl_counter int unsigned not null
)
engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci
;
-- then fill the table with all multiple names on a single row including min and max id
insert into pref_dpl
select
substr(name, 1, 95) as dpl_namek
, min(id) as dpl_min_id
, max(id) as dpl_max_id
, count(*) as dpl_counter
from pref_options
where theme = "" -- when theme is not empty, duplicates are ok: one entry per theme
group by
dpl_namek
having dpl_counter > 1
;
commit;
-- create a second temporary table
drop table if exists pref_ald;
create table pref_ald
(
ald_namek varchar(95) not null
, ald_id int unsigned not null
)
engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci
;
-- then fill the table with all multiple entries with their ids
insert into pref_ald
select
substr(name, 1, 95) as ald_namek
, id as ald_id
from pref_options
inner join pref_dpl
on substr(name, 1, 95) = dpl_namek
;
commit;
-- create a third temporary table
drop table if exists pref_did;
create table pref_did
(
did_id int unsigned not null
)
engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci
;
-- then fill the table with all ids to delete
insert into pref_did
select
ald_id as did_id
from pref_dpl
inner join pref_ald
on dpl_namek = ald_namek
-- and dpl_min_id <> ald_id -- do not delete the lowest id
and dpl_max_id <> ald_id -- do not delete the highest id
;
commit;
-- finally, delete the duplicates on the pref_options table
delete
from pref_options
where id in (select did_id from pref_did)
;
commit;
-- now, we are ready to alter the table to adjust the index in advance of the update to 1.6.0
alter table pref_options
drop index unique_option
, add unique unique_option (`name`(95), `ownerid`, `theme`(95)) using btree
;
-- housekeeping
drop table if exists pref_dpl;
drop table if exists pref_ald;
drop table if exists pref_did;[/code]</pre>
End of SQL-Statements
They run on my MySQL with my provider without any problem, now everything is fine, I am on 1.6.2 with 1.6.5 as target.