Skip to content

Commit 8efbd9e

Browse files
committed
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.
1 parent 1d62d8d commit 8efbd9e

File tree

4 files changed

+41
-38
lines changed

4 files changed

+41
-38
lines changed

bin/expected/repack.out

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ SELECT * FROM tbl_with_dropped_toast;
114114
--
115115
-- do repack
116116
--
117-
\! pg_repack --dbname=contrib_regression --no-order
117+
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
118118
WARNING: skipping invalid index: CREATE UNIQUE INDEX idx_badindex_n ON tbl_badindex USING btree (n)
119119
\! pg_repack --dbname=contrib_regression
120120
\! 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)
301301
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
302302
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
303303
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
304-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn
304+
\! pg_repack --dbname=contrib_regression --table=tbl_nn
305305
WARNING: relation "tbl_nn" must have a primary key or not-null unique keys
306306
-- => WARNING
307-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_uk
307+
\! pg_repack --dbname=contrib_regression --table=tbl_uk
308308
WARNING: relation "tbl_uk" must have a primary key or not-null unique keys
309309
-- => WARNING
310-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_uk
310+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
311311
-- => OK
312-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk
312+
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
313313
-- => OK
314-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk
314+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
315315
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
316316
-- => WARNING
317317
--
@@ -325,7 +325,7 @@ SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::
325325
col1, col2 DESC
326326
(1 row)
327327

328-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_1
328+
\! pg_repack --dbname=contrib_regression --table=issue3_1
329329
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
330330
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
331331
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::
334334
col1 DESC, col2 USING ~<~
335335
(1 row)
336336

337-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_2
337+
\! pg_repack --dbname=contrib_regression --table=issue3_2
338338
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
339339
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
340340
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::
343343
col1 DESC, col2 DESC
344344
(1 row)
345345

346-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_3
346+
\! pg_repack --dbname=contrib_regression --table=issue3_3
347347
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
348348
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
349349
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::
352352
col1 NULLS FIRST, col2 DESC USING ~<~ NULLS LAST
353353
(1 row)
354354

355-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_4
355+
\! pg_repack --dbname=contrib_regression --table=issue3_4
356356
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
357357
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
358358
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::
361361
col1 DESC, col2 COLLATE "POSIX" DESC
362362
(1 row)
363363

364-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_5
364+
\! pg_repack --dbname=contrib_regression --table=issue3_5

bin/pg_repack.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -521,27 +521,28 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
521521
resetStringInfo(&sql);
522522
if (!orderby)
523523
{
524-
/* CLUSTER mode */
525-
if (ckey == NULL)
524+
if (ckey != NULL)
526525
{
527-
ereport(WARNING,
528-
(errcode(E_PG_COMMAND),
529-
errmsg("relation \"%s\" has no cluster key", table.target_name)));
530-
continue;
526+
/* CLUSTER mode */
527+
appendStringInfo(&sql, "%s ORDER BY %s", create_table, ckey);
528+
table.create_table = sql.data;
529+
}
530+
else
531+
{
532+
/* VACUUM FULL mode (non-clustered tables) */
533+
table.create_table = create_table;
531534
}
532-
appendStringInfo(&sql, "%s ORDER BY %s", create_table, ckey);
533-
table.create_table = sql.data;
534535
}
535536
else if (!orderby[0])
536537
{
537-
/* VACUUM FULL mode */
538-
table.create_table = create_table;
538+
/* VACUUM FULL mode (for clustered tables too) */
539+
table.create_table = create_table;
539540
}
540541
else
541542
{
542543
/* User specified ORDER BY */
543544
appendStringInfo(&sql, "%s ORDER BY %s", create_table, orderby);
544-
table.create_table = sql.data;
545+
table.create_table = sql.data;
545546
}
546547

547548
table.sql_peek = getstr(res, i, c++);

bin/sql/repack.sql

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ SELECT * FROM tbl_with_dropped_toast;
120120
-- do repack
121121
--
122122

123-
\! pg_repack --dbname=contrib_regression --no-order
123+
\! pg_repack --dbname=contrib_regression --table=tbl_badindex
124124
\! pg_repack --dbname=contrib_regression
125125
\! pg_repack --dbname=contrib_regression --table=tbl_cluster
126126

@@ -177,15 +177,15 @@ CREATE TABLE tbl_nn_uk (col1 int NOT NULL, col2 int NOT NULL, UNIQUE(col1, col2)
177177
CREATE TABLE tbl_pk_uk (col1 int NOT NULL, col2 int NOT NULL, PRIMARY KEY(col1, col2), UNIQUE(col2, col1));
178178
CREATE TABLE tbl_nn_puk (col1 int NOT NULL, col2 int NOT NULL);
179179
CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
180-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn
180+
\! pg_repack --dbname=contrib_regression --table=tbl_nn
181181
-- => WARNING
182-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_uk
182+
\! pg_repack --dbname=contrib_regression --table=tbl_uk
183183
-- => WARNING
184-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_uk
184+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_uk
185185
-- => OK
186-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_pk_uk
186+
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk
187187
-- => OK
188-
\! pg_repack --dbname=contrib_regression --no-order --table=tbl_nn_puk
188+
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
189189
-- => WARNING
190190

191191
--
@@ -194,24 +194,24 @@ CREATE UNIQUE INDEX tbl_nn_puk_pcol1_idx ON tbl_nn_puk(col1) WHERE col1 < 10;
194194
CREATE TABLE issue3_1 (col1 int NOT NULL, col2 text NOT NULL);
195195
CREATE UNIQUE INDEX issue3_1_idx ON issue3_1 (col1, col2 DESC);
196196
SELECT repack.get_order_by('issue3_1_idx'::regclass::oid, 'issue3_1'::regclass::oid);
197-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_1
197+
\! pg_repack --dbname=contrib_regression --table=issue3_1
198198

199199
CREATE TABLE issue3_2 (col1 int NOT NULL, col2 text NOT NULL);
200200
CREATE UNIQUE INDEX issue3_2_idx ON issue3_2 (col1 DESC, col2 text_pattern_ops);
201201
SELECT repack.get_order_by('issue3_2_idx'::regclass::oid, 'issue3_2'::regclass::oid);
202-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_2
202+
\! pg_repack --dbname=contrib_regression --table=issue3_2
203203

204204
CREATE TABLE issue3_3 (col1 int NOT NULL, col2 text NOT NULL);
205205
CREATE UNIQUE INDEX issue3_3_idx ON issue3_3 (col1 DESC, col2 DESC);
206206
SELECT repack.get_order_by('issue3_3_idx'::regclass::oid, 'issue3_3'::regclass::oid);
207-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_3
207+
\! pg_repack --dbname=contrib_regression --table=issue3_3
208208

209209
CREATE TABLE issue3_4 (col1 int NOT NULL, col2 text NOT NULL);
210210
CREATE UNIQUE INDEX issue3_4_idx ON issue3_4 (col1 NULLS FIRST, col2 text_pattern_ops DESC NULLS LAST);
211211
SELECT repack.get_order_by('issue3_4_idx'::regclass::oid, 'issue3_4'::regclass::oid);
212-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_4
212+
\! pg_repack --dbname=contrib_regression --table=issue3_4
213213

214214
CREATE TABLE issue3_5 (col1 int NOT NULL, col2 text NOT NULL);
215215
CREATE UNIQUE INDEX issue3_5_idx ON issue3_5 (col1 DESC NULLS FIRST, col2 COLLATE "POSIX" DESC);
216216
SELECT repack.get_order_by('issue3_5_idx'::regclass::oid, 'issue3_5'::regclass::oid);
217-
\! pg_repack --dbname=contrib_regression --no-order --table=issue3_5
217+
\! pg_repack --dbname=contrib_regression --table=issue3_5

doc/pg_repack.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ Environment
253253
Examples
254254
--------
255255

256-
Execute the following command to perform an online CLUSTER of all tables in
257-
database ``test``::
256+
Perform an online CLUSTER of all the clustered tables in the database
257+
``test``, and perform an online VACUUM FULL of all the non-clustered tables::
258258

259259
$ pg_repack test
260260

261-
Execute the following command to perform an online VACUUM FULL of table
262-
``foo`` in database ``test``::
261+
Perform an online VACUUM FULL on the table ``foo`` in the database ``test``
262+
(an eventual cluster index is ignored)::
263263

264264
$ pg_repack --no-order --table foo -d test
265265

@@ -319,7 +319,7 @@ ERROR: relation "table" has no cluster key
319319
Define a CLUSTER KEY on the table, via ALTER TABLE CLUSTER ON, or use
320320
one of the --no-order or --order-by modes.
321321

322-
pg_repack: query failed: ERROR: column "col" does not exist
322+
ERROR: query failed: ERROR: column "col" does not exist
323323
The target table doesn't have columns specified by ``--order-by`` option.
324324

325325
Specify existing columns.
@@ -404,6 +404,8 @@ Releases
404404
* pg_repack 1.2
405405

406406
* Added --jobs option for parallel operation.
407+
* Don't require --no-order to perform a VACUUM FULL on non-clustered tables
408+
(pg_repack issue #6).
407409
* More helpful error messages.
408410
* Bugfix: correctly handle key indexes with options such as DESC, NULL
409411
FIRST/LAST, COLLATE (pg_repack issue #3).

0 commit comments

Comments
 (0)