Skip to content

Commit fb85322

Browse files
committed
Fix migration script, return to old version, so tests can work
1 parent e38be2b commit fb85322

File tree

5 files changed

+62
-54
lines changed

5 files changed

+62
-54
lines changed

pg_pathman--1.3--1.4.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ ALTER TABLE @[email protected]_config
3131
/* mark 'expression_p' and 'atttype' to update on next start */
3232
UPDATE @[email protected]_config SET upd_expr = TRUE;
3333

34+
/* we've changed the format of constraint names, and we need rename them */
35+
CREATE OR REPLACE FUNCTION @[email protected]_constraints()
36+
RETURNS BOOLEAN AS
37+
$$
38+
DECLARE
39+
v_rec RECORD;
40+
BEGIN
41+
FOR v_rec IN (SELECT conrelid::regclass AS t, conname, regexp_replace(conname, '\d+_check', 'check') as new_conname
42+
FROM pg_constraint
43+
WHERE conname ~ 'pathman_.*_\d+_\d+_check')
44+
LOOP
45+
EXECUTE format('ALTER TABLE %s RENAME CONSTRAINT %s TO %s',
46+
v_rec.t, v_rec.conname, v_rec.new_conname);
47+
END LOOP;
48+
49+
RETURN TRUE;
50+
END
51+
$$
52+
LANGUAGE plpgsql;
53+
54+
SELECT @[email protected]_constraints();
55+
56+
/* we don't need this function anymore */
57+
DROP FUNCTION @[email protected]_constraints();
58+
3459
DROP FUNCTION @[email protected]_relation_checks(REGCLASS, TEXT);
3560
CREATE OR REPLACE FUNCTION @[email protected]_relation_checks(
3661
relation REGCLASS,

pg_pathman.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# pg_pathman extension
22
comment = 'Partitioning tool for PostgreSQL'
3-
default_version = '1.4'
3+
default_version = '1.3'
44
module_pathname = '$libdir/pg_pathman'

src/include/relation_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ PrelLastChild(const PartRelationInfo *prel)
237237
}
238238

239239

240+
PartRelationInfo *create_pathman_relation_info(Oid relid);
240241
const PartRelationInfo *refresh_pathman_relation_info(Oid relid,
241242
Datum *values,
242243
bool allow_incomplete);

src/init.c

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -733,16 +733,6 @@ read_pathman_config(void)
733733
HeapScanDesc scan;
734734
Snapshot snapshot;
735735
HeapTuple htup;
736-
Oid *relids = NULL;
737-
Size relids_index = 0,
738-
relids_count = 100,
739-
j;
740-
741-
/*
742-
* Initialize relids array, we keep here relations that require
743-
* update their expression.
744-
*/
745-
relids = (Oid *) palloc(sizeof(Oid) * relids_count);
746736

747737
/* Open PATHMAN_CONFIG with latest snapshot available */
748738
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
@@ -776,21 +766,9 @@ read_pathman_config(void)
776766
Assert(!isnull[Anum_pathman_config_expression_p - 1]);
777767
Assert(!isnull[Anum_pathman_config_upd_expression - 1]);
778768

779-
upd_expr = DatumGetBool(values[Anum_pathman_config_upd_expression - 1]);
780-
if (upd_expr)
781-
{
782-
if (relids_index >= relids_count)
783-
{
784-
relids_count += 100;
785-
relids = (Oid *) repalloc(relids, sizeof(Oid) * relids_count);
786-
}
787-
788-
relids[relids_index] = relid;
789-
relids_index += 1;
790-
}
791-
792769
/* Extract values from Datums */
793770
relid = DatumGetObjectId(values[Anum_pathman_config_partrel - 1]);
771+
upd_expr = DatumGetBool(values[Anum_pathman_config_upd_expression - 1]);
794772

795773
/* Check that relation 'relid' exists */
796774
if (get_rel_type_id(relid) == InvalidOid)
@@ -802,8 +780,9 @@ read_pathman_config(void)
802780
errhint(INIT_ERROR_HINT)));
803781
}
804782

805-
/* get_pathman_relation_info() will refresh this entry */
806-
if (!upd_expr)
783+
if (upd_expr)
784+
create_pathman_relation_info(relid);
785+
else
807786
refresh_pathman_relation_info(relid,
808787
values,
809788
true); /* allow lazy prel loading */
@@ -813,12 +792,6 @@ read_pathman_config(void)
813792
heap_endscan(scan);
814793
UnregisterSnapshot(snapshot);
815794
heap_close(rel, AccessShareLock);
816-
817-
/* Update expressions */
818-
for (j = 0; j < relids_index; j++)
819-
get_pathman_relation_info(relids[j]);
820-
821-
pfree(relids);
822795
}
823796

824797

src/relation_info.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,18 @@ init_relation_info_static_data(void)
116116
NULL);
117117
}
118118

119-
120-
/*
121-
* refresh\invalidate\get\remove PartRelationInfo functions.
122-
*/
123-
124119
/* Create or update PartRelationInfo in local cache. Might emit ERROR. */
125-
const PartRelationInfo *
126-
refresh_pathman_relation_info(Oid relid,
127-
Datum *values,
128-
bool allow_incomplete)
120+
PartRelationInfo *
121+
create_pathman_relation_info(Oid relid)
129122
{
130-
const LOCKMODE lockmode = AccessShareLock;
131-
const TypeCacheEntry *typcache;
132-
Oid *prel_children;
133-
uint32 prel_children_count = 0,
134-
i;
135-
bool found_entry;
136123
PartRelationInfo *prel;
137-
Datum param_values[Natts_pathman_config_params];
138-
bool param_isnull[Natts_pathman_config_params];
139-
char *expr;
140-
HeapTuple tp;
141-
MemoryContext oldcontext;
124+
bool found_entry;
142125

143126
AssertTemporaryContext();
144-
145127
prel = (PartRelationInfo *) pathman_cache_search_relid(partitioned_rels,
146128
relid, HASH_ENTER,
147129
&found_entry);
130+
148131
elog(DEBUG2,
149132
found_entry ?
150133
"Refreshing record for relation %u in pg_pathman's cache [%u]" :
@@ -166,7 +149,33 @@ refresh_pathman_relation_info(Oid relid,
166149
}
167150

168151
/* First we assume that this entry is invalid */
169-
prel->valid = false;
152+
prel->valid = false;
153+
return prel;
154+
}
155+
156+
/*
157+
* refresh\invalidate\get\remove PartRelationInfo functions.
158+
*/
159+
160+
const PartRelationInfo *
161+
refresh_pathman_relation_info(Oid relid,
162+
Datum *values,
163+
bool allow_incomplete)
164+
{
165+
const LOCKMODE lockmode = AccessShareLock;
166+
const TypeCacheEntry *typcache;
167+
Oid *prel_children;
168+
uint32 prel_children_count = 0,
169+
i;
170+
PartRelationInfo *prel;
171+
Datum param_values[Natts_pathman_config_params];
172+
bool param_isnull[Natts_pathman_config_params];
173+
char *expr;
174+
HeapTuple tp;
175+
MemoryContext oldcontext;
176+
177+
AssertTemporaryContext();
178+
prel = create_pathman_relation_info(relid);
170179

171180
/* Try locking parent, exit fast if 'allow_incomplete' */
172181
if (allow_incomplete)

0 commit comments

Comments
 (0)