Skip to content

Conversation

@jakubno
Copy link
Member

@jakubno jakubno commented Oct 27, 2025

Before

QUERY PLAN
Limit (cost=3.36..231.54 rows=100 width=748) (actual time=1628.941..1744.904 rows=100 loops=1)
-> Nested Loop (cost=3.36..2292711.14 rows=1004759 width=748) (actual time=1628.940..1744.870 rows=100 loops=1)
-> Nested Loop Left Join (cost=2.93..248843.50 rows=1004759 width=253) (actual time=1628.324..1630.706 rows=100 loops=1)
-> Index Scan using idx_snapshots_team_time_id on snapshots s (cost=0.43..223714.47 rows=1004759 width=221) (actual time=1628.220..1630.322 rows=100 loops=1)
Index Cond: (team_id = 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'::uuid)
Filter: ((sandbox_started_at < '2025-09-20 00:00:00+00'::timestamp with time zone) OR ((sandbox_started_at = '2025-09-20 00:00:00+00'::timestamp with time zone) AND (sandbox_id > ''::text)))
Rows Removed by Filter: 277449
-> Memoize (cost=2.50..2.52 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=100)
Cache Key: s.base_env_id
Cache Mode: binary
Hits: 99 Misses: 1 Evictions: 0 Overflows: 0 Memory Usage: 1kB
-> Aggregate (cost=2.50..2.50 rows=1 width=32) (actual time=0.092..0.093 rows=1 loops=1)
-> Index Scan using idx_envs_envs_aliases on env_aliases (cost=0.27..2.49 rows=1 width=50) (actual time=0.035..0.036 rows=1 loops=1)
Index Cond: (env_id = s.base_env_id)
-> Limit (cost=0.43..2.01 rows=1 width=495) (actual time=1.139..1.139 rows=1 loops=100)
-> Index Scan using idx_env_builds_env_status_created on env_builds eb (cost=0.43..3.60 rows=2 width=495) (actual time=1.138..1.138 rows=1 loops=100)
Index Cond: ((env_id = s.env_id) AND (status = 'success'::text))
Planning Time: 2.641 ms
Execution Time: 1745.111 ms

After

QUERY PLAN
Limit (cost=3.36..227.07 rows=100 width=748) (actual time=5.317..105.461 rows=100 loops=1)
-> Nested Loop (cost=3.36..2638655.63 rows=1179508 width=748) (actual time=5.316..105.433 rows=100 loops=1)
-> Nested Loop Left Join (cost=2.93..239315.86 rows=1179508 width=253) (actual time=3.320..5.273 rows=100 loops=1)
-> Index Scan using idx_snapshots_team_time_id on snapshots s (cost=0.43..209818.11 rows=1179508 width=221) (actual time=3.224..4.971 rows=100 loops=1)
Index Cond: ((team_id = 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx'::uuid) AND (sandbox_started_at <= '2025-10-10 00:00:00+00'::timestamp with time zone))
Filter: (ROW(sandbox_started_at, ''::text) < ROW('2025-10-10 00:00:00+00'::timestamp with time zone, sandbox_id))
-> Memoize (cost=2.50..2.52 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=100)
Cache Key: s.base_env_id
Cache Mode: binary
Hits: 99 Misses: 1 Evictions: 0 Overflows: 0 Memory Usage: 1kB
-> Aggregate (cost=2.50..2.50 rows=1 width=32) (actual time=0.086..0.087 rows=1 loops=1)
-> Index Scan using idx_envs_envs_aliases on env_aliases (cost=0.27..2.49 rows=1 width=50) (actual time=0.036..0.037 rows=1 loops=1)
Index Cond: (env_id = s.base_env_id)
-> Limit (cost=0.43..2.01 rows=1 width=495) (actual time=0.993..0.993 rows=1 loops=100)
-> Index Scan using idx_env_builds_env_status_created on env_builds eb (cost=0.43..3.60 rows=2 width=495) (actual time=0.992..0.992 rows=1 loops=100)
Index Cond: ((env_id = s.env_id) AND (status = 'success'::text))
Planning Time: 1.498 ms
Execution Time: 105.644 ms

@linear
Copy link

linear bot commented Oct 27, 2025

AND (s.sandbox_started_at, @cursor_id) < (@cursor_time, s.sandbox_id)
AND NOT (s.sandbox_id = ANY (@snapshot_exclude_sbx_ids::text[]))
ORDER BY s.sandbox_started_at DESC, s.sandbox_id
ORDER BY s.sandbox_started_at DESC, s.sandbox_id ASC
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is here just make it explicit

@jakubno jakubno marked this pull request as ready for review October 27, 2025 21:01
@jakubno jakubno added the improvement Improvement for current functionality label Oct 27, 2025
@jakubno jakubno merged commit fcbfaf8 into main Oct 28, 2025
27 checks passed
@jakubno jakubno deleted the improve-the-snapshot-pagination-query-eng-3228 branch October 28, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement for current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants