From da333382e1050f432e17e1b487fc16a9999a1744 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 6 Dec 2024 22:13:17 +0100 Subject: [PATCH] fix: don't specify FOR clause for index hint - I made a mistake when specifying the `FOR` clause for the index hint, I read it as being an required argument by XORM. The [MariaDB documention](https://mariadb.com/kb/en/use-index/) tells that it defaults to the `FOR JOIN` clause hence why I specified `JOIN` (As can be seen in the previous PR's SQL analyze I didn't specify the `FOR` clause). However apparently there seems to be some wizardy going on as we need to tell MariaDB to use this index for the `ORDER BY` clause to actually force MariaDB to use this index over the `updated_unix` index. However because it's not actually required by XORM to specify this value I leave this empty as mariadb is apparently smart enough to figure out for which type we want to use this index. - TL;DR make this index hint actually effective for MariaDB. - Ref: #6146 --- routers/web/user/notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index d3c9365dfe..c3358dbf62 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -113,7 +113,7 @@ func getNotifications(ctx *context.Context) { sess := db.GetEngine(ctx).Table("notification") if setting.Database.Type.IsMySQL() { - sess = sess.IndexHint("USE", "JOIN", "IDX_notification_user_id") + sess = sess.IndexHint("USE", "", "IDX_notification_user_id") } sess.Where("user_id = ?", ctx.Doer.ID). And("status = ? OR status = ?", status, activities_model.NotificationStatusPinned).