2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

クエリを書くときの注意

Last updated at Posted at 2019-04-23

SQLを書くときの注意点

先輩からコードレビューで指摘をもらったのでメモ

悪い例

select * from BbsApp
where id <> 20

↑のクエリでは20に等しくないレコードを取得している。
ですが、このクエリだと実行時に全レコードの20ではないやつを探り、データが多ければ多いほど負荷がかかってきてしまう。
「!=」も同様。

良い例

select * from BbsApp
where id < 20

必ずどちらかの不等号をつけて実行する。
↑のクエリであればid < 20なので20より下のレコードを探るので、負荷が軽減される。
小さなことだが、データ次第では致命的になるので気を付けよ

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?