Skip to content

Commit e8e6cb2

Browse files
authored
feat: add index on actions(time) for time-range query performance (#369)
Co-authored-by: Netcrafts <netcrafts@users.noreply.github.com>
1 parent be53ba0 commit e8e6cb2

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ object DatabaseManager {
122122
Tables.Sources,
123123
Tables.Worlds,
124124
)
125+
try {
126+
exec("CREATE INDEX IF NOT EXISTS actions_time ON actions(time)")
127+
} catch (e: java.sql.SQLException) {
128+
logWarn("Could not create actions_time index (MySQL 8.0.12+ required if using MySQL): ${e.message}")
129+
}
125130
logInfo("Tables created")
126131
}
127132

src/main/kotlin/com/github/quiltservertools/ledger/database/Tables.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object Tables {
5555

5656
object Actions : IntIdTable("actions") {
5757
val actionIdentifier = reference("action_id", ActionIdentifiers.id).index()
58-
val timestamp = timestamp("time")
58+
val timestamp = timestamp("time").index("actions_time")
5959
val x = integer("x")
6060
val y = integer("y")
6161
val z = integer("z")

0 commit comments

Comments
 (0)