$30 off During Our Annual Pro Sale. View Details »
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.9k
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
280
Shibuya.Java #04
grimrose
1
620
I made out Gradle plug-in
grimrose
0
920
Other Decks in Programming
See All in Programming
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
2
1.1k
テストやOSS開発に役立つSetup PHP Action
matsuo_atsushi
0
140
Google Antigravity and Vibe Coding: Agentic Development Guide
mickey_kubo
2
130
AWS CDKの推しポイントN選
akihisaikeda
1
240
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
130
Herb to ReActionView: A New Foundation for the View Layer @ San Francisco Ruby Conference 2025
marcoroth
0
240
How Software Deployment tools have changed in the past 20 years
geshan
0
28k
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
5
270
社内オペレーション改善のためのTypeScript / TSKaigi Hokuriku 2025
dachi023
1
470
Media Capture and Streams: W3C仕様と現場での知見
nowaki28
0
130
関数実行の裏側では何が起きているのか?
minop1205
1
570
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
110
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
186
22k
Automating Front-end Workflow
addyosmani
1371
200k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
700
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
120
20k
Building Applications with DynamoDB
mza
96
6.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
GitHub's CSS Performance
jonrohan
1032
470k
Faster Mobile Websites
deanohume
310
31k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
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),
',') • カスタム関数 • ストアドプロシージャ
まとめ 曖昧なクエリ結果を避けるために、 単一値の原則に従う