1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Use "pathIndex" in some owners package queries to improve query plans

Summary: Depends on D19184. Ref T11015. Now that we have a digest index column, we can improve some of the queries a bit.

Test Plan:
  - Ran queries from revision pages before and after with and without EXPLAIN.
  - Saw the same results with much better EXPLAIN plans.
  - Fragment size is now fixed at 12 bytes per fragment, so we can shove more of them in a single query.

Maniphest Tasks: T11015

Differential Revision: https://secure.phabricator.com/D19185
This commit is contained in:
epriestley 2018-03-06 20:25:17 -08:00
parent df1e9ce646
commit 516aaad341
3 changed files with 26 additions and 8 deletions

View file

@ -206,8 +206,8 @@ final class PhabricatorOwnersPackageQuery
if ($this->paths !== null) { if ($this->paths !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'rpath.path IN (%Ls)', 'rpath.pathIndex IN (%Ls)',
$this->getFragmentsForPaths($this->paths)); $this->getFragmentIndexesForPaths($this->paths));
} }
if ($this->statuses !== null) { if ($this->statuses !== null) {
@ -220,13 +220,13 @@ final class PhabricatorOwnersPackageQuery
if ($this->controlMap) { if ($this->controlMap) {
$clauses = array(); $clauses = array();
foreach ($this->controlMap as $repository_phid => $paths) { foreach ($this->controlMap as $repository_phid => $paths) {
$fragments = $this->getFragmentsForPaths($paths); $indexes = $this->getFragmentIndexesForPaths($paths);
$clauses[] = qsprintf( $clauses[] = qsprintf(
$conn, $conn,
'(rpath.repositoryPHID = %s AND rpath.path IN (%Ls))', '(rpath.repositoryPHID = %s AND rpath.pathIndex IN (%Ls))',
$repository_phid, $repository_phid,
$fragments); $indexes);
} }
$where[] = implode(' OR ', $clauses); $where[] = implode(' OR ', $clauses);
} }
@ -333,6 +333,16 @@ final class PhabricatorOwnersPackageQuery
return $fragments; return $fragments;
} }
private function getFragmentIndexesForPaths(array $paths) {
$indexes = array();
foreach ($this->getFragmentsForPaths($paths) as $fragment) {
$indexes[] = PhabricatorHash::digestForIndex($fragment);
}
return $indexes;
}
/* -( Path Control )------------------------------------------------------- */ /* -( Path Control )------------------------------------------------------- */

View file

@ -218,15 +218,20 @@ final class PhabricatorOwnersPackage
// and then merge results in PHP. // and then merge results in PHP.
$rows = array(); $rows = array();
foreach (array_chunk(array_keys($fragments), 128) as $chunk) { foreach (array_chunk(array_keys($fragments), 1024) as $chunk) {
$indexes = array();
foreach ($chunk as $fragment) {
$indexes[] = PhabricatorHash::digestForIndex($fragment);
}
$rows[] = queryfx_all( $rows[] = queryfx_all(
$conn, $conn,
'SELECT pkg.id, pkg.dominion, p.excluded, p.path 'SELECT pkg.id, pkg.dominion, p.excluded, p.path
FROM %T pkg JOIN %T p ON p.packageID = pkg.id FROM %T pkg JOIN %T p ON p.packageID = pkg.id
WHERE p.path IN (%Ls) AND pkg.status IN (%Ls) %Q', WHERE p.pathIndex IN (%Ls) AND pkg.status IN (%Ls) %Q',
$package->getTableName(), $package->getTableName(),
$path->getTableName(), $path->getTableName(),
$chunk, $indexes,
array( array(
self::STATUS_ACTIVE, self::STATUS_ACTIVE,
), ),

View file

@ -26,6 +26,9 @@ final class PhabricatorOwnersPath extends PhabricatorOwnersDAO {
'columns' => array('packageID', 'repositoryPHID', 'pathIndex'), 'columns' => array('packageID', 'repositoryPHID', 'pathIndex'),
'unique' => true, 'unique' => true,
), ),
'key_repository' => array(
'columns' => array('repositoryPHID', 'pathIndex'),
),
), ),
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }