#120 Added indexes on finalclass and enum columns

SVN:trunk[405]
This commit is contained in:
Romain Quetiez
2010-05-15 07:44:46 +00:00
parent 2e07f73122
commit cf042a795d
2 changed files with 25 additions and 4 deletions

View File

@@ -175,6 +175,7 @@ abstract class AttributeDefinition
public function FromSQLToValue($aCols, $sPrefix = '') {return null;} // returns a value out of suffix/value pairs, for SELECT result interpretation
public function GetSQLColumns() {return array();} // returns column/spec pairs (1 in most of the cases), for STRUCTURING (DB creation)
public function GetSQLValues($value) {return array();} // returns column/value pairs (1 in most of the cases), for WRITING (Insert, Update)
public function RequiresIndex() {return false;}
public function GetJSCheckFunc()
{
@@ -676,6 +677,11 @@ class AttributeClass extends AttributeString
{
return MetaModel::GetName($sValue);
}
public function RequiresIndex()
{
return true;
}
}
/**
@@ -704,6 +710,11 @@ class AttributeFinalClass extends AttributeString
return false;
}
public function RequiresIndex()
{
return true;
}
public function SetFixedValue($sValue)
{
$this->m_sValue = $sValue;
@@ -869,8 +880,8 @@ class AttributeEnum extends AttributeString
}
if (count($aValues) > 0)
{
// The syntax used here is matters
// In particular, I had to remove unnecessary spaces to stick to
// The syntax used here do matters
// In particular, I had to remove unnecessary spaces to
// make sure that this string will match the field type returned by the DB
// (used to perform a comparison between the current DB format and the data model)
return "ENUM(".implode(",", $aValues).")";
@@ -881,6 +892,11 @@ class AttributeEnum extends AttributeString
}
}
public function RequiresIndex()
{
return true;
}
public function GetBasicFilterOperators()
{
return parent::GetBasicFilterOperators();
@@ -1109,6 +1125,10 @@ class AttributeExternalKey extends AttributeDBFieldVoid
public function GetTypeDesc() {return "Link to another object";}
public function GetEditClass() {return "ExtKey";}
protected function GetSQLCol() {return "INT(11)";}
public function RequiresIndex()
{
return true;
}
public function IsExternalKey($iType = EXTKEY_RELATIVE) {return true;}
public function GetTargetClass($iType = EXTKEY_RELATIVE) {return $this->Get("targetclass");}

View File

@@ -2320,12 +2320,13 @@ abstract class MetaModel
foreach($oAttDef->GetSQLColumns() as $sField => $sDBFieldType)
{
$bIndexNeeded = $oAttDef->RequiresIndex();
$sFieldSpecs = $oAttDef->IsNullAllowed() ? "$sDBFieldType NULL" : "$sDBFieldType NOT NULL";
if (!CMDBSource::IsField($sTable, $sField))
{
$aErrors[$sClass][$sAttCode][] = "field '$sField' could not be found in table '$sTable'";
$aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` ADD `$sField` $sFieldSpecs";
if ($oAttDef->IsExternalKey())
if ($bIndexNeeded)
{
$aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` ADD INDEX (`$sField`)";
}
@@ -2360,7 +2361,7 @@ abstract class MetaModel
// Create indexes (external keys only... so far)
//
if ($oAttDef->IsExternalKey() && !CMDBSource::HasIndex($sTable, $sField))
if ($bIndexNeeded && !CMDBSource::HasIndex($sTable, $sField))
{
$aErrors[$sClass][$sAttCode][] = "Foreign key '$sField' in table '$sTable' should have an index";
$aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` ADD INDEX (`$sField`)";