Skip to content

Commit 37772cf

Browse files
authored
feat: add toggle to disableEmulatorNullFilteredIndexCheck for ease of use (#286)
1 parent a18d5b8 commit 37772cf

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Query/Builder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,10 @@ public function forceIndex($index): static
268268
}
269269

270270
/**
271+
* @param bool $toggle checking disabled when true, enabled when false
271272
* @return $this
272273
*/
273-
public function disableEmulatorNullFilteredIndexCheck(): static
274+
public function disableEmulatorNullFilteredIndexCheck(bool $toggle = true): static
274275
{
275276
$indexHint = $this->indexHint;
276277

@@ -279,7 +280,7 @@ public function disableEmulatorNullFilteredIndexCheck(): static
279280
}
280281

281282
assert($indexHint instanceof IndexHint);
282-
$indexHint->disableEmulatorNullFilteredIndexCheck = true;
283+
$indexHint->disableEmulatorNullFilteredIndexCheck = $toggle;
283284

284285
return $this;
285286
}

tests/Query/BuilderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,32 @@ public function test_disableEmulatorNullFilteredIndexCheck(): void
474474
$this->assertSame([], $qb->get()->all());
475475
}
476476

477+
public function test_disableEmulatorNullFilteredIndexCheck_with_toggle_as_true(): void
478+
{
479+
$conn = $this->getDefaultConnection();
480+
$tableName = 'Test';
481+
482+
$qb = $conn->table($tableName)
483+
->forceIndex('test_index_name')
484+
->disableEmulatorNullFilteredIndexCheck(true);
485+
486+
$hint = '@{FORCE_INDEX=test_index_name,spanner_emulator.disable_query_null_filtered_index_check=true}';
487+
$this->assertSame("select * from `{$tableName}` {$hint}", $qb->toSql());
488+
}
489+
490+
public function test_disableEmulatorNullFilteredIndexCheck_with_toggle_as_false(): void
491+
{
492+
$conn = $this->getDefaultConnection();
493+
$tableName = 'Test';
494+
495+
$qb = $conn->table($tableName)
496+
->forceIndex('test_index_name')
497+
->disableEmulatorNullFilteredIndexCheck(false);
498+
499+
$hint = '@{FORCE_INDEX=test_index_name}';
500+
$this->assertSame("select * from `{$tableName}` {$hint}", $qb->toSql());
501+
}
502+
477503
public function test_disableEmulatorNullFilteredIndexCheck_without_calling_force_index(): void
478504
{
479505
$this->expectExceptionMessage('Force index must be set before disabling null filter index check');

0 commit comments

Comments
 (0)