Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Indexの種類
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
patorash
January 25, 2020
Technology
850
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Indexの種類
データベースのIndexの種類について、代表的なものについて整理しました。
patorash
January 25, 2020
More Decks by patorash
See All by patorash
中間管理職はそこそこ楽しい
patorash
0
57
情報共有戦略と戦術
patorash
1
1.4k
exists?で起きるN+1問題にSetで対処する
patorash
0
870
DBのメタデータを管理する文化を作る
patorash
0
720
Stimulusのススメ
patorash
0
99
ActiveRecordの速度改善Tips2020冬
patorash
0
95
わかった気になる!OpenID Connect
patorash
2
2.2k
Start-SQLの紹介
patorash
0
790
RailsアプリにGraphQLを導入してみた話
patorash
1
710
Other Decks in Technology
See All in Technology
AI に書かせたその API、 “信頼” できますか?
nagix
0
110
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
4
1.7k
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
1.5k
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
3
510
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
820
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
1.9k
SREは、MCPとAutopilotをこう使え!
kazumax55
2
810
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
0
2.2k
What the customer really needed
kawaguti
PRO
2
180
2026_devsumi_ozono.pdf
o3
3
510
アクセスキーこわい やめかたと漏らさない工夫
sassssan68
1
250
Issue 駆動でスペシャリストの意図を届ける、AI 実装のアクセシビリティ向上
thkt
0
110
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Unsuck your backbone
ammeep
672
58k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
Skip the Path - Find Your Career Trail
mkilby
1
230
Google's AI Overviews - The New Search
badams
0
1.6k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Agile that works and the tools we love
rasmusluckow
331
22k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
280
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
500
Transcript
インデックスの種類 2020-01-25 第28回 中国地方DB勉強会 @patorash 1
自己紹介 名前:尾古 豊明(おこ とよあき) twitter: @patorash 所属:株式会社リゾーム システム開発部 役職:専門職 仕事内容:
ショッピングセンターに関連するサービス開発 Ruby on Railsで自社サービスの開発・運用(7年目) データベースについて詳しくなりたい。OSS-DB Silver取得済み。 現在、データベーススペシャリスト試験に向けて勉強中 2
OSS-DB Silverを受けた頃のワイ 3 よくわからんけど普通に使うのB-Tree Indexだけじゃない? B-Tree Index理解しとけばいいや。 よし、Index完全に理解した。
データベーススペシャリストの勉強をしてるワイ 4 まったくわからない。 俺は雰囲気でIndexを使っている。
Indexについて整理 5
Indexの種類 • B-tree Index • Bitmap Index • Hash Index
• その他(GiSTとか)※今回は取り上げない 6
B-tree Index • PostgreSQLのデフォルトのIndex • MySQLはストレージエンジンによって デフォルトは異なるが、 Inno DBだと デフォルトのIndex
• 木構造で作られる • BはBalanced • カーディナリティ(選択性)が 高い列に有効 • カーディナリティが低い列だと フルスキャンが発生する • 範囲検索でも使える 31 17 20 35 42 10 15 32 33 37 39 50 52 18 19 25 30 ※EXAM PRESS うかる!データベーススペシャリスト より抜粋 7
Bitmap Index • Bitmap形式のIndex ◦ 0と1で表現 • カーディナリティの低い場合に有効 ◦ 性別、権限、カテゴリー等の種類の少ない
ケースのこと • PostgreSQLの場合、明示的にこの Indexを 指定することはできないが、実行時に Bitmapを作成し、それを使ってスキャンする ことがある ◦ Bitmapの作成にコストがかかるが、 それでもフルスキャンに比べるとマシ というケースで発動 8 性別 権限 浜田 男 管理者 松本 男 編集者 今田 男 ゲスト 東野 男 編集者 板尾 男 管理者 蔵野 男 ゲスト 篠原 女 編集者 YOU 女 ゲスト
Bitmap Index • Bitmap形式のIndex ◦ 0と1で表現 • カーディナリティの低い場合に有効 ◦ 性別、権限、カテゴリー等の種類の少ない
ケースのこと • PostgreSQLの場合、明示的にこの Indexを 指定することはできないが、実行時に Bitmapを作成し、それを使ってスキャンする ことがある ◦ Bitmapの作成にコストがかかるが、 それでもフルスキャンに比べるとマシ というケースで発動 9 男性 女性 管理者 編集者 ゲスト 浜田 1 0 1 0 0 松本 1 0 0 1 0 今田 1 0 0 0 1 東野 1 0 0 1 0 板尾 1 0 1 0 0 蔵野 1 0 0 0 1 篠原 0 1 0 1 0 YOU 0 1 0 0 1
Bitmap Index • Bitmap形式のIndex ◦ 0と1で表現 • カーディナリティの低い場合に有効 ◦ 性別、権限、カテゴリー等の種類の少ない
ケースのこと • PostgreSQLの場合、明示的にこの Indexを 指定することはできないが、実行時に Bitmapを作成し、それを使ってスキャンする ことがある ◦ Bitmapの作成にコストがかかるが、 それでもフルスキャンに比べるとマシ というケースで発動 • 男で管理者、という条件にしたら、浜田と板 尾がすぐに浮かび上がる 10 男性 女性 管理者 編集者 ゲスト 浜田 1 0 1 0 0 松本 1 0 0 1 0 今田 1 0 0 0 1 東野 1 0 0 1 0 板尾 1 0 1 0 0 蔵野 1 0 0 0 1 篠原 0 1 0 1 0 YOU 0 1 0 0 1
Hash Index • 値のHash値を作るIndex • 完全一致の際に効果的 • 範囲検索はできない • Indexの物理量の増え方が一定になる
• PostgreSQLでは使えるが非推奨 ◦ WALに書き込めない ◦ ストリーミングレプリケーションで 使えない 11 メールアドレス Hash値 浜田
[email protected]
723E7 松本
[email protected]
83AB4 今田
[email protected]
15D1C 東野
[email protected]
9AB2F 板尾
[email protected]
699FE 蔵野
[email protected]
1DAF8 篠原
[email protected]
3E783 YOU
[email protected]
AB415
OSS-DB Silverを受けた頃のワイ 12 よくわからんけど普通に使うのB-Tree Indexだけじゃない? B-Tree Index理解しとけばいいや。 よし、Index完全に理解した。
PostgreSQL10でHash Indexが強化! 13
Hash Index • 値のHash値を作るIndex • 完全一致の際に効果的 • 範囲検索はできない • Indexの物理量の増え方が一定になる
• PostgreSQL 9.xでは使えるが非推奨 ◦ WALに書き込めない ◦ ストリーミングレプリケーションで 使えない • PostgreSQL 10以上で使える! ◦ WALに書き込める! ◦ ストリーミングレプリケーションで 使える! 14 メールアドレス Hash値 浜田
[email protected]
723E7 松本
[email protected]
83AB4 今田
[email protected]
15D1C 東野
[email protected]
9AB2F 板尾
[email protected]
699FE 蔵野
[email protected]
1DAF8 篠原
[email protected]
3E783 YOU
[email protected]
AB415
Hash Indexを試してみた • データ1万件程度 • ユニーク制約のついた列 • 完全一致で利用 • B-Tree
Indexと速度面・データ量で比較 15
結果 • 検索速度はB-Tree Indexと、ほぼ変わらず • 実行計画では、Hash Indexでは若干コストが低い • Indexのデータ量も1万件程度だと、ほぼ変わらず ◦
行数が増えるとHash Indexのほうがデータ量的に少なくて済んだという記事を見た (@nuko_yokohamaさんの記事) ◦ 1000万行入れた時のデータについて。 ◦ https://qiita.com/nuko_yokohama/items/05ece8313af0f81a870d 16
まとめ B-Tree Indexを使っておけば、基本は大丈夫。 Bitmap Index はクエリ実行時に自動で作られる。(B-Tree Indexは必要) Hash Indexは(ほぼ)ユニークで完全一致のケースならば有効。 使ってみてはいかがでしょうか?(ただし、PostgreSQL
10以上) 適用できそうな例: • メールアドレス • 電話番号 • ユーザーコード • 認証系 • アクセスキー • アクセスシークレット 他にありそうな例があったら教えてください! 17