/* Setup */
CREATE TABLE testtable (id bigint PRIMARY KEY, payload text not null);
CREATE INDEX ON testtable (payload) WHERE (testtable IS NOT NULL);
INSERT INTO testtable (id, payload) SELECT i, i::text FROM generate_series(1, 1000) i;
VACUUM (FREEZE, ANALYZE) testtable;

/* Corrupt the index */
ALTER TABLE testtable ADD COLUMN inull int NULL;

/* Show index corruption; index scan used */
SET enable_indexonlyscan = on;
SET enable_indexscan = on;
EXPLAIN SELECT count(payload) FROM testtable WHERE testtable IS NOT NULL;
SELECT count(payload) FROM testtable WHERE testtable IS NOT NULL;
-- count = 1000

/* Show index corruption; seq scan used */
SET enable_indexonlyscan = off;
SET enable_indexscan = off;
EXPLAIN SELECT count(payload) FROM testtable WHERE testtable IS NOT NULL;
SELECT count(payload) FROM testtable WHERE testtable IS NOT NULL;
-- count = 0
