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
870
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.7k
Gradleで始めるGroovy expand #jjug_ccc #ccc_r14
grimrose
4
5.9k
I wanna tell you about "Groovy Template"
grimrose
3
5.3k
Groovy Shell with Gradle
grimrose
0
5.2k
Shibuya.Java #07
grimrose
0
830
ぼっちプロジェクトとアジャイルサムライ
grimrose
0
260
Shibuya.Java #04
grimrose
1
610
I made out Gradle plug-in
grimrose
0
910
Other Decks in Programming
See All in Programming
機械学習って何? 5分で解説頑張ってみる
kuroneko2828
0
210
GoのWebAssembly活用パターン紹介
syumai
3
10k
A comprehensive view of refactoring
marabesi
0
470
ドメインモデリングにおける抽象の役割、tagless-finalによるDSL構築、そして型安全な最適化
knih
11
1.8k
2度もゼロから書き直して、やっとブラウザでぬるぬる動くAIに辿り着いた話
tomoino
0
160
業務自動化をJavaとSeleniumとAWS Lambdaで実現した方法
greenflagproject
1
110
Enterprise Web App. Development (2): Version Control Tool Training Ver. 5.1
knakagawa
1
110
Using AI Tools Around Software Development
inouehi
0
1.2k
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
670
iOSアプリ開発で 関数型プログラミングを実現する The Composable Architectureの紹介
yimajo
2
210
生成AIで日々のエラー調査を進めたい
yuyaabo
0
570
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
360
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
910
Being A Developer After 40
akosma
90
590k
Navigating Team Friction
lara
186
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
The Invisible Side of Design
smashingmag
299
51k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Designing for Performance
lara
609
69k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う