there are views or functions depending on columns after dropped ones. The issue was reported by depesz, and original patch by Denish Patel. Improved documentation how to build binaries from source. COPYRIGHT updated.
285 lines
14 KiB
Plaintext
Executable File
285 lines
14 KiB
Plaintext
Executable File
SET client_min_messages = warning;
|
|
--
|
|
-- create table.
|
|
--
|
|
CREATE TABLE tbl_cluster (
|
|
col1 int,
|
|
"time" timestamp,
|
|
","")" text,
|
|
PRIMARY KEY (","")", col1) WITH (fillfactor = 75)
|
|
) WITH (fillfactor = 70);
|
|
CREATE INDEX ","") cluster" ON tbl_cluster ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor = 75);
|
|
ALTER TABLE tbl_cluster CLUSTER ON ","") cluster";
|
|
CREATE TABLE tbl_only_pkey (
|
|
col1 int PRIMARY KEY,
|
|
","")" text
|
|
);
|
|
CREATE TABLE tbl_only_ckey (
|
|
col1 int,
|
|
col2 timestamp,
|
|
","")" text
|
|
) WITH (fillfactor = 70);
|
|
CREATE INDEX cidx_only_ckey ON tbl_only_ckey (col2, ","")");
|
|
ALTER TABLE tbl_only_ckey CLUSTER ON cidx_only_ckey;
|
|
CREATE TABLE tbl_gistkey (
|
|
id integer PRIMARY KEY,
|
|
c circle
|
|
);
|
|
CREATE INDEX cidx_circle ON tbl_gistkey USING gist (c);
|
|
ALTER TABLE tbl_gistkey CLUSTER ON cidx_circle;
|
|
CREATE TABLE tbl_with_dropped_column (
|
|
d1 text,
|
|
c1 text,
|
|
id integer PRIMARY KEY,
|
|
d2 text,
|
|
c2 text,
|
|
d3 text
|
|
);
|
|
ALTER INDEX tbl_with_dropped_column_pkey SET (fillfactor = 75);
|
|
ALTER TABLE tbl_with_dropped_column CLUSTER ON tbl_with_dropped_column_pkey;
|
|
CREATE INDEX idx_c1c2 ON tbl_with_dropped_column (c1, c2) WITH (fillfactor = 75);
|
|
CREATE INDEX idx_c2c1 ON tbl_with_dropped_column (c2, c1);
|
|
CREATE TABLE tbl_with_dropped_toast (
|
|
i integer,
|
|
j integer,
|
|
t text,
|
|
PRIMARY KEY (i, j)
|
|
);
|
|
ALTER TABLE tbl_with_dropped_toast CLUSTER ON tbl_with_dropped_toast_pkey;
|
|
--
|
|
-- insert data
|
|
--
|
|
INSERT INTO tbl_cluster VALUES(1, '2008-12-31 10:00:00', 'admin');
|
|
INSERT INTO tbl_cluster VALUES(2, '2008-01-01 00:00:00', 'king');
|
|
INSERT INTO tbl_cluster VALUES(3, '2008-03-04 12:00:00', 'joker');
|
|
INSERT INTO tbl_cluster VALUES(4, '2008-03-05 15:00:00', 'queen');
|
|
INSERT INTO tbl_cluster VALUES(5, '2008-01-01 00:30:00', sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
|
INSERT INTO tbl_only_pkey VALUES(1, 'abc');
|
|
INSERT INTO tbl_only_pkey VALUES(2, 'def');
|
|
INSERT INTO tbl_only_ckey VALUES(1, '2008-01-01 00:00:00', 'abc');
|
|
INSERT INTO tbl_only_ckey VALUES(2, '2008-02-01 00:00:00', 'def');
|
|
INSERT INTO tbl_gistkey VALUES(1, '<(1,2),3>');
|
|
INSERT INTO tbl_gistkey VALUES(2, '<(4,5),6>');
|
|
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 2, 'd2', 'c2', 'd3');
|
|
INSERT INTO tbl_with_dropped_column VALUES('d1', 'c1', 1, 'd2', 'c2', 'd3');
|
|
ALTER TABLE tbl_with_dropped_column DROP COLUMN d1;
|
|
ALTER TABLE tbl_with_dropped_column DROP COLUMN d2;
|
|
ALTER TABLE tbl_with_dropped_column DROP COLUMN d3;
|
|
ALTER TABLE tbl_with_dropped_column ADD COLUMN c3 text;
|
|
CREATE VIEW view_for_dropped_column AS
|
|
SELECT * FROM tbl_with_dropped_column;
|
|
INSERT INTO tbl_with_dropped_toast VALUES(1, 10, 'abc');
|
|
INSERT INTO tbl_with_dropped_toast VALUES(2, 20, sqrt(2::numeric(1000,999))::text || sqrt(3::numeric(1000,999))::text);
|
|
ALTER TABLE tbl_with_dropped_toast DROP COLUMN t;
|
|
--
|
|
-- before
|
|
--
|
|
SELECT * FROM tbl_with_dropped_column;
|
|
c1 | id | c2 | c3
|
|
----+----+----+----
|
|
c1 | 2 | c2 |
|
|
c1 | 1 | c2 |
|
|
(2 rows)
|
|
|
|
SELECT * FROM view_for_dropped_column;
|
|
c1 | id | c2 | c3
|
|
----+----+----+----
|
|
c1 | 2 | c2 |
|
|
c1 | 1 | c2 |
|
|
(2 rows)
|
|
|
|
SELECT * FROM tbl_with_dropped_toast;
|
|
i | j
|
|
---+----
|
|
1 | 10
|
|
2 | 20
|
|
(2 rows)
|
|
|
|
--
|
|
-- do reorg
|
|
--
|
|
\! pg_reorg --dbname=contrib_regression --no-order
|
|
\! pg_reorg --dbname=contrib_regression
|
|
\! pg_reorg --dbname=contrib_regression --table=tbl_cluster
|
|
--
|
|
-- after
|
|
--
|
|
\d tbl_cluster
|
|
Table "public.tbl_cluster"
|
|
Column | Type | Modifiers
|
|
--------+-----------------------------+-----------
|
|
col1 | integer | not null
|
|
time | timestamp without time zone |
|
|
,") | text | not null
|
|
Indexes:
|
|
"tbl_cluster_pkey" PRIMARY KEY, btree (","")", col1) WITH (fillfactor=75)
|
|
",") cluster" btree ("time", length(","")"), ","")" text_pattern_ops) WITH (fillfactor=75) CLUSTER
|
|
|
|
\d tbl_gistkey
|
|
Table "public.tbl_gistkey"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
id | integer | not null
|
|
c | circle |
|
|
Indexes:
|
|
"tbl_gistkey_pkey" PRIMARY KEY, btree (id)
|
|
"cidx_circle" gist (c) CLUSTER
|
|
|
|
\d tbl_only_ckey
|
|
Table "public.tbl_only_ckey"
|
|
Column | Type | Modifiers
|
|
--------+-----------------------------+-----------
|
|
col1 | integer |
|
|
col2 | timestamp without time zone |
|
|
,") | text |
|
|
Indexes:
|
|
"cidx_only_ckey" btree (col2, ","")") CLUSTER
|
|
|
|
\d tbl_only_pkey
|
|
Table "public.tbl_only_pkey"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
col1 | integer | not null
|
|
,") | text |
|
|
Indexes:
|
|
"tbl_only_pkey_pkey" PRIMARY KEY, btree (col1)
|
|
|
|
\d tbl_with_dropped_column
|
|
Table "public.tbl_with_dropped_column"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
c1 | text |
|
|
id | integer | not null
|
|
c2 | text |
|
|
c3 | text |
|
|
Indexes:
|
|
"tbl_with_dropped_column_pkey" PRIMARY KEY, btree (id) WITH (fillfactor=75) CLUSTER
|
|
"idx_c1c2" btree (c1, c2) WITH (fillfactor=75)
|
|
"idx_c2c1" btree (c2, c1)
|
|
|
|
\d tbl_with_dropped_toast
|
|
Table "public.tbl_with_dropped_toast"
|
|
Column | Type | Modifiers
|
|
--------+---------+-----------
|
|
i | integer | not null
|
|
j | integer | not null
|
|
Indexes:
|
|
"tbl_with_dropped_toast_pkey" PRIMARY KEY, btree (i, j) CLUSTER
|
|
|
|
SELECT col1, to_char("time", 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
|
col1 | to_char | ,")
|
|
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
2 | 2008-01-01 00:00:00 | king
|
|
5 | 2008-01-01 00:30:00 | 1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727350138462309122970249248360558507372126441214970999358314132226659275055927557999505011527820605714701095599716059702745345968620147285174186408891986095523292304843087143214508397626036279952514079896872533965463318088296406206152583523950547457502877599617298355752203375318570113543746034084988471603868999706990048150305440277903164542478230684929369186215805784631115966687130130156185689872372352885092648612494977154218334204285686060146824720771435854874155657069677653720226485447015858801620758474922657226002085584466521458398893944370926591800311388246468157082630100594858704003186480342194897278290641045072636881313739855256117322040245091227700226941127573627280495738108967504018369868368450725799364729060762996941380475654823728997180326802474420629269124859052181004459842150591120249441341728531478105803603371077309182869314710171111683916581726889419758716582152128229518488471.732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
|
|
3 | 2008-03-04 12:00:00 | joker
|
|
4 | 2008-03-05 15:00:00 | queen
|
|
1 | 2008-12-31 10:00:00 | admin
|
|
(5 rows)
|
|
|
|
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
|
col1 | col2 | ,")
|
|
------+--------------------------+-----
|
|
1 | Tue Jan 01 00:00:00 2008 | abc
|
|
2 | Fri Feb 01 00:00:00 2008 | def
|
|
(2 rows)
|
|
|
|
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
|
col1 | ,")
|
|
------+-----
|
|
1 | abc
|
|
2 | def
|
|
(2 rows)
|
|
|
|
SELECT * FROM tbl_gistkey ORDER BY 1;
|
|
id | c
|
|
----+-----------
|
|
1 | <(1,2),3>
|
|
2 | <(4,5),6>
|
|
(2 rows)
|
|
|
|
SET enable_seqscan = on;
|
|
SET enable_indexscan = off;
|
|
SELECT * FROM tbl_with_dropped_column;
|
|
c1 | id | c2 | c3
|
|
----+----+----+----
|
|
c1 | 1 | c2 |
|
|
c1 | 2 | c2 |
|
|
(2 rows)
|
|
|
|
SELECT * FROM view_for_dropped_column;
|
|
c1 | id | c2 | c3
|
|
----+----+----+----
|
|
c1 | 1 | c2 |
|
|
c1 | 2 | c2 |
|
|
(2 rows)
|
|
|
|
SELECT * FROM tbl_with_dropped_toast;
|
|
i | j
|
|
---+----
|
|
1 | 10
|
|
2 | 20
|
|
(2 rows)
|
|
|
|
SET enable_seqscan = off;
|
|
SET enable_indexscan = on;
|
|
SELECT * FROM tbl_with_dropped_column;
|
|
c1 | id | c2 | c3
|
|
----+----+----+----
|
|
c1 | 1 | c2 |
|
|
c1 | 2 | c2 |
|
|
(2 rows)
|
|
|
|
SELECT * FROM view_for_dropped_column;
|
|
c1 | id | c2 | c3
|
|
----+----+----+----
|
|
c1 | 1 | c2 |
|
|
c1 | 2 | c2 |
|
|
(2 rows)
|
|
|
|
SELECT * FROM tbl_with_dropped_toast;
|
|
i | j
|
|
---+----
|
|
1 | 10
|
|
2 | 20
|
|
(2 rows)
|
|
|
|
RESET enable_seqscan;
|
|
RESET enable_indexscan;
|
|
--
|
|
-- check broken links or orphan toast relations
|
|
--
|
|
SELECT oid, relname
|
|
FROM pg_class
|
|
WHERE relkind = 't'
|
|
AND oid NOT IN (SELECT reltoastrelid FROM pg_class WHERE relkind = 'r');
|
|
oid | relname
|
|
-----+---------
|
|
(0 rows)
|
|
|
|
SELECT oid, relname
|
|
FROM pg_class
|
|
WHERE relkind = 'r'
|
|
AND reltoastrelid <> 0
|
|
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
|
oid | relname
|
|
-----+---------
|
|
(0 rows)
|
|
|
|
--
|
|
-- NOT NULL UNIQUE
|
|
--
|
|
CREATE TABLE tbl_nn (col1 int NOT NULL, col2 int NOT NULL);
|
|
CREATE TABLE tbl_uk (col1 int NOT NULL, col2 int , UNIQUE(col1, col2));
|
|
CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2));
|
|
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
|
|
\! pg_reorg --dbname=contrib_regression --no-order --table=tbl_nn
|
|
ERROR: relation "tbl_nn" must have a primary key or not-null unique keys
|
|
-- => ERROR
|
|
\! pg_reorg --dbname=contrib_regression --no-order --table=tbl_uk
|
|
ERROR: relation "tbl_uk" must have a primary key or not-null unique keys
|
|
-- => ERROR
|
|
\! pg_reorg --dbname=contrib_regression --no-order --table=tbl_nn_uk
|
|
-- => OK
|
|
\! pg_reorg --dbname=contrib_regression --no-order --table=tbl_pk_uk
|
|
-- => OK
|