Imply --no-order for non-clustered tables

--no-order can still be specified to VACUUM FULL a clustered tables
(not so useful I guess...)

Fixes issue #6.
This commit is contained in:
Daniele Varrazzo 2013-04-17 01:42:22 +01:00
parent 1d62d8d0c5
commit 8efbd9e1c6
4 changed files with 41 additions and 38 deletions

View File

@ -114,7 +114,7 @@ SELECT * FROM tbl_with_dropped_toast;
-- --
-- do repack -- do repack
-- --
\! pg_repack --dbname=contrib_regression --no-order \! pg_repack --dbname=contrib_regression --table=tbl_badindex
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n) WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
\! pg_repack --dbname=contrib_regression \! pg_repack --dbname=contrib_regression
\! pg_repack --dbname=contrib_regression --table=tbl_cluster \! pg_repack --dbname=contrib_regression --table=tbl_cluster
@ -301,17 +301,17 @@ 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)); CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn \! pg_repack --dbname=contrib_regression --table=tbl_nn
WARNING: relation "tbl_nn" must have a primary key or not-null unique keys WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
-- => WARNING -- => WARNING
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_uk \! pg_repack --dbname=contrib_regression --table=tbl_uk
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
-- => WARNING -- => WARNING
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_uk \! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
-- => OK -- => OK
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk \! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
-- => OK -- => OK
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk \! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
-- => WARNING -- => WARNING
-- --
@ -325,7 +325,7 @@ SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::
col1, col2 DESC col1, col2 DESC
(1 row) (1 row)
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_1 \! pg_repack --dbname=contrib_regression --table=issue3_1
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
@ -334,7 +334,7 @@ SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::
col1 DESC, col2 USING ~<~ col1 DESC, col2 USING ~<~
(1 row) (1 row)
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_2 \! pg_repack --dbname=contrib_regression --table=issue3_2
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
@ -343,7 +343,7 @@ SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::
col1 DESC, col2 DESC col1 DESC, col2 DESC
(1 row) (1 row)
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_3 \! pg_repack --dbname=contrib_regression --table=issue3_3
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
@ -352,7 +352,7 @@ SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::
col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST
(1 row) (1 row)
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_4 \! pg_repack --dbname=contrib_regression --table=issue3_4
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
@ -361,4 +361,4 @@ SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::
col1 DESC, col2 COLLATE "POSIX" DESC col1 DESC, col2 COLLATE "POSIX" DESC
(1 row) (1 row)
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_5 \! pg_repack --dbname=contrib_regression --table=issue3_5

View File

@ -521,27 +521,28 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
resetStringInfo(&sql); resetStringInfo(&sql);
if (!orderby) if (!orderby)
{ {
/* CLUSTER mode */ if (ckey != NULL)
if (ckey == NULL)
{ {
ereport(WARNING, /* CLUSTER mode */
(errcode(E_PG_COMMAND), appendStringInfo(&sql, "%s ORDER BY %s", create_table, ckey);
errmsg("relation \"%s\" has no cluster key", table.target_name))); table.create_table = sql.data;
continue; }
else
{
/* VACUUM FULL mode (non-clustered tables) */
table.create_table = create_table;
} }
appendStringInfo(&sql, "%s ORDER BY %s", create_table, ckey);
table.create_table = sql.data;
} }
else if (!orderby[0]) else if (!orderby[0])
{ {
/* VACUUM FULL mode */ /* VACUUM FULL mode (for clustered tables too) */
table.create_table = create_table; table.create_table = create_table;
} }
else else
{ {
/* User specified ORDER BY */ /* User specified ORDER BY */
appendStringInfo(&sql, "%s ORDER BY %s", create_table, orderby); appendStringInfo(&sql, "%s ORDER BY %s", create_table, orderby);
table.create_table = sql.data; table.create_table = sql.data;
} }
table.sql_peek = getstr(res, i, c++); table.sql_peek = getstr(res, i, c++);

View File

@ -120,7 +120,7 @@ SELECT * FROM tbl_with_dropped_toast;
-- do repack -- do repack
-- --
\! pg_repack --dbname=contrib_regression --no-order \! pg_repack --dbname=contrib_regression --table=tbl_badindex
\! pg_repack --dbname=contrib_regression \! pg_repack --dbname=contrib_regression
\! pg_repack --dbname=contrib_regression --table=tbl_cluster \! pg_repack --dbname=contrib_regression --table=tbl_cluster
@ -177,15 +177,15 @@ 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)); CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL); CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10; CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn \! pg_repack --dbname=contrib_regression --table=tbl_nn
-- => WARNING -- => WARNING
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_uk \! pg_repack --dbname=contrib_regression --table=tbl_uk
-- => WARNING -- => WARNING
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_uk \! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
-- => OK -- => OK
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk \! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
-- => OK -- => OK
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk \! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
-- => WARNING -- => WARNING
-- --
@ -194,24 +194,24 @@ CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC); CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC);
SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid); SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid);
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_1 \! pg_repack --dbname=contrib_regression --table=issue3_1
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops); CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid); SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_2 \! pg_repack --dbname=contrib_regression --table=issue3_2
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC); CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid); SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_3 \! pg_repack --dbname=contrib_regression --table=issue3_3
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST); CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid); SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_4 \! pg_repack --dbname=contrib_regression --table=issue3_4
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL); CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC); CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid); SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_5 \! pg_repack --dbname=contrib_regression --table=issue3_5

View File

@ -253,13 +253,13 @@ Environment
Examples Examples
-------- --------
Execute the following command to perform an online CLUSTER of all tables in Perform an online CLUSTER of all the clustered tables in the database
database ``test``:: ``test``, and perform an online VACUUM FULL of all the non-clustered tables::
$ pg_repack test $ pg_repack test
Execute the following command to perform an online VACUUM FULL of table Perform an online VACUUM FULL on the table ``foo`` in the database ``test``
``foo`` in database ``test``:: (an eventual cluster index is ignored)::
$ pg_repack --no-order --table foo -d test $ pg_repack --no-order --table foo -d test
@ -319,7 +319,7 @@ ERROR: relation "table" has no cluster key
Define a CLUSTER KEY on the table, via ALTER TABLE CLUSTER ON, or use Define a CLUSTER KEY on the table, via ALTER TABLE CLUSTER ON, or use
one of the --no-order or --order-by modes. one of the --no-order or --order-by modes.
pg_repack: query failed: ERROR: column "col" does not exist ERROR: query failed: ERROR: column "col" does not exist
The target table doesn't have columns specified by ``--order-by`` option. The target table doesn't have columns specified by ``--order-by`` option.
Specify existing columns. Specify existing columns.
@ -404,6 +404,8 @@ Releases
* pg_repack 1.2 * pg_repack 1.2
* Added --jobs option for parallel operation. * Added --jobs option for parallel operation.
* Don't require --no-order to perform a VACUUM FULL on non-clustered tables
(pg_repack issue #6).
* More helpful error messages. * More helpful error messages.
* Bugfix: correctly handle key indexes with options such as DESC, NULL * Bugfix: correctly handle key indexes with options such as DESC, NULL
FIRST/LAST, COLLATE (pg_repack issue #3). FIRST/LAST, COLLATE (pg_repack issue #3).