translation icon indicating copy to clipboard operation
translation copied to clipboard

Wrong DB table example?

Open zraly opened this issue 2 years ago • 1 comments

In docs, there is this DB table example:

CREATE TABLE `messages` (
    `id` varchar(191) NOT NULL,
    `locale` char(5) NOT NULL,
    `message` varchar(191) NOT NULL,
    UNIQUE KEY `id` (`id`),
    KEY `locale` (`locale`),
    KEY `message` (`message`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

But maybe the UNIQUE KEY should be multi-column (id, locale)? This example would work for only one language.

Also, why the varchars are set to exactly 191 chars?

zraly avatar Oct 19 '22 10:10 zraly

You are right, UNIQUE key must be over id-locale, but it is possible without any unique key. And no idea, why varchar set for 191 characters.

How the table will look, it is only on you.

aleswita avatar Oct 20 '22 10:10 aleswita

@zraly Hi, varchar 191 is max that u can use when adding key on that column in UTF8MB4 table, at least in some versions of MySQL or MariaDB database, so it´s because of compatibility. http://mysql.rjweb.org/doc.php/limits#767_limit_in_innodb_indexes

darkWolf-PR avatar Nov 23 '22 14:11 darkWolf-PR