How to create index (sql) to a meta_key?

I am new in programming, and the sql is absolutely stranger for me. I create today a new meta_key on my multisite, but when I use this in a query, my site will be horrible slow... I read (here: https://css-tricks.com/finding-and-fixing-slow-wordpress-database-queries/), that need for me creating a sql index for the meta_key, and this will doing incredibly faster my site... So here this sql command:

CREATE INDEX wp_postmeta_csstricks ON wp_postmeta (meta_key)

If my meta_key is _my_first_meta, I can use this code?:

CREATE INDEX wp_postmeta_my_first_meta ON wp_postmeta (_my_first_meta)

And where can I use this? In phpmyadmin? Please, If you can help me, write a reply for this, any help is usefull! I really dont find a simple and helpfull total tutorial for this on the net!

Topic mysql database Wordpress sql

Category Web


I'm not going to tell you about what will happen. I'll here give you an example on how you can run that piece of sql without phpMyadmin. Add this to your functions.php for temporary purpose. Not to forget about removing this after one run of your website.

$mymeta="_my_first_meta";
$wpdb->query(
   $wpdb->prepare("CREATE INDEX wp_postmeta_my_first_meta ON wp_postmeta (%s)",$mymeta)
);

Don't forget to replace your Database Prefix with "wp_"

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.