1
0

InvalidPartitionedQueryException.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\DB\QueryBuilder\Partitioned;
  8. /**
  9. * Partitioned queries impose limitations that queries have to follow:
  10. *
  11. * 1. Any reference to columns not in the "main table" (the table referenced by "FROM"), needs to explicitly include the
  12. * table or alias the column belongs to.
  13. *
  14. * For example:
  15. * ```
  16. * $query->select("mount_point", "mimetype")
  17. * ->from("mounts", "m")
  18. * ->innerJoin("m", "filecache", "f", $query->expr()->eq("root_id", "fileid"));
  19. * ```
  20. * will not work, as the query builder doesn't know that the `mimetype` column belongs to the "filecache partition".
  21. * Instead, you need to do
  22. * ```
  23. * $query->select("mount_point", "f.mimetype")
  24. * ->from("mounts", "m")
  25. * ->innerJoin("m", "filecache", "f", $query->expr()->eq("m.root_id", "f.fileid"));
  26. * ```
  27. *
  28. * 2. The "ON" condition for the join can only perform a comparison between both sides of the join once.
  29. *
  30. * For example:
  31. * ```
  32. * $query->select("mount_point", "mimetype")
  33. * ->from("mounts", "m")
  34. * ->innerJoin("m", "filecache", "f", $query->expr()->andX($query->expr()->eq("m.root_id", "f.fileid"), $query->expr()->eq("m.storage_id", "f.storage")));
  35. * ```
  36. * will not work.
  37. *
  38. * 3. An "OR" expression in the "WHERE" cannot mention both sides of the join, this does not apply to "AND" expressions.
  39. *
  40. * For example:
  41. * ```
  42. * $query->select("mount_point", "mimetype")
  43. * ->from("mounts", "m")
  44. * ->innerJoin("m", "filecache", "f", $query->expr()->eq("m.root_id", "f.fileid")))
  45. * ->where($query->expr()->orX(
  46. * $query->expr()-eq("m.user_id", $query->createNamedParameter("test"))),
  47. * $query->expr()-eq("f.name", $query->createNamedParameter("test"))),
  48. * ));
  49. * ```
  50. * will not work, but.
  51. * ```
  52. * $query->select("mount_point", "mimetype")
  53. * ->from("mounts", "m")
  54. * ->innerJoin("m", "filecache", "f", $query->expr()->eq("m.root_id", "f.fileid")))
  55. * ->where($query->expr()->andX(
  56. * $query->expr()-eq("m.user_id", $query->createNamedParameter("test"))),
  57. * $query->expr()-eq("f.name", $query->createNamedParameter("test"))),
  58. * ));
  59. * ```
  60. * will.
  61. *
  62. * 4. Queries that join cross-partition cannot use position parameters, only named parameters are allowed
  63. * 5. The "ON" condition of a join cannot contain and "OR" expression.
  64. * 6. Right-joins are not allowed.
  65. * 7. Update, delete and insert statements aren't allowed to contain cross-partition joins.
  66. * 8. Queries that "GROUP BY" a column from the joined partition are not allowed.
  67. * 9. Any `join` call needs to be made before any `where` call.
  68. * 10. Queries that join cross-partition with an "INNER JOIN" or "LEFT JOIN" with a condition on the left side
  69. * cannot use "LIMIT" or "OFFSET" in queries.
  70. *
  71. * The part of the query running on the sharded table has some additional limitations,
  72. * see the `InvalidShardedQueryException` documentation for more information.
  73. */
  74. class InvalidPartitionedQueryException extends \Exception {
  75. }