Skip to content

Commit

Permalink
Increase the number of applicable indexes when primary key might change
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 12, 2023
1 parent b7e3e2a commit 048071e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,20 @@ protected function applySet(
$set_clauses[] = shape('column' => $column, 'expression' => $right);
}

$primary_key_columns = $table_schema?->getPrimaryKeyColumns() ?? keyset[];
$primary_key_changed = false;

foreach ($set_clauses as $clause) {
if (C\contains_key($primary_key_columns, $clause['column'])) {
$primary_key_changed = true;
}
}

$applicable_indexes = vec[];

if ($table_schema is nonnull) {
foreach ($table_schema->indexes as $index) {
if (Keyset\intersect($index->fields, $columns) !== keyset[]) {
if ($primary_key_changed || Keyset\intersect($index->fields, $columns) !== keyset[]) {
$applicable_indexes[] = $index;
}
}
Expand All @@ -320,11 +329,8 @@ protected function applySet(
}
}

list($unique_index_ref_deletes, $index_ref_deletes) = self::getIndexRemovalsForRow(
$applicable_indexes,
$row_id,
$row,
);
list($unique_index_ref_deletes, $index_ref_deletes) =
self::getIndexRemovalsForRow($applicable_indexes, $row_id, $row);

foreach ($set_clauses as $clause) {
$existing_value = $row[$clause['column']] ?? null;
Expand Down Expand Up @@ -362,10 +368,8 @@ protected function applySet(
}
}

list($unique_index_ref_additions, $index_ref_additions) = self::getIndexAdditionsForRow(
$applicable_indexes,
$row,
);
list($unique_index_ref_additions, $index_ref_additions) =
self::getIndexAdditionsForRow($applicable_indexes, $row);
}

if ($changes_found) {
Expand Down

0 comments on commit 048071e

Please sign in to comment.