From ea057d1777750fc21d60234f6d9766c1a92f145a Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Mon, 12 Aug 2024 12:46:50 +0300 Subject: [PATCH] feat: add index on events created at (#7836) After adding an index, the time for the new event search on 100k events decreased from 5000ms to 4ms. This improvement is due to the query using an index scan instead of a sequence scan. --- ...40812120954-add-archived-at-to-projects.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/migrations/20240812120954-add-archived-at-to-projects.js diff --git a/src/migrations/20240812120954-add-archived-at-to-projects.js b/src/migrations/20240812120954-add-archived-at-to-projects.js new file mode 100644 index 0000000000..3599c72bf7 --- /dev/null +++ b/src/migrations/20240812120954-add-archived-at-to-projects.js @@ -0,0 +1,19 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + CREATE INDEX idx_events_created_at_desc ON events (created_at DESC); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ` + DROP INDEX IF EXISTS idx_events_created_at_desc; + `, + callback, + ); +};