• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/db/mysqlcommonconnection.php
  • Класс: BitrixMainDBMysqlCommonConnection
  • Вызов: MysqlCommonConnection::createIndex
public function createIndex($tableName, $indexName, $columnNames, $columnLengths = null, $indexType = null)
{
	if (!is_array($columnNames))
	{
		$columnNames = array($columnNames);
	}

	$sqlHelper = $this->getSqlHelper();

	foreach ($columnNames as &$columnName)
	{
		if (is_array($columnLengths) && isset($columnLengths[$columnName]) && $columnLengths[$columnName] > 0)
		{
			$maxLength = intval($columnLengths[$columnName]);
		}
		else
		{
			$maxLength = 0;
		}

		$columnName = $sqlHelper->quote($columnName);
		if ($maxLength > 0)
		{
			$columnName .= '('.$maxLength.')';
		}
	}
	unset($columnName);

	$indexTypeSql = '';

	if ($indexType !== null
		&& in_array(strtoupper($indexType), [static::INDEX_UNIQUE, static::INDEX_FULLTEXT, static::INDEX_SPATIAL], true)
	)
	{
		$indexTypeSql = strtoupper($indexType);
	}

	$sql = 'CREATE '.$indexTypeSql.' INDEX '.$sqlHelper->quote($indexName).' ON '.$sqlHelper->quote($tableName)
		.' ('.join(', ', $columnNames).')';

	return $this->query($sql);
}