aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-12-12 21:33:02 +0100
committerGitHub <noreply@github.com>2024-12-12 21:33:02 +0100
commit08e959d03fdf772fde58cdd1191adc495659e0b9 (patch)
tree70a6931d6814cebb702862abe893ef2067a4aa26 /lib
parentc8741b4462ab6638e5e8f05554d8944883c4aeb7 (diff)
parent0f55a589ba4a28b979ff1f4b825a309cad2a6c6b (diff)
downloadnextcloud-server-08e959d03fdf772fde58cdd1191adc495659e0b9.tar.gz
nextcloud-server-08e959d03fdf772fde58cdd1191adc495659e0b9.zip
Merge pull request #49832 from nextcloud/sharding-select-fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
index a9cc3e74c97..2942eeccdf7 100644
--- a/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
@@ -76,6 +76,9 @@ class PartitionedQueryBuilder extends ShardedQueryBuilder {
// 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;
@@ -99,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;
}
}
@@ -284,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>
*/