HelPHP

index_associations.php

Lists and creates the missing indexes on association columns (issue #544).

An association column (id_item, id_users_data, votes_id...) is the key of every join on its table. When it is not the leading column of an index, the engine reads the whole table for each row of the other side: a report that joins an unindexed line table takes tens of seconds on a real instance. sql_from_json() now indexes those columns by itself, but an instance installed before that fix keeps its schemas: this tool is the catch-up pass for an existing database.

The probe is the audit of the issue, with one addition: only integer columns are considered, so a varchar named key_id is not mistaken for an association. A column that already leads an index (simple, unique, composite or primary) is left alone: what matters is the query path, not the index name.

To call from CLI, inside the container as www-data: php index_associations.php /path/to/my/instance # report only, no write php index_associations.php /path/to/my/instance --apply # create the indexes

Read-only by default. Every index created is named index_: the name is derived from the column, so running the tool twice cannot create a second one.

Table of Contents

Functions

missing_association_indexes()  : array<string|int, mixed>
Association columns that are not the leading column of any index, in the current database.

Functions

missing_association_indexes()

Association columns that are not the leading column of any index, in the current database.

missing_association_indexes(mixed $DB) : array<string|int, mixed>
Parameters
$DB : mixed
Return values
array<string|int, mixed> —

list of ['TABLE_NAME' => ..., 'COLUMN_NAME' => ..., 'COLUMN_TYPE' => ...]

On this page

Search results