Optimized server player list table query

Original benchmark: 4 seconds
Improved benchmark: 500 milliseconds
-> 8x faster
This commit is contained in:
Aurora Lahtela 2023-01-21 12:17:46 +02:00
parent 1b0942c988
commit 987fb7b56a

View File

@ -76,10 +76,9 @@ public class ExtensionServerTableDataQuery implements Query<Map<UUID, ExtensionT
private Query<Map<UUID, ExtensionTabData>> fetchPlayerData() {
String selectLimitedNumberOfPlayerUUIDsByLastSeenDate = SELECT +
UsersTable.USER_UUID + ",MAX(" + SessionsTable.SESSION_END + ") as last_seen" +
SessionsTable.USER_ID + ",MAX(" + SessionsTable.SESSION_END + ") as last_seen" +
FROM + SessionsTable.TABLE_NAME +
INNER_JOIN + UsersTable.TABLE_NAME + " u on u." + UsersTable.ID + '=' + SessionsTable.TABLE_NAME + '.' + SessionsTable.USER_ID +
GROUP_BY + UsersTable.USER_UUID +
GROUP_BY + SessionsTable.USER_ID +
ORDER_BY + "last_seen DESC LIMIT ?";
String sql = SELECT +
@ -98,7 +97,8 @@ public class ExtensionServerTableDataQuery implements Query<Map<UUID, ExtensionT
"i1." + ExtensionIconTable.ICON_NAME + " as provider_icon_name," +
"i1." + ExtensionIconTable.FAMILY + " as provider_icon_family" +
FROM + ExtensionPlayerValueTable.TABLE_NAME + " v1" +
INNER_JOIN + '(' + selectLimitedNumberOfPlayerUUIDsByLastSeenDate + ") as last_seen_q on last_seen_q.uuid=v1." + ExtensionPlayerValueTable.USER_UUID +
INNER_JOIN + UsersTable.TABLE_NAME + " u on u." + UsersTable.USER_UUID + "=v1." + ExtensionPlayerValueTable.USER_UUID +
INNER_JOIN + '(' + selectLimitedNumberOfPlayerUUIDsByLastSeenDate + ") as last_seen_q on last_seen_q.user_id=u." + UsersTable.ID +
INNER_JOIN + ExtensionProviderTable.TABLE_NAME + " p1 on p1." + ExtensionProviderTable.ID + "=v1." + ExtensionPlayerValueTable.PROVIDER_ID +
INNER_JOIN + ExtensionPluginTable.TABLE_NAME + " e1 on e1." + ExtensionPluginTable.ID + "=p1." + ExtensionProviderTable.PLUGIN_ID +
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i1 on i1." + ExtensionIconTable.ID + "=p1." + ExtensionProviderTable.ICON_ID +
@ -124,11 +124,10 @@ public class ExtensionServerTableDataQuery implements Query<Map<UUID, ExtensionT
private Query<Map<UUID, ExtensionTabData>> fetchPlayerGroups() {
String selectLimitedNumberOfPlayerUUIDsByLastSeenDate = SELECT +
UsersTable.USER_UUID + "," +
SessionsTable.USER_ID + "," +
"MAX(" + SessionsTable.SESSION_END + ") as last_seen" +
FROM + SessionsTable.TABLE_NAME +
INNER_JOIN + UsersTable.TABLE_NAME + " u on u." + UsersTable.ID + '=' + SessionsTable.TABLE_NAME + '.' + SessionsTable.USER_ID +
GROUP_BY + UsersTable.USER_UUID +
GROUP_BY + SessionsTable.USER_ID +
ORDER_BY + "last_seen DESC LIMIT ?";
String sql = SELECT +
@ -139,7 +138,8 @@ public class ExtensionServerTableDataQuery implements Query<Map<UUID, ExtensionT
"i1." + ExtensionIconTable.ICON_NAME + " as provider_icon_name," +
"i1." + ExtensionIconTable.FAMILY + " as provider_icon_family" +
FROM + ExtensionGroupsTable.TABLE_NAME + " v1" +
INNER_JOIN + '(' + selectLimitedNumberOfPlayerUUIDsByLastSeenDate + ") as last_seen_q on last_seen_q.uuid=v1." + ExtensionGroupsTable.USER_UUID +
INNER_JOIN + UsersTable.TABLE_NAME + " u on u." + UsersTable.USER_UUID + "=v1." + ExtensionGroupsTable.USER_UUID +
INNER_JOIN + '(' + selectLimitedNumberOfPlayerUUIDsByLastSeenDate + ") as last_seen_q on last_seen_q.user_id=u." + UsersTable.ID +
INNER_JOIN + ExtensionProviderTable.TABLE_NAME + " p1 on p1." + ExtensionProviderTable.ID + "=v1." + ExtensionGroupsTable.PROVIDER_ID +
INNER_JOIN + ExtensionPluginTable.TABLE_NAME + " e1 on e1." + ExtensionPluginTable.ID + "=p1." + ExtensionProviderTable.PLUGIN_ID +
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i1 on i1." + ExtensionIconTable.ID + "=p1." + ExtensionProviderTable.ICON_ID +