[MM-53408] server/user_store: avoid antijoin for IsEmpty query (#23966)

This commit is contained in:
Ibrahim Serdar Acikgoz
2023-07-20 18:50:28 +03:00
committed by GitHub
parent 6c821c8b13
commit a307fd9da3

View File

@@ -2140,7 +2140,11 @@ func (us SqlUserStore) IsEmpty(excludeBots bool) (bool, error) {
From("Users")
if excludeBots {
builder = builder.LeftJoin("Bots ON Users.Id = Bots.UserId").Where("Bots.UserId IS NULL")
if us.DriverName() == model.DatabaseDriverPostgres {
builder = builder.LeftJoin("Bots ON Users.Id = Bots.UserId").Where("Bots.UserId IS NULL")
} else {
builder = builder.Where(sq.Expr("Users.Id NOT IN (SELECT UserId FROM Bots)"))
}
}
builder = builder.Suffix(")")