Any point in using LIMIT in EXISTS query?

后端 未结 3 2369
Happy的楠姐
Happy的楠姐 2021-02-19 06:53

Is there any performance benefit in adding a LIMIT to an EXISTS query, or would MySQL apply the limit on its own?

Example:

IF E         


        
3条回答
  •  鱼传尺愫
    2021-02-19 07:29

    The purpose of EXISTS() is to perform the query only until it can decide if there are any rows in that table matching the WHERE clause. That is, it logically does the same thing as LIMIT 1. EXISTS is probably called semi-join in some circles.

    Bottom line: Don't use LIMIT 1 inside EXISTS().

    Addenda: As Paul points out, a LIMIT with an OFFSET (or LIMIT m,n) does have meaning.

提交回复
热议问题