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
grimrose
February 05, 2014
Programming
0
930
Ambiguous Groups #sqlap
SQLアンチパターン読書会 「アンビギュアスグループ」
grimrose
February 05, 2014
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
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
290
Shibuya.Java #04
grimrose
1
640
I made out Gradle plug-in
grimrose
0
940
Other Decks in Programming
See All in Programming
OTP を自動で入力する裏技
megabitsenmzq
0
110
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
240
AHC061解説
shun_pi
0
380
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
340
Windows on Ryzen and I
seosoft
0
300
TipKitTips
ktcryomm
0
170
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
510
Ruby x Terminal
a_matsuda
7
600
GoのDB アクセスにおける 「型安全」と「柔軟性」の両立 - Bob という選択肢
tak848
0
110
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
220
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
270
The free-lunch guide to idea circularity
hollycummins
0
230
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
50
14k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
150
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
71
The Art of Programming - Codeland 2020
erikaheidi
57
14k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
480
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.9k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
310
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
100
Fireside Chat
paigeccino
42
3.8k
We Have a Design System, Now What?
morganepeng
55
8k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う