public function Schema::calculateClusteredIndexRowSizeBytes in Drupal driver for SQL Server and SQL Azure 4.0.x
Same name and namespace in other branches
- 4.2.x src/Driver/Database/sqlsrv/Schema.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Schema::calculateClusteredIndexRowSizeBytes()
- 3.1.x src/Driver/Database/sqlsrv/Schema.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Schema::calculateClusteredIndexRowSizeBytes()
- 4.1.x src/Driver/Database/sqlsrv/Schema.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Schema::calculateClusteredIndexRowSizeBytes()
Estimates the row size of a clustered index.
See also
https://msdn.microsoft.com/en-us/library/ms178085.aspx
2 calls to Schema::calculateClusteredIndexRowSizeBytes()
- Schema::addIndex in src/
Driver/ Database/ sqlsrv/ Schema.php - Add an index.
- Schema::createPrimaryKey in src/
Driver/ Database/ sqlsrv/ Schema.php - Create primary key.
File
- src/
Driver/ Database/ sqlsrv/ Schema.php, line 1172
Class
Namespace
Drupal\sqlsrv\Driver\Database\sqlsrvCode
public function calculateClusteredIndexRowSizeBytes($table, $fields, $unique = TRUE) {
// The fields must already be in the database to retrieve their real size.
$info = $this
->queryColumnInformation($table);
// Specify the number of fixed-length and variable-length columns
// and calculate the space that is required for their storage.
$num_cols = count($fields);
$num_variable_cols = 0;
$max_var_size = 0;
$max_fixed_size = 0;
foreach ($fields as $field) {
if ($this
->isVariableLengthType($info['columns'][$field]['type'])) {
$num_variable_cols++;
$max_var_size += $info['columns'][$field]['max_length'];
}
else {
$max_fixed_size += $info['columns'][$field]['max_length'];
}
}
// If the clustered index is nonunique, account for the uniqueifier column.
if (!$unique) {
$num_cols++;
$num_variable_cols++;
$max_var_size += 4;
}
// Part of the row, known as the null bitmap, is reserved to manage column
// nullability. Calculate its size.
$null_bitmap = 2 + ($num_cols + 7) / 8;
// Calculate the variable-length data size.
$variable_data_size = empty($num_variable_cols) ? 0 : 2 + $num_variable_cols * 2 + $max_var_size;
// Calculate total row size.
$row_size = $max_fixed_size + $variable_data_size + $null_bitmap + 4;
return $row_size;
}