r/mysql • u/dominbdg • Oct 07 '25
question issue with create unique index
Hello,
I'm doing grafana update and have issue with create unique index.
Gragana is trying to create new index but failed:
mysql> CREATE UNIQUE INDEX `UQE_library_element_org_id_folder_uid_name_kind` ON `library_element` (`org_id`,`folder_uid`,`name`,`kind`);
ERROR 1170 (42000): BLOB/TEXT column 'name' used in key specification without a key length
Can You help me on that ?
0
Upvotes
2
u/Informal_Pace9237 Oct 07 '25
One of the columns you used is too long for indexing. Need to remove that column or specify how many characters of the column need to be (partially) indexed.
Or reduce the size of column
2
u/Aggressive_Ad_5454 Oct 08 '25 edited Oct 08 '25
When you create an index on a TEXT column in MySql or MariaDb, you must declare it as a so-called prefix index.Your error message makes it sound like your
namecolumn has the TEXT data type.You might try changing that column’s data type from TEXT to something like VARCHAR(250).
If grafana provided the table definition (including the TEXT column) and the CREATE UNIQUE INDEX statement you’re having trouble running, then, sad to say, grafana is defective. This is a well-known limitation of MariaDb and MySQL.
1
u/kickingtyres Oct 08 '25
It sounds like the column called “name” is a blob or text column. For blob or text you also need to include the first “n” characters to he indexed of that column. 767 is the max.
https://dev.mysql.com/doc/refman/8.4/en/column-indexes.html
Try
CREATE UNIQUE INDEX
UQE_library_element_org_id_folder_uid_name_kindONlibrary_element(org_id,folder_uid,name(767),kind);