[ticket/17524] Try not to hit MSSQL index key length limitations

900 bytes for a clustered index. 1,700 bytes for a nonclustered index.
For SQL Server 2014 (12.x) and earlier, all versions supported 900 bytes
for all index types.

PHPBB-17524
This commit is contained in:
rxu 2025-06-12 01:16:25 +07:00
parent ffcd71ac87
commit 967a7349da
No known key found for this signature in database
GPG key ID: 955F0567380E586A
2 changed files with 8 additions and 6 deletions

View file

@ -26,9 +26,9 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration
'COLUMNS' => [
'module_id' => ['UINT:3', NULL, 'auto_increment'],
'user_id' => ['ULINT', 0],
'endpoint' => ['TEXT', ''],
'endpoint' => ['VCHAR:220', ''],
'expiration_time' => ['TIMESTAMP', 0],
'p256dh' => ['VCHAR', ''],
'p256dh' => ['VCHAR:200', ''],
'auth' => ['VCHAR:100', ''],
],
'PRIMARY_KEY' => 'module_id',

View file

@ -419,14 +419,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertTrue(isset($index_data_row['i_auth']));
$is_mysql = $this->db->get_sql_layer() === 'mysqli'; // Key 'lengths' option only applies to MySQL indexes
$is_mssql = in_array($this->db->get_sql_layer(), ['mssqlnative', 'mssql_odbc']); // MSSQL primary index key has 'clustered' flag
// MSSQL primary index key has 'clustered' flag, 'nonclustered' otherwise
// See https://learn.microsoft.com/en-us/sql/relational-databases/indexes/clustered-and-nonclustered-indexes-described?view=sql-server-ver17#indexes-and-constraints
$is_mssql = in_array($this->db->get_sql_layer(), ['mssqlnative', 'mssql_odbc']);
foreach ($index_data_row as $index_name => $index_data)
{
switch ($index_name)
{
case 'i_simple':
$this->assertEquals(['user_id', 'endpoint'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertEquals($is_mssql ? ['nonclustered'] : [], $index_data['flags']);
$this->assertFalse($index_data['is_primary']);
$this->assertFalse($index_data['is_unique']);
$this->assertTrue($index_data['is_simple']);
@ -436,7 +438,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
break;
case 'i_uniq':
$this->assertEquals(['expiration_time', 'p256dh'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertEquals($is_mssql ? ['nonclustered'] : [], $index_data['flags']);
$this->assertFalse($index_data['is_primary']);
$this->assertTrue($index_data['is_unique']);
$this->assertFalse($index_data['is_simple']);
@ -446,7 +448,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
break;
case 'i_auth':
$this->assertEquals(['auth'], $index_data['columns']);
$this->assertEmpty($index_data['flags']);
$this->assertEquals($is_mssql ? ['nonclustered'] : [], $index_data['flags']);
$this->assertFalse($index_data['is_primary']);
$this->assertFalse($index_data['is_unique']);
$this->assertTrue($index_data['is_simple']);