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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
grimrose
February 05, 2014
Programming
0
920
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
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
320
CSC307 Lecture 15
javiergs
PRO
0
240
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
650
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
330
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.3k
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
260
CSC307 Lecture 13
javiergs
PRO
0
320
ロボットのための工場に灯りは要らない
watany
7
2.1k
Ruby x Terminal
a_matsuda
7
590
AI活用のコスパを最大化する方法
ochtum
0
130
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
780
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
990
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
270
Designing Experiences People Love
moore
143
24k
My Coaching Mixtape
mlcsv
0
69
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
The Invisible Side of Design
smashingmag
302
51k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
120
Designing for Timeless Needs
cassininazir
0
150
The World Runs on Bad Software
bkeepers
PRO
72
12k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
210
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.1k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う