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
Ambiguous Groups #sqlap
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
grimrose
February 05, 2014
Programming
940
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ambiguous Groups #sqlap
SQLアンチパターン読書会 「アンビギュアスグループ」
grimrose
February 05, 2014
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.1k
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
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
300
Shibuya.Java #04
grimrose
1
670
I made out Gradle plug-in
grimrose
0
960
Other Decks in Programming
See All in Programming
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
400
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
500
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
0
170
Foundry Localでエージェント開発
seosoft
0
120
MySQLとPostgreSQLって何が違うの?
akagami
PRO
0
160
[DroidKaigi 26] How We Moved from Android Studio to Slack
thisaay
0
200
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
970
信頼性の目標を誰も求めてない
shubox
0
490
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
110
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
140
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
440
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
9
970
Documentation Writing (for coders)
carmenintech
77
5.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
WENDY [Excerpt]
tessaabrams
12
39k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
What's in a price? How to price your products and services
michaelherold
247
13k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
260
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
640
The Limits of Empathy - UXLibs8
cassininazir
1
630
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Transcript
SQLアンチパターン読書会 14章 「アンビギュアスグループ」 2014/02/06 @grimrose
目的 グループ内で最大値を持つ行
アンチパターン 非グループ化列を参照する
単一値の原則 Single-Value Rule
アンチパターンの見つけ方 _人人人人人人人人人人_ > エラーメッセージ <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄ ※SQLiteとMySQLを除く
アンチパターンを用いてもよい場合 MySQLとSQLiteの場合 関係従属性を持つ列のみに クエリを実行するように注意
解決策 曖昧でない列を使用する
関数従属性のある列のみ クエリから曖昧な列を排除
相関サブクエリ • 読みやすい • コードの記述も簡単 • パフォーマンスに注意
導出テーブル • 相関サブクエリよりパフォーマ ンスが高い • テンポラリテーブル
JOIN • 大量のデータに対するパフォーマンス が重要な場合 • パフォーマンスの測定してね
他の列に対しても集約関数 単一値の原則
グループ毎に全ての値を連結 • GROUP_CONCAT関数 ◦ MySQL, SQLite • PostgreSQLの場合 ◦ ARRAY_TO_STRING(ARRAY_AGG(any),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う