Migration_20221028_105818.php
3 months ago
Migration_20221110_151621.php
3 years ago
Migration_20230111_120000.php
2 years ago
Migration_20230111_130000.php
3 years ago
Migration_20230215_050813.php
3 months ago
Migration_20230221_200520.php
3 years ago
Migration_20230421_135915.php
3 years ago
Migration_20230503_210945.php
3 years ago
Migration_20230605_174836.php
3 years ago
Migration_20230703_105957.php
3 years ago
Migration_20230716_130221_Db.php
2 years ago
Migration_20230824_054259_Db.php
2 years ago
Migration_20230831_124214_Db.php
2 years ago
Migration_20230831_143755_Db.php
1 year ago
Migration_20240119_113943_Db.php
2 years ago
Migration_20240617_122847_Db.php
2 years ago
Migration_20240725_182318_Db.php
2 years ago
Migration_20241007_170437_Db.php
1 year ago
Migration_20241108_103249_Db.php
3 months ago
Migration_20250903_151331_Db.php
11 months ago
Migration_20250926_153050_Db.php
10 months ago
Migration_20260415_090055_Db.php
3 months ago
Migration_20260427_100000.php
3 months ago
Migration_20260428_120000.php
3 months ago
Migration_20260430_103000_Db.php
3 months ago
Migration_20260430_120000.php
3 months ago
Migration_20260504_120000_Db.php
3 months ago
Migration_20260514_120000_Db.php
3 months ago
Migration_20260609_120000_Db.php
2 months ago
Migration_20260610_120000_Db.php
1 month ago
Migration_20260622_120000_Db.php
1 month ago
Migration_20260709_120000_Db.php
1 month ago
Migration_20260715_100000_Db.php
1 month ago
index.php
3 years ago
Migration_20260609_120000_Db.php
41 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Migrations\Db; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SubscriberEntity; |
| 9 | use MailPoet\Migrator\DbMigration; |
| 10 | |
| 11 | class Migration_20260609_120000_Db extends DbMigration { |
| 12 | public function run(): void { |
| 13 | $subscribersTable = $this->getTableName(SubscriberEntity::class); |
| 14 | |
| 15 | // Index (deleted_at, created_at) so the subscribers listing's default view |
| 16 | // (non-trashed, newest first) reads its rows straight from the index: |
| 17 | // `deleted_at IS NULL` pins the first column, so entries come out ordered |
| 18 | // by created_at — and by id within ties, since InnoDB appends the primary |
| 19 | // key to secondary indexes. Without it the query has no usable index at |
| 20 | // all (every other index leads with another column) and degrades to a |
| 21 | // full-table scan plus a filesort of every non-trashed subscriber. |
| 22 | // |
| 23 | // A single-column created_at index would serve the same query slightly |
| 24 | // worse (it scans trashed rows too), but the important difference shows |
| 25 | // under `deleted_at IS NULL` filtering: a single-column index is then |
| 26 | // fully bound, which qualifies it as a rowid-ordered scan that the |
| 27 | // optimizer can combine into an index-merge intersect with other |
| 28 | // status/deleted_at indexes — a plan that materializes and filesorts |
| 29 | // millions of rows on large sites. With created_at as an unbound second |
| 30 | // column, this index never qualifies, so that plan cannot be built from |
| 31 | // it. The deleted_at prefix also covers Trash counts |
| 32 | // (`deleted_at IS NOT NULL`) as an index-only range scan. |
| 33 | if (!$this->indexExists($subscribersTable, 'deleted_at_created')) { |
| 34 | $this->connection->executeQuery( |
| 35 | "ALTER TABLE `{$subscribersTable}` |
| 36 | ADD INDEX `deleted_at_created` (`deleted_at`, `created_at`)" |
| 37 | ); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 |