简体   繁体   中英

How could I improve the performance of this query?

Consider that you have a MySQL table named “user” with millions of rows that have the following structure, and doesn't have any index.

TABLE:  user_id (PK) email name signup_date

We want to execute the following query:

SELECT user_id
FROM user
WHERE email=’email@bolidea.com’ AND name=’Olivier Cabanes’ 
  1. How does MySQL handle that query in term of speed?
  2. How can you improve the performance of that query?

您需要在电子邮件和名称上建立索引,否则它将需要遍历表格的每一行,而且速度非常慢...

Put an index on either email or name. No need for an index on both, since both are basically unique on their own

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM