Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SQL antipatterns #5
Search
grimrose
June 22, 2013
Programming
0
3.4k
SQL antipatterns #5
SQLアンチパターン読書会 「EAV(エンティティ・アトリビュート・バリュー)」
grimrose
June 22, 2013
Tweet
Share
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.8k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
6.1k
I wanna tell you about "Groovy Template"
grimrose
3
5.4k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
880
Ambiguous Groups #sqlap
grimrose
0
930
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
290
Shibuya.Java #04
grimrose
1
640
Other Decks in Programming
See All in Programming
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
1.1k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
750
ロボットのための工場に灯りは要らない
watany
11
3k
Migration to Signals, Signal Forms, Resource API, and NgRx Signal Store @Angular Days 03/2026 Munich
manfredsteyer
PRO
0
120
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
500
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
150
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
1.2k
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
230
[SF Ruby Feb'26] The Silicon Heel
palkan
0
120
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
280
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1k
How to stabilize UI tests using XCTest
akkeylab
0
140
Featured
See All Featured
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
150
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
200
Paper Plane
katiecoart
PRO
0
48k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
500
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
400
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
150
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
330
A designer walks into a library…
pauljervisheath
210
24k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.5k
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型に格納
後処理 • 行の集合として取得し、アプリケーションで何と かする。
おわりに • メタデータは、メタデータのために使いましょう。