Fix two bugs.
#1010789 : pg_reorg 1.1.0 and "unexpected toast relations" #1010790 : reorg.get_index_keys() does not handle composite indexes
This commit is contained in:
@ -39,6 +39,13 @@ 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
|
||||
--
|
||||
@ -59,6 +66,9 @@ 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;
|
||||
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
|
||||
--
|
||||
@ -69,6 +79,13 @@ SELECT * FROM tbl_with_dropped_column;
|
||||
c1 | 1 | c2 |
|
||||
(2 rows)
|
||||
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
i | j
|
||||
---+----
|
||||
1 | 10
|
||||
2 | 20
|
||||
(2 rows)
|
||||
|
||||
--
|
||||
-- do reorg
|
||||
--
|
||||
@ -131,6 +148,15 @@ Indexes:
|
||||
"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(col2, 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
||||
col1 | to_char | ,")
|
||||
------+---------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@ -169,6 +195,33 @@ SELECT * FROM tbl_with_dropped_column;
|
||||
c1 | 2 | c2 |
|
||||
(2 rows)
|
||||
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
i | j
|
||||
---+----
|
||||
1 | 10
|
||||
2 | 20
|
||||
(2 rows)
|
||||
|
||||
--
|
||||
-- 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)
|
||||
|
||||
--
|
||||
-- clean up
|
||||
--
|
||||
|
@ -8,7 +8,7 @@
|
||||
* @brief Client Modules
|
||||
*/
|
||||
|
||||
const char *PROGRAM_VERSION = "1.1.0";
|
||||
const char *PROGRAM_VERSION = "1.1.1";
|
||||
const char *PROGRAM_URL = "http://reorg.projects.postgresql.org/";
|
||||
const char *PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org";
|
||||
|
||||
|
@ -273,6 +273,7 @@ parse_int64(const char *value, int64 *result)
|
||||
#elif defined(HAVE_LONG_INT_64)
|
||||
val = strtol(value, &endptr, 0);
|
||||
#elif defined(HAVE_LONG_LONG_INT_64)
|
||||
val = strtoll(value, &endptr, 0);
|
||||
#else
|
||||
val = strtol(value, &endptr, 0);
|
||||
#endif
|
||||
|
@ -47,6 +47,14 @@ 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
|
||||
--
|
||||
@ -72,11 +80,16 @@ 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;
|
||||
|
||||
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;
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
|
||||
--
|
||||
-- do reorg
|
||||
@ -95,12 +108,28 @@ SELECT * FROM tbl_with_dropped_column;
|
||||
\d tbl_only_ckey
|
||||
\d tbl_only_pkey
|
||||
\d tbl_with_dropped_column
|
||||
\d tbl_with_dropped_toast
|
||||
|
||||
SELECT col1, to_char(col2, 'YYYY-MM-DD HH24:MI:SS'), ","")" FROM tbl_cluster;
|
||||
SELECT * FROM tbl_only_ckey ORDER BY 1;
|
||||
SELECT * FROM tbl_only_pkey ORDER BY 1;
|
||||
SELECT * FROM tbl_gistkey ORDER BY 1;
|
||||
SELECT * FROM tbl_with_dropped_column;
|
||||
SELECT * FROM tbl_with_dropped_toast;
|
||||
|
||||
--
|
||||
-- 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');
|
||||
|
||||
SELECT oid, relname
|
||||
FROM pg_class
|
||||
WHERE relkind = 'r'
|
||||
AND reltoastrelid <> 0
|
||||
AND reltoastrelid NOT IN (SELECT oid FROM pg_class WHERE relkind = 't');
|
||||
|
||||
--
|
||||
-- clean up
|
||||
|
Reference in New Issue
Block a user