rails db
EXPLAIN
ActiveRecord::Base.connection .execute('SQL').to_a
SELECT * FROM staff_shifts;
(cost=0.00..133081.67 rows=5852267 width=74)
SELECT id FROM staff_shifts;
(cost=0.00..133081.67 rows=5852267 width=4)
(5523.0ms) SELECT * FROM staff_shifts
(783.0ms) SELECT id FROM staff_shifts
SELECT * FROM staff_shifts;
(cost=0.00..133081.67 rows=5852267 width=74)
SELECT * FROM staff_shifts LIMIT 100;
(cost=0.00..2.27 rows=100 width=74)
(cost=0.00..133081.67 rows=5852267 width=74)
SELECT COUNT(*) FROM staff_shifts;
(cost=147712.34..147712.35 rows=1 width=0)
(1171.2ms) SELECT count(*) FROM staff_shifts
SELECT COUNT(id) FROM staff_shifts;
(cost=147712.34..147712.35 rows=1 width=4)
(1481.2ms) SELECT count(id) FROM staff_shifts
SELECT COUNT(*) FROM staff_shifts LIMIT 1000;
(cost=147712.34..147712.35 rows=1 width=0)
(1171.2ms) SELECT count(*) FROM staff_shifts
SELECT COUNT(*) FROM ( SELECT id FROM staff_shifts LIMIT 1000 );
(cost=35.24..35.25 rows=1 width=0)
(7.0ms) SELECT count(*) FROM ...
SELECT COUNT(*) FROM ( SELECT 1 FROM staff_shifts LIMIT 1000 );
(cost=35.24..35.25 rows=1 width=0)
(6.3ms) SELECT count(*) FROM ...
SELECT id FROM staff_shifts ORDER BY created_at;
(cost=990924.99..1005555.66 rows=5852267 width=12)
SELECT * FROM staff_shifts ORDER BY created_at LIMIT 100;
(cost=356751.11..356751.36 rows=100 width=12)
(cost=990924.99..1005555.66 rows=5852267 width=12)
SELECT * FROM staff_shifts ORDER BY created_at LIMIT 100;
(cost=0.43..5.37 rows=100 width=12)
(cost=990924.99..1005555.66 rows=5852267 width=12)
SELECT id FROM shiftplan_notifications WHERE shift_id = ?;
(cost=0.00..60555.66 rows=4 width=4)
CREATE INDEX shiftplan_notifications__shift_id ON shiftplan_notifications (shift_id);
SELECT id FROM shiftplan_notifications WHERE shift_id = ?;
(cost=0.43..10.82 rows=4 width=4)
(cost=0.00..60555.66 rows=4 width=4)
SELECT id FROM shiftplan_notifications WHERE employment_ids @> ARRAY[?];
(cost=0.00..60555.66 rows=159 width=4)
CREATE INDEX shiftplan_notifications__employment_ids ON shiftplan_notifications (employment_ids);
SELECT id FROM shiftplan_notifications WHERE employment_ids @> ARRAY[?];
(cost=0.00..60555.66 rows=159 width=4)
(cost=0.00..60555.66 rows=159 width=4)
CREATE INDEX shiftplan_notifications__employment_ids ON shiftplan_notifications USING GIN (employment_ids);
SELECT id FROM shiftplan_notifications WHERE shift_id = ?;
(cost=17.23..623.83 rows=159 width=4)
(cost=0.00..60555.66 rows=159 width=4)