Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33d2cf7

Browse files
committed
reimplement functions validate_relname(), get_number_of_partitions() in C language, refactoring & code cleanup
1 parent000130d commit33d2cf7

File tree

9 files changed

+774
-736
lines changed

9 files changed

+774
-736
lines changed

‎expected/pathman_calamity.out

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,28 @@ set client_min_messages = NOTICE;
1414
CREATE TABLE calamity.part_test(val serial);
1515
/* check function validate_relname() */
1616
SELECT validate_relname('calamity.part_test');
17-
validate_relname
18-
--------------------
19-
calamity.part_test
17+
validate_relname
18+
------------------
19+
20+
(1 row)
21+
22+
SELECT validate_relname(1::REGCLASS);
23+
ERROR: relation "1" does not exist
24+
SELECT validate_relname(NULL);
25+
ERROR: relation should not be NULL
26+
/* check function get_number_of_partitions() */
27+
SELECT get_number_of_partitions('calamity.part_test');
28+
get_number_of_partitions
29+
--------------------------
30+
0
31+
(1 row)
32+
33+
SELECT get_number_of_partitions(NULL) IS NULL;
34+
?column?
35+
----------
36+
t
2037
(1 row)
2138

22-
/* SELECT validate_relname(NULL); -- FIXME: %s */
2339
/* check function get_parent_of_partition() */
2440
SELECT get_parent_of_partition('calamity.part_test');
2541
ERROR: "part_test" is not a partition

‎hash.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ BEGIN
147147
att_val_fmt,
148148
att_fmt;
149149

150-
partitions_count :=COUNT(*)FROMpg_catalog.pg_inherits
151-
WHERE inhparent= parent_relid::oid;
150+
partitions_count := @extschema@.get_number_of_partitions(parent_relid);
152151

153152
/* Build trigger & trigger function's names*/
154153
funcname := @extschema@.build_update_trigger_func_name(parent_relid);

‎init.sql

Lines changed: 47 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ SELECT pg_catalog.pg_extension_config_dump('@extschema@.pathman_config', '');
104104
SELECTpg_catalog.pg_extension_config_dump('@extschema@.pathman_config_params','');
105105

106106

107-
CREATEOR REPLACE FUNCTION @extschema@.partitions_count(relation REGCLASS)
108-
RETURNSINTAS
109-
$$
110-
BEGIN
111-
RETURNcount(*)FROM pg_inheritsWHERE inhparent= relation;
112-
END
113-
$$
114-
LANGUAGE plpgsql STRICT;
115-
116107
/*
117108
* Add a row describing the optional parameter to pathman_config_params.
118109
*/
@@ -185,7 +176,8 @@ RETURNS TABLE (
185176
partattrTEXT,
186177
range_minTEXT,
187178
range_maxTEXT)
188-
AS'pg_pathman','show_partition_list_internal' LANGUAGE C STRICT;
179+
AS'pg_pathman','show_partition_list_internal'
180+
LANGUAGE C STRICT;
189181

190182
/*
191183
* View for show_partition_list().
@@ -206,7 +198,8 @@ RETURNS TABLE (
206198
relidREGCLASS,
207199
processedINT,
208200
statusTEXT)
209-
AS'pg_pathman','show_concurrent_part_tasks_internal' LANGUAGE C STRICT;
201+
AS'pg_pathman','show_concurrent_part_tasks_internal'
202+
LANGUAGE C STRICT;
210203

211204
/*
212205
* View for show_concurrent_part_tasks().
@@ -353,28 +346,6 @@ END
353346
$$
354347
LANGUAGE plpgsql STRICT;
355348

356-
/*
357-
* Validates relation name. It must be schema qualified.
358-
*/
359-
CREATEOR REPLACE FUNCTION @extschema@.validate_relname(
360-
clsREGCLASS)
361-
RETURNSTEXTAS
362-
$$
363-
DECLARE
364-
relnameTEXT;
365-
366-
BEGIN
367-
relname= @extschema@.get_schema_qualified_name(cls);
368-
369-
IF relname ISNULL THEN
370-
RAISE EXCEPTION'relation %s does not exist', cls;
371-
END IF;
372-
373-
RETURN relname;
374-
END
375-
$$
376-
LANGUAGE plpgsql;
377-
378349
/*
379350
* Aggregates several common relation checks before partitioning.
380351
* Suitable for every partitioning type.
@@ -444,25 +415,6 @@ END
444415
$$
445416
LANGUAGE plpgsql STRICT;
446417

447-
/*
448-
* Returns the schema-qualified name of table.
449-
*/
450-
CREATEOR REPLACE FUNCTION @extschema@.get_schema_qualified_name(
451-
clsREGCLASS,
452-
delimiterTEXT DEFAULT'.',
453-
suffixTEXT DEFAULT'')
454-
RETURNSTEXTAS
455-
$$
456-
BEGIN
457-
RETURN (SELECT quote_ident(relnamespace::regnamespace::text)||
458-
delimiter||
459-
quote_ident(relname|| suffix)
460-
FROMpg_catalog.pg_class
461-
WHEREoid= cls::oid);
462-
END
463-
$$
464-
LANGUAGE plpgsql STRICT;
465-
466418
/*
467419
* Check if two relations have equal structures.
468420
*/
@@ -662,41 +614,62 @@ RETURNS VOID AS 'pg_pathman', 'on_partitions_removed'
662614
LANGUAGE C STRICT;
663615

664616

617+
/*
618+
* Get number of partitions managed by pg_pathman.
619+
*/
620+
CREATEOR REPLACE FUNCTION @extschema@.get_number_of_partitions(
621+
parent_relidREGCLASS)
622+
RETURNS INT4AS'pg_pathman','get_number_of_partitions_pl'
623+
LANGUAGE C STRICT;
624+
665625
/*
666626
* Get parent of pg_pathman's partition.
667627
*/
668-
CREATEOR REPLACE FUNCTION @extschema@.get_parent_of_partition(REGCLASS)
628+
CREATEOR REPLACE FUNCTION @extschema@.get_parent_of_partition(
629+
partition_relidREGCLASS)
669630
RETURNS REGCLASSAS'pg_pathman','get_parent_of_partition_pl'
670631
LANGUAGE C STRICT;
671632

672633
/*
673634
* Extract basic type of a domain.
674635
*/
675-
CREATEOR REPLACE FUNCTION @extschema@.get_base_type(REGTYPE)
636+
CREATEOR REPLACE FUNCTION @extschema@.get_base_type(
637+
typidREGTYPE)
676638
RETURNS REGTYPEAS'pg_pathman','get_base_type_pl'
677639
LANGUAGE C STRICT;
678640

679641
/*
680642
* Returns attribute type name for relation.
681643
*/
682644
CREATEOR REPLACE FUNCTION @extschema@.get_attribute_type(
683-
REGCLASS,TEXT)
645+
relidREGCLASS,
646+
attnameTEXT)
684647
RETURNS REGTYPEAS'pg_pathman','get_attribute_type_pl'
685648
LANGUAGE C STRICT;
686649

687650
/*
688651
* Return tablespace name for specified relation.
689652
*/
690-
CREATEOR REPLACE FUNCTION @extschema@.get_rel_tablespace_name(REGCLASS)
691-
RETURNSTEXTAS'pg_pathman','get_rel_tablespace_name'
653+
CREATEOR REPLACE FUNCTION @extschema@.get_tablespace(
654+
relidREGCLASS)
655+
RETURNSTEXTAS'pg_pathman','get_tablespace_pl'
692656
LANGUAGE C STRICT;
693657

694658

659+
/*
660+
* Check that relation exists.
661+
*/
662+
CREATEOR REPLACE FUNCTION @extschema@.validate_relname(
663+
relidREGCLASS)
664+
RETURNS VOIDAS'pg_pathman','validate_relname'
665+
LANGUAGE C;
666+
695667
/*
696668
* Checks if attribute is nullable
697669
*/
698670
CREATEOR REPLACE FUNCTION @extschema@.is_attribute_nullable(
699-
REGCLASS,TEXT)
671+
relidREGCLASS,
672+
attnameTEXT)
700673
RETURNSBOOLEANAS'pg_pathman','is_attribute_nullable'
701674
LANGUAGE C STRICT;
702675

@@ -713,25 +686,27 @@ LANGUAGE C STRICT;
713686
* Build check constraint name for a specified relation's column.
714687
*/
715688
CREATEOR REPLACE FUNCTION @extschema@.build_check_constraint_name(
716-
REGCLASS, INT2)
689+
partition_relidREGCLASS,
690+
partitioned_colINT2)
717691
RETURNSTEXTAS'pg_pathman','build_check_constraint_name_attnum'
718692
LANGUAGE C STRICT;
719693

720694
CREATEOR REPLACE FUNCTION @extschema@.build_check_constraint_name(
721-
REGCLASS,TEXT)
695+
partition_relidREGCLASS,
696+
partitioned_colTEXT)
722697
RETURNSTEXTAS'pg_pathman','build_check_constraint_name_attname'
723698
LANGUAGE C STRICT;
724699

725700
/*
726701
* Build update trigger and its underlying function's names.
727702
*/
728703
CREATEOR REPLACE FUNCTION @extschema@.build_update_trigger_name(
729-
REGCLASS)
704+
relidREGCLASS)
730705
RETURNSTEXTAS'pg_pathman','build_update_trigger_name'
731706
LANGUAGE C STRICT;
732707

733708
CREATEOR REPLACE FUNCTION @extschema@.build_update_trigger_func_name(
734-
REGCLASS)
709+
relidREGCLASS)
735710
RETURNSTEXTAS'pg_pathman','build_update_trigger_func_name'
736711
LANGUAGE C STRICT;
737712

@@ -746,7 +721,8 @@ CREATE OR REPLACE FUNCTION @extschema@.add_to_pathman_config(
746721
RETURNSBOOLEANAS'pg_pathman','add_to_pathman_config'
747722
LANGUAGE C;
748723

749-
CREATEOR REPLACE FUNCTION @extschema@.invalidate_relcache(relidOID)
724+
CREATEOR REPLACE FUNCTION @extschema@.invalidate_relcache(
725+
OID)
750726
RETURNS VOIDAS'pg_pathman'
751727
LANGUAGE C STRICT;
752728

@@ -755,18 +731,18 @@ LANGUAGE C STRICT;
755731
* Lock partitioned relation to restrict concurrent
756732
* modification of partitioning scheme.
757733
*/
758-
CREATEOR REPLACE FUNCTION @extschema@.lock_partitioned_relation(
759-
REGCLASS)
760-
RETURNS VOIDAS'pg_pathman','lock_partitioned_relation'
761-
LANGUAGE C STRICT;
734+
CREATEOR REPLACE FUNCTION @extschema@.lock_partitioned_relation(
735+
parent_relidREGCLASS)
736+
RETURNS VOIDAS'pg_pathman','lock_partitioned_relation'
737+
LANGUAGE C STRICT;
762738

763739
/*
764740
* Lock relation to restrict concurrent modification of data.
765741
*/
766-
CREATEOR REPLACE FUNCTION @extschema@.prevent_relation_modification(
767-
REGCLASS)
768-
RETURNS VOIDAS'pg_pathman','prevent_relation_modification'
769-
LANGUAGE C STRICT;
742+
CREATEOR REPLACE FUNCTION @extschema@.prevent_relation_modification(
743+
parent_relidREGCLASS)
744+
RETURNS VOIDAS'pg_pathman','prevent_relation_modification'
745+
LANGUAGE C STRICT;
770746

771747

772748
/*

‎range.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ BEGIN
158158
parent_relid,
159159
start_value,
160160
start_value+ p_interval,
161-
@extschema@.get_rel_tablespace_name(parent_relid);
161+
@extschema@.get_tablespace(parent_relid);
162162

163163
start_value := start_value+ p_interval;
164164
END LOOP;
@@ -270,7 +270,7 @@ BEGIN
270270
parent_relid,
271271
start_value,
272272
start_value+ p_interval,
273-
tablespace := @extschema@.get_rel_tablespace_name(parent_relid));
273+
tablespace := @extschema@.get_tablespace(parent_relid));
274274

275275
start_value := start_value+ p_interval;
276276
END LOOP;
@@ -343,7 +343,7 @@ BEGIN
343343
parent_relid,
344344
start_value,
345345
start_value+ p_interval,
346-
tablespace := @extschema@.get_rel_tablespace_name(parent_relid));
346+
tablespace := @extschema@.get_tablespace(parent_relid));
347347

348348
start_value := start_value+ p_interval;
349349
part_count := part_count+1;
@@ -416,7 +416,7 @@ BEGIN
416416
parent_relid,
417417
start_value,
418418
start_value+ p_interval,
419-
@extschema@.get_rel_tablespace_name(parent_relid);
419+
@extschema@.get_tablespace(parent_relid);
420420

421421
start_value := start_value+ p_interval;
422422
part_count := part_count+1;
@@ -733,7 +733,7 @@ DECLARE
733733
v_atttypeREGTYPE;
734734

735735
BEGIN
736-
IF @extschema@.partitions_count(parent_relid)=0 THEN
736+
IF @extschema@.get_number_of_partitions(parent_relid)=0 THEN
737737
RAISE EXCEPTION'cannot append to empty partitions set';
738738
END IF;
739739

@@ -843,7 +843,7 @@ DECLARE
843843
v_atttypeREGTYPE;
844844

845845
BEGIN
846-
IF @extschema@.partitions_count(parent_relid)=0 THEN
846+
IF @extschema@.get_number_of_partitions(parent_relid)=0 THEN
847847
RAISE EXCEPTION'cannot prepend to empty partitions set';
848848
END IF;
849849

@@ -907,7 +907,7 @@ BEGIN
907907
END IF;
908908

909909
/* check range overlap*/
910-
IF @extschema@.partitions_count(parent_relid)>0 THEN
910+
IF @extschema@.get_number_of_partitions(parent_relid)>0 THEN
911911
PERFORM @extschema@.check_range_available(parent_relid,
912912
start_value,
913913
end_value);

‎sql/pathman_calamity.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ CREATE TABLE calamity.part_test(val serial);
1616

1717
/* check function validate_relname()*/
1818
SELECT validate_relname('calamity.part_test');
19-
/* SELECT validate_relname(NULL); -- FIXME: %s*/
19+
SELECT validate_relname(1::REGCLASS);
20+
SELECT validate_relname(NULL);
21+
22+
/* check function get_number_of_partitions()*/
23+
SELECT get_number_of_partitions('calamity.part_test');
24+
SELECT get_number_of_partitions(NULL) ISNULL;
2025

2126
/* check function get_parent_of_partition()*/
2227
SELECT get_parent_of_partition('calamity.part_test');

‎src/partition_creation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ spawn_partitions_val(Oid parent_relid,/* parent's Oid */
556556

557557
/* What, again? Don't want to deal with this nightmare */
558558
if (move_bound_op_ret_type!=range_bound_type)
559-
elog(ERROR,"error inspawn_partitions_val()");
559+
elog(ERROR,"error infunction "CppAsString(spawn_partitions_val));
560560
}
561561

562562
/* Get operator's underlying function */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp