Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite39af82

Browse files
committed
pathman:
* split partition function* PL functions enchancement
1 parentc36721e commite39af82

File tree

3 files changed

+307
-234
lines changed

3 files changed

+307
-234
lines changed

‎contrib/pathman/pathman.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ PG_FUNCTION_INFO_V1( on_partitions_created );
7575
PG_FUNCTION_INFO_V1(on_partitions_updated );
7676
PG_FUNCTION_INFO_V1(on_partitions_removed );
7777
PG_FUNCTION_INFO_V1(find_range_partition );
78+
PG_FUNCTION_INFO_V1(get_partition_range );
7879

7980

8081
/*
@@ -1162,3 +1163,54 @@ find_range_partition(PG_FUNCTION_ARGS)
11621163

11631164
PG_RETURN_NULL();
11641165
}
1166+
1167+
/*
1168+
* Returns range (min, max) as output parameters
1169+
*
1170+
* first argument is parent relid
1171+
* second is partition relid
1172+
* third and forth are MIN and MAX output parameters
1173+
*/
1174+
Datum
1175+
get_partition_range(PG_FUNCTION_ARGS)
1176+
{
1177+
intparent_oid=DatumGetInt32(PG_GETARG_DATUM(0));
1178+
intchild_oid=DatumGetInt32(PG_GETARG_DATUM(1));
1179+
intnelems=2;
1180+
Datum*elems=palloc(nelems*sizeof(Datum));
1181+
Oidelemtype=INT4OID;
1182+
PartRelationInfo*prel;
1183+
RangeRelation*rangerel;
1184+
RangeEntry*ranges;
1185+
boolfound;
1186+
inti;
1187+
1188+
prel= (PartRelationInfo*)
1189+
hash_search(relations, (constvoid*)&parent_oid,HASH_FIND,0);
1190+
1191+
rangerel= (RangeRelation*)
1192+
hash_search(range_restrictions, (constvoid*)&parent_oid,HASH_FIND,NULL);
1193+
1194+
if (!prel|| !rangerel)
1195+
PG_RETURN_NULL();
1196+
1197+
ranges=dsm_array_get_pointer(&rangerel->ranges);
1198+
for(i=0;i<rangerel->ranges.length;i++)
1199+
if (ranges[i].child_oid==child_oid)
1200+
{
1201+
found= true;
1202+
break;
1203+
}
1204+
1205+
if (found)
1206+
{
1207+
elems[0]=ranges[i].min;
1208+
elems[1]=ranges[i].max;
1209+
1210+
ArrayType*arr=
1211+
construct_array(elems,nelems,prel->atttype,sizeof(Oid), true,'i');
1212+
PG_RETURN_ARRAYTYPE_P(arr);
1213+
}
1214+
1215+
PG_RETURN_NULL();
1216+
}

‎contrib/pathman/sql/init.sql

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,32 @@ RETURNS VOID AS 'pathman', 'on_partitions_removed' LANGUAGE C STRICT;
169169
CREATE OR REPLACEFUNCTIONfind_range_partition(relidOID, value ANYELEMENT)
170170
RETURNSOIDAS'pathman','find_range_partition' LANGUAGE C STRICT;
171171

172+
/*
173+
* Returns min and max values for specified RANGE partition.
174+
*/
175+
CREATE OR REPLACEFUNCTIONget_partition_range(
176+
parent_relid ANYELEMENT,
177+
partition_relid ANYELEMENT)
178+
RETURNS ANYARRAYAS'pathman','get_partition_range' LANGUAGE C STRICT;
179+
180+
/*
181+
* Copy rows to partitions
182+
*/
172183
CREATE OR REPLACEFUNCTIONpartition_data(p_parenttext)
173184
RETURNSbigintAS
174185
$$
175186
DECLARE
176187
rec RECORD;
177188
BEGIN
178189
FOR recIN (SELECTchild.relname,pg_constraint.consrc
179-
FROM pg_pathman_rels
180-
JOIN pg_classAS parentONparent.relname=pg_pathman_rels.relname
181-
JOIN pg_inheritsON inhparent=parent.relfilenode
182-
JOIN pg_constraintON conrelid= inhrelidAND contype='c'
183-
JOIN pg_classAS childONchild.relfilenode= inhrelid
184-
WHEREpg_pathman_rels.relname= p_parent)
190+
FROM pg_pathman_rels
191+
JOIN pg_classAS parentONparent.relname=pg_pathman_rels.relname
192+
JOIN pg_inheritsON inhparent=parent.relfilenode
193+
JOIN pg_constraintON conrelid= inhrelidAND contype='c'
194+
JOIN pg_classAS childONchild.relfilenode= inhrelid
195+
WHEREpg_pathman_rels.relname= p_parent)
185196
LOOP
186-
RAISE NOTICE'child %, condition %',rec.relname,rec.consrc;
187-
197+
RAISE NOTICE'Copying data to % (condition: %)',rec.relname,rec.consrc;
188198
EXECUTE format('WITH part_data AS (
189199
DELETE FROM ONLY %s WHERE %s RETURNING *)
190200
INSERT INTO %s SELECT * FROM part_data'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp