Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up fetching range reports, evolution and sparkline reports #20121

Merged
merged 7 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/DataAccess/ArchiveSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public static function getArchiveIds($siteIds, $periods, $segment, $plugins, $in
FROM %s
WHERE idsite IN (" . implode(',', $siteIds) . ")
AND " . self::getNameCondition($plugins, $segment, $includeInvalidated) . "
AND ts_archived IS NOT NULL
sgiehl marked this conversation as resolved.
Show resolved Hide resolved
AND %s
GROUP BY idsite, date1, date2";

Expand Down
2 changes: 0 additions & 2 deletions core/DataAccess/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public function getInvalidatedArchiveIdsSafeToDelete($archiveTable, $setGroupCon
GROUP_CONCAT(idarchive, '.', value ORDER BY ts_archived DESC) as archives
FROM `$archiveTable`
WHERE name LIKE 'done%'
AND ts_archived IS NOT NULL
AND `value` NOT IN (" . ArchiveWriter::DONE_ERROR . ")
GROUP BY idsite, date1, date2, period, name HAVING count(*) > 1";

Expand Down Expand Up @@ -461,7 +460,6 @@ public function getArchiveIdAndVisits($numericTable, $idSite, $period, $dateStar
AND arc1.period = ?
AND ($sqlWhereArchiveName)
$timeStampWhere
AND arc1.ts_archived IS NOT NULL
ORDER BY arc1.ts_archived DESC, arc1.idarchive DESC";

$results = Db::fetchAll($sqlQuery, $bindSQL);
Expand Down
2 changes: 1 addition & 1 deletion core/Db/Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function getTablesCreateSql()
ts_archived DATETIME NULL,
value DOUBLE NULL,
PRIMARY KEY(idarchive, name),
INDEX index_idsite_dates_period(idsite, date1, date2, period, ts_archived),
INDEX index_idsite_dates_period(idsite, date1, date2, period, name(6)),
INDEX index_period_archived(period, ts_archived)
) ENGINE=$engine DEFAULT CHARSET=$charset
",
Expand Down
24 changes: 21 additions & 3 deletions core/Updates/5.0.0-b1.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Piwik\Updates;

use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Db;
use Piwik\Common;
use Piwik\Updater;
Expand Down Expand Up @@ -44,17 +45,34 @@ public function doUpdate(Updater $updater)

public function getMigrations(Updater $updater)
{
$migrations = $this->getUpdateArchiveIndexMigrations();

if ($this->requiresUpdatedLogVisitTableIndex()) {
return $this->getLogVisitTableMigrations();
return $this->getLogVisitTableMigrations($migrations);
}

return [];
sgiehl marked this conversation as resolved.
Show resolved Hide resolved
}

private function getLogVisitTableMigrations()
private function getUpdateArchiveIndexMigrations()
{
$migrations = [];

$tables = ArchiveTableCreator::getTablesArchivesInstalled('numeric');
foreach ($tables as $table) {
$hasPrefix = strpos($table, 'archive') !== 0;
if ($hasPrefix) {
$table = Common::unprefixTable($table);
}
$migrations[] = $this->migration->db->dropIndex($table, 'index_idsite_dates_period');
$migrations[] = $this->migration->db->addIndex($table, ['idsite', 'date1', 'date2', 'period', 'name(6)'], 'index_idsite_dates_period');
}

return $migrations;
}

private function getLogVisitTableMigrations($migrations)
{
$migrations[] = $this->migration->db->dropIndex('log_visit', $this->indexName);

// Using the custom `sql` method instead of the `addIndex` method as it doesn't support DESC collation
Expand Down Expand Up @@ -88,4 +106,4 @@ private function requiresUpdatedLogVisitTableIndex()

return true;
}
}
}