Skip to content

Commit b6d92d6

Browse files
committed
Revert "Merge pull request #627 from utopia-php/disable-array-index-mysql"
This reverts commit 83278d6, reversing changes made to eb2f759.
1 parent 39c6140 commit b6d92d6

7 files changed

Lines changed: 64 additions & 112 deletions

File tree

src/Database/Adapter.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -907,20 +907,6 @@ abstract public function getSupportForSchemaAttributes(): bool;
907907
*/
908908
abstract public function getSupportForIndex(): bool;
909909

910-
/**
911-
* Is indexing array supported?
912-
*
913-
* @return bool
914-
*/
915-
abstract public function getSupportForIndexArray(): bool;
916-
917-
/**
918-
* Is cast index as array supported?
919-
*
920-
* @return bool
921-
*/
922-
abstract public function getSupportForCastIndexArray(): bool;
923-
924910
/**
925911
* Is unique index supported?
926912
*
@@ -994,6 +980,13 @@ abstract public function getSupportForAttributeResizing(): bool;
994980
*/
995981
abstract public function getSupportForGetConnectionId(): bool;
996982

983+
/**
984+
* Is cast index as array supported?
985+
*
986+
* @return bool
987+
*/
988+
abstract public function getSupportForCastIndexArray(): bool;
989+
997990
/**
998991
* Is upserting supported?
999992
*

src/Database/Adapter/MySQL.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,8 @@ public function getSizeOfCollectionOnDisk(string $collection): int
7878
return $size;
7979
}
8080

81-
public function getSupportForIndexArray(): bool
82-
{
83-
/**
84-
* Disabling index creation due to Mysql bug
85-
* @link https://bugs.mysql.com/bug.php?id=111037
86-
*/
87-
return false;
88-
}
89-
9081
public function getSupportForCastIndexArray(): bool
9182
{
92-
if (!$this->getSupportForIndexArray()) {
93-
return false;
94-
}
95-
9683
return true;
9784
}
9885

src/Database/Adapter/Pool.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,6 @@ public function getSupportForIndex(): bool
335335
return $this->delegate(__FUNCTION__, \func_get_args());
336336
}
337337

338-
public function getSupportForIndexArray(): bool
339-
{
340-
return $this->delegate(__FUNCTION__, \func_get_args());
341-
}
342-
343-
public function getSupportForCastIndexArray(): bool
344-
{
345-
return $this->delegate(__FUNCTION__, \func_get_args());
346-
}
347-
348338
public function getSupportForUniqueIndex(): bool
349339
{
350340
return $this->delegate(__FUNCTION__, \func_get_args());
@@ -400,6 +390,11 @@ public function getSupportForGetConnectionId(): bool
400390
return $this->delegate(__FUNCTION__, \func_get_args());
401391
}
402392

393+
public function getSupportForCastIndexArray(): bool
394+
{
395+
return $this->delegate(__FUNCTION__, \func_get_args());
396+
}
397+
403398
public function getSupportForUpserts(): bool
404399
{
405400
return $this->delegate(__FUNCTION__, \func_get_args());

src/Database/Adapter/SQL.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,11 +1401,6 @@ public function getSupportForQueryContains(): bool
14011401
*/
14021402
abstract public function getSupportForJSONOverlaps(): bool;
14031403

1404-
public function getSupportForIndexArray(): bool
1405-
{
1406-
return true;
1407-
}
1408-
14091404
public function getSupportForCastIndexArray(): bool
14101405
{
14111406
return false;

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,14 +1402,12 @@ public function testArrayAttribute(): void
14021402
$this->assertEquals('Antony', $document->getAttribute('names')[1]);
14031403
$this->assertEquals(100, $document->getAttribute('numbers')[1]);
14041404

1405-
if ($database->getAdapter()->getSupportForIndexArray()) {
1406-
/**
1407-
* functional index dependency cannot be dropped or rename
1408-
*/
1409-
$database->createIndex($collection, 'idx_cards', Database::INDEX_KEY, ['cards'], [100]);
1410-
}
1405+
/**
1406+
* functional index dependency cannot be dropped or rename
1407+
*/
1408+
$database->createIndex($collection, 'idx_cards', Database::INDEX_KEY, ['cards'], [100]);
14111409

1412-
if ($database->getAdapter()->getSupportForCastIndexArray()) {
1410+
if ($this->getDatabase()->getAdapter()->getSupportForCastIndexArray()) {
14131411
/**
14141412
* Delete attribute
14151413
*/
@@ -1448,24 +1446,22 @@ public function testArrayAttribute(): void
14481446
$this->assertTrue($database->deleteAttribute($collection, 'cards_new'));
14491447
}
14501448

1451-
if ($database->getAdapter()->getSupportForIndexArray()) {
1452-
try {
1453-
$database->createIndex($collection, 'indx', Database::INDEX_FULLTEXT, ['names']);
1454-
$this->fail('Failed to throw exception');
1455-
} catch (Throwable $e) {
1456-
if ($database->getAdapter()->getSupportForFulltextIndex()) {
1457-
$this->assertEquals('"Fulltext" index is forbidden on array attributes', $e->getMessage());
1458-
} else {
1459-
$this->assertEquals('Fulltext index is not supported', $e->getMessage());
1460-
}
1449+
try {
1450+
$database->createIndex($collection, 'indx', Database::INDEX_FULLTEXT, ['names']);
1451+
$this->fail('Failed to throw exception');
1452+
} catch (Throwable $e) {
1453+
if ($this->getDatabase()->getAdapter()->getSupportForFulltextIndex()) {
1454+
$this->assertEquals('"Fulltext" index is forbidden on array attributes', $e->getMessage());
1455+
} else {
1456+
$this->assertEquals('Fulltext index is not supported', $e->getMessage());
14611457
}
1458+
}
14621459

1463-
try {
1464-
$database->createIndex($collection, 'indx', Database::INDEX_KEY, ['numbers', 'names'], [100,100]);
1465-
$this->fail('Failed to throw exception');
1466-
} catch (Throwable $e) {
1467-
$this->assertEquals('An index may only contain one array attribute', $e->getMessage());
1468-
}
1460+
try {
1461+
$database->createIndex($collection, 'indx', Database::INDEX_KEY, ['numbers', 'names'], [100,100]);
1462+
$this->fail('Failed to throw exception');
1463+
} catch (Throwable $e) {
1464+
$this->assertEquals('An index may only contain one array attribute', $e->getMessage());
14691465
}
14701466

14711467
$this->assertEquals(true, $database->createAttribute(
@@ -1477,36 +1473,32 @@ public function testArrayAttribute(): void
14771473
array: true
14781474
));
14791475

1480-
if ($database->getAdapter()->getSupportForIndexArray()) {
1481-
1482-
1483-
if ($database->getAdapter()->getMaxIndexLength() > 0) {
1484-
// If getMaxIndexLength() > 0 We clear length for array attributes
1485-
$database->createIndex($collection, 'indx1', Database::INDEX_KEY, ['long_size'], [], []);
1486-
$database->createIndex($collection, 'indx2', Database::INDEX_KEY, ['long_size'], [1000], []);
1487-
1488-
try {
1489-
$database->createIndex($collection, 'indx_numbers', Database::INDEX_KEY, ['tv_show', 'numbers'], [], []); // [700, 255]
1490-
$this->fail('Failed to throw exception');
1491-
} catch (Throwable $e) {
1492-
$this->assertEquals('Index length is longer than the maximum: ' . $database->getAdapter()->getMaxIndexLength(), $e->getMessage());
1493-
}
1494-
}
1495-
1496-
// We clear orders for array attributes
1497-
$database->createIndex($collection, 'indx3', Database::INDEX_KEY, ['names'], [255], ['desc']);
1476+
if ($database->getAdapter()->getMaxIndexLength() > 0) {
1477+
// If getMaxIndexLength() > 0 We clear length for array attributes
1478+
$database->createIndex($collection, 'indx1', Database::INDEX_KEY, ['long_size'], [], []);
1479+
$database->createIndex($collection, 'indx2', Database::INDEX_KEY, ['long_size'], [1000], []);
14981480

14991481
try {
1500-
$database->createIndex($collection, 'indx4', Database::INDEX_KEY, ['age', 'names'], [10, 255], []);
1482+
$database->createIndex($collection, 'indx_numbers', Database::INDEX_KEY, ['tv_show', 'numbers'], [], []); // [700, 255]
15011483
$this->fail('Failed to throw exception');
15021484
} catch (Throwable $e) {
1503-
$this->assertEquals('Cannot set a length on "integer" attributes', $e->getMessage());
1485+
$this->assertEquals('Index length is longer than the maximum: ' . $database->getAdapter()->getMaxIndexLength(), $e->getMessage());
15041486
}
1487+
}
1488+
1489+
// We clear orders for array attributes
1490+
$database->createIndex($collection, 'indx3', Database::INDEX_KEY, ['names'], [255], ['desc']);
15051491

1506-
$this->assertTrue($database->createIndex($collection, 'indx6', Database::INDEX_KEY, ['age', 'names'], [null, 999], []));
1507-
$this->assertTrue($database->createIndex($collection, 'indx7', Database::INDEX_KEY, ['age', 'booleans'], [0, 999], []));
1492+
try {
1493+
$database->createIndex($collection, 'indx4', Database::INDEX_KEY, ['age', 'names'], [10, 255], []);
1494+
$this->fail('Failed to throw exception');
1495+
} catch (Throwable $e) {
1496+
$this->assertEquals('Cannot set a length on "integer" attributes', $e->getMessage());
15081497
}
15091498

1499+
$this->assertTrue($database->createIndex($collection, 'indx6', Database::INDEX_KEY, ['age', 'names'], [null, 999], []));
1500+
$this->assertTrue($database->createIndex($collection, 'indx7', Database::INDEX_KEY, ['age', 'booleans'], [0, 999], []));
1501+
15101502
if ($this->getDatabase()->getAdapter()->getSupportForQueryContains()) {
15111503
try {
15121504
$database->find($collection, [

tests/e2e/Adapter/Scopes/CollectionTests.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ public function testRowSizeToLarge(): void
649649

650650
public function testCreateCollectionWithSchemaIndexes(): void
651651
{
652-
/** @var Database $database */
653652
$database = static::getDatabase();
654653

655654
$attributes = [
@@ -672,6 +671,13 @@ public function testCreateCollectionWithSchemaIndexes(): void
672671
];
673672

674673
$indexes = [
674+
new Document([
675+
'$id' => ID::custom('idx_cards'),
676+
'type' => Database::INDEX_KEY,
677+
'attributes' => ['cards'],
678+
'lengths' => [500], // Will be changed to Database::ARRAY_INDEX_LENGTH (255)
679+
'orders' => [Database::ORDER_DESC],
680+
]),
675681
new Document([
676682
'$id' => ID::custom('idx_username'),
677683
'type' => Database::INDEX_KEY,
@@ -688,16 +694,6 @@ public function testCreateCollectionWithSchemaIndexes(): void
688694
]),
689695
];
690696

691-
if ($database->getAdapter()->getSupportForIndexArray()) {
692-
$indexes[] = new Document([
693-
'$id' => ID::custom('idx_cards'),
694-
'type' => Database::INDEX_KEY,
695-
'attributes' => ['cards'],
696-
'lengths' => [500], // Will be changed to Database::ARRAY_INDEX_LENGTH (255)
697-
'orders' => [Database::ORDER_DESC],
698-
]);
699-
}
700-
701697
$collection = $database->createCollection(
702698
'collection98',
703699
$attributes,
@@ -707,18 +703,16 @@ public function testCreateCollectionWithSchemaIndexes(): void
707703
]
708704
);
709705

710-
$this->assertEquals($collection->getAttribute('indexes')[0]['attributes'][0], 'username');
711-
$this->assertEquals($collection->getAttribute('indexes')[0]['lengths'][0], null);
706+
$this->assertEquals($collection->getAttribute('indexes')[0]['attributes'][0], 'cards');
707+
$this->assertEquals($collection->getAttribute('indexes')[0]['lengths'][0], Database::ARRAY_INDEX_LENGTH);
708+
$this->assertEquals($collection->getAttribute('indexes')[0]['orders'][0], null);
712709

713710
$this->assertEquals($collection->getAttribute('indexes')[1]['attributes'][0], 'username');
714-
$this->assertEquals($collection->getAttribute('indexes')[1]['lengths'][0], 99);
715-
$this->assertEquals($collection->getAttribute('indexes')[1]['orders'][0], Database::ORDER_DESC);
711+
$this->assertEquals($collection->getAttribute('indexes')[1]['lengths'][0], null);
716712

717-
if ($database->getAdapter()->getSupportForIndexArray()) {
718-
$this->assertEquals($collection->getAttribute('indexes')[2]['attributes'][0], 'cards');
719-
$this->assertEquals($collection->getAttribute('indexes')[2]['lengths'][0], Database::ARRAY_INDEX_LENGTH);
720-
$this->assertEquals($collection->getAttribute('indexes')[2]['orders'][0], null);
721-
}
713+
$this->assertEquals($collection->getAttribute('indexes')[2]['attributes'][0], 'username');
714+
$this->assertEquals($collection->getAttribute('indexes')[2]['lengths'][0], 99);
715+
$this->assertEquals($collection->getAttribute('indexes')[2]['orders'][0], Database::ORDER_DESC);
722716
}
723717

724718
public function testCollectionUpdate(): Document
@@ -1060,7 +1054,6 @@ public function testSharedTables(): void
10601054
/**
10611055
* Default mode already tested, we'll test 'schema' and 'table' isolation here
10621056
*/
1063-
/** @var Database $database */
10641057
$database = static::getDatabase();
10651058
$sharedTables = $database->getSharedTables();
10661059
$namespace = $database->getNamespace();
@@ -1264,7 +1257,6 @@ public function testCreateDuplicates(): void
12641257
}
12651258
public function testSharedTablesDuplicates(): void
12661259
{
1267-
/** @var Database $database */
12681260
$database = static::getDatabase();
12691261
$sharedTables = $database->getSharedTables();
12701262
$namespace = $database->getNamespace();

tests/e2e/Adapter/Scopes/IndexTests.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public function testCreateIndex(): void
2828
* Check ticks sounding cast index for reserved words
2929
*/
3030
$database->createAttribute('indexes', 'int', Database::VAR_INTEGER, 8, false, array:true);
31-
if ($database->getAdapter()->getSupportForIndexArray()) {
32-
$database->createIndex('indexes', 'indx8711', Database::INDEX_KEY, ['int'], [255]);
33-
}
31+
$database->createIndex('indexes', 'indx8711', Database::INDEX_KEY, ['int'], [255]);
3432

3533
$database->createAttribute('indexes', 'name', Database::VAR_STRING, 10, false);
3634

0 commit comments

Comments
 (0)