-- 1. reloptions override reverts to parent
CREATE TABLE p1 (id int NOT NULL, val int NOT NULL) PARTITION BY RANGE (id);
CREATE TABLE c1 PARTITION OF p1 FOR VALUES FROM (0) TO (100);
CREATE INDEX p1_idx ON p1 (id, val) WITH (fillfactor = 70);
ALTER INDEX c1_id_val_idx SET (fillfactor = 30);
SELECT 'BEFORE', ic.relname, ic.reloptions FROM pg_class ic
  JOIN pg_index i ON ic.oid = i.indexrelid
  JOIN pg_class tc ON i.indrelid = tc.oid WHERE tc.relname = 'c1';
ALTER TABLE p1 ALTER COLUMN val TYPE bigint;
SELECT 'AFTER', ic.relname, ic.reloptions FROM pg_class ic
  JOIN pg_index i ON ic.oid = i.indexrelid
  JOIN pg_class tc ON i.indrelid = tc.oid WHERE tc.relname = 'c1';
DROP TABLE p1;

-- 2. COMMENT ON INDEX lost
CREATE TABLE p2 (id int NOT NULL, val int NOT NULL) PARTITION BY RANGE (id);
CREATE TABLE c2 PARTITION OF p2 FOR VALUES FROM (0) TO (100);
CREATE INDEX p2_idx ON p2 (id, val);
COMMENT ON INDEX c2_id_val_idx IS 'important index';
SELECT 'BEFORE', ic.relname, d.description FROM pg_class ic
  JOIN pg_index i ON ic.oid = i.indexrelid
  JOIN pg_class tc ON i.indrelid = tc.oid
  LEFT JOIN pg_description d ON d.objoid = ic.oid AND d.classoid = 'pg_class'::regclass
  WHERE tc.relname = 'c2';
ALTER TABLE p2 ALTER COLUMN val TYPE bigint;
SELECT 'AFTER', ic.relname, d.description FROM pg_class ic
  JOIN pg_index i ON ic.oid = i.indexrelid
  JOIN pg_class tc ON i.indrelid = tc.oid
  LEFT JOIN pg_description d ON d.objoid = ic.oid AND d.classoid = 'pg_class'::regclass
  WHERE tc.relname = 'c2';
DROP TABLE p2;

-- 3. Statistics target lost (expression index)
CREATE TABLE p3 (id int NOT NULL, val int NOT NULL) PARTITION BY RANGE (id);
CREATE TABLE c3 PARTITION OF p3 FOR VALUES FROM (0) TO (100);
CREATE INDEX p3_idx ON p3 ((id + val));
ALTER INDEX c3_id_val_idx ALTER COLUMN 1 SET STATISTICS 5000;
SELECT 'BEFORE', ic.relname, a.attstattarget FROM pg_class ic
  JOIN pg_index i ON ic.oid = i.indexrelid
  JOIN pg_class tc ON i.indrelid = tc.oid
  JOIN pg_attribute a ON a.attrelid = ic.oid AND a.attnum = 1
  WHERE tc.relname = 'c3';
ALTER TABLE p3 ALTER COLUMN val TYPE bigint;
SELECT 'AFTER', ic.relname, a.attstattarget FROM pg_class ic
  JOIN pg_index i ON ic.oid = i.indexrelid
  JOIN pg_class tc ON i.indrelid = tc.oid
  JOIN pg_attribute a ON a.attrelid = ic.oid AND a.attnum = 1
  WHERE tc.relname = 'c3';
DROP TABLE p3;