Skip to content

Commit a27dfd6

Browse files
committed
small adjustments to error messages + more locks
1 parent 1167351 commit a27dfd6

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

expected/pathman_expressions.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SELECT create_hash_partitions('test_exprs.hash_rel', 'random()', 4);
2020
ERROR: functions in partitioning expression must be marked IMMUTABLE
2121
\set VERBOSITY default
2222
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2))', 4);
23-
ERROR: partitioning expression parse error
23+
ERROR: failed to parse partitioning expression
2424
DETAIL: syntax error at or near ")"
2525
QUERY: SELECT public.validate_expression(parent_relid, expression)
2626
CONTEXT: PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
@@ -29,7 +29,7 @@ SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
2929
partition_data)"
3030
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
3131
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value3', 4);
32-
ERROR: partitioning expression analyze error
32+
ERROR: failed to analyze partitioning expression
3333
DETAIL: column "value3" does not exist
3434
HINT: Perhaps you meant to reference the column "hash_rel.value" or the column "hash_rel.value2".
3535
QUERY: SELECT public.validate_expression(parent_relid, expression)

src/pl_funcs.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,9 @@ validate_relname(PG_FUNCTION_ARGS)
597597
}
598598

599599
/*
600-
* Validate a partitioning expression
601-
* We need this in range functions because we do many things
602-
* before actual partitioning.
600+
* Validate a partitioning expression.
601+
* NOTE: We need this in range functions because
602+
* we do many things before actual partitioning.
603603
*/
604604
Datum
605605
validate_expression(PG_FUNCTION_ARGS)
@@ -610,6 +610,9 @@ validate_expression(PG_FUNCTION_ARGS)
610610
/* Fetch relation's Oid */
611611
relid = PG_GETARG_OID(0);
612612

613+
/* Protect relation from concurrent drop */
614+
LockRelationOid(relid, AccessShareLock);
615+
613616
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(relid)))
614617
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
615618
errmsg("relation \"%u\" does not exist", relid),
@@ -623,7 +626,11 @@ validate_expression(PG_FUNCTION_ARGS)
623626
else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
624627
errmsg("'expression' should not be NULL")));
625628

629+
/* Perform some checks */
626630
cook_partitioning_expression(relid, expression, NULL);
631+
632+
UnlockRelationOid(relid, AccessShareLock);
633+
627634
PG_RETURN_VOID();
628635
}
629636

@@ -763,7 +770,7 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
763770
else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
764771
errmsg("'parent_relid' should not be NULL")));
765772

766-
/* Lock relation */
773+
/* Protect relation from concurrent modification */
767774
xact_lock_rel_exclusive(relid, true);
768775

769776
/* Check that relation exists */

src/relation_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ parse_partitioning_expression(const Oid relid,
592592
FlushErrorState();
593593

594594
error->detail = error->message;
595-
error->message = "partitioning expression parse error";
595+
error->message = "failed to parse partitioning expression";
596596
error->sqlerrcode = ERRCODE_INVALID_PARAMETER_VALUE;
597597
error->cursorpos = 0;
598598
error->internalpos = 0;
@@ -700,7 +700,7 @@ cook_partitioning_expression(const Oid relid,
700700
FlushErrorState();
701701

702702
error->detail = error->message;
703-
error->message = "partitioning expression analyze error";
703+
error->message = "failed to analyze partitioning expression";
704704
error->sqlerrcode = ERRCODE_INVALID_PARAMETER_VALUE;
705705
error->cursorpos = 0;
706706
error->internalpos = 0;

0 commit comments

Comments
 (0)