Builds the DDL SQL to add an Index.

@param  Index  $index
@return string
357271
public function getAddIndexDDL(Index $index)
    {
        $pattern = "
CREATE %sINDEX %s ON %s (%s);
";

        return sprintf($pattern,
            $this->getIndexType($index),
            $this->quoteIdentifier($index->getName()),
            $this->quoteIdentifier($index->getTable()->getName()),
            $this->getIndexColumnListDDL($index)
        );
    }
1272565
public function getAddIndexDDL(Index $index)
    {
        // don't create index form primary key
        if ($this->getPrimaryKeyName($index->getTable()) == $this->quoteIdentifier($index->getName())) {
            return '';
        }

        $pattern = "
CREATE %sINDEX %s ON %s (%s)%s;
";

        return sprintf($pattern,
            $index->isUnique() ? 'UNIQUE ' : '',
            $this->quoteIdentifier($index->getName()),
            $this->quoteIdentifier($index->getTable()->getName()),
            $this->getColumnListDDL($index->getColumnObjects()),
            $this->generateBlockStorage($index)
        );
    }
473493
protected function getIndexColumnListDDL(Index $index)
    {
        $list = array();
        foreach ($index->getColumns() as $col) {
            $list[] = $this->quoteIdentifier($col) . ($index->hasColumnSize($col) ? '(' . $index->getColumnSize($col) . ')' : '');
        }

        return implode(', ', $list);
    }
754832
public function remove($index)
    {
        $db = $this->load();
        array_splice($db, $index, 1);
        return $this->rewrite($db);
    }
221459
public function getIndexDDL(Index $index)
    {
        return sprintf('%sINDEX %s (%s)', $index->getIsUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->getColumnListDDL($index->getColumns()));
    }
374329
public function getAddIndexDDL(Index $index)
    {
        // don't create index form primary key
        if ($this->getPrimaryKeyName($index->getTable()) == $this->quoteIdentifier($index->getName())) {
            return "";
        }

        $pattern = "
CREATE %sINDEX %s ON %s (%s)%s;
";

        return sprintf($pattern,
            $index->getIsUnique() ? 'UNIQUE ' : '',
            $this->quoteIdentifier($index->getName()),
            $this->quoteIdentifier($index->getTable()->getName()),
            $this->getColumnListDDL($index->getColumns()),
            $this->generateBlockStorage($index)
        );
    }
814146
public function getIndexDeclarationSQL($name, Index $index)
    {
        $columns = $index->getQuotedColumns($this);
        $name = new Identifier($name);

        if (count($columns) == 0) {
            throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
        }

        return 'INDEX ' . $name->getQuotedName($this) . ' USING FULLTEXT ('. $this->getIndexFieldDeclarationListSQL($columns) . ')';
    }
564266
public function index($index = null)
	{
		if (null === $index) {
			$index = Config::get('search.default_index', 'default');
		}
		
		if (!isset($this->indexes[$index])) {
			$this->indexes[$index] = Index::factory($index, $this->driver);
		}
		
		return $this->indexes[$index];
	}
831511
public function createIndex(Index $index, $table)
    {
        $this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
    }
84753
protected function findColumns($index)
    {
        $sql = 'DESCRIBE ' . $this->quoteSimpleIndexName($index->name);
        try {
            $columns = $this->db->createCommand($sql)->queryAll();
        } catch (\Exception $e) {
            $previous = $e->getPrevious();
            if ($previous instanceof \PDOException && strpos($previous->getMessage(), 'SQLSTATE[42S02') !== false) {
                // index does not exist
                // https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html#error_er_bad_table_error
                return false;
            }
            throw $e;
        }

        if (empty($columns[0]['Agent'])) {
            foreach ($columns as $info) {
                $column = $this->loadColumnSchema($info);
                if (isset($index->columns[$column->name])) {
                    $column = $this->mergeColumnSchema($index->columns[$column->name], $column);
                }
                $index->columns[$column->name] = $column;
                if ($column->isPrimaryKey) {
                    $index->primaryKey = $column->name;
                }
            }

            return true;
        }

        // Distributed index :
        foreach ($columns as $column) {
            if (!empty($column['Type']) && strcasecmp('local', $column['Type']) !== 0) {
                // skip type 'agent'
                continue;
            }

            $agent = $this->getIndexSchema($column['Agent']);
            if ($agent !== null) {
                $index->columns = $agent->columns;
                $index->primaryKey = $agent->primaryKey;
                return true;
            }
        }

        $this->applyDefaultColumns($index);

        return true;
    }
622456
public function getColumnByIndex($index)
    {
        $keys = array_keys($this->columns);
        if (empty($keys[$index]) || empty($column = $this->columns[$keys[$index]])) {
            throw new \InvalidArgumentException('Table don\'t have a column index : ' . $index);
        }

        return $column;
    }
228280
protected function prepareIndex($index)
    {
        foreach ($index as &$value) {
            // Convert ascending
            $value = $value === 'asc' ? 1 : $value;

            // Convert descending
            $value = $value === 'desc' ? -1 : $value;

            // Convert geo to 2d
            $value = $value === 'geo' ? '2d' : $value;
        }

        return $index;
    }
270429
protected function populateIndex($index)
    {
        $this->line('Populating the index « '.$index.' » ...');

        // Replaces the current default index by the one we want to populate
        $defaultIndex = Plastic::getDefaultIndex();
        Plastic::setDefaultIndex($index);

        // Disables query logging to prevent memory leak
        $logging = DB::connection()->logging();
        DB::connection()->disableQueryLog();

        // Populates from models
        $models = $this->models($index);
        $chunkSize = $this->chunkSize();
        foreach ($models as $model) {
            $this->line('Indexing documents of model « '.$model.' » ...');
            $model::chunk($chunkSize, function ($items) {
                $this->line('Indexing chunk of '.$items->count().' documents ...');
                Plastic::persist()->bulkSave($items);
            });
        }

        // Restores query logging
        if ($logging) {
            DB::connection()->enableQueryLog();
        }

        // Restores the current default index
        Plastic::setDefaultIndex($defaultIndex);
    }
251147
protected function getAdvancedIndexOptionsSQL(Index $index)
    {
        $sql = '';

        if (! $index->isPrimary() && $index->hasFlag('for_olap_workload')) {
            $sql .= ' FOR OLAP WORKLOAD';
        }

        return $sql;
    }
59245
public function setId($index): self
    {
        \assert($index === null || \is_int($index) === true || \is_string($index) === true);

        $this->index = $index;

        return $this;
    }
617304
private function _appendUniqueConstraintDefinition($sql, Index $index)
    {
        $fields = [];

        foreach ($index->getQuotedColumns($this) as $field) {
            $fields[] = $field . ' IS NOT NULL';
        }

        return $sql . ' WHERE ' . implode(' AND ', $fields);
    }
104095
public static function getDeleted(Index $index)
    {
        $change = new IndexMigrationChange();

        $change->isDeleted = true;
        $change->index = $index;

        return $change;
    }