Does limiting a query to one record improve performance

前端 未结 6 991
清酒与你
清酒与你 2020-12-06 09:30

Will limiting a query to one result record, improve performance in a large(ish) MySQL table if the table only has one matching result?

for example

 s         


        
6条回答
  •  [愿得一人]
    2020-12-06 09:51

    To answer your questions in order: 1) yes, if there is no index on name. The query will end as soon as it finds the first record. take off the limit and it has to do a full table scan every time. 2) no. primary/unique keys are guaranteed to be unique. The query should stop running as soon as it finds the row.

提交回复
热议问题