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
940
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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.9k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
6.1k
I wanna tell you about "Groovy Template"
grimrose
3
5.5k
Groovy Shell with Gradle
grimrose
0
5.3k
Shibuya.Java #07
grimrose
0
900
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
300
Shibuya.Java #04
grimrose
1
670
I made out Gradle plug-in
grimrose
0
960
Other Decks in Programming
See All in Programming
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.7k
業務時間外もAIに働いてもらう話
colorful12
3
9.9k
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
430
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
140
typoなんかねぇよ
raspython3
0
660
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
400
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
110
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
810
My Marp Sample
sinoue0108
0
140
Foundry Localでエージェント開発
seosoft
0
120
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.3k
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
Featured
See All Featured
Accessibility Awareness
sabderemane
1
200
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
500
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
370
How to make the Groovebox
asonas
2
2.4k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.5k
Chasing Engaging Ingredients in Design
codingconduct
0
300
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
870
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.3k
Darren the Foodie - Storyboard
khoart
PRO
3
3.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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う