mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-28 17:01:14 +00:00
d3aaab0692
Deleting a character runs one DELETE per table that has an identifier/owner column, all in a single transaction. Only users.identifier is indexed; the other core tables (billing, owned_vehicles, user_licenses, society_moneywash, addon_account_data, addon_inventory_items, datastore_data) have no usable index on the delete column, so each DELETE is a full table scan and they all hold locks at once. Measured on 200k rows per table (MariaDB 12.3.2): the transaction went from about 1573 ms to about 22 ms once the seven columns are indexed, EXPLAIN going from type=ALL scanning ~200k rows to a single-row index lookup per table. The addon and datastore tables were the worst because their composite indexes do not lead with the delete column, so they cannot serve WHERE owner = ?. Adds the indexes to legacy.sql for fresh installs and a migration for existing databases. The migration checks INFORMATION_SCHEMA for an index that leads with the column (SEQ_IN_INDEX = 1) and only creates one where it is missing, so it is a no-op on databases that already have it and re-running is guarded by the migration key.