Skip to content

Commit

Permalink
fix: solve perf issue in log's query (upgrade scripts+debug)
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 committed Oct 31, 2024
1 parent f8e3871 commit bcb83b1
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion EMS/common-bundle/src/Entity/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Ramsey\Uuid\UuidInterface;

/**
* @ORM\Table(name="log_message",indexes={@Index(name="channel_ouuid_idx", columns={"channel", "ouuid"})})
* @ORM\Table(name="log_message",indexes={@ORM\Index(name="channel_ouuid_idx", columns={"channel", "ouuid"})})
*
* @ORM\Entity
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241031110947 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a non-unique channel/ouuid index in logs table';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);
$this->addSql('CREATE INDEX channel_ouuid_idx ON log_message (channel, ouuid)');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);
$this->addSql('DROP INDEX channel_ouuid_idx');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241031110947 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a non-unique channel/ouuid index in logs table';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);
$this->addSql('CREATE INDEX channel_ouuid_idx ON log_message (channel, ouuid)');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);
$this->addSql('DROP INDEX channel_ouuid_idx');
}
}
35 changes: 35 additions & 0 deletions elasticms-web/migrations/pdo_mysql/Version20241031110947.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241031110947 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a non-unique channel/ouuid index in logs table';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);
$this->addSql('CREATE INDEX channel_ouuid_idx ON log_message (channel, ouuid)');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof MySQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySQLPlatform'."
);
$this->addSql('DROP INDEX channel_ouuid_idx');
}
}
35 changes: 35 additions & 0 deletions elasticms-web/migrations/pdo_pgsql/Version20241031110947.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241031110947 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a non-unique channel/ouuid index in logs table';
}

public function up(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);
$this->addSql('CREATE INDEX channel_ouuid_idx ON log_message (channel, ouuid)');
}

public function down(Schema $schema): void
{
$this->abortIf(
!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform,
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\PostgreSQLPlatform'."
);
$this->addSql('DROP INDEX channel_ouuid_idx');
}
}

0 comments on commit bcb83b1

Please sign in to comment.