首先,我可以描述表的架构,但我的表本身大约是 80GB,所以我希望一些专家的眼睛可以看到可以执行的任何明显的优化。我正在进行一些基于活动的分析,以了解来自内部虚拟游戏环境的一组用户。
我有两个基表:
EventTable: Moderately big at 10GB
Activity_ID UserName ActivityStart ActivityEnd Badge
ActivityTable: Super big at 100GB
UserName ActivityTime Game1Points Game2Points
Run Code Online (Sandbox Code Playgroud)
简而言之,我正在尝试以下操作:
- For each activity in the EventTable:
- Compute the median of Game1Points, Game2Points
for two cases: for all entries in the ActivityTable
that were present since 1 hour before the activity
and for all entries stored during the activity itself
Run Code Online (Sandbox Code Playgroud)
因此,我期待的决赛桌是这样的:
ResultTable:
Activity_ID Badge Game1_Before Game1_During Game2_Before Game2_During
Run Code Online (Sandbox Code Playgroud)
这显然看起来像是CURSOR
s的工作,所以我首先使用这种方法编写了我的查询。它正在运行,我可以看到进度,但在阅读了这么多恐怖故事之后,我决定用基于集合的方法重写我的 200 行基于 CURSOR 的方法。这非常适用于小桌子。但是,对于我这种大小的桌子,它似乎停滞不前(或者至少我不确定应该运行多长时间)。我运行Display …