Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Created July 6, 2011 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryandotsmith/1066559 to your computer and use it in GitHub Desktop.
Save ryandotsmith/1066559 to your computer and use it in GitHub Desktop.
explain analyze on lock_head()
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
Limit (cost=21.03..21.04 rows=1 width=10) (actual time=0.063..0.063 rows=1 loops=1)
-> LockRows (cost=21.03..21.11 rows=6 width=10) (actual time=0.062..0.062 rows=1 loops=1)
-> Sort (cost=21.03..21.05 rows=6 width=10) (actual time=0.046..0.046 rows=1 loops=1)
Sort Key: id
Sort Method: quicksort Memory: 25kB
-> Seq Scan on queue_classic_jobs (cost=0.00..21.00 rows=6 width=10) (actual time=0.035..0.036 rows=1 loops=1)
Filter: (locked_at IS NULL)
Total runtime: 0.105 ms
(8 rows)
queue_classic_test=# EXPLAIN ANALYZE select id from queue_classic_jobs where locked_at IS NULL order by id ASC limit 1 offset 0 for update nowait;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=244.02..244.03 rows=1 width=10) (actual time=7.853..7.854 rows=1 loops=1)
-> LockRows (cost=244.02..369.03 rows=10001 width=10) (actual time=7.852..7.852 rows=1 loops=1)
-> Sort (cost=244.02..269.02 rows=10001 width=10) (actual time=7.807..7.807 rows=1 loops=1)
Sort Key: id
Sort Method: quicksort Memory: 853kB
-> Seq Scan on queue_classic_jobs (cost=0.00..194.01 rows=10001 width=10) (actual time=0.010..3.831 rows=10001 loops=1)
Filter: (locked_at IS NULL)
Total runtime: 7.916 ms
(8 rows)
queue_classic_test=# EXPLAIN ANALYZE select id from queue_classic_jobs where locked_at IS NULL order by id ASC limit 1 offset 0 for update nowait;
queue_classic_test=# EXPLAIN ANALYZE select id from queue_classic_jobs where locked_at IS NULL order by id ASC limit 1 offset 0 for update nowait;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=3979.23..3979.24 rows=1 width=10) (actual time=232.550..232.550 rows=1 loops=1)
-> LockRows (cost=3979.23..6009.41 rows=162415 width=10) (actual time=232.549..232.549 rows=1 loops=1)
-> Sort (cost=3979.23..4385.26 rows=162415 width=10) (actual time=232.519..232.519 rows=1 loops=1)
Sort Key: id
Sort Method: external sort Disk: 3224kB
-> Seq Scan on queue_classic_jobs (cost=0.00..3167.15 rows=162415 width=10) (actual time=0.022..62.179 rows=165017 loops=1)
Filter: (locked_at IS NULL)
Total runtime: 249.135 ms
(8 rows)
queue_classic_test=# EXPLAIN ANALYZE select id from queue_classic_jobs where locked_at IS NULL order by id ASC limit 1 offset 0 for update nowait;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=4788.99..4789.00 rows=1 width=10) (actual time=286.976..286.977 rows=1 loops=1)
-> LockRows (cost=4788.99..7232.32 rows=195466 width=10) (actual time=286.976..286.976 rows=1 loops=1)
-> Sort (cost=4788.99..5277.66 rows=195466 width=10) (actual time=286.891..286.891 rows=1 loops=1)
Sort Key: id
Sort Method: external sort Disk: 3880kB
-> Seq Scan on queue_classic_jobs (cost=0.00..3811.66 rows=195466 width=10) (actual time=5.221..82.348 rows=198638 loops=1)
Filter: (locked_at IS NULL)
Total runtime: 306.601 ms
(8 rows)
queue_classic_test=# EXPLAIN ANALYZE select id from queue_classic_jobs where locked_at IS NULL order by id ASC limit 1 offset 0 for update nowait;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=7509.96..7509.97 rows=1 width=10) (actual time=439.953..439.954 rows=1 loops=1)
-> LockRows (cost=7509.96..11345.76 rows=306864 width=10) (actual time=439.952..439.952 rows=1 loops=1)
-> Sort (cost=7509.96..8277.12 rows=306864 width=10) (actual time=439.921..439.921 rows=1 loops=1)
Sort Key: id
Sort Method: external sort Disk: 6080kB
-> Seq Scan on queue_classic_jobs (cost=0.00..5975.64 rows=306864 width=10) (actual time=0.021..118.558 rows=311002 loops=1)
Filter: (locked_at IS NULL)
Total runtime: 471.116 ms
(8 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment