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

Commit834db2d

Browse files
committed
move HASH & RANGE function declarations from init.sql to their corresponding files, get_partition_range() -> +get_range_by_part_oid()
1 parent476acbe commit834db2d

File tree

6 files changed

+73
-72
lines changed

6 files changed

+73
-72
lines changed

‎hash.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,17 @@ BEGIN
176176
END LOOP;
177177
END
178178
$$ LANGUAGE plpgsql;
179+
180+
/*
181+
* Returns hash function OID for specified type
182+
*/
183+
CREATEOR REPLACE FUNCTION @extschema@.get_type_hash_func(OID)
184+
RETURNSOIDAS'pg_pathman','get_type_hash_func'
185+
LANGUAGE C STRICT;
186+
187+
/*
188+
* Calculates hash for integer value
189+
*/
190+
CREATEOR REPLACE FUNCTION @extschema@.get_hash(INTEGER,INTEGER)
191+
RETURNSINTEGERAS'pg_pathman','get_hash'
192+
LANGUAGE C STRICT;

‎init.sql

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,6 @@ CREATE OR REPLACE FUNCTION @extschema@.is_date_type(cls REGTYPE)
312312
RETURNSBOOLEANAS'pg_pathman','is_date_type'
313313
LANGUAGE C STRICT;
314314

315-
/*
316-
* Checks if range overlaps with existing partitions.
317-
* Returns TRUE if overlaps and FALSE otherwise.
318-
*/
319-
CREATEOR REPLACE FUNCTION @extschema@.check_overlap(
320-
parent_relidOID, range_min ANYELEMENT, range_max ANYELEMENT)
321-
RETURNSBOOLEANAS'pg_pathman','check_overlap'
322-
LANGUAGE C STRICT;
323-
324315

325316
CREATEOR REPLACE FUNCTION @extschema@.on_create_partitions(relidOID)
326317
RETURNS VOIDAS'pg_pathman','on_partitions_created'
@@ -335,58 +326,6 @@ RETURNS VOID AS 'pg_pathman', 'on_partitions_removed'
335326
LANGUAGE C STRICT;
336327

337328

338-
CREATEOR REPLACE FUNCTION @extschema@.find_or_create_range_partition(relidOID, value ANYELEMENT)
339-
RETURNSOIDAS'pg_pathman','find_or_create_range_partition'
340-
LANGUAGE C STRICT;
341-
342-
343-
/*
344-
* Returns min and max values for specified RANGE partition.
345-
*/
346-
CREATEOR REPLACE FUNCTION @extschema@.get_partition_range(
347-
parent_relidOID, partition_relidOID, dummy ANYELEMENT)
348-
RETURNS ANYARRAYAS'pg_pathman','get_partition_range'
349-
LANGUAGE C STRICT;
350-
351-
352-
/*
353-
* Returns N-th range (in form of array)
354-
*/
355-
CREATEOR REPLACE FUNCTION @extschema@.get_range_by_idx(
356-
parent_relidOID, idxINTEGER, dummy ANYELEMENT)
357-
RETURNS ANYARRAYAS'pg_pathman','get_range_by_idx'
358-
LANGUAGE C STRICT;
359-
360-
/*
361-
* Returns min value of the first range for relation
362-
*/
363-
CREATEOR REPLACE FUNCTION @extschema@.get_min_range_value(
364-
parent_relidOID, dummy ANYELEMENT)
365-
RETURNS ANYELEMENTAS'pg_pathman','get_min_range_value'
366-
LANGUAGE C STRICT;
367-
368-
/*
369-
* Returns max value of the last range for relation
370-
*/
371-
CREATEOR REPLACE FUNCTION @extschema@.get_max_range_value(
372-
parent_relidOID, dummy ANYELEMENT)
373-
RETURNS ANYELEMENTAS'pg_pathman','get_max_range_value'
374-
LANGUAGE C STRICT;
375-
376-
/*
377-
* Returns hash function OID for specified type
378-
*/
379-
CREATEOR REPLACE FUNCTION @extschema@.get_type_hash_func(OID)
380-
RETURNSOIDAS'pg_pathman','get_type_hash_func'
381-
LANGUAGE C STRICT;
382-
383-
/*
384-
* Calculates hash for integer value
385-
*/
386-
CREATEOR REPLACE FUNCTION @extschema@.get_hash(INTEGER,INTEGER)
387-
RETURNSINTEGERAS'pg_pathman','get_hash'
388-
LANGUAGE C STRICT;
389-
390329
/*
391330
* Checks if attribute is nullable
392331
*/

‎range.sql

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ BEGIN
465465
END IF;
466466

467467
/* Get partition values range*/
468-
p_range := @extschema@.get_partition_range(v_parent_relid, v_child_relid,0);
468+
p_range := @extschema@.get_range_by_part_oid(v_parent_relid, v_child_relid,0);
469469
IF p_range ISNULL THEN
470470
RAISE EXCEPTION'Could not find specified partition';
471471
END IF;
@@ -602,8 +602,8 @@ BEGIN
602602
* first and second elements of array are MIN and MAX of partition1
603603
* third and forth elements are MIN and MAX of partition2
604604
*/
605-
p_range := @extschema@.get_partition_range(p_parent_relid, p_part1::oid,0)||
606-
@extschema@.get_partition_range(p_parent_relid, p_part2::oid,0);
605+
p_range := @extschema@.get_range_by_part_oid(p_parent_relid, p_part1,0)||
606+
@extschema@.get_range_by_part_oid(p_parent_relid, p_part2,0);
607607

608608
/* Check if ranges are adjacent*/
609609
IF p_range[1]!= p_range[4]AND p_range[2]!= p_range[3] THEN
@@ -1080,6 +1080,7 @@ BEGIN
10801080
END
10811081
$$ LANGUAGE plpgsql;
10821082

1083+
10831084
/*
10841085
* Construct CHECK constraint condition for a range partition.
10851086
*/
@@ -1089,3 +1090,52 @@ CREATE OR REPLACE FUNCTION @extschema@.get_range_condition(
10891090
p_end_value ANYELEMENT)
10901091
RETURNSTEXTAS'pg_pathman','get_range_condition'
10911092
LANGUAGE C STRICT;
1093+
1094+
/*
1095+
* Returns N-th range (as an array of two elements).
1096+
*/
1097+
CREATEOR REPLACE FUNCTION @extschema@.get_range_by_idx(
1098+
parent_relidOID, idxINTEGER, dummy ANYELEMENT)
1099+
RETURNS ANYARRAYAS'pg_pathman','get_range_by_idx'
1100+
LANGUAGE C STRICT;
1101+
1102+
/*
1103+
* Returns min and max values for specified RANGE partition.
1104+
*/
1105+
CREATEOR REPLACE FUNCTION @extschema@.get_range_by_part_oid(
1106+
parent_relidOID, partition_relidOID, dummy ANYELEMENT)
1107+
RETURNS ANYARRAYAS'pg_pathman','get_range_by_part_oid'
1108+
LANGUAGE C STRICT;
1109+
1110+
/*
1111+
* Returns min value of the first partition's RangeEntry.
1112+
*/
1113+
CREATEOR REPLACE FUNCTION @extschema@.get_min_range_value(
1114+
parent_relidOID, dummy ANYELEMENT)
1115+
RETURNS ANYELEMENTAS'pg_pathman','get_min_range_value'
1116+
LANGUAGE C STRICT;
1117+
1118+
/*
1119+
* Returns max value of the last partition's RangeEntry.
1120+
*/
1121+
CREATEOR REPLACE FUNCTION @extschema@.get_max_range_value(
1122+
parent_relidOID, dummy ANYELEMENT)
1123+
RETURNS ANYELEMENTAS'pg_pathman','get_max_range_value'
1124+
LANGUAGE C STRICT;
1125+
1126+
/*
1127+
* Checks if range overlaps with existing partitions.
1128+
* Returns TRUE if overlaps and FALSE otherwise.
1129+
*/
1130+
CREATEOR REPLACE FUNCTION @extschema@.check_overlap(
1131+
parent_relidOID, range_min ANYELEMENT, range_max ANYELEMENT)
1132+
RETURNSBOOLEANAS'pg_pathman','check_overlap'
1133+
LANGUAGE C STRICT;
1134+
1135+
/*
1136+
* Needed for an UPDATE trigger.
1137+
*/
1138+
CREATEOR REPLACE FUNCTION @extschema@.find_or_create_range_partition(
1139+
relidOID, value ANYELEMENT)
1140+
RETURNSOIDAS'pg_pathman','find_or_create_range_partition'
1141+
LANGUAGE C STRICT;

‎src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
396396

397397
PlannedStmt*result;
398398

399-
/*TODO: fix these commands (traverse whole query tree) */
399+
/*FIXME: fix these commands (traverse whole query tree) */
400400
if (IsPathmanReady())
401401
{
402402
switch(parse->commandType)

‎src/pl_funcs.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PG_FUNCTION_INFO_V1( on_partitions_removed );
3030
PG_FUNCTION_INFO_V1(find_or_create_range_partition);
3131
PG_FUNCTION_INFO_V1(get_range_condition );
3232
PG_FUNCTION_INFO_V1(get_range_by_idx );
33-
PG_FUNCTION_INFO_V1(get_partition_range );
33+
PG_FUNCTION_INFO_V1(get_range_by_part_oid );
3434
PG_FUNCTION_INFO_V1(acquire_partitions_lock );
3535
PG_FUNCTION_INFO_V1(release_partitions_lock );
3636
PG_FUNCTION_INFO_V1(check_overlap );
@@ -169,14 +169,10 @@ find_or_create_range_partition(PG_FUNCTION_ARGS)
169169
}
170170

171171
/*
172-
* Returns range (min, max) as output parameters
173-
*
174-
* first argument is the parent relid
175-
* second is the partition relid
176-
* third and forth are MIN and MAX output parameters
172+
* Returns range (min, max) as output parameters.
177173
*/
178174
Datum
179-
get_partition_range(PG_FUNCTION_ARGS)
175+
get_range_by_part_oid(PG_FUNCTION_ARGS)
180176
{
181177
Oidparent_oid=PG_GETARG_OID(0);
182178
Oidchild_oid=PG_GETARG_OID(1);

‎src/relation_info.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ get_pathman_relation_info(Oid relid)
219219
attname=TextDatumGetCString(values[Anum_pathman_config_attname-1]);
220220

221221
/* Refresh partitioned table cache entry */
222+
/* TODO: possible refactoring, pass found 'prel' instead of searching */
222223
refresh_pathman_relation_info(relid,part_type,attname);
223224
}
224225
/* Else clear remaining cache entry */
@@ -347,6 +348,7 @@ finish_delayed_invalidation(void)
347348
* cache\forget\get PartParentInfo functions.
348349
*/
349350

351+
/* Create "partition+parent" pair in local cache */
350352
void
351353
cache_parent_of_partition(Oidpartition,Oidparent)
352354
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp