Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
860
Ambiguous Groups #sqlap
grimrose
0
900
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
280
Shibuya.Java #04
grimrose
1
620
Other Decks in Programming
See All in Programming
sbt 2
xuwei_k
0
190
Herb to ReActionView: A New Foundation for the View Layer @ San Francisco Ruby Conference 2025
marcoroth
0
240
CloudNative Days Winter 2025: 一週間で作る低レイヤコンテナランタイム
ternbusty
7
1.9k
スタートアップを支える技術戦略と組織づくり
pospome
8
15k
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
10
11k
How Software Deployment tools have changed in the past 20 years
geshan
0
28k
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
1
210
Reactive Thinking with Signals and the new Resource API
manfredsteyer
PRO
0
160
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
130
GeistFabrik and AI-augmented software development
adewale
PRO
0
250
AIコーディングエージェント(skywork)
kondai24
0
110
Integrating WordPress and Symfony
alexandresalome
0
120
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
How GitHub (no longer) Works
holman
316
140k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Designing for humans not robots
tammielis
254
26k
Navigating Team Friction
lara
191
16k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
RailsConf 2023
tenderlove
30
1.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Speed Design
sergeychernyshev
33
1.4k
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型に格納
後処理 • 行の集合として取得し、アプリケーションで何と かする。
おわりに • メタデータは、メタデータのために使いましょう。