1. Go to this page and download the library: Download heyosseus/vacuum library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Heyosseus\Vacuum\Advisor\{Finding, Severity, TableRule};
use Heyosseus\Vacuum\Values\TableStatistic;
final readonly class NeverAnalyzed implements TableRule
{
public function inspect(TableStatistic $table): ?Finding
{
if ($table->lastAnalyzedAt() !== null) {
return null;
}
return new Finding(
rule: 'never-analyzed',
subject: $table->qualifiedName(),
severity: Severity::Warning,
summary: 'Nothing has ever analyzed this table, so the planner is guessing.',
impact: 'Without statistics the planner cannot estimate row counts, and it will choose a bad plan confidently.',
remediation: "ANALYZE {$table->qualifiedName()};",
);
}
}
use Heyosseus\Vacuum\VacuumServiceProvider;
$this->app->tag([NeverAnalyzed::class], VacuumServiceProvider::TABLE_RULES);