From a307fd9da3ad3799662af196b30675c37180f33a Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Thu, 20 Jul 2023 18:50:28 +0300 Subject: [PATCH] [MM-53408] server/user_store: avoid antijoin for IsEmpty query (#23966) --- server/channels/store/sqlstore/user_store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/channels/store/sqlstore/user_store.go b/server/channels/store/sqlstore/user_store.go index cc63bc038a..729fc15152 100644 --- a/server/channels/store/sqlstore/user_store.go +++ b/server/channels/store/sqlstore/user_store.go @@ -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(")")