Skip to content

Instantly share code, notes, and snippets.

@anarazel
Created October 18, 2012 10:49
Show Gist options
  • Save anarazel/3910956 to your computer and use it in GitHub Desktop.
Save anarazel/3910956 to your computer and use it in GitHub Desktop.
Session 1:
DROP TABLE IF EXISTS test_drop_concurrently ;
CREATE TABLE test_drop_concurrently(id serial primary key, data int);
INSERT INTO test_drop_concurrently(data) SELECT * FROM generate_series(1,
100);
CREATE INDEX test_drop_concurrently_data ON test_drop_concurrently(data);
SET enable_seqscan = false;
PREPARE getrow_idx AS SELECT * FROM test_drop_concurrently WHERE data = 34;
PREPARE getrow_seq AS SELECT * FROM test_drop_concurrently WHERE data::text = 34::text;
BEGIN;
EXPLAIN (ANALYZE, COSTS off) EXECUTE getrow_idx;
EXPLAIN (ANALYZE, COSTS off) EXECUTE getrow_seq;
(1 row)
Session 2:
BEGIN;
SELECT * FROM test_drop_concurrently WHERE data = 34;
Session 3:
DROP INDEX CONCURRENTLY test_drop_concurrently_data;
(in-progress)
Session 2:
INSERT INTO test_drop_concurrently(data) SELECT * FROM generate_series(1,
100);
COMMIT;
Session 1:
EXPLAIN (ANALYZE, COSTS off) EXECUTE getrow_idx;
EXPLAIN (ANALYZE, COSTS off) EXECUTE getrow_seq;
(2 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment