I conducted a simple test: create 3 tables, one for storing the data itself with two columns and ID (int) and data (varchar [120]), another table that uses the identifier as a foreign key and the last one that uses data as a foreign key:
CREATE TABLE `dados` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(120) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) USING BTREE, KEY `idx` (`id`,`name`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE `refINT` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `dado` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `id` (`dado`), CONSTRAINT `id` FOREIGN KEY (`dado`) REFERENCES `dados` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE `refSTR` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `dado` varchar(120) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `nome` (`dado`), CONSTRAINT `nome` FOREIGN KEY (`dado`) REFERENCES `dados` (`name`) ON DELETE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
Insert 100 records into each table and compare the size of the final table:
dados: 192.0 KB refINT: 32.0 KB refSTR: 32.0 KB
So, I think the data is NOT replicated to the varchar foreign key, well, at least in MySQL 5.1.
Magus Apr 23 2018-11-21T00: 00Z
source share