';
return $htmlOutput;
}
/**
* find all the possible partial dependencies based on data in the table.
*
* @param string $table current table
* @param string $db current database
*
* @return string HTML containing the list of all the possible partial dependencies
*/
public function findPartialDependencies($table, $db)
{
$dependencyList = [];
$this->dbi->selectDb($db);
$columnNames = $this->dbi->getColumnNames($db, $table);
$columns = [];
foreach ($columnNames as $column) {
$columns[] = Util::backquote($column);
}
$totalRowsRes = $this->dbi->fetchResult(
'SELECT COUNT(*) FROM (SELECT * FROM '
. Util::backquote($table) . ' LIMIT 500) as dt;'
);
$totalRows = $totalRowsRes[0];
$primary = Index::getPrimary($table, $db);
$primarycols = $primary === false ? [] : $primary->getColumns();
$pk = [];
foreach ($primarycols as $col) {
$pk[] = Util::backquote($col->getName());
}
$partialKeys = $this->getAllCombinationPartialKeys($pk);
$distinctValCount = $this->findDistinctValuesCount(
array_unique(
array_merge($columns, $partialKeys)
),
$table
);
foreach ($columns as $column) {
if (in_array($column, $pk)) {
continue;
}
foreach ($partialKeys as $partialKey) {
if (
! $partialKey
|| ! $this->checkPartialDependency(
$partialKey,
$column,
$table,
$distinctValCount[$partialKey],
$distinctValCount[$column],
$totalRows
)
) {
continue;
}
$dependencyList[$partialKey][] = $column;
}
}
$html = __('This list is based on a subset of the table\'s data and is not necessarily accurate. ')
. '