Skip to main content
added 117 characters in body
Source Link
Rick James
  • 79.4k
  • 5
  • 51
  • 117
FROM    
   CustomerTable tbl  
   INNER JOIN TeamCustomerMapping tbl2 on tbl.customerId= tbl2.customerId
WHERE
    1 = 1                       
        and tbl2.teamId = 9
        order by tbl.lastLoginDate asc

For at least this one query, you need this composite index (possibly the PRIMARY KEY): INDEX(teamId, customerId)

Is customerId the PRIMARY KEY of tbl? If not, then you need INDEX(customerId, lastLoginDate)

Are you leaving out something? Or does the query really return "millions" of rows?

For other queries, you may need the mapping table to work the other direction; add INDEX(customerId, teamId).

FROM    
   CustomerTable tbl  
   INNER JOIN TeamCustomerMapping tbl2 on tbl.customerId= tbl2.customerId
WHERE
    1 = 1                       
        and tbl2.teamId = 9
        order by tbl.lastLoginDate asc

For at least this one query, you need this composite index (possibly the PRIMARY KEY): INDEX(teamId, customerId)

Is customerId the PRIMARY KEY of tbl? If not, then you need INDEX(customerId, lastLoginDate)

Are you leaving out something? Or does the query really return "millions" of rows?

FROM    
   CustomerTable tbl  
   INNER JOIN TeamCustomerMapping tbl2 on tbl.customerId= tbl2.customerId
WHERE
    1 = 1                       
        and tbl2.teamId = 9
        order by tbl.lastLoginDate asc

For at least this one query, you need this composite index (possibly the PRIMARY KEY): INDEX(teamId, customerId)

Is customerId the PRIMARY KEY of tbl? If not, then you need INDEX(customerId, lastLoginDate)

Are you leaving out something? Or does the query really return "millions" of rows?

For other queries, you may need the mapping table to work the other direction; add INDEX(customerId, teamId).

Source Link
Rick James
  • 79.4k
  • 5
  • 51
  • 117

FROM    
   CustomerTable tbl  
   INNER JOIN TeamCustomerMapping tbl2 on tbl.customerId= tbl2.customerId
WHERE
    1 = 1                       
        and tbl2.teamId = 9
        order by tbl.lastLoginDate asc

For at least this one query, you need this composite index (possibly the PRIMARY KEY): INDEX(teamId, customerId)

Is customerId the PRIMARY KEY of tbl? If not, then you need INDEX(customerId, lastLoginDate)

Are you leaving out something? Or does the query really return "millions" of rows?