原理在用于定义对象关系的列上自动创建索引,
例如
用户: id,名称
消息: id,sender_id,receiver_id,消息
如果我定义消息和用户之间关系,消息只有一个发送者和接收者,则当我从模型生成sender_id时,sql将自动索引receiver_id和SQL域。我想禁用发送者的索引,因为我用sender_id和接收者id一起手动创建了索引。如何禁用自动生成的索引?
发布于 2011-01-09 22:41:05
你好,我以为你在用MySQL,然后看了一下Doctrine/Export/Mysql.php,我找到了这个:
// build indexes for all foreign key fields (needed in MySQL!!)
if (isset($options['foreignKeys'])) {
foreach ($options['foreignKeys'] as $fk) {
$local = $fk['local'];
$found = false;
if (isset($options['indexes'])) {
foreach ($options['indexes'] as $definition) {
if (is_string($definition['fields'])) {
// Check if index already exists on the column
$found = $found || ($local == $definition['fields']);
} else if (in_array($local, $definition['fields']) && count($definition['fields']) === 1) {
// Index already exists on the column
$found = true;
}
}
}
if (isset($options['primary']) && !empty($options['primary']) &&
in_array($local, $options['primary'])) {
// field is part of the PK and therefore already indexed
$found = true;
}
if ( ! $found) {
if (is_array($local)) {
foreach($local as $localidx) {
$options['indexes'][$localidx] = array('fields' => array($localidx => array()));
}
} else {
$options['indexes'][$local] = array('fields' => array($local => array()));
}
}
}
} 如果我理解正确的话,禁用索引应该是主键的一部分。
https://stackoverflow.com/questions/4614031
复制相似问题