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 5 years have passed since last update.

[Oracle]暗黙の型変換が存在するとインデックスが効かない

Posted at

このようなインデックスがあったとして

# id varchar(16) に対してのindex

CREATE INDEX test ON user(id);

これは varchar(16) で宣言されています。ですが、実態として中身が数値しか入っていなかったとします

mysql> select id from user;
+----------+
| id       |
+----------+
| 11111111 |
| 22222222 |
| 33333333 |
| 44444444 |
| 55555555 |
| 66666666 |
+----------+

これに対して、数値で検索をかけてしまうとインデックスは効きません。

select * from user where id in (22222222, 66666666);

文字列で定義されているため、暗黙の型変換が入りインデックスが外れます。文字列で指定してあげましょう。

select * from user where id in ('22222222', '66666666');

インデックスきいているはずなのに遅いなと思ったら要注意。

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?