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
900
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.4k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
860
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
270
Shibuya.Java #04
grimrose
1
620
I made out Gradle plug-in
grimrose
0
920
Other Decks in Programming
See All in Programming
Flutterチームから作る組織の越境文化
findy_eventslides
0
470
開発生産性が組織文化になるまでの軌跡
tonegawa07
0
180
モビリティSaaSにおけるデータ利活用の発展
nealle
0
530
全員アーキテクトで挑む、 巨大で高密度なドメインの紐解き方
agatan
3
3.5k
自動テストのアーキテクチャとその理由ー大規模ゲーム開発の場合ー
segadevtech
2
1k
Herb to ReActionView: A New Foundation for the View Layer @ San Francisco Ruby Conference 2025
marcoroth
0
140
複数チーム並行開発下でのコード移行アプローチ ~手動 Codemod から「生成AI 活用」への進化
andpad
0
170
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
仕様がそのままテストになる!Javaで始める振る舞い駆動開発
ohmori_yusuke
8
4.5k
DartASTとその活用
sotaatos
2
140
カンファレンス遠征を(安く)楽しむ技術
wp_daisuke
0
180
What’s Fair is FAIR: A Decentralised Future for WordPress Distribution
rmccue
0
190
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.6k
Practical Orchestrator
shlominoach
190
11k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
680
Rails Girls Zürich Keynote
gr2m
95
14k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
YesSQL, Process and Tooling at Scale
rocio
174
15k
Embracing the Ebb and Flow
colly
88
4.9k
Music & Morning Musume
bryan
46
7k
The Language of Interfaces
destraynor
162
25k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う