Skip to content

Commit 7d31d32

Browse files
committed
print relation name instead of Oid whenever possible, new TODOs
1 parent 834db2d commit 7d31d32

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

range.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
* ------------------------------------------------------------------------
99
*/
1010

11-
CREATE OR REPLACE FUNCTION @extschema@.get_sequence_name(plain_schema TEXT, plain_relname TEXT)
11+
CREATE OR REPLACE FUNCTION @extschema@.get_sequence_name(
12+
plain_schema TEXT,
13+
plain_relname TEXT)
1214
RETURNS TEXT AS
1315
$$
1416
BEGIN
@@ -17,7 +19,10 @@ END
1719
$$
1820
LANGUAGE plpgsql;
1921

20-
CREATE OR REPLACE FUNCTION @extschema@.create_or_replace_sequence(plain_schema TEXT, plain_relname TEXT, OUT seq_name TEXT)
22+
CREATE OR REPLACE FUNCTION @extschema@.create_or_replace_sequence(
23+
plain_schema TEXT,
24+
plain_relname TEXT,
25+
OUT seq_name TEXT)
2126
AS $$
2227
BEGIN
2328
seq_name := @extschema@.get_sequence_name(plain_schema, plain_relname);

src/init.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ fill_prel_with_partitions(const Oid *partitions,
187187
prel->children[hash] = partitions[i];
188188
else
189189
elog(ERROR,
190-
"Wrong constraint format for HASH partition %u",
191-
partitions[i]);
190+
"Wrong constraint format for HASH partition \"%s\"",
191+
get_rel_name_or_relid(partitions[i]));
192192
}
193193
break;
194194

@@ -205,13 +205,14 @@ fill_prel_with_partitions(const Oid *partitions,
205205
}
206206
else
207207
elog(ERROR,
208-
"Wrong constraint format for RANGE partition %u",
209-
partitions[i]);
208+
"Wrong constraint format for RANGE partition \"%s\"",
209+
get_rel_name_or_relid(partitions[i]));
210210
}
211211
break;
212212

213213
default:
214-
elog(ERROR, "Unknown partitioning type for relation %u", prel->key);
214+
elog(ERROR, "Unknown partitioning type for relation \"%s\"",
215+
get_rel_name_or_relid(prel->key));
215216
}
216217
}
217218

@@ -237,8 +238,9 @@ fill_prel_with_partitions(const Oid *partitions,
237238
for (i = 0; i < PrelChildrenCount(prel); i++)
238239
{
239240
if (prel->children[i] == InvalidOid)
240-
elog(ERROR, "pg_pathman's cache for relation %u "
241-
"has not been properly initialized", prel->key);
241+
elog(ERROR, "pg_pathman's cache for relation \"%s\" "
242+
"has not been properly initialized",
243+
get_rel_name_or_relid(prel->key));
242244
}
243245
#endif
244246
}

src/pg_pathman.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ spawn_partitions(const PartRelationInfo *prel,
754754
/* ...and create partition */
755755
ret = SPI_execute_with_args(query, 3, types, values, nulls, false, 0);
756756
if (ret != SPI_OK_SELECT)
757-
elog(ERROR, "Could not create partition");
757+
elog(ERROR, "Could not spawn a partition");
758758

759759
/* Set 'last_partition' if necessary */
760760
if (last_partition)
@@ -877,7 +877,8 @@ create_partitions_internal(Oid relid, Datum value, Oid value_type)
877877
SPI_finish(); /* close SPI connection */
878878
}
879879
else
880-
elog(ERROR, "Relation %u is not partitioned by pg_pathman", relid);
880+
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
881+
get_rel_name_or_relid(relid));
881882
}
882883
PG_CATCH();
883884
{
@@ -928,7 +929,8 @@ create_partitions(Oid relid, Datum value, Oid value_type)
928929
}
929930
}
930931
else
931-
elog(ERROR, "Relation %u is not partitioned by pg_pathman", relid);
932+
elog(ERROR, "Relation \"%s\" is not partitioned by pg_pathman",
933+
get_rel_name_or_relid(relid));
932934

933935
/* Check that 'last_partition' is valid */
934936
if (last_partition == InvalidOid)

src/pl_funcs.c

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ get_range_by_idx(PG_FUNCTION_ARGS)
277277

278278
prel = get_pathman_relation_info(parent_oid);
279279
if (!prel)
280-
elog(ERROR, "Cannot get partitioning cache entry for relation %u", parent_oid);
280+
elog(ERROR, "Cannot get partitioning cache entry for relation \"%s\"",
281+
get_rel_name_or_relid(parent_oid));
281282

282283
if (((uint32) abs(idx)) >= PrelChildrenCount(prel))
283284
elog(ERROR, "Partition #%d does not exist (max is #%u)",
@@ -334,6 +335,7 @@ get_max_range_value(PG_FUNCTION_ARGS)
334335

335336
prel = get_pathman_relation_info(parent_oid);
336337

338+
/* TODO: separate all these checks, they look ugly together */
337339
if (!prel || prel->parttype != PT_RANGE || PrelChildrenCount(prel) == 0)
338340
PG_RETURN_NULL();
339341

@@ -392,6 +394,7 @@ check_overlap(PG_FUNCTION_ARGS)
392394
Datum
393395
acquire_partitions_lock(PG_FUNCTION_ARGS)
394396
{
397+
/* FIXME: have to find another way (shmem maybe?) */
395398
LWLockAcquire(pmstate->edit_partitions_lock, LW_EXCLUSIVE);
396399
PG_RETURN_NULL();
397400
}
@@ -426,6 +429,32 @@ get_hash(PG_FUNCTION_ARGS)
426429
PG_RETURN_UINT32(make_hash(value, part_count));
427430
}
428431

432+
Datum
433+
get_attribute_type_name(PG_FUNCTION_ARGS)
434+
{
435+
Oid relid = PG_GETARG_OID(0);
436+
text *attname = PG_GETARG_TEXT_P(1);
437+
char *result;
438+
HeapTuple tp;
439+
440+
/* NOTE: for now it's the most efficient way */
441+
tp = SearchSysCacheAttName(relid, text_to_cstring(attname));
442+
if (HeapTupleIsValid(tp))
443+
{
444+
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
445+
result = format_type_be(att_tup->atttypid);
446+
ReleaseSysCache(tp);
447+
448+
PG_RETURN_TEXT_P(cstring_to_text(result));
449+
}
450+
else
451+
elog(ERROR, "Cannot find type name for attribute \"%s\" "
452+
"of relation \"%s\"",
453+
text_to_cstring(attname), get_rel_name_or_relid(relid));
454+
455+
PG_RETURN_NULL(); /* keep compiler happy */
456+
}
457+
429458
Datum
430459
build_check_constraint_name_attnum(PG_FUNCTION_ARGS)
431460
{
@@ -459,8 +488,7 @@ build_check_constraint_name_attname(PG_FUNCTION_ARGS)
459488

460489
if (attnum == InvalidAttrNumber)
461490
elog(ERROR, "Relation \"%s\" has no column '%s'",
462-
get_rel_name_or_relid(relid),
463-
text_to_cstring(attname));
491+
get_rel_name_or_relid(relid), text_to_cstring(attname));
464492

465493
result = build_check_constraint_name_internal(relid, attnum);
466494

@@ -473,31 +501,6 @@ is_date_type(PG_FUNCTION_ARGS)
473501
PG_RETURN_BOOL(is_date_type_internal(PG_GETARG_OID(0)));
474502
}
475503

476-
Datum
477-
get_attribute_type_name(PG_FUNCTION_ARGS)
478-
{
479-
Oid relid = PG_GETARG_OID(0);
480-
text *attname = PG_GETARG_TEXT_P(1);
481-
char *result;
482-
HeapTuple tp;
483-
484-
tp = SearchSysCacheAttName(relid, text_to_cstring(attname));
485-
if (HeapTupleIsValid(tp))
486-
{
487-
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
488-
result = format_type_be(att_tup->atttypid);
489-
ReleaseSysCache(tp);
490-
491-
PG_RETURN_TEXT_P(cstring_to_text(result));
492-
}
493-
else
494-
elog(ERROR, "Cannot find type name for attribute \"%s\" "
495-
"of relation \"%s\"",
496-
text_to_cstring(attname), get_rel_name_or_relid(relid));
497-
498-
PG_RETURN_NULL(); /* keep compiler happy */
499-
}
500-
501504
Datum
502505
is_attribute_nullable(PG_FUNCTION_ARGS)
503506
{
@@ -522,7 +525,7 @@ is_attribute_nullable(PG_FUNCTION_ARGS)
522525
}
523526

524527
/*
525-
* DEBUG: set breakpoint here.
528+
* NOTE: used for DEBUG, set breakpoint here.
526529
*/
527530
Datum
528531
debug_capture(PG_FUNCTION_ARGS)

0 commit comments

Comments
 (0)