Skip to content

Commit 649e72c

Browse files
committed
Add some ORDER BYs to queries fetching lists of tables/indexes
to be repacked, in order to ensure consistent installcheck results.
1 parent e2c720b commit 649e72c

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

bin/pg_repack.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
634634
{
635635
appendStringInfoString(&sql, "pkid IS NOT NULL");
636636
}
637+
/* Ensure the regression tests get a consistent ordering of tables */
638+
appendStringInfoString(&sql, " ORDER BY t.relname, t.schemaname");
637639

638640
/* double check the parameters array is sane */
639641
if (iparam != num_params)
@@ -1865,17 +1867,13 @@ repack_all_indexes(char *errbuf, size_t errsize)
18651867
if (!preliminary_checks(errbuf, errsize))
18661868
goto cleanup;
18671869

1868-
/* XXX: tighten these ORDER BYs to avoid intermittent installcheck
1869-
* failures due to differently-ordered results for some of the
1870-
* --only-indexes tests.
1871-
*/
18721870
if (r_index.head)
18731871
{
18741872
appendStringInfoString(&sql,
18751873
"SELECT i.relname, idx.indexrelid, idx.indisvalid, idx.indrelid, idx.indrelid::regclass, n.nspname"
18761874
" FROM pg_index idx JOIN pg_class i ON i.oid = idx.indexrelid"
18771875
" JOIN pg_namespace n ON n.oid = i.relnamespace"
1878-
" WHERE idx.indexrelid = $1::regclass ORDER BY indisvalid DESC");
1876+
" WHERE idx.indexrelid = $1::regclass ORDER BY indisvalid DESC, i.relname, n.nspname");
18791877

18801878
cell = r_index.head;
18811879
}
@@ -1885,7 +1883,7 @@ repack_all_indexes(char *errbuf, size_t errsize)
18851883
"SELECT i.relname, idx.indexrelid, idx.indisvalid, idx.indrelid, $1::text, n.nspname"
18861884
" FROM pg_index idx JOIN pg_class i ON i.oid = idx.indexrelid"
18871885
" JOIN pg_namespace n ON n.oid = i.relnamespace"
1888-
" WHERE idx.indrelid = $1::regclass ORDER BY indisvalid DESC");
1886+
" WHERE idx.indrelid = $1::regclass ORDER BY indisvalid DESC, i.relname, n.nspname");
18891887

18901888
cell = table_list.head;
18911889
}

regress/expected/repack.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ INFO: repacking table "tbl_pk_uk"
325325
-- => OK
326326
\! pg_repack --dbname=contrib_regression --table=tbl_pk_uk --only-indexes
327327
INFO: repacking indexes of "tbl_pk_uk"
328-
INFO: repacking index "public"."tbl_pk_uk_pkey"
329328
INFO: repacking index "public"."tbl_pk_uk_col2_col1_key"
329+
INFO: repacking index "public"."tbl_pk_uk_pkey"
330330
-- => OK
331331
\! pg_repack --dbname=contrib_regression --table=tbl_nn_puk
332332
WARNING: relation "tbl_nn_puk" must have a primary key or not-null unique keys
@@ -377,10 +377,10 @@ INFO: repacking table "test_schema1.tbl1"
377377
INFO: repacking table "test_schema1.tbl2"
378378
-- => OK
379379
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --schema=test_schema2
380+
INFO: repacking table "test_schema1.tbl1"
381+
INFO: repacking table "test_schema1.tbl2"
380382
INFO: repacking table "test_schema2.tbl1"
381383
INFO: repacking table "test_schema2.tbl2"
382-
INFO: repacking table "test_schema1.tbl2"
383-
INFO: repacking table "test_schema1.tbl1"
384384
-- => ERROR
385385
\! pg_repack --dbname=contrib_regression --schema=test_schema1 --table=tbl1
386386
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead

regress/expected/tablespace.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ INFO: repacking table "testts1"
135135
--move all indexes of the table to a tablespace
136136
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=testts
137137
INFO: repacking indexes of "testts1"
138-
INFO: repacking index "public"."testts1_pkey"
139138
INFO: repacking index "public"."testts1_partial_idx"
139+
INFO: repacking index "public"."testts1_pkey"
140140
INFO: repacking index "public"."testts1_with_idx"
141141
SELECT relname, spcname
142142
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
@@ -152,8 +152,8 @@ ORDER BY relname;
152152
--all indexes of tablespace remain in same tablespace
153153
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes
154154
INFO: repacking indexes of "testts1"
155-
INFO: repacking index "public"."testts1_pkey"
156155
INFO: repacking index "public"."testts1_partial_idx"
156+
INFO: repacking index "public"."testts1_pkey"
157157
INFO: repacking index "public"."testts1_with_idx"
158158
SELECT relname, spcname
159159
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
@@ -169,8 +169,8 @@ ORDER BY relname;
169169
--move all indexes of the table to pg_default
170170
\! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --tablespace=pg_default
171171
INFO: repacking indexes of "testts1"
172-
INFO: repacking index "public"."testts1_pkey"
173172
INFO: repacking index "public"."testts1_partial_idx"
173+
INFO: repacking index "public"."testts1_pkey"
174174
INFO: repacking index "public"."testts1_with_idx"
175175
SELECT relname, spcname
176176
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace

0 commit comments

Comments
 (0)