Skip to content

Commit 05caed2

Browse files
committed
clean code, remove function get_attribute_type_pl(), small fixes
1 parent d98e1af commit 05caed2

File tree

10 files changed

+309
-336
lines changed

10 files changed

+309
-336
lines changed

expected/pathman_basic.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,9 +1610,9 @@ NOTICE: sequence "zero_seq" does not exist, skipping
16101610
(1 row)
16111611

16121612
SELECT pathman.append_range_partition('test.zero', 'test.zero_0');
1613-
ERROR: cannot append to empty partitions set
1613+
ERROR: relation "zero" has no partitions
16141614
SELECT pathman.prepend_range_partition('test.zero', 'test.zero_1');
1615-
ERROR: cannot prepend to empty partitions set
1615+
ERROR: relation "zero" has no partitions
16161616
SELECT pathman.add_range_partition('test.zero', 50, 70, 'test.zero_50');
16171617
add_range_partition
16181618
---------------------

expected/pathman_calamity.out

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,26 +230,12 @@ SELECT get_base_type(NULL) IS NULL;
230230
t
231231
(1 row)
232232

233-
/* check function get_attribute_type() */
234-
SELECT get_attribute_type('calamity.part_test', 'val');
235-
get_attribute_type
236-
--------------------
237-
integer
238-
(1 row)
239-
240-
SELECT get_attribute_type('calamity.part_test', NULL) IS NULL;
241-
?column?
242-
----------
243-
t
244-
(1 row)
245-
246-
SELECT get_attribute_type(NULL, 'val') IS NULL;
247-
?column?
248-
----------
249-
t
250-
(1 row)
251-
252-
SELECT get_attribute_type(NULL, NULL) IS NULL;
233+
/* check function get_partition_key_type() */
234+
SELECT get_partition_key_type('calamity.part_test');
235+
ERROR: relation "part_test" has no partitions
236+
SELECT get_partition_key_type(0::regclass);
237+
ERROR: relation "0" has no partitions
238+
SELECT get_partition_key_type(NULL) IS NULL;
253239
?column?
254240
----------
255241
t

hash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ BEGIN
261261
quote_ident(plain_relname || '_%s');
262262

263263
/* Fetch base hash function for atttype */
264-
atttype := @extschema@.get_attribute_type(parent_relid, attr);
264+
atttype := @extschema@.get_partition_key_type(parent_relid);
265265

266266
/* Format function definition and execute it */
267267
EXECUTE format(func, funcname, attr, partitions_count, att_val_fmt,

init.sql

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,6 @@ CREATE OR REPLACE FUNCTION @extschema@.get_base_type(
704704
RETURNS REGTYPE AS 'pg_pathman', 'get_base_type_pl'
705705
LANGUAGE C STRICT;
706706

707-
/*
708-
* Returns attribute type name for relation.
709-
*/
710-
CREATE OR REPLACE FUNCTION @extschema@.get_attribute_type(
711-
relid REGCLASS,
712-
attname TEXT)
713-
RETURNS REGTYPE AS 'pg_pathman', 'get_attribute_type_pl'
714-
LANGUAGE C STRICT;
715-
716707
/*
717708
* Return partition key type
718709
*/

range.sql

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -488,22 +488,18 @@ BEGIN
488488
/* Acquire data modification lock (prevent further modifications) */
489489
PERFORM @extschema@.prevent_relation_modification(partition_relid);
490490

491+
v_atttype = @extschema@.get_partition_key_type(v_parent);
492+
491493
SELECT attname, parttype
492494
FROM @extschema@.pathman_config
493495
WHERE partrel = v_parent
494496
INTO v_attname, v_part_type;
495497

496-
IF v_attname IS NULL THEN
497-
RAISE EXCEPTION 'table "%" is not partitioned', v_parent::TEXT;
498-
END IF;
499-
500498
/* Check if this is a RANGE partition */
501499
IF v_part_type != 2 THEN
502500
RAISE EXCEPTION '"%" is not a RANGE partition', partition_relid::TEXT;
503501
END IF;
504502

505-
v_atttype = @extschema@.get_attribute_type(v_parent, v_attname);
506-
507503
/* Get partition values range */
508504
EXECUTE format('SELECT @extschema@.get_part_range($1, NULL::%s)',
509505
@extschema@.get_base_type(v_atttype)::TEXT)
@@ -589,7 +585,6 @@ CREATE OR REPLACE FUNCTION @extschema@.append_range_partition(
589585
RETURNS TEXT AS
590586
$$
591587
DECLARE
592-
v_attname TEXT;
593588
v_atttype REGTYPE;
594589
v_part_name TEXT;
595590
v_interval TEXT;
@@ -600,16 +595,12 @@ BEGIN
600595
/* Acquire lock on parent */
601596
PERFORM @extschema@.lock_partitioned_relation(parent_relid);
602597

603-
SELECT attname, range_interval
598+
v_atttype := @extschema@.get_partition_key_type(parent_relid);
599+
600+
SELECT range_interval
604601
FROM @extschema@.pathman_config
605602
WHERE partrel = parent_relid
606-
INTO v_attname, v_interval;
607-
608-
IF v_attname IS NULL THEN
609-
RAISE EXCEPTION 'table "%" is not partitioned', parent_relid::TEXT;
610-
END IF;
611-
612-
v_atttype := @extschema@.get_attribute_type(parent_relid, v_attname);
603+
INTO v_interval;
613604

614605
EXECUTE
615606
format('SELECT @extschema@.append_partition_internal($1, $2, $3, ARRAY[]::%s[], $4, $5)',
@@ -700,7 +691,6 @@ CREATE OR REPLACE FUNCTION @extschema@.prepend_range_partition(
700691
RETURNS TEXT AS
701692
$$
702693
DECLARE
703-
v_attname TEXT;
704694
v_atttype REGTYPE;
705695
v_part_name TEXT;
706696
v_interval TEXT;
@@ -711,16 +701,12 @@ BEGIN
711701
/* Acquire lock on parent */
712702
PERFORM @extschema@.lock_partitioned_relation(parent_relid);
713703

714-
SELECT attname, range_interval
704+
v_atttype := @extschema@.get_partition_key_type(parent_relid);
705+
706+
SELECT range_interval
715707
FROM @extschema@.pathman_config
716708
WHERE partrel = parent_relid
717-
INTO v_attname, v_interval;
718-
719-
IF v_attname IS NULL THEN
720-
RAISE EXCEPTION 'table "%" is not partitioned', parent_relid::TEXT;
721-
END IF;
722-
723-
v_atttype := @extschema@.get_attribute_type(parent_relid, v_attname);
709+
INTO v_interval;
724710

725711
EXECUTE
726712
format('SELECT @extschema@.prepend_partition_internal($1, $2, $3, ARRAY[]::%s[], $4, $5)',

sql/pathman_calamity.sql

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ SELECT get_base_type('int4'::regtype);
7777
SELECT get_base_type('calamity.test_domain'::regtype);
7878
SELECT get_base_type(NULL) IS NULL;
7979

80-
/* check function get_attribute_type() */
81-
SELECT get_attribute_type('calamity.part_test', 'val');
82-
SELECT get_attribute_type('calamity.part_test', NULL) IS NULL;
83-
SELECT get_attribute_type(NULL, 'val') IS NULL;
84-
SELECT get_attribute_type(NULL, NULL) IS NULL;
80+
/* check function get_partition_key_type() */
81+
SELECT get_partition_key_type('calamity.part_test');
82+
SELECT get_partition_key_type(0::regclass);
83+
SELECT get_partition_key_type(NULL) IS NULL;
8584

8685
/* check function build_check_constraint_name_attnum() */
8786
SELECT build_check_constraint_name('calamity.part_test', 1::int2);

src/partition_creation.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,10 +1511,6 @@ invoke_init_callback_internal(init_callback_params *cb_params)
15111511
ev_datum = cb_params->params.range_params.end_value;
15121512
Oid type = cb_params->params.range_params.value_type;
15131513

1514-
/* Convert min & max to CSTRING */
1515-
// start_value = datum_to_cstring(sv_datum, type);
1516-
// end_value = datum_to_cstring(ev_datum, type);
1517-
15181514
pushJsonbValue(&jsonb_state, WJB_BEGIN_OBJECT, NULL);
15191515

15201516
JSB_INIT_VAL(&key, WJB_KEY, "parent");
@@ -1532,6 +1528,7 @@ invoke_init_callback_internal(init_callback_params *cb_params)
15321528
JSB_INIT_VAL(&key, WJB_KEY, "range_min");
15331529
if (!IsInfinite(&sv_datum))
15341530
{
1531+
/* Convert min to CSTRING */
15351532
start_value = datum_to_cstring(BoundGetValue(&sv_datum), type);
15361533
JSB_INIT_VAL(&val, WJB_VALUE, start_value);
15371534
}
@@ -1542,12 +1539,12 @@ invoke_init_callback_internal(init_callback_params *cb_params)
15421539
JSB_INIT_VAL(&key, WJB_KEY, "range_max");
15431540
if (!IsInfinite(&ev_datum))
15441541
{
1542+
/* Convert max to CSTRING */
15451543
end_value = datum_to_cstring(BoundGetValue(&ev_datum), type);
15461544
JSB_INIT_VAL(&val, WJB_VALUE, end_value);
15471545
}
15481546
else
15491547
JSB_INIT_NULL_VAL(&val, WJB_VALUE);
1550-
// JSB_INIT_VAL(&val, WJB_VALUE, end_value);
15511548

15521549
result = pushJsonbValue(&jsonb_state, WJB_END_OBJECT, NULL);
15531550
}

src/pg_pathman.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,14 @@ select_range_partitions(const Datum value,
536536

537537
current_re = &ranges[i];
538538

539-
// cmp_min = FunctionCall2(cmp_func, value, current_re->min);
540-
// cmp_max = FunctionCall2(cmp_func, value, current_re->max);
541539
cmp_min = IsInfinite(&current_re->min) ?
542-
1 : FunctionCall2(cmp_func, value, BoundGetValue(&current_re->min));
540+
1 :
541+
FunctionCall2(cmp_func, value,
542+
BoundGetValue(&current_re->min));
543543
cmp_max = IsInfinite(&current_re->max) ?
544-
-1 : FunctionCall2(cmp_func, value, BoundGetValue(&current_re->max));
544+
-1 :
545+
FunctionCall2(cmp_func, value,
546+
BoundGetValue(&current_re->max));
545547

546548
is_less = (cmp_min < 0 || (cmp_min == 0 && strategy == BTLessStrategyNumber));
547549
is_greater = (cmp_max > 0 || (cmp_max >= 0 && strategy != BTLessStrategyNumber));

src/pl_funcs.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,6 @@ get_base_type_pl(PG_FUNCTION_ARGS)
217217
PG_RETURN_OID(getBaseType(PG_GETARG_OID(0)));
218218
}
219219

220-
/*
221-
* Get type (as REGTYPE) of a given attribute.
222-
*/
223-
Datum
224-
get_attribute_type_pl(PG_FUNCTION_ARGS)
225-
{
226-
Oid relid = PG_GETARG_OID(0);
227-
text *attname = PG_GETARG_TEXT_P(1);
228-
229-
PG_RETURN_OID(get_attribute_type(relid, text_to_cstring(attname), false));
230-
}
231-
232220
/*
233221
* Return partition key type
234222
*/

0 commit comments

Comments
 (0)