Forráskód Böngészése

#120 Added indexes on finalclass and enum columns

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@405 a333f486-631f-4898-b8df-5754b55c2be0
romainq 15 éve
szülő
commit
65e7f1c132
2 módosított fájl, 25 hozzáadás és 4 törlés
  1. 22 2
      core/attributedef.class.inc.php
  2. 3 2
      core/metamodel.class.php

+ 22 - 2
core/attributedef.class.inc.php

@@ -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");}

+ 3 - 2
core/metamodel.class.php

@@ -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`)";