0
0

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 1 year has passed since last update.

inとかnot inは遅い

Posted at

何がおきてしまったか

  • しくじりってほどじゃないけど、実装してて気づいたこと
  • データが多いテーブルへのinとかnot inは遅い。
sample.sql
select r0.id from reserves r0 
where
r0.reserved_at is not null
and r0.member_cd not in (select member_cd from members)

しくじりはなぜおこってしまったのか

  • オプティマイザがいい感じにしてくれるかと思ったらそんなことなかった
  • explainかけたら全然index効いてなかった

二度としくじらないためにどうしたのか(どうしようと思っているか)

  • joinすればちゃんとindex効いて速い。
  • クエリの検証はまあまあデータ入ってるテーブルでやろう。
    • データ少ないとクソクエリでも高速に動いてしまう。
sample.sql
select r0.id from reserves r0 
left outer join members m on m.member_cd = r0.member_cd 
where
r0.reserved_ts is not null
and m.member_cd is null
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?