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

Commite961ef2

Browse files
committed
added add_range_partitions() function
1 parent1d45b48 commite961ef2

File tree

2 files changed

+120
-7
lines changed

2 files changed

+120
-7
lines changed

‎range.sql

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,33 @@ LANGUAGE C;
476476

477477

478478
CREATEOR REPLACE FUNCTION @extschema@.generate_bounds(
479-
p_startANYELEMENT,
480-
p_intervalINTERVAL,
481-
p_countINTEGER)
479+
p_startANYELEMENT,
480+
p_intervalINTERVAL,
481+
p_countINTEGER)
482482
RETURNS ANYARRAYAS'pg_pathman','generate_bounds'
483483
LANGUAGE C;
484484

485-
486485
CREATEOR REPLACE FUNCTION @extschema@.generate_bounds(
487-
p_startANYELEMENT,
488-
p_intervalANYELEMENT,
489-
p_countINTEGER)
486+
p_startANYELEMENT,
487+
p_intervalANYELEMENT,
488+
p_countINTEGER)
490489
RETURNS ANYARRAYAS'pg_pathman','generate_bounds'
491490
LANGUAGE C;
492491

492+
-- CREATE OR REPLACE FUNCTION @extschema@.generate_bounds_by_range(
493+
-- p_startANYELEMENT,
494+
-- p_endANYELEMENT,
495+
-- p_intervalINTERVAL)
496+
-- RETURNS ANYARRAY AS 'pg_pathman', 'generate_bounds_by_range'
497+
-- LANGUAGE C;
498+
499+
-- CREATE OR REPLACE FUNCTION @extschema@.generate_bounds_by_range(
500+
-- p_startANYELEMENT,
501+
-- p_endANYELEMENT,
502+
-- p_intervalANYELEMENT)
503+
-- RETURNS ANYARRAY AS 'pg_pathman', 'generate_bounds_by_range'
504+
-- LANGUAGE C;
505+
493506

494507
/*
495508
* Split RANGE partition
@@ -871,6 +884,40 @@ END
871884
$$
872885
LANGUAGE plpgsql;
873886

887+
888+
/*
889+
* Add multiple partitions
890+
*/
891+
CREATEOR REPLACE FUNCTION @extschema@.add_range_partitions(
892+
parent_relidREGCLASS,
893+
boundsANYARRAY,
894+
relnamesTEXT[] DEFAULTNULL,
895+
tablespacesTEXT[] DEFAULTNULL)
896+
RETURNSINTEGERAS
897+
$$
898+
DECLARE
899+
part_countINTEGER;
900+
BEGIN
901+
PERFORM @extschema@.validate_relname(parent_relid);
902+
903+
/* Acquire lock on parent*/
904+
PERFORM @extschema@.lock_partitioned_relation(parent_relid);
905+
906+
/* Create partitions*/
907+
part_count := @extschema@.create_range_partitions_internal(parent_relid,
908+
bounds,
909+
relnames,
910+
tablespaces);
911+
912+
/* Notify backend about changes*/
913+
PERFORM @extschema@.on_create_partitions(parent_relid);
914+
915+
RETURN part_count;
916+
END
917+
$$
918+
LANGUAGE plpgsql;
919+
920+
874921
/*
875922
* Drop range partition
876923
*/

‎src/pl_range_funcs.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ PG_FUNCTION_INFO_V1( validate_interval_value );
7171

7272
PG_FUNCTION_INFO_V1(create_range_partitions_internal );
7373
PG_FUNCTION_INFO_V1(generate_bounds );
74+
// PG_FUNCTION_INFO_V1( generate_bounds_by_range );
7475

7576

7677
/*
@@ -1170,3 +1171,68 @@ generate_bounds(PG_FUNCTION_ARGS)
11701171

11711172
PG_RETURN_ARRAYTYPE_P(arr);
11721173
}
1174+
1175+
1176+
// Datum
1177+
// generate_bounds_by_range(PG_FUNCTION_ARGS)
1178+
// {
1179+
// /* input params */
1180+
// Datumstart = PG_GETARG_DATUM(0);
1181+
// Datumend = PG_GETARG_DATUM(1);
1182+
// Oidv_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
1183+
// Datuminterval = PG_GETARG_DATUM(2);
1184+
// Oidi_type = get_fn_expr_argtype(fcinfo->flinfo, 2);
1185+
// inti;
1186+
1187+
// /* operators */
1188+
// Oidplus_op_func;
1189+
// Datumplus_op_result;
1190+
// Oidplus_op_result_type;
1191+
1192+
// FmgrInfocmp_func;
1193+
1194+
// /* array */
1195+
// ArrayType *arr;
1196+
// int16elemlen;
1197+
// boolelembyval;
1198+
// charelemalign;
1199+
// Datum *datums;
1200+
// List *datum_list = NIL;
1201+
1202+
// /* Find suitable addition operator for given value and interval */
1203+
// extract_op_func_and_ret_type("+", v_type, i_type,
1204+
// &plus_op_func,
1205+
// &plus_op_result_type);
1206+
1207+
// /* Find comparison operator */
1208+
// fill_type_cmp_fmgr_info(&cmp_func,
1209+
// getBaseType(v_type),
1210+
// getBaseType(v_type));
1211+
1212+
// while (DatumGetInt32(FunctionCall2(cmp_func, start, end)) < 0)
1213+
// {
1214+
// /* Invoke addition operator and get a result */
1215+
// plus_op_result = OidFunctionCall2(plus_op_func, start, interval);
1216+
1217+
// if (plus_op_result_type != v_type)
1218+
// plus_op_result = perform_type_cast(plus_op_result,
1219+
// plus_op_result_type,
1220+
// v_type, NULL);
1221+
// start = plus_op_result;
1222+
// datum_list = lappend(datum_list, start);
1223+
// }
1224+
1225+
// datums = palloc(sizeof(Datum) * list_length(datum_list));
1226+
// foreach(lc, datum_list)
1227+
// datums[i++] = (Datum) lfirst(lc);
1228+
1229+
// /* build an array based on calculated datums */
1230+
// get_typlenbyvalalign(v_type, &elemlen, &elembyval, &elemalign);
1231+
// arr = construct_array(datums, count + 1, v_type,
1232+
// elemlen, elembyval, elemalign);
1233+
1234+
// pfree(datums);
1235+
// list_free(datum_list);
1236+
1237+
// PG_RETURN_ARRAYTYPE_P(arr);
1238+
// }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp