src/Db/QueryBuilder.php
protected function getTableUniqueColumnNames($name, $columns, &$constraints = [])
    {
        $schema = $this->db->getSchema();
        if (!$schema instanceof ConstraintFinderInterface) {
            return [];
        }

        $constraints = [];
        $primaryKey = $schema->getTablePrimaryKey($name);
        if ($primaryKey !== null) {
            $constraints[] = $primaryKey;
        }
        $indexes = $schema->getTableIndexes($name);
        foreach ($indexes as $constraint) {
            if ($constraint->isUnique) {
                $constraints[] = $constraint;
            }
        }
        $uniques = $schema->getTableUniques($name);
        $constraints = array_merge($constraints, $uniques);
        // Remove duplicates
        $constraints = array_combine(array_map(function(Constraint $constraint) {
            $columns = $constraint->columnNames;
            sort($columns, SORT_STRING);
            return json_encode($columns);
        }, $constraints), $constraints);
        $columnNames = [];
        // Remove all constraints which do not cover the specified column list
        $constraints = array_values(array_filter($constraints, function(Constraint $constraint) use ($schema, $columns, &$columnNames) {
            $constraintColumnNames = array_map([$schema, 'quoteColumnName'], $constraint->columnNames);
            $result = !array_diff($constraintColumnNames, $columns);
            if ($result) {
                $columnNames = array_merge($columnNames, $constraintColumnNames);
            }
            return $result;
        }));
        return array_unique($columnNames);
    }
protected function getTableUniqueColumnNames($name, $columns, &$constraints = [])
    {
        $schema = $this->db->getSchema();
        if (!$schema instanceof ConstraintFinderInterface) {
            return [];
        }

        $constraints = [];
        $primaryKey = $schema->getTablePrimaryKey($name);
        if ($primaryKey !== null) {
            $constraints[] = $primaryKey;
        }
        $indexes = $schema->getTableIndexes($name);
        foreach ($indexes as $constraint) {
            if ($constraint->isUnique) {
                $constraints[] = $constraint;
            }
        }
        $uniques = $schema->getTableUniques($name);
        $constraints = array_merge($constraints, $uniques);
        // Remove duplicates
        $constraints = array_combine(array_map(function(Constraint $constraint) {
            $columns = $constraint->columnNames;
            sort($columns, SORT_STRING);
            return json_encode($columns);
        }, $constraints), $constraints);
        $columnNames = [];
        // Remove all constraints which do not cover the specified column list
        $constraints = array_values(array_filter($constraints, function(Constraint $constraint) use ($schema, $columns, &$columnNames) {
            $constraintColumnNames = array_map([$schema, 'quoteColumnName'], $constraint->columnNames);
            $result = !array_diff($constraintColumnNames, $columns);
            if ($result) {
                $columnNames = array_merge($columnNames, $constraintColumnNames);
            }
            return $result;
        }));
        return array_unique($columnNames);
    }
Returns all column names belonging to constraints enforcing uniqueness (`PRIMARY KEY`, `UNIQUE INDEX`, etc.)
for the named table removing constraints which did not cover the specified column list.
The column list will be unique by column names.

@param string $name table name. The table name may contain schema name if any. Do not quote the table name.
@param string[] $columns source column list.
@param Constraint[] $constraints this parameter optionally recieves a matched constraint list.
The constraints will be unique by their column names.
@return string[] column list.