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
890
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.8k
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.3k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
840
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
270
Shibuya.Java #04
grimrose
1
620
I made out Gradle plug-in
grimrose
0
910
Other Decks in Programming
See All in Programming
How Android Uses Data Structures Behind The Scenes
l2hyunwoo
0
480
ユーザーも開発者も悩ませない TV アプリ開発 ~Compose の内部実装から学ぶフォーカス制御~
taked137
0
190
奥深くて厄介な「改行」と仲良くなる20分
oguemon
1
560
RDoc meets YARD
okuramasafumi
4
170
OSS開発者という働き方
andpad
5
1.7k
時間軸から考えるTerraformを使う理由と留意点
fufuhu
16
4.8k
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
710
請來的 AI Agent 同事們在寫程式時,怎麼用 pytest 去除各種幻想與盲點
keitheis
0
120
Tool Catalog Agent for Bedrock AgentCore Gateway
licux
7
2.5k
ファインディ株式会社におけるMCP活用とサービス開発
starfish719
0
1.9k
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
400
Navigating Dependency Injection with Metro
zacsweers
3
2.5k
Featured
See All Featured
Bash Introduction
62gerente
615
210k
Faster Mobile Websites
deanohume
309
31k
Designing Experiences People Love
moore
142
24k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Side Projects
sachag
455
43k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
Thoughts on Productivity
jonyablonski
70
4.8k
Producing Creativity
orderedlist
PRO
347
40k
Speed Design
sergeychernyshev
32
1.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う