How do I tell the MySQL Optimizer to use the index on a derived table?

前端 未结 3 1351
我在风中等你
我在风中等你 2021-02-04 19:28

Suppose you have a query like this...

SELECT T.TaskID, T.TaskName, TAU.AssignedUsers
FROM `tasks` T
    LEFT OUTER JOIN (
        SELECT TaskID, GROUP_CONCAT(U.F         


        
3条回答
  •  情话喂你
    2021-02-04 20:11

    The problem I see is that by doing a subquery there is no underlying indexed table. If you are having a performance I'd do the grouping at the end, something like this:

    SELECT T.TaskID, T.TaskName, GROUP_CONCAT(U.FirstName, ' ', U.LastName SEPARATOR ', ') AS AssignedUsers
    FROM `tasks` T
        LEFT OUTER JOIN  `tasks_assigned_users` TAU ON (T.TaskID=TAU.TaskID)
        INNER JOIN `users` U ON (TAU.UserID=U.UserID)
    GROUP BY T.TaskID, T.TaskName
    

提交回复
热议问题