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
930
0
Share
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.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
300
Shibuya.Java #04
grimrose
1
650
I made out Gradle plug-in
grimrose
0
940
Other Decks in Programming
See All in Programming
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
830
의존성 주입과 모듈화
fornewid
0
150
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
4
1.3k
🦞OpenClaw works with AWS
licux
1
300
Explore CoroutineScope
tomoeng11
0
120
t *testing.T は どこからやってくるの?
otakakot
1
820
Vibe NLP for Applied NLP
inesmontani
PRO
0
520
How Swift's Type System Guides AI Agents
koher
0
310
Running Swift without an OS
kishikawakatsumi
0
860
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
700
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
120
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
130
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
6.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The Spectacular Lies of Maps
axbom
PRO
1
720
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
73k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
380
Discover your Explorer Soul
emna__ayadi
2
1.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う