Skip to content

Commit

Permalink
fix: improve left/inner join handling
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jul 25, 2024
1 parent e097f74 commit 2bd9f28
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/private/DB/QueryBuilder/Partitioned/PartitionQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ public function mergeWith(array $rows): array {
$partitionedRows = $this->query->executeQuery()->fetchAll();
$partitionedRowsByKey = [];
foreach ($partitionedRows as $partitionedRow) {
$partitionedRowsByKey[$partitionedRow[$joinToColumn]] = $partitionedRow;
$partitionedRowsByKey[$partitionedRow[$joinToColumn]][] = $partitionedRow;
}
$result = [];
foreach ($rows as $row) {
if (isset($partitionedRowsByKey[$row[$joinFromColumn]])) {
if ($this->joinMode !== self::JOIN_MODE_LEFT_NULL) {
$result[] = array_merge($row, $partitionedRowsByKey[$row[$joinFromColumn]]);
foreach ($partitionedRowsByKey[$row[$joinFromColumn]] as $partitionedRow) {
$result[] = array_merge($row, $partitionedRow);
}
}
} elseif ($this->joinMode === self::JOIN_MODE_LEFT || $this->joinMode === self::JOIN_MODE_LEFT_NULL) {
$result[] = array_merge($nullResult, $row);
Expand Down

0 comments on commit 2bd9f28

Please sign in to comment.