Skip to content

Commit f3ee021

Browse files
committed
refactoring (static inline), introduce function WrongPartType()
1 parent 879dc1d commit f3ee021

File tree

6 files changed

+49
-54
lines changed

6 files changed

+49
-54
lines changed

src/include/relation_info.h

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,47 @@ void forget_bounds_of_partition(Oid partition);
308308
PartBoundInfo *get_bounds_of_partition(Oid partition,
309309
const PartRelationInfo *prel);
310310

311-
/* Safe casts for PartType */
312-
PartType DatumGetPartType(Datum datum);
313-
char *PartTypeToCString(PartType parttype);
311+
/* PartType wrappers */
312+
313+
static inline void
314+
WrongPartType(PartType parttype)
315+
{
316+
elog(ERROR, "Unknown partitioning type %u", parttype);
317+
}
318+
319+
static inline PartType
320+
DatumGetPartType(Datum datum)
321+
{
322+
uint32 parttype = DatumGetUInt32(datum);
323+
324+
if (parttype < 1 || parttype > 2)
325+
WrongPartType(parttype);
326+
327+
return (PartType) parttype;
328+
}
329+
330+
static inline char *
331+
PartTypeToCString(PartType parttype)
332+
{
333+
static char *hash_str = "1",
334+
*range_str = "2";
335+
336+
switch (parttype)
337+
{
338+
case PT_HASH:
339+
return hash_str;
340+
341+
case PT_RANGE:
342+
return range_str;
343+
344+
default:
345+
WrongPartType(parttype);
346+
return NULL; /* keep compiler happy */
347+
}
348+
}
349+
350+
351+
314352

315353
/* PartRelationInfo checker */
316354
void shout_if_prel_is_invalid(const Oid parent_oid,

src/partition_creation.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,7 @@ invoke_init_callback_internal(init_callback_params *cb_params)
15881588
break;
15891589

15901590
default:
1591-
elog(ERROR, "Unknown partitioning type %u", cb_params->parttype);
1592-
break;
1591+
WrongPartType(cb_params->parttype);
15931592
}
15941593

15951594
/* Fetch function call data */

src/pg_pathman.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,7 @@ handle_const(const Const *c, WalkerContext *context)
781781
break;
782782

783783
default:
784-
elog(ERROR, "Unknown partitioning type %u", prel->parttype);
785-
break;
784+
WrongPartType(prel->parttype);
786785
}
787786

788787
return result;
@@ -966,7 +965,7 @@ handle_arrexpr(const ScalarArrayOpExpr *expr, WalkerContext *context)
966965
break;
967966

968967
default:
969-
elog(ERROR, "Unknown partitioning type %u", prel->parttype);
968+
WrongPartType(prel->parttype);
970969
}
971970

972971
/* Free resources */
@@ -1100,7 +1099,7 @@ handle_binary_opexpr(const Const *c,
11001099
}
11011100

11021101
default:
1103-
elog(ERROR, "Unknown partitioning type %u", prel->parttype);
1102+
WrongPartType(prel->parttype);
11041103
}
11051104

11061105
binary_opexpr_return:

src/pl_funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ show_partition_list_internal(PG_FUNCTION_ARGS)
506506
break;
507507

508508
default:
509-
elog(ERROR, "Unknown partitioning type %u", prel->parttype);
509+
WrongPartType(prel->parttype);
510510
}
511511

512512
/* Fill tuptable */

src/rangeset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ irange_union_internal(IndexRange first,
162162
/* IndexRanges intersect */
163163
if (iranges_intersect(first, second))
164164
{
165-
/* Calculate the intersection of 'first' and 'second' */
165+
/* Calculate the union of 'first' and 'second' */
166166
IndexRange ir_union = irange_union_simple(first, second);
167167

168168
/* if lossiness is the same, unite them and skip */

src/relation_info.c

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,7 @@ fill_prel_with_partitions(PartRelationInfo *prel,
509509
default:
510510
{
511511
DisablePathman(); /* disable pg_pathman since config is broken */
512-
ereport(ERROR,
513-
(errmsg("Unknown partitioning type for relation \"%s\"",
514-
get_rel_name_or_relid(PrelParentRelid(prel))),
515-
errhint(INIT_ERROR_HINT)));
512+
WrongPartType(prel->parttype);
516513
}
517514
break;
518515
}
@@ -1243,10 +1240,7 @@ fill_pbin_with_bounds(PartBoundInfo *pbin,
12431240
default:
12441241
{
12451242
DisablePathman(); /* disable pg_pathman since config is broken */
1246-
ereport(ERROR,
1247-
(errmsg("Unknown partitioning type for relation \"%s\"",
1248-
get_rel_name_or_relid(PrelParentRelid(prel))),
1249-
errhint(INIT_ERROR_HINT)));
1243+
WrongPartType(prel->parttype);
12501244
}
12511245
break;
12521246
}
@@ -1264,41 +1258,6 @@ cmp_range_entries(const void *p1, const void *p2, void *arg)
12641258
}
12651259

12661260

1267-
/*
1268-
* Safe PartType wrapper.
1269-
*/
1270-
PartType
1271-
DatumGetPartType(Datum datum)
1272-
{
1273-
uint32 val = DatumGetUInt32(datum);
1274-
1275-
if (val < 1 || val > 2)
1276-
elog(ERROR, "Unknown partitioning type %u", val);
1277-
1278-
return (PartType) val;
1279-
}
1280-
1281-
char *
1282-
PartTypeToCString(PartType parttype)
1283-
{
1284-
static char *hash_str = "1",
1285-
*range_str = "2";
1286-
1287-
switch (parttype)
1288-
{
1289-
case PT_HASH:
1290-
return hash_str;
1291-
1292-
case PT_RANGE:
1293-
return range_str;
1294-
1295-
default:
1296-
elog(ERROR, "Unknown partitioning type %u", parttype);
1297-
return NULL; /* keep compiler happy */
1298-
}
1299-
}
1300-
1301-
13021261
/*
13031262
* Common PartRelationInfo checks. Emit ERROR if anything is wrong.
13041263
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy