Search code examples
mysqlpercona

Create integer only table with a default charset, bad idea?


When I create a table, even if it's using integers only, I set the default charset to utf8 (because I copy paste the code and because in case I introduce a string column in the future).

Example:

CREATE TABLE IF NOT EXISTS `articles` (
  `id` smallint(6) unsigned NOT NULL,
  `disabled` tinyint(1) unsigned NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

However, i'm wondering if it's affecting "performances" to have a default charset in a table that do not make use of it.


Solution

  • The DEFAULT CHARSET clause at the bottom of your table creation is only metadata. It is only used if you add a CHAR/VARCHAR/TEXT column and don't explicitly define the column's character set. Then the table's default character set is used.

    Tables don't have any performance characteristic — they are just storage. Queries have performance.

    Since your table has no columns with character sets, there can be no query against this table that is affected by the character set. Therefore the default character set has no effect.