aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-12-12 17:39:04 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2024-12-12 21:44:05 +0000
commit68db21f829117c1ace9ef2738e331da852eac310 (patch)
tree301c99ea0593b74c2c928cf7511cd01021fd748c
parentf333fbb8f5bfd400c339d7fb5562a347d14b6219 (diff)
downloadnextcloud-server-backport/49832/stable30.tar.gz
nextcloud-server-backport/49832/stable30.zip
fix: improve logic for ensuring join columns are selected for partitioned queriesbackport/49832/stable30
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
index 794ac7484d7..ba1e5a80c0f 100644
--- a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
@@ -102,16 +102,33 @@ class PartitionedQueryBuilder extends ShardedQueryBuilder {
*
* 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 @@ class PartitionedQueryBuilder extends ShardedQueryBuilder {
/**
* Split an array of predicates (WHERE query parts) by the partition they reference
+ *
* @param array $predicates
* @return array<string, array>
*/