Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
taka-oyama committed Sep 3, 2024
1 parent 15e027d commit 5de5d62
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v8.3.0 (2024-09-02)

- add support for `Query\Builder::whereNotInUnnest(...)` (#225)
- `Query\Builder::whereIn` will now wrap values in `UNNEST` if the number of values exceeds the limit (950). (#)

# v8.2.0 (2024-08-05)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ Currently only supports Spanner running GoogleSQL (PostgreSQL mode is not suppor

### Query
- [Binding more than 950 parameters in a single query will result in an error](https://cloud.google.com/spanner/quotas#query-limits)
by the server. You may by-pass this limitation by using `Query\Builder::whereInUnnest(...)` method to pass the values
as an array and unnest them on the server side instead of using query parameters.
by the server. In order to by-pass this limitation, this driver will attempt to switch to using `Query\Builder::whereInUnnest(...)`
internally when the passed parameter exceeds the limit set by `parameter_unnest_threshold` config (default: `900`).
You can turn this feature off by setting the value to `false`.

### Eloquent
If you use interleaved keys, you MUST define them in the `interleaveKeys` property, or else you won't be able to save.
Expand Down
7 changes: 3 additions & 4 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ public function whereIn($column, $values, $boolean = 'and', $not = false)
{
// If parameter is over the limit, Spanner will throw an error. We will bypass this limit by
// using UNNEST(). This is enabled by default, but can be disabled by setting the config.
if (is_countable($values) && count($values) > self::PARAMETER_LIMIT) {
if ($this->connection->getConfig('use_unnest_on_parameter_overflow') ?? true) {
return $this->whereInUnnest($column, $values, $boolean, $not);
}
$unnestThreshold = $this->connection->getConfig('parameter_unnest_threshold') ?? 900;
if ($unnestThreshold !== false && is_countable($values) && count($values) > $unnestThreshold) {
return $this->whereInUnnest($column, $values, $boolean, $not);
}

return parent::whereIn($column, $values, $boolean, $not);
Expand Down
2 changes: 1 addition & 1 deletion tests/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ public function test_whereIn_with_unnest_overflow_flag_turned_off(): void
$this->expectExceptionMessage('Number of parameters in query exceeds the maximum allowed limit of 950.');
$this->expectException(QueryException::class);

config()->set('database.connections.main.use_unnest_on_parameter_overflow', false);
config()->set('database.connections.main.parameter_unnest_threshold', false);
$query = $this->getDefaultConnection()->table(self::TABLE_NAME_USER);
$query->whereIn('userId', array_map(Uuid::uuid4()->toString(...), range(1, 1000)))->get();
}
Expand Down

0 comments on commit 5de5d62

Please sign in to comment.