MySQL/MariaDB – Do Unused Columns Notably Affect Performance?

mariadbMySQLoptimization

In the WordPress MySQL/MariaDB database there is a table with some columns that in my own uses of WordPress are never used.

The exact columns I am talking about are:

comment_status varchar(20)
ping_status varchar(20)
to_ping text
pinged text
comment_count bigint(20)

None of them is part of an index.

I wonder if removing those columns would make a notable performance difference.

Of course I cannot just remove those columns without modifying the WordPress core. My real goal behind the question is to gain feedback to know if it's worth the effort to participate in the WordPress development and find an alternative way to manage that information for websites still using those columns.

Best Answer

Unused columns do carry a cost, but rarely one that most people will notice or care about in systems with well-written, targeted queries. If you are curious about testing performance and contributing in a meaningful way to the WordPress project, you might want to consider doing something like this:

  1. Make a workable backup of your WordPress database. For example:

    sudo mysqldump wordpress > wordpress.sql
    

    Note: This assumes you would create backups via a command-line. If you prefer GUIs, make a backup in your preferred way.

  2. Drop the columns that you think you can live without:

    ALTER TABLE wp_posts DROP COLUMN comment_status;
    ALTER TABLE wp_posts DROP COLUMN ping_status;
    ALTER TABLE wp_posts DROP COLUMN to_ping;
    ALTER TABLE wp_posts DROP COLUMN pinged;
    ALTER TABLE wp_posts DROP COLUMN comment_count;
    
  3. See what breaks over the next few days. If WordPress is unhappy about something, it is not shy about telling the world that something is wrong.

    Then, if nothing bad happens...

  4. Begin modifying the WordPress API to handle those fields differently (if at all) and tweak the database to be more performant.

Working on a large project like WordPress can bring a great deal of satisfaction, particularly if any of your modifications are adopted by the core project.