Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
6k
I wanna tell you about "Groovy Template"
grimrose
3
5.4k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
870
Ambiguous Groups #sqlap
grimrose
0
900
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
280
Shibuya.Java #04
grimrose
1
630
Other Decks in Programming
See All in Programming
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
2
440
AIコーディングエージェント(Manus)
kondai24
0
210
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
150
Cell-Based Architecture
larchanjo
0
140
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
160
Go コードベースの構成と AI コンテキスト定義
andpad
0
130
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.2k
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
430
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
140
AIコーディングエージェント(skywork)
kondai24
0
190
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
430
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
0
1.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
A better future with KSS
kneath
240
18k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
64
35k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
170
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
77
エンジニアに許された特別な時間の終わり
watany
105
220k
First, design no harm
axbom
PRO
1
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
1.9k
Between Models and Reality
mayunak
0
150
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型に格納
後処理 • 行の集合として取得し、アプリケーションで何と かする。
おわりに • メタデータは、メタデータのために使いましょう。