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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
grimrose
June 22, 2013
Programming
3.4k
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.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.3k
Shibuya.Java #07
grimrose
0
890
Ambiguous Groups #sqlap
grimrose
0
940
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
300
Shibuya.Java #04
grimrose
1
660
Other Decks in Programming
See All in Programming
dRuby over BLE
makicamel
2
340
Webフレームワークの ベンチマークについて
yusukebe
0
170
Contextとはなにか
chiroruxx
1
330
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
510
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
230
3Dシーンの圧縮
fadis
1
770
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
6.2k
Lessons from Spec-Driven Development
simas
PRO
0
200
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
680
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
250
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
340
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.2k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
The Limits of Empathy - UXLibs8
cassininazir
1
360
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
390
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
610
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Prompt Engineering for Job Search
mfonobong
0
350
So, you think you're a good person
axbom
PRO
2
2.1k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Visualization
eitanlees
152
17k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
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型に格納
後処理 • 行の集合として取得し、アプリケーションで何と かする。
おわりに • メタデータは、メタデータのために使いましょう。