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
SQL antipatterns #5
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
grimrose
June 22, 2013
Programming
3.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SQL antipatterns #5
SQLアンチパターン読書会 「EAV(エンティティ・アトリビュート・バリュー)」
grimrose
June 22, 2013
More Decks by grimrose
See All by grimrose
だいたい10分くらいで 知った気になれる Vert.x 3.0 #渋谷Java / Shibuya.java #11
grimrose
0
1.9k
Syobochim should read book of modeling #syoboben
grimrose
0
1.9k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
6.2k
I wanna tell you about "Groovy Template"
grimrose
3
5.5k
Groovy Shell with Gradle
grimrose
0
5.3k
Shibuya.Java #07
grimrose
0
900
Ambiguous Groups #sqlap
grimrose
0
950
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
300
Shibuya.Java #04
grimrose
1
670
Other Decks in Programming
See All in Programming
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
130
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
150
XHTMLが残したもの
yosuke_furukawa
PRO
2
830
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
260
Java 27新機能 / Java 27 new features
kishida
2
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
230
SREの越境 / SRE Collaboration
y0hgi
2
260
setup-vp GitLab対応の裏側
naokihaba
0
120
速習iPhone Duo対応
yuukiw00w
1
710
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
830
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
270
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
410
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
4 Signs Your Business is Dying
shpigford
187
23k
Faster Mobile Websites
deanohume
310
32k
Designing for Timeless Needs
cassininazir
1
480
My Coaching Mixtape
mlcsv
0
320
BBQ
matthewcrist
89
10k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
600
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Design in an AI World
tapps
1
330
Transcript
SQLアンチパターン読書会 5章 「EAV(エンティティ・アトリビュート・バリュー)」 2013/06/27 @grimrose
章構成 • 目的 ◦ 可変属性をサポートする • アンチパターン ◦ 汎用的な属性テーブルを使用する ▪
属性を取得するにはどうするか ▪ データの整合性をどう保つのか ▪ 行を再構築しなければならない • アンチパターンの見つけ方 • アンチパターンを用いてもよい場合
章構成 • 解決策 ◦ サブタイプのモデリングを行う ▪ シングルテーブル継承 ▪ 具象テーブル継承 ▪
クラステーブル継承 ▪ 半構造化データ ▪ 後処理
EAVとは • エンティティ • 属性(アトリビュート) • 値(バリュー)
EAV issue_id attr_name attr_value 1234 product 1 1234 date_reported 2009-06-01
1234 status NEW 1234 description 保存処理に失敗する 1234 reported_by Bill 1234 version_affected 1.0 1234 severity 機能の損失 1234 priority HIGH IssueAttribytes
デメリット • 属性を取得するのが冗長 • 必須属性を設定できない • データ型を使えない • 参照整合性を強制できない •
属性名を補わなければならない • 行を再構築しなければならない
可変属性を使うには • NoSQL • サブタイプ
NoSQL • Key/Value型 • カラム指向型 • ドキュメント指向型 • etc...
サブタイプ • うまく機能するのは? ◦ サブタイプの数が限られる ◦ 開発者が各サブタイプの属性をよく知っている
シングルテーブル継承 • 属性を全て個別の列に格納
具象テーブル継承 • サブタイプ毎にテーブルを作成 • 基底型と固有の属性を含む
クラステーブル継承 • 基底型テーブルとサブタイプ毎にテーブルを追 加
ORM • 各テーブル継承をサポートしている場合も • Ruby ◦ ActiveRecord • PHP ◦
doctrine2 • Java ◦ JPA • Python ◦ SQLAlchemy
半構造化データ • その他の属性をBLOB、CLOB、TEXT型に格納
後処理 • 行の集合として取得し、アプリケーションで何と かする。
おわりに • メタデータは、メタデータのために使いましょう。