Removed redundant left join

This commit is contained in:
Rsl1122 2019-04-02 17:29:13 +03:00
parent e1860cc62c
commit 8928ded103
3 changed files with 6 additions and 10 deletions

View File

@ -1,4 +1,4 @@
package com.djrapitops.plan.db.patches;
package com.djrapitops.plan.db.access.transactions.init;
import com.djrapitops.plan.db.access.transactions.Transaction;
import com.djrapitops.plan.db.sql.tables.UserInfoTable;
@ -17,19 +17,15 @@ public class RemoveDuplicateUserInfoTransaction extends Transaction {
private static final String COLUMN_ID = UserInfoTable.TABLE_NAME + '.' + UserInfoTable.ID;
private static final String STATEMENT_SELECT_DUPLICATE_IDS =
'(' + SELECT + "MIN(" + COLUMN_ID + ") as id" + FROM + UserInfoTable.TABLE_NAME +
GROUP_BY + UserInfoTable.USER_UUID + ", " + UserInfoTable.SERVER_UUID + ')';
SELECT + "MIN(" + COLUMN_ID + ") as id" + FROM + UserInfoTable.TABLE_NAME +
GROUP_BY + UserInfoTable.USER_UUID + ", " + UserInfoTable.SERVER_UUID;
@Override
protected void performOperations() {
execute(
"DELETE" + FROM + UserInfoTable.TABLE_NAME +
WHERE + COLUMN_ID +
" IN (" +
SELECT + COLUMN_ID + FROM + UserInfoTable.TABLE_NAME +
LEFT_JOIN + STATEMENT_SELECT_DUPLICATE_IDS + " q2 on q2.id=" + COLUMN_ID +
WHERE + "q2.id" + IS_NULL +
')'
" NOT IN (" + STATEMENT_SELECT_DUPLICATE_IDS + ')'
);
}
}

View File

@ -21,8 +21,8 @@ import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.Query;
import com.djrapitops.plan.db.access.QueryStatement;
import com.djrapitops.plan.db.access.transactions.commands.RemovePlayerTransaction;
import com.djrapitops.plan.db.access.transactions.init.RemoveDuplicateUserInfoTransaction;
import com.djrapitops.plan.db.access.transactions.init.RemoveOldSampledDataTransaction;
import com.djrapitops.plan.db.patches.RemoveDuplicateUserInfoTransaction;
import com.djrapitops.plan.db.sql.tables.SessionsTable;
import com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalResultsTransaction;
import com.djrapitops.plan.system.database.DBSystem;

View File

@ -44,8 +44,8 @@ import com.djrapitops.plan.db.access.transactions.commands.*;
import com.djrapitops.plan.db.access.transactions.events.*;
import com.djrapitops.plan.db.access.transactions.init.CreateIndexTransaction;
import com.djrapitops.plan.db.access.transactions.init.CreateTablesTransaction;
import com.djrapitops.plan.db.access.transactions.init.RemoveDuplicateUserInfoTransaction;
import com.djrapitops.plan.db.patches.Patch;
import com.djrapitops.plan.db.patches.RemoveDuplicateUserInfoTransaction;
import com.djrapitops.plan.db.tasks.DBCleanTask;
import com.djrapitops.plan.extension.CallEvents;
import com.djrapitops.plan.extension.DataExtension;