Skip to content

Commit

Permalink
Added composite index for resources and values (fix omeka#2040).
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Aug 28, 2023
1 parent dfdcf0d commit 89d17f0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions application/data/install/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ CREATE TABLE `resource` (
KEY `IDX_BC91F41616131EA` (`resource_template_id`),
KEY `IDX_BC91F416FDFF2E92` (`thumbnail_id`),
KEY `title` (`title`(190)),
KEY `idx_public_type_id_title` (`is_public`,`resource_type`,`id`,`title`(190)),
CONSTRAINT `FK_BC91F41616131EA` FOREIGN KEY (`resource_template_id`) REFERENCES `resource_template` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_BC91F416448CC1BD` FOREIGN KEY (`resource_class_id`) REFERENCES `resource_class` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_BC91F4167E3C61F9` FOREIGN KEY (`owner_id`) REFERENCES `user` (`id`) ON DELETE SET NULL,
Expand Down Expand Up @@ -357,6 +358,7 @@ CREATE TABLE `value` (
KEY `IDX_1D7758344BC72506` (`value_resource_id`),
KEY `value` (`value`(190)),
KEY `uri` (`uri`(190)),
KEY `idx_public_resource_property` (`is_public`,`resource_id`,`property_id`),
CONSTRAINT `FK_1D7758344BC72506` FOREIGN KEY (`value_resource_id`) REFERENCES `resource` (`id`) ON DELETE CASCADE,
CONSTRAINT `FK_1D775834549213EC` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`) ON DELETE CASCADE,
CONSTRAINT `FK_1D77583489329D25` FOREIGN KEY (`resource_id`) REFERENCES `resource` (`id`),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

namespace Omeka\Db\Migrations;

use Doctrine\DBAL\Connection;
use Omeka\Db\Migration\MigrationInterface;

class AddCompositeIndexToResourceAndValueEntities implements MigrationInterface
{
public function up(Connection $conn)
{
try {
$conn->executeStatement('ALTER TABLE `resource` ADD INDEX `idx_public_type_id_title` (`is_public`,`resource_type`,`id`,`title` (190));');
} catch (\Exception $e) {
// Index exists.
}

try {
$conn->executeStatement('ALTER TABLE `value` ADD INDEX `idx_public_resource_property` (`is_public`,`resource_id`,`property_id`);');
} catch (\Exception $e) {
// Index exists.
}
}
}
5 changes: 5 additions & 0 deletions application/src/Entity/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
* name="title",
* columns={"title"},
* options={"lengths":{190}}
* ),
* @Index(
* name="idx_public_type_id_title",
* columns={"is_public", "resource_type", "id", "title"},
* options={"lengths":{null, null, null, 190}}
* )
* }
* )
Expand Down
6 changes: 5 additions & 1 deletion application/src/Entity/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* @Entity
* @Table(name="`value`", indexes={
* @Index(name="`value`", columns={"`value`"}, options={"lengths":{190}}),
* @Index(name="`uri`", columns={"`uri`"}, options={"lengths":{190}})
* @Index(name="`uri`", columns={"`uri`"}, options={"lengths":{190}}),
* @Index(
* name="idx_public_resource_property",
* columns={"is_public", "resource_id", "property_id"}
* )
* })
*/
class Value extends AbstractEntity
Expand Down

0 comments on commit 89d17f0

Please sign in to comment.