Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/schema/PhabricatorConfigColumnSchema.php
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function setCharacterSet($character_set) { | ||||
$this->characterSet = $character_set; | $this->characterSet = $character_set; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getCharacterSet() { | public function getCharacterSet() { | ||||
return $this->characterSet; | return $this->characterSet; | ||||
} | } | ||||
public function getKeyByteLength() { | public function getKeyByteLength($prefix = null) { | ||||
$type = $this->getColumnType(); | $type = $this->getColumnType(); | ||||
$matches = null; | $matches = null; | ||||
if (preg_match('/^varchar\((\d+)\)$/', $type, $matches)) { | if (preg_match('/^varchar\((\d+)\)$/', $type, $matches)) { | ||||
// For utf8mb4, each character requires 4 bytes. | // For utf8mb4, each character requires 4 bytes. | ||||
return ((int)$matches[1]) * 4; | $size = (int)$matches[1]; | ||||
if ($prefix && $prefix < $size) { | |||||
$size = $prefix; | |||||
} | |||||
return $size * 4; | |||||
} | } | ||||
$matches = null; | $matches = null; | ||||
if (preg_match('/^char\((\d+)\)$/', $type, $matches)) { | if (preg_match('/^char\((\d+)\)$/', $type, $matches)) { | ||||
// We use char() only for fixed-length binary data, so its size | // We use char() only for fixed-length binary data, so its size | ||||
// is always the column size. | // is always the column size. | ||||
return ((int)$matches[1]); | $size = (int)$matches[1]; | ||||
if ($prefix && $prefix < $size) { | |||||
$size = $prefix; | |||||
} | |||||
return $size; | |||||
} | |||||
// The "long..." types are arbitrarily long, so just use a big number to | |||||
// get the point across. In practice, these should always index only a | |||||
// prefix. | |||||
if ($type == 'longtext') { | |||||
$size = (1 << 16); | |||||
if ($prefix && $prefix < $size) { | |||||
$size = $prefix; | |||||
} | |||||
return $size * 4; | |||||
} | |||||
if ($type == 'longblob') { | |||||
$size = (1 << 16); | |||||
if ($prefix && $prefix < $size) { | |||||
$size = $prefix; | |||||
} | |||||
return $size * 1; | |||||
} | } | ||||
switch ($type) { | switch ($type) { | ||||
case 'int(10) unsigned': | case 'int(10) unsigned': | ||||
return 4; | return 4; | ||||
} | } | ||||
// TODO: Build this out to catch overlong indexes. | // TODO: Build this out to catch overlong indexes. | ||||
Show All 33 Lines |