Optimize wordpress database


ALTER TABLE wp_usermeta ADD UNIQUE KEY umeta_id (umeta_id);
ALTER TABLE wp_usermeta DROP PRIMARY KEY;
ALTER TABLE wp_usermeta ADD PRIMARY KEY (user_id, meta_key, umeta_id);
ALTER TABLE wp_usermeta DROP KEY user_id;
ALTER TABLE wp_usermeta DROP KEY meta_key;
ALTER TABLE wp_usermeta ADD KEY meta_key (meta_key, user_id);

ALTER TABLE wp_postmeta ADD UNIQUE KEY meta_id (meta_id);
ALTER TABLE wp_postmeta DROP PRIMARY KEY;
#ALTER TABLE wp_postmeta ADD PRIMARY KEY (post_id, meta_key, meta_id);
#ALTER TABLE wp_postmeta ADD KEY (post_id, meta_key, meta_value(64));
CREATE INDEX wp_postmeta_idx_1 ON wp_postmeta (post_id, meta_key, meta_value(64));
ALTER TABLE wp_postmeta DROP KEY post_id;
ALTER TABLE wp_postmeta DROP KEY meta_key;
ALTER TABLE wp_postmeta ADD PRIMARY KEY meta_key (meta_key, post_id);

ALTER TABLE wp_posts ADD KEY posts_key (post_status, post_type);

ALTER TABLE wp_wfIssues ADD PRIMARY KEY (ignoreP);

CREATE INDEX wp_wfissues1_idx ON wp_wfIssues (ignoreP);

CREATE INDEX wp_wfissues2_idx ON wp_wfIssues (ignoreC);

ALTER TABLE wp_terms ADD PRIMARY KEY (term_id);

CREATE INDEX wp_posts_post_modified_gmt_idx ON wp_posts (post_modified_gmt);
— wp_comments
— wp_commentmeta
— wp_posts
— wp_postmeta
— wp_termmeta
— wp_users
— wp_usermeta
— wp_options

delete from wp_comments where user_id = 0;

ALTER TABLE wp_comments ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES wp_users(id);

delete from wp_usermeta where umeta_id in (
select wp_usermeta.`umeta_id` from wp_usermeta left join wp_users on wp_users.id = wp_usermeta.user_id where wp_users.id is null
);
ALTER TABLE wp_usermeta ADD CONSTRAINT fk_usermeta_user_id FOREIGN KEY (user_id) REFERENCES wp_users(id);

ALTER TABLE wp_termmeta ADD CONSTRAINT fk_termmeta_terms FOREIGN KEY (term_id) REFERENCES wp_terms(term_id);


select wp_usermeta.`umeta_id` from wp_usermeta left join wp_users on wp_users.id = wp_usermeta.user_id where wp_users.id is null


ALTER TABLE wp_term_relationships ADD CONSTRAINT fk_wp_posts_wp_term_relationships FOREIGN KEY (object_id) REFERENCES wp_posts(ID);



Leave a Reply