문제

What happens if both values in an or statement are non-null?

Does mysql uses the left side every time or is there a possibility that mysql uses the right side?

SELECT * 
FROM posts p 
WHERE parent_id = ? OR id = ?
ORDER BY date 
DESC LIMIT 1
도움이 되었습니까?

해결책

  1. If the values are null then the comparison with = will fail. Use IS instead.
  2. You can't really tell which condition will be executed first and how the DB handles the filtering. This is totally up to the optimizer at runtime.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top