public function DatabaseSchema_sqlsrv::calculateClusteredIndexRowSizeBytes in Drupal driver for SQL Server and SQL Azure 7.2
Same name and namespace in other branches
- 7.3 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::calculateClusteredIndexRowSizeBytes()
Estimates the row size of a clustered index.
See also
https://msdn.microsoft.com/en-us/library/ms178085.aspx
2 calls to DatabaseSchema_sqlsrv::calculateClusteredIndexRowSizeBytes()
- DatabaseSchema_sqlsrv::addIndex in sqlsrv/
schema.inc - Override DatabaseSchema::addIndex().
- DatabaseSchema_sqlsrv::createPrimaryKey in sqlsrv/
schema.inc - Create a Primary Key for the table, does not drop any prior primary keys neither it takes care of cleaning technical primary column. Only call this if you are sure the table does not currently hold a primary key.
File
- sqlsrv/
schema.inc, line 520 - Database schema code for Microsoft SQL Server database servers.
Class
Code
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;
}