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

Commitd98e1af

Browse files
committed
refactor Bound-related macros, fix spawn_partitions_val()
1 parentf5257ca commitd98e1af

File tree

6 files changed

+210
-192
lines changed

6 files changed

+210
-192
lines changed

‎range.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ $$
558558
LANGUAGE plpgsql;
559559

560560
/*
561-
* Merge multiple partitions. All data will be copied to the first one. The rest
562-
* of partitions will be dropped
561+
* Merge multiple partitions. All data will be copied to the first one.
562+
*The restof partitions will be dropped.
563563
*/
564564
CREATEOR REPLACE FUNCTION @extschema@.merge_range_partitions(
565565
partitionsREGCLASS[])

‎src/init.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,15 @@ fill_prel_with_partitions(const Oid *partitions,
407407
&lower,&upper,
408408
&lower_null,&upper_null))
409409
{
410-
prel->ranges[i].child_oid=partitions[i];
411-
MakeBound(&prel->ranges[i].min,
412-
lower,
413-
lower_null ?MINUS_INFINITY :FINITE);
414-
MakeBound(&prel->ranges[i].max,
415-
upper,
416-
upper_null ?PLUS_INFINITY :FINITE);
410+
prel->ranges[i].child_oid=partitions[i];
411+
412+
prel->ranges[i].min=lower_null ?
413+
MakeBoundInf(MINUS_INFINITY) :
414+
MakeBound(lower);
415+
416+
prel->ranges[i].max=upper_null ?
417+
MakeBoundInf(PLUS_INFINITY) :
418+
MakeBound(upper);
417419
}
418420
else
419421
{
@@ -459,24 +461,15 @@ fill_prel_with_partitions(const Oid *partitions,
459461
old_mcxt=MemoryContextSwitchTo(TopMemoryContext);
460462
for (i=0;i<PrelChildrenCount(prel);i++)
461463
{
462-
// prel->ranges[i].max = datumCopy(prel->ranges[i].max,
463-
// prel->attbyval,
464-
// prel->attlen);
465-
CopyBound(&(prel->ranges[i].max),
466-
&(prel->ranges[i].max),
467-
prel->attbyval,
468-
prel->attlen);
469-
470-
// prel->ranges[i].min = datumCopy(prel->ranges[i].min,
471-
// prel->attbyval,
472-
// prel->attlen);
473-
CopyBound(&prel->ranges[i].min,
474-
&prel->ranges[i].min,
475-
prel->attbyval,
476-
prel->attlen);
464+
prel->ranges[i].min=CopyBound(&prel->ranges[i].min,
465+
prel->attbyval,
466+
prel->attlen);
467+
468+
prel->ranges[i].max=CopyBound(&prel->ranges[i].max,
469+
prel->attbyval,
470+
prel->attlen);
477471
}
478472
MemoryContextSwitchTo(old_mcxt);
479-
480473
}
481474

482475
#ifdefUSE_ASSERT_CHECKING
@@ -847,7 +840,7 @@ read_pathman_config(void)
847840
{
848841
DisablePathman();/* disable pg_pathman since config is broken */
849842
ereport(ERROR,
850-
(errmsg("Table \"%s\" contains nonexistent relation %u",
843+
(errmsg("table \"%s\" contains nonexistent relation %u",
851844
PATHMAN_CONFIG,relid),
852845
errhint(INIT_ERROR_HINT)));
853846
}

‎src/partition_creation.c

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static void extract_op_func_and_ret_type(char *opname, Oid type1, Oid type2,
4848
Oid*move_bound_op_ret_type);
4949

5050
staticOidspawn_partitions_val(Oidparent_relid,
51-
Datumrange_bound_min,
52-
Datumrange_bound_max,
51+
constBound*range_bound_min,
52+
constBound*range_bound_max,
5353
Oidrange_bound_type,
5454
Datuminterval_binary,
5555
Oidinterval_type,
@@ -359,26 +359,27 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
359359
if (partid==InvalidOid)
360360
{
361361
RangeEntry*ranges=PrelGetRangesArray(prel);
362-
Datumbound_min,/* absolute MIN */
362+
Boundbound_min,/* absolute MIN */
363363
bound_max;/* absolute MAX */
364364

365365
Oidinterval_type=InvalidOid;
366366
Datuminterval_binary,/* assigned 'width' of one partition */
367367
interval_text;
368368

369-
/* Read max & min range values from PartRelationInfo */
370-
bound_min=BoundGetValue(&ranges[0].min);
371-
bound_max=BoundGetValue(&ranges[PrelLastChild(prel)].max);
369+
/* Copy datums in order to protect them from cache invalidation */
370+
bound_min=CopyBound(&ranges[0].min,
371+
prel->attbyval,
372+
prel->attlen);
372373

373-
/* Copy datums on order to protect them from cache invalidation */
374-
bound_min=datumCopy(bound_min,prel->attbyval,prel->attlen);
375-
bound_max=datumCopy(bound_max,prel->attbyval,prel->attlen);
374+
bound_max=CopyBound(&ranges[PrelLastChild(prel)].max,
375+
prel->attbyval,
376+
prel->attlen);
376377

377378
/* Check if interval is set */
378379
if (isnull[Anum_pathman_config_range_interval-1])
379380
{
380381
elog(ERROR,
381-
"Could not find appropriate partition for key '%s'",
382+
"cannot find appropriate partition for key '%s'",
382383
datum_to_cstring(value,value_type));
383384
}
384385

@@ -392,7 +393,7 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
392393

393394
/* At last, spawn partitions to store the value */
394395
partid=spawn_partitions_val(PrelParentRelid(prel),
395-
bound_min,bound_max,base_bound_type,
396+
&bound_min,&bound_max,base_bound_type,
396397
interval_binary,interval_type,
397398
value,base_value_type);
398399
}
@@ -455,14 +456,14 @@ extract_op_func_and_ret_type(char *opname, Oid type1, Oid type2,
455456
* it into account while searching for the 'cmp_proc'.
456457
*/
457458
staticOid
458-
spawn_partitions_val(Oidparent_relid,/* parent's Oid */
459-
Datumrange_bound_min,/* parent's MIN boundary */
460-
Datumrange_bound_max,/* parent's MAX boundary */
461-
Oidrange_bound_type,/* type of boundary's value */
462-
Datuminterval_binary,/* interval in binary form */
463-
Oidinterval_type,/* INTERVALOID or prel->atttype */
464-
Datumvalue,/* value to be INSERTed */
465-
Oidvalue_type)/* type of value */
459+
spawn_partitions_val(Oidparent_relid,/* parent's Oid */
460+
constBound*range_bound_min,/* parent's MIN boundary */
461+
constBound*range_bound_max,/* parent's MAX boundary */
462+
Oidrange_bound_type,/* type of boundary's value */
463+
Datuminterval_binary,/* interval in binary form */
464+
Oidinterval_type,/* INTERVALOID or prel->atttype */
465+
Datumvalue,/* value to be INSERTed */
466+
Oidvalue_type)/* type of value */
466467
{
467468
boolshould_append;/* append or prepend? */
468469

@@ -475,27 +476,37 @@ spawn_partitions_val(Oid parent_relid,/* parent's Oid */
475476
Datumcur_leading_bound,/* boundaries of a new partition */
476477
cur_following_bound;
477478

479+
Boundvalue_bound=MakeBound(value);
480+
478481
Oidlast_partition=InvalidOid;
479482

480483

481484
fill_type_cmp_fmgr_info(&cmp_value_bound_finfo,value_type,range_bound_type);
482485

486+
/* Is it possible to append\prepend a partition? */
487+
if (IsInfinite(range_bound_min)&&IsInfinite(range_bound_max))
488+
ereport(ERROR, (errmsg("cannot spawn a partition"),
489+
errdetail("both bounds are infinite")));
490+
483491
/* value >= MAX_BOUNDARY */
484-
if (check_ge(&cmp_value_bound_finfo,value,range_bound_max))
492+
elseif (cmp_bounds(&cmp_value_bound_finfo,
493+
&value_bound,range_bound_max) >=0)
485494
{
486495
should_append= true;
487-
cur_leading_bound=range_bound_max;
496+
cur_leading_bound=BoundGetValue(range_bound_max);
488497
}
489498

490499
/* value < MIN_BOUNDARY */
491-
elseif (check_lt(&cmp_value_bound_finfo,value,range_bound_min))
500+
elseif (cmp_bounds(&cmp_value_bound_finfo,
501+
&value_bound,range_bound_min)<0)
492502
{
493503
should_append= false;
494-
cur_leading_bound=range_bound_min;
504+
cur_leading_bound=BoundGetValue(range_bound_min);
495505
}
496506

497507
/* There's a gap, halt and emit ERROR */
498-
elseelog(ERROR,"cannot spawn a partition inside a gap");
508+
elseereport(ERROR, (errmsg("cannot spawn a partition"),
509+
errdetail("there is a gap")));
499510

500511
/* Fetch operator's underlying function and ret type */
501512
extract_op_func_and_ret_type(should_append ?"+" :"-",
@@ -541,7 +552,6 @@ spawn_partitions_val(Oid parent_relid,/* parent's Oid */
541552
check_ge(&cmp_value_bound_finfo,value,cur_leading_bound) :
542553
check_lt(&cmp_value_bound_finfo,value,cur_leading_bound))
543554
{
544-
Datumargs[2];
545555
Boundbounds[2];
546556

547557
/* Assign the 'following' boundary to current 'leading' value */
@@ -552,11 +562,8 @@ spawn_partitions_val(Oid parent_relid,/* parent's Oid */
552562
cur_leading_bound,
553563
interval_binary);
554564

555-
args[0]=should_append ?cur_following_bound :cur_leading_bound;
556-
args[1]=should_append ?cur_leading_bound :cur_following_bound;
557-
558-
MakeBound(&bounds[0],args[0],FINITE);
559-
MakeBound(&bounds[1],args[1],FINITE);
565+
bounds[0]=MakeBound(should_append ?cur_following_bound :cur_leading_bound);
566+
bounds[1]=MakeBound(should_append ?cur_leading_bound :cur_following_bound);
560567

561568
last_partition=create_single_range_partition_internal(parent_relid,
562569
&bounds[0],&bounds[1],
@@ -1143,7 +1150,7 @@ build_raw_range_check_tree(char *attname,
11431150
}
11441151

11451152
if (and_oper->args==NIL)
1146-
elog(ERROR,"Cannot create infinite range constraint");
1153+
elog(ERROR,"cannot create infinite range constraint");
11471154

11481155
return (Node*)and_oper;
11491156
}
@@ -1207,39 +1214,23 @@ check_range_available(Oid parent_relid,
12071214
{
12081215
intc1,c2;
12091216

1210-
/*
1211-
* If the range we're checking starts with minus infinity or current
1212-
* range ends in plus infinity then the left boundary of the first
1213-
* range is on the left. Otherwise compare specific values
1214-
*/
1215-
// c1 = (IsInfinite(start) || IsInfinite(&ranges[i].max)) ?
1216-
// -1 :
1217-
// FunctionCall2(&cmp_func,
1218-
// BoundGetValue(start),
1219-
// BoundGetValue(&ranges[i].max));
1220-
/*
1221-
* Similary check that right boundary of the range we're checking is on
1222-
* the right of the beginning of the current one
1223-
*/
1224-
// c2 = (IsInfinite(end) || IsInfinite(&ranges[i].min)) ?
1225-
// 1 :
1226-
// FunctionCall2(&cmp_func,
1227-
// BoundGetValue(end),
1228-
// BoundGetValue(&ranges[i].min));
1229-
12301217
c1=cmp_bounds(&cmp_func,start,&ranges[i].max);
12311218
c2=cmp_bounds(&cmp_func,end,&ranges[i].min);
12321219

1233-
/* There'ssomeone! */
1220+
/* There'ssomething! */
12341221
if (c1<0&&c2>0)
12351222
{
12361223
if (raise_error)
12371224
elog(ERROR,"specified range [%s, %s) overlaps "
12381225
"with existing partitions",
1239-
!IsInfinite(start) ?datum_to_cstring(BoundGetValue(start),value_type) :"NULL",
1240-
!IsInfinite(end) ?datum_to_cstring(BoundGetValue(end),value_type) :"NULL");
1241-
else
1242-
return false;
1226+
!IsInfinite(start) ?
1227+
datum_to_cstring(BoundGetValue(start),value_type) :
1228+
"NULL",
1229+
!IsInfinite(end) ?
1230+
datum_to_cstring(BoundGetValue(end),value_type) :
1231+
"NULL");
1232+
1233+
elsereturn false;
12431234
}
12441235
}
12451236

‎src/pl_funcs.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,11 @@ get_attribute_type_pl(PG_FUNCTION_ARGS)
235235
Datum
236236
get_partition_key_type(PG_FUNCTION_ARGS)
237237
{
238-
Oidrelid=PG_GETARG_OID(0);
239-
constPartRelationInfo*prel=get_pathman_relation_info(relid);
238+
Oidrelid=PG_GETARG_OID(0);
239+
constPartRelationInfo*prel;
240240

241-
if (!prel)
242-
elog(ERROR,
243-
"Relation '%s' isn't partitioned by pg_pathman",
244-
get_rel_name(relid));
241+
prel=get_pathman_relation_info(relid);
242+
shout_if_prel_is_invalid(relid,prel,PT_INDIFFERENT);
245243

246244
PG_RETURN_OID(prel->atttype);
247245
}
@@ -420,15 +418,17 @@ show_partition_list_internal(PG_FUNCTION_ARGS)
420418

421419
/* Lower bound text */
422420
rmin= !IsInfinite(&re->min) ?
423-
CStringGetTextDatum(
424-
datum_to_cstring(BoundGetValue(&re->min),prel->atttype)) :
425-
CStringGetTextDatum("NULL");
421+
CStringGetTextDatum(
422+
datum_to_cstring(BoundGetValue(&re->min),
423+
prel->atttype)) :
424+
CStringGetTextDatum("NULL");
426425

427426
/* Upper bound text */
428427
rmax= !IsInfinite(&re->max) ?
429-
CStringGetTextDatum(
430-
datum_to_cstring(BoundGetValue(&re->max),prel->atttype)) :
431-
CStringGetTextDatum("NULL");
428+
CStringGetTextDatum(
429+
datum_to_cstring(BoundGetValue(&re->max),
430+
prel->atttype)) :
431+
CStringGetTextDatum("NULL");
432432

433433
values[Anum_pathman_pl_partition-1]=re->child_oid;
434434
values[Anum_pathman_pl_range_min-1]=rmin;
@@ -843,8 +843,6 @@ invoke_on_partition_created_callback(PG_FUNCTION_ARGS)
843843

844844
case5:
845845
{
846-
// Datumsv_datum,
847-
// ev_datum;
848846
Boundstart,
849847
end;
850848
Oidvalue_type;
@@ -853,15 +851,15 @@ invoke_on_partition_created_callback(PG_FUNCTION_ARGS)
853851
elog(ERROR,"both bounds must be provided for RANGE partition");
854852

855853
/* Fetch start & end values for RANGE + their type */
856-
// sv_datum= PG_GETARG_DATUM(ARG_RANGE_START);
857-
// ev_datum= PG_GETARG_DATUM(ARG_RANGE_END);
858-
MakeBound(&start,
859-
PG_GETARG_DATUM(ARG_RANGE_START),
860-
PG_ARGISNULL(ARG_RANGE_START) ?MINUS_INFINITY :FINITE);
861-
MakeBound(&end,
862-
PG_GETARG_DATUM(ARG_RANGE_END),
863-
PG_ARGISNULL(ARG_RANGE_END) ?PLUS_INFINITY :FINITE);
864-
value_type=get_fn_expr_argtype(fcinfo->flinfo,ARG_RANGE_START);
854+
start=PG_ARGISNULL(ARG_RANGE_START) ?
855+
MakeBoundInf(MINUS_INFINITY) :
856+
MakeBound(PG_GETARG_DATUM(ARG_RANGE_START));
857+
858+
end=PG_ARGISNULL(ARG_RANGE_END) ?
859+
MakeBoundInf(PLUS_INFINITY) :
860+
MakeBound(PG_GETARG_DATUM(ARG_RANGE_END));
861+
862+
value_type=get_fn_expr_argtype(fcinfo->flinfo,ARG_RANGE_START);
865863

866864
MakeInitCallbackRangeParams(&callback_params,
867865
callback_oid,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp