|
40 | 40 | # REINDEX operations. A set of relfilenodes is saved from the catalogs
|
41 | 41 | # and then compared with pg_class.
|
42 | 42 | $node->safe_psql('postgres',
|
43 |
| - 'CREATE TABLE index_relfilenodes (parent regclass, indname regclass, relfilenode oid);' |
| 43 | + 'CREATE TABLE index_relfilenodes (parent regclass, indname text, indoid oid, relfilenode oid);' |
44 | 44 | );
|
45 | 45 | # Save the relfilenode of a set of toast indexes, one from the catalog
|
46 | 46 | # pg_constraint and one from the test table.
|
47 | 47 | my $fetch_toast_relfilenodes =
|
48 |
| - qq{SELECT b.oid::regclass, c.oid::regclass, c.relfilenode |
| 48 | + qq{SELECT b.oid::regclass, c.oid::regclass::text, c.oid, c.relfilenode |
49 | 49 | FROM pg_class a
|
50 | 50 | JOIN pg_class b ON (a.oid = b.reltoastrelid)
|
51 | 51 | JOIN pg_index i on (a.oid = i.indrelid)
|
52 | 52 | JOIN pg_class c on (i.indexrelid = c.oid)
|
53 | 53 | WHERE b.oid IN ('pg_constraint'::regclass, 'test1'::regclass)};
|
54 | 54 | # Same for relfilenodes of normal indexes. This saves the relfilenode
|
55 | 55 | # from an index of pg_constraint, and from the index of the test table.
|
56 |
| -my $fetch_index_relfilenodes = qq{SELECT i.indrelid, a.oid, a.relfilenode |
| 56 | +my $fetch_index_relfilenodes = qq{SELECT i.indrelid, a.oid::regclass::text, a.oid, a.relfilenode |
57 | 57 | FROM pg_class a
|
58 | 58 | JOIN pg_index i ON (i.indexrelid = a.oid)
|
59 | 59 | WHERE a.relname IN ('pg_constraint_oid_index', 'test1x')};
|
|
69 | 69 | # parent table is included to provide more context.
|
70 | 70 | my $compare_relfilenodes = qq(SELECT b.parent::regclass,
|
71 | 71 | regexp_replace(b.indname::text, '(pg_toast.pg_toast_)\\d+(_index)', '\\1<oid>\\2'),
|
| 72 | + CASE WHEN a.oid = b.indoid THEN 'OID is unchanged' |
| 73 | + ELSE 'OID has changed' END, |
72 | 74 | CASE WHEN a.relfilenode = b.relfilenode THEN 'relfilenode is unchanged'
|
73 | 75 | ELSE 'relfilenode has changed' END
|
74 | 76 | FROM index_relfilenodes b
|
|
83 | 85 | 'SQL REINDEX run');
|
84 | 86 | my $relnode_info = $node->safe_psql('postgres', $compare_relfilenodes);
|
85 | 87 | is( $relnode_info,
|
86 |
| - qq(pg_constraint|pg_constraint_oid_index|relfilenode is unchanged |
87 |
| -pg_constraint|pg_toast.pg_toast_<oid>_index|relfilenode is unchanged |
88 |
| -test1|pg_toast.pg_toast_<oid>_index|relfilenode has changed |
89 |
| -test1|test1x|relfilenode has changed), |
| 88 | + qq(pg_constraint|pg_constraint_oid_index|OID is unchanged|relfilenode is unchanged |
| 89 | +pg_constraint|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode is unchanged |
| 90 | +test1|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode has changed |
| 91 | +test1|test1x|OID is unchanged|relfilenode has changed), |
90 | 92 | 'relfilenode change after REINDEX DATABASE');
|
91 | 93 |
|
92 | 94 | # Re-save and run the second one.
|
|
98 | 100 | 'reindex system tables');
|
99 | 101 | $relnode_info = $node->safe_psql('postgres', $compare_relfilenodes);
|
100 | 102 | is( $relnode_info,
|
101 |
| - qq(pg_constraint|pg_constraint_oid_index|relfilenode has changed |
102 |
| -pg_constraint|pg_toast.pg_toast_<oid>_index|relfilenode has changed |
103 |
| -test1|pg_toast.pg_toast_<oid>_index|relfilenode is unchanged |
104 |
| -test1|test1x|relfilenode is unchanged), |
| 103 | + qq(pg_constraint|pg_constraint_oid_index|OID is unchanged|relfilenode has changed |
| 104 | +pg_constraint|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode has changed |
| 105 | +test1|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode is unchanged |
| 106 | +test1|test1x|OID is unchanged|relfilenode is unchanged), |
105 | 107 | 'relfilenode change after REINDEX SYSTEM');
|
106 | 108 |
|
107 | 109 | $node->issues_sql_like(
|
|
132 | 134 | qr/statement: REINDEX \(VERBOSE, TABLESPACE $tbspace_name\) TABLE public\.test1;/,
|
133 | 135 | 'reindex with verbose output and tablespace');
|
134 | 136 |
|
135 |
| -# the same with --concurrently |
| 137 | +# Same with --concurrently. |
| 138 | +# Save the state of the relations and compare them after the DATABASE |
| 139 | +# rebuild. |
| 140 | +$node->safe_psql('postgres', |
| 141 | + "TRUNCATE index_relfilenodes; $save_relfilenodes"); |
136 | 142 | $node->issues_sql_like(
|
137 | 143 | [ 'reindexdb', '--concurrently', 'postgres' ],
|
138 | 144 | qr/statement: REINDEX DATABASE CONCURRENTLY postgres;/,
|
139 | 145 | 'SQL REINDEX CONCURRENTLY run');
|
| 146 | +$relnode_info = $node->safe_psql('postgres', $compare_relfilenodes); |
| 147 | +is( $relnode_info, |
| 148 | + qq(pg_constraint|pg_constraint_oid_index|OID is unchanged|relfilenode is unchanged |
| 149 | +pg_constraint|pg_toast.pg_toast_<oid>_index|OID is unchanged|relfilenode is unchanged |
| 150 | +test1|pg_toast.pg_toast_<oid>_index|OID has changed|relfilenode has changed |
| 151 | +test1|test1x|OID has changed|relfilenode has changed), |
| 152 | + 'OID change after REINDEX DATABASE CONCURRENTLY'); |
140 | 153 |
|
141 | 154 | $node->issues_sql_like(
|
142 | 155 | [ 'reindexdb', '--concurrently', '-t', 'test1', 'postgres' ],
|
|
0 commit comments