Skip to content

Commit e23663c

Browse files
committed
introduce function shout_if_prel_is_invalid(), fixes
1 parent e5ad134 commit e23663c

File tree

6 files changed

+74
-50
lines changed

6 files changed

+74
-50
lines changed

src/init.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,10 @@ init_pathman_relation_oids(void)
155155

156156
/* Cache PATHMAN_CONFIG relation's Oid */
157157
pathman_config_relid = get_relname_relid(PATHMAN_CONFIG, schema);
158-
/* NOTE: add more relations to be cached right here ^^^ */
159-
160-
/* Return false if *any* relation doesn't exist yet */
161158
if (pathman_config_relid == InvalidOid)
162-
{
163159
return false;
164-
}
160+
161+
/* NOTE: add more relations to be cached right here ^^^ */
165162

166163
/* Everything is fine, proceed */
167164
return true;

src/pg_pathman.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,11 @@ create_partitions_internal(Oid relid, Datum value, Oid value_type)
813813
Datum values[Natts_pathman_config];
814814
bool isnull[Natts_pathman_config];
815815

816+
prel = get_pathman_relation_info(relid);
817+
shout_if_prel_is_invalid(relid, prel, PT_RANGE);
818+
816819
/* Get both PartRelationInfo & PATHMAN_CONFIG contents for this relation */
817-
if ((prel = get_pathman_relation_info(relid)) != NULL &&
818-
pathman_config_contains_relation(relid, values, isnull, NULL))
820+
if (pathman_config_contains_relation(relid, values, isnull, NULL))
819821
{
820822
Datum min_rvalue,
821823
max_rvalue;
@@ -827,10 +829,6 @@ create_partitions_internal(Oid relid, Datum value, Oid value_type)
827829

828830
FmgrInfo interval_type_cmp;
829831

830-
if (prel->parttype != PT_RANGE)
831-
elog(ERROR, "Relation \"%s\" is not partitioned by RANGE",
832-
get_rel_name_or_relid(relid));
833-
834832
/* Fill the FmgrInfo struct with a cmp(value, part_attribute) function */
835833
fill_type_cmp_fmgr_info(&interval_type_cmp, value_type, prel->atttype);
836834

@@ -892,7 +890,7 @@ create_partitions_internal(Oid relid, Datum value, Oid value_type)
892890
SPI_finish(); /* close SPI connection */
893891
}
894892
else
895-
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
893+
elog(ERROR, "pg_pathman's config does not contain relation \"%s\"",
896894
get_rel_name_or_relid(relid));
897895
}
898896
PG_CATCH();
@@ -931,7 +929,8 @@ create_partitions(Oid relid, Datum value, Oid value_type)
931929
if (pathman_config_contains_relation(relid, NULL, NULL, &rel_xmin))
932930
{
933931
/* If table was partitioned in some previous xact, run BGWorker */
934-
if (TransactionIdPrecedes(rel_xmin, GetCurrentTransactionId()))
932+
if (TransactionIdPrecedes(rel_xmin, GetCurrentTransactionId()) ||
933+
TransactionIdEquals(rel_xmin, FrozenTransactionId))
935934
{
936935
elog(DEBUG2, "create_partitions(): chose BGW [%u]", MyProcPid);
937936
last_partition = create_partitions_bg_worker(relid, value, value_type);
@@ -1178,6 +1177,9 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
11781177
result);
11791178
return;
11801179
}
1180+
1181+
default:
1182+
elog(ERROR, "Unknown partitioning type %u", prel->parttype);
11811183
}
11821184

11831185
result->rangeset = list_make1_irange(make_irange(0,

src/pl_funcs.c

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,12 @@ find_or_create_range_partition(PG_FUNCTION_ARGS)
180180
search_rangerel_result search_state;
181181

182182
prel = get_pathman_relation_info(parent_oid);
183-
184-
if (!prel)
185-
PG_RETURN_NULL();
183+
shout_if_prel_is_invalid(parent_oid, prel, PT_RANGE);
186184

187185
fill_type_cmp_fmgr_info(&cmp_func, value_type, prel->atttype);
188186

189-
/* FIXME: does this function even work? */
190-
search_state = search_range_partition_eq(value, &cmp_func,prel,
187+
/* Use available PartRelationInfo to find partition */
188+
search_state = search_range_partition_eq(value, &cmp_func, prel,
191189
&found_rentry);
192190

193191
/*
@@ -246,9 +244,7 @@ get_range_by_part_oid(PG_FUNCTION_ARGS)
246244
const PartRelationInfo *prel;
247245

248246
prel = get_pathman_relation_info(parent_oid);
249-
if (!prel)
250-
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
251-
get_rel_name_or_relid(parent_oid));
247+
shout_if_prel_is_invalid(parent_oid, prel, PT_RANGE);
252248

253249
ranges = PrelGetRangesArray(prel);
254250

@@ -266,6 +262,7 @@ get_range_by_part_oid(PG_FUNCTION_ARGS)
266262
PG_RETURN_ARRAYTYPE_P(arr);
267263
}
268264

265+
/* No partition found, report error */
269266
elog(ERROR, "Relation \"%s\" has no partition \"%s\"",
270267
get_rel_name_or_relid(parent_oid),
271268
get_rel_name_or_relid(child_oid));
@@ -290,9 +287,7 @@ get_range_by_idx(PG_FUNCTION_ARGS)
290287
const PartRelationInfo *prel;
291288

292289
prel = get_pathman_relation_info(parent_oid);
293-
if (!prel)
294-
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
295-
get_rel_name_or_relid(parent_oid));
290+
shout_if_prel_is_invalid(parent_oid, prel, PT_RANGE);
296291

297292
if (((uint32) abs(idx)) >= PrelChildrenCount(prel))
298293
elog(ERROR, "Partition #%d does not exist (total amount is %u)",
@@ -326,14 +321,7 @@ get_min_range_value(PG_FUNCTION_ARGS)
326321
const PartRelationInfo *prel;
327322

328323
prel = get_pathman_relation_info(parent_oid);
329-
if (!prel)
330-
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
331-
get_rel_name_or_relid(parent_oid));
332-
333-
if (prel->parttype != PT_RANGE)
334-
if (!prel)
335-
elog(ERROR, "Relation \"%s\" is not partitioned by RANGE",
336-
get_rel_name_or_relid(parent_oid));
324+
shout_if_prel_is_invalid(parent_oid, prel, PT_RANGE);
337325

338326
ranges = PrelGetRangesArray(prel);
339327

@@ -351,14 +339,7 @@ get_max_range_value(PG_FUNCTION_ARGS)
351339
const PartRelationInfo *prel;
352340

353341
prel = get_pathman_relation_info(parent_oid);
354-
if (!prel)
355-
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
356-
get_rel_name_or_relid(parent_oid));
357-
358-
if (prel->parttype != PT_RANGE)
359-
if (!prel)
360-
elog(ERROR, "Relation \"%s\" is not partitioned by RANGE",
361-
get_rel_name_or_relid(parent_oid));
342+
shout_if_prel_is_invalid(parent_oid, prel, PT_RANGE);
362343

363344
ranges = PrelGetRangesArray(prel);
364345

@@ -388,14 +369,7 @@ check_overlap(PG_FUNCTION_ARGS)
388369
const PartRelationInfo *prel;
389370

390371
prel = get_pathman_relation_info(parent_oid);
391-
if (!prel)
392-
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
393-
get_rel_name_or_relid(parent_oid));
394-
395-
if (prel->parttype != PT_RANGE)
396-
if (!prel)
397-
elog(ERROR, "Relation \"%s\" is not partitioned by RANGE",
398-
get_rel_name_or_relid(parent_oid));
372+
shout_if_prel_is_invalid(parent_oid, prel, PT_RANGE);
399373

400374
/* comparison functions */
401375
fill_type_cmp_fmgr_info(&cmp_func_1, p1_type, prel->atttype);

src/relation_info.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020

2121
/*
22-
* Partitioning type
22+
* Partitioning type.
2323
*/
2424
typedef enum
2525
{
26-
PT_HASH = 1,
26+
PT_INDIFFERENT = 0, /* for part type traits (virtual type) */
27+
PT_HASH,
2728
PT_RANGE
2829
} PartType;
2930

src/utils.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,53 @@ is_string_type_internal(Oid typid)
711711
typid == CSTRINGOID;
712712
}
713713

714+
/*
715+
* Common PartRelationInfo checks. Emit ERROR if anything is wrong.
716+
*/
717+
void
718+
shout_if_prel_is_invalid(Oid parent_oid,
719+
const PartRelationInfo *prel,
720+
PartType expected_part_type)
721+
{
722+
if (!prel)
723+
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
724+
get_rel_name_or_relid(parent_oid));
725+
726+
if (!PrelIsValid(prel))
727+
elog(ERROR, "pg_pathman's cache contains invalid entry "
728+
"for relation \"%s\" [%u]",
729+
get_rel_name_or_relid(parent_oid),
730+
MyProcPid);
731+
732+
/* Check partitioning type unless it's "indifferent" */
733+
if (expected_part_type != PT_INDIFFERENT &&
734+
expected_part_type != prel->parttype)
735+
{
736+
char *expected_str;
737+
738+
switch (expected_part_type)
739+
{
740+
case PT_HASH:
741+
expected_str = "HASH";
742+
break;
743+
744+
case PT_RANGE:
745+
expected_str = "RANGE";
746+
break;
747+
748+
default:
749+
elog(ERROR,
750+
"expected_str selection not implemented for type %d",
751+
expected_part_type);
752+
}
753+
754+
elog(ERROR, "Relation \"%s\" is not partitioned by %s",
755+
get_rel_name_or_relid(parent_oid),
756+
expected_str);
757+
}
758+
}
759+
760+
714761
/*
715762
* Try to find binary operator.
716763
*

src/utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ bool is_string_type_internal(Oid typid);
5555
bool check_rinfo_for_partitioned_attr(List *rinfo,
5656
Index varno,
5757
AttrNumber varattno);
58+
void shout_if_prel_is_invalid(Oid parent_oid,
59+
const PartRelationInfo *prel,
60+
PartType expected_part_type);
5861

5962
/*
6063
* Misc.

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