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
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
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
470
UIの境界線をデザインする | React Tokyo #15 メイントーク
sasagar
2
360
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
150
Making the RBS Parser Faster
soutaro
0
410
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
Claude Codeをカスタムして自分だけのClaude Codeを作ろう
terisuke
0
140
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
200
How Swift's Type System Guides AI Agents
koher
0
270
tRPCの概要と少しだけパフォーマンス
misoton665
2
210
「話せることがない」を乗り越える 〜日常業務から登壇テーマをつくる思考法〜
shoheimitani
4
820
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
420
Swift Concurrency Type System
inamiy
0
530
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
290
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
Crafting Experiences
bethany
1
120
Building Applications with DynamoDB
mza
96
7k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
110
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.4k
Making Projects Easy
brettharned
120
6.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Faster Mobile Websites
deanohume
310
31k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.8k
A designer walks into a library…
pauljervisheath
211
24k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う