diff --git a/migrations/20210517135636-add-order-by-indexes.js b/migrations/20210517135636-add-order-by-indexes.js new file mode 100644 index 000000000..b314f2703 --- /dev/null +++ b/migrations/20210517135636-add-order-by-indexes.js @@ -0,0 +1,21 @@ +'use strict'; + +var async = require('async'); + +exports.up = function(db, callback) { + async.series([ + db.runSql.bind(db, 'ALTER TABLE backups ADD INDEX creationTime_index (creationTime)'), + db.runSql.bind(db, 'ALTER TABLE eventlog ADD INDEX creationTime_index (creationTime)'), + db.runSql.bind(db, 'ALTER TABLE notifications ADD INDEX creationTime_index (creationTime)'), + db.runSql.bind(db, 'ALTER TABLE tasks ADD INDEX creationTime_index (creationTime)'), + ], callback); +}; + +exports.down = function(db, callback) { + async.series([ + db.runSql.bind(db, 'ALTER TABLE backups DROP INDEX creationTime_index'), + db.runSql.bind(db, 'ALTER TABLE eventlog DROP INDEX creationTime_index'), + db.runSql.bind(db, 'ALTER TABLE notifications DROP INDEX creationTime_index'), + db.runSql.bind(db, 'ALTER TABLE tasks DROP INDEX creationTime_index'), + ], callback); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 67b295371..95ef488ff 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -138,6 +138,7 @@ CREATE TABLE IF NOT EXISTS backups( format VARCHAR(16) DEFAULT "tgz", preserveSecs INTEGER DEFAULT 0, + INDEX creationTime_index (creationTime), PRIMARY KEY (id)); CREATE TABLE IF NOT EXISTS eventlog( @@ -147,6 +148,7 @@ CREATE TABLE IF NOT EXISTS eventlog( data TEXT, /* free flowing json based on action */ creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX creationTime_index (creationTime), PRIMARY KEY (id)); CREATE TABLE IF NOT EXISTS domains( @@ -225,6 +227,8 @@ CREATE TABLE IF NOT EXISTS tasks( resultJson TEXT, creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + + INDEX creationTime_index (creationTime), PRIMARY KEY (id)); CREATE TABLE IF NOT EXISTS notifications( @@ -235,6 +239,8 @@ CREATE TABLE IF NOT EXISTS notifications( message TEXT, acknowledged BOOLEAN DEFAULT false, creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + INDEX creationTime_index (creationTime), FOREIGN KEY(eventId) REFERENCES eventlog(id), PRIMARY KEY (id) ); diff --git a/setup/start/mysql.cnf b/setup/start/mysql.cnf index 243b3703f..722dfa369 100644 --- a/setup/start/mysql.cnf +++ b/setup/start/mysql.cnf @@ -18,6 +18,12 @@ default_time_zone='+00:00' # disable bin logs. they are only useful in replication mode skip-log-bin +# this is used when creating an index using ALTER command +innodb_sort_buffer_size=2097152 + +# this is a per session sort (ORDER BY) variable for non-indexed fields +sort_buffer_size = 4M + [mysqldump] quick quote-names