diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index 73a09be6fc..d6df3942b8 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -1233,7 +1233,20 @@ public function table_sql(string $table_name): string break; } - $line .= ' (`' . implode('`, `', $index['columns']) . '`)'; + $index_columns = []; + + foreach ($index['columns'] as $index_column) { + // A column can be indexed by its first so many characters. + // The count belongs after the name rather than inside it, + // so it has to be left outside the quoting. + if (preg_match('~^(.+)\((\d+)\)$~', $index_column, $matches) === 1) { + $index_columns[] = '`' . $matches[1] . '`(' . $matches[2] . ')'; + } else { + $index_columns[] = '`' . $index_column . '`'; + } + } + + $line .= ' (' . implode(', ', $index_columns) . ')'; $inner_lines[] = $line; }