Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to improve performance on Mysql table - index, clustering, PK?
    primarykey
    data
    text
    <p>I have a mysql table that stores status information about our users on a per-minute basis, but inserts have started taking up to 30 seconds to complete - we're still in private beta with only a couple of dozen users, but need to be able to handle thousands.</p> <p>Usage info:</p> <ul> <li>Inserts: A new row is inserted about once per minute, per user</li> <li>Updates: Every few minutes the last few rows will be updated with revised data, per user</li> <li>Deletes: Entries more than 6 months ago are deleted once a day</li> <li>Selects: Only about 10 selects a day, per user (some select all rows per user for the day, some only get the most recent row for the user.)</li> <li>We're using AWS RDS, if that affects anything (Mysql 5.5.27)</li> </ul> <p>This is the table definition that I've inherited:</p> <pre><code>CREATE TABLE statusMonitor ( personId int(10) unsigned NOT NULL, monitorDateTime datetime NOT NULL, /* Other columns */ UNIQUE KEY UQIX_statusMonitor (personId,monitorDateTime) USING BTREE, KEY personId (personId,monitorDateTime/* other cols */) ) ENGINE = MyISAM; </code></pre> <p><strong>I have three changes in mind, am I on the right track with these?</strong></p> <ol> <li><strong>InnoDB</strong> would be a better choice than MyISAM for a high-write table.</li> <li>I'm thinking that doing the index based on the <strong>date first</strong> will be more efficient</li> <li>A <strong>primary key</strong> would cluster the data making lookups faster, and inserts would be physically closer together.</li> </ol> <p>So this would be my new definition:</p> <pre><code>CREATE TABLE statusMonitor ( personId int(10) unsigned NOT NULL, monitorDateTime datetime NOT NULL, /* Other columns */ PRIMARY KEY ( monitorDateTime, personId ), UQIX_statusMonitor (monitorDateTime,personId) USING BTREE, KEY personId (monitorDateTime,personId/* other cols */) ) ENGINE = InnoDB; </code></pre> <p>Because we have fairly few users I can afford to break things for a little while by changing the table definition, but would rather get it right the first time, so it only happens once.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload