From c3930163a278d212254302a6e638b4f287d60f8a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Dec 2024 17:38:21 +0100 Subject: [PATCH 1/2] fix: handle calling select on partitioned queries with an array of columns Signed-off-by: Robin Appelman --- .../DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php index a9cc3e74c97fd..c373e14afd8d1 100644 --- a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php +++ b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php @@ -76,6 +76,9 @@ private function newQuery(): IQueryBuilder { // we need to save selects until we know all the table aliases public function select(...$selects) { + if (count($selects) === 1 && is_array($selects[0])) { + $selects = $selects[0]; + } $this->selects = []; $this->addSelect(...$selects); return $this; From 0f55a589ba4a28b979ff1f4b825a309cad2a6c6b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Dec 2024 17:39:04 +0100 Subject: [PATCH 2/2] fix: improve logic for ensuring join columns are selected for partitioned queries Signed-off-by: Robin Appelman --- .../Partitioned/PartitionedQueryBuilder.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php index c373e14afd8d1..2942eeccdf79c 100644 --- a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php +++ b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php @@ -102,16 +102,33 @@ public function selectAlias($select, $alias) { * * This is mainly used to ensure that the returned rows from both sides of a partition contains the columns of the join predicate * - * @param string $column + * @param string|IQueryFunction $column * @return void */ private function ensureSelect(string|IQueryFunction $column, ?string $alias = null): void { $checkColumn = $alias ?: $column; if (str_contains($checkColumn, '.')) { - [, $checkColumn] = explode('.', $checkColumn); + [$table, $checkColumn] = explode('.', $checkColumn); + $partition = $this->getPartition($table); + } else { + $partition = null; } foreach ($this->selects as $select) { - if ($select['select'] === $checkColumn || $select['select'] === '*' || str_ends_with($select['select'], '.' . $checkColumn)) { + $select = $select['select']; + if (!is_string($select)) { + continue; + } + + if (str_contains($select, '.')) { + [$table, $select] = explode('.', $select); + $selectPartition = $this->getPartition($table); + } else { + $selectPartition = null; + } + if ( + ($select === $checkColumn || $select === '*') && + $selectPartition === $partition + ) { return; } } @@ -287,6 +304,7 @@ private function flattenPredicates(array $predicates): array { /** * Split an array of predicates (WHERE query parts) by the partition they reference + * * @param array $predicates * @return array */