Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Doctrine/DBAL/Schema/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function isFullfilledBy(Index $other)
return false;
}

if (! $this->hasSameColumnLengths($other)) {
if (! $this->sameFlag('spatial', $other) && ! $this->hasSameColumnLengths($other)) {
return false;
}

Expand Down Expand Up @@ -373,4 +373,12 @@ private function hasSameColumnLengths(self $other): bool
return array_filter($this->options['lengths'] ?? [], $filter)
=== array_filter($other->options['lengths'] ?? [], $filter);
}

/**
* Returns whether the index has the same flag as the other
*/
private function sameFlag(string $flag, Index $other): bool
{
return $this->hasFlag($flag) && $other->hasFlag($flag);
}
}
40 changes: 40 additions & 0 deletions tests/Doctrine/Tests/DBAL/Schema/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,44 @@ public function testOptions(): void
self::assertSame('name IS NULL', $idx2->getOption('WHERE'));
self::assertSame(['where' => 'name IS NULL'], $idx2->getOptions());
}

/**
* @param string[] $flags1
* @param string[] $flags2
* @param int[] $lengths1
* @param int[] $lengths2
*
* @dataProvider spatialIndexProvider
*/
public function testFulfilledSpatialIndex(
array $flags1,
array $flags2,
array $lengths1,
array $lengths2,
bool $expected
): void {
$index1 = new Index('index1', ['geo_location'], false, false, $flags1, ['lengths' => $lengths1]);
$index2 = new Index('index2', ['geo_location'], false, false, $flags2, ['lengths' => $lengths2]);

self::assertSame($expected, $index1->isFullfilledBy($index2));
self::assertSame($expected, $index2->isFullfilledBy($index1));
}

/**
* @return mixed[][]
*/
public static function spatialIndexProvider(): iterable
{
return [
'spatial-indexes-without-length' => [['spatial'], ['spatial'], [], [], true],
'spatial-indexes-with-2nd-length' => [['spatial'], ['spatial'], [], [32], true],
'spatial-indexes-with-length' => [['spatial'], ['spatial'], [32], [32], true],
'spatial-indexes-with-different-lengths' => [['spatial'], ['spatial'], [32], [24], true],
'spatial-indexes-with-1st-length' => [['spatial'], ['spatial'], [24], [], true],
'index-with-length-compare-to-spatial-index' => [[], ['spatial'], [24], [], false],
'spatial-with-length-index-compare-to-index' => [['spatial'], [], [24], [], false],
'index-compare-to-spatial-with-length-index' => [[], ['spatial'], [], [24], false],
'spatial-index-compare-to-index-with-length' => [['spatial'], [], [], [24], false],
];
}
}