Skip to content

Commit da8aba6

Browse files
committed
introduce view 'pathman_partition_list', pl/pgSQL refactoring, extract pl_range_funcs.c & pl_hash_funcs.c from pl_funcs.c
1 parent 56bfc94 commit da8aba6

File tree

9 files changed

+691
-361
lines changed

9 files changed

+691
-361
lines changed

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# contrib/pg_pathman/Makefile
22

33
MODULE_big = pg_pathman
4-
OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o src/runtimeappend.o \
5-
src/runtime_merge_append.o src/pg_pathman.o src/rangeset.o src/pl_funcs.o \
6-
src/pathman_workers.o src/hooks.o src/nodes_common.o src/xact_handling.o \
7-
src/copy_stmt_hooking.o src/pg_compat.o $(WIN32RES)
4+
OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o \
5+
src/runtimeappend.o src/runtime_merge_append.o src/pg_pathman.o src/rangeset.o \
6+
src/pl_funcs.o src/pl_range_funcs.o src/pl_hash_funcs.o src/pathman_workers.o \
7+
src/hooks.o src/nodes_common.o src/xact_handling.o src/copy_stmt_hooking.o \
8+
src/pg_compat.o $(WIN32RES)
89

910
EXTENSION = pg_pathman
1011
EXTVERSION = 1.0

init.sql

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ SELECT pg_catalog.pg_extension_config_dump('@extschema@.pathman_config', '');
7777
SELECT pg_catalog.pg_extension_config_dump('@extschema@.pathman_config_params', '');
7878

7979

80-
CREATE OR REPLACE FUNCTION @extschema@.invalidate_relcache(relid OID)
81-
RETURNS VOID AS 'pg_pathman' LANGUAGE C STRICT;
82-
8380
CREATE OR REPLACE FUNCTION @extschema@.partitions_count(relation REGCLASS)
8481
RETURNS INT AS
8582
$$
@@ -150,6 +147,25 @@ END
150147
$$
151148
LANGUAGE plpgsql;
152149

150+
/*
151+
* Show all existing parents and partitions.
152+
*/
153+
CREATE OR REPLACE FUNCTION @extschema@.show_partition_list()
154+
RETURNS TABLE (
155+
parent REGCLASS,
156+
partition REGCLASS,
157+
parttype INT4,
158+
partattr TEXT,
159+
range_min TEXT,
160+
range_max TEXT)
161+
AS 'pg_pathman', 'show_partition_list_internal' LANGUAGE C STRICT;
162+
163+
/*
164+
* View for show_partition_list().
165+
*/
166+
CREATE OR REPLACE VIEW @extschema@.pathman_partition_list
167+
AS SELECT * FROM @extschema@.show_partition_list();
168+
153169
/*
154170
* Show all existing concurrent partitioning tasks.
155171
*/
@@ -160,8 +176,8 @@ RETURNS TABLE (
160176
dbid OID,
161177
relid REGCLASS,
162178
processed INT,
163-
status TEXT
164-
) AS 'pg_pathman', 'show_concurrent_part_tasks_internal' LANGUAGE C STRICT;
179+
status TEXT)
180+
AS 'pg_pathman', 'show_concurrent_part_tasks_internal' LANGUAGE C STRICT;
165181

166182
/*
167183
* View for show_concurrent_part_tasks().
@@ -348,7 +364,7 @@ $$
348364
LANGUAGE plpgsql;
349365

350366
/*
351-
* Returns relname without quotes or something
367+
* Returns relname without quotes or something.
352368
*/
353369
CREATE OR REPLACE FUNCTION @extschema@.get_plain_schema_and_relname(
354370
cls REGCLASS,
@@ -366,7 +382,7 @@ $$
366382
LANGUAGE plpgsql STRICT;
367383

368384
/*
369-
* Returns schema-qualified name for table
385+
* Returns the schema-qualified name of table.
370386
*/
371387
CREATE OR REPLACE FUNCTION @extschema@.get_schema_qualified_name(
372388
cls REGCLASS,
@@ -385,7 +401,7 @@ $$
385401
LANGUAGE plpgsql STRICT;
386402

387403
/*
388-
* Validates relation name. It must be schema qualified
404+
* Validates relation name. It must be schema qualified.
389405
*/
390406
CREATE OR REPLACE FUNCTION @extschema@.validate_relname(
391407
cls REGCLASS)
@@ -407,7 +423,7 @@ $$
407423
LANGUAGE plpgsql;
408424

409425
/*
410-
* Check if two relations have equal structures
426+
* Check if two relations have equal structures.
411427
*/
412428
CREATE OR REPLACE FUNCTION @extschema@.validate_relations_equality(
413429
relation1 OID, relation2 OID)
@@ -439,7 +455,7 @@ $$
439455
LANGUAGE plpgsql;
440456

441457
/*
442-
* DDL trigger that deletes entry from pathman_config table
458+
* DDL trigger that deletes entry from pathman_config table.
443459
*/
444460
CREATE OR REPLACE FUNCTION @extschema@.pathman_ddl_trigger_func()
445461
RETURNS event_trigger AS
@@ -472,7 +488,7 @@ $$
472488
LANGUAGE plpgsql;
473489

474490
/*
475-
* Drop trigger
491+
* Drop triggers.
476492
*/
477493
CREATE OR REPLACE FUNCTION @extschema@.drop_triggers(
478494
parent_relid REGCLASS)
@@ -485,8 +501,8 @@ END
485501
$$ LANGUAGE plpgsql STRICT;
486502

487503
/*
488-
* Drop partitions
489-
* If delete_data set to TRUE then partitions will be dropped with all the data
504+
* Drop partitions. If delete_data set to TRUE, partitions
505+
* will be dropped with all the data.
490506
*/
491507
CREATE OR REPLACE FUNCTION @extschema@.drop_partitions(
492508
parent_relid REGCLASS,
@@ -578,16 +594,6 @@ ON sql_drop
578594
EXECUTE PROCEDURE @extschema@.pathman_ddl_trigger_func();
579595

580596

581-
/*
582-
* Attach a previously partitioned table
583-
*/
584-
CREATE OR REPLACE FUNCTION @extschema@.add_to_pathman_config(
585-
parent_relid REGCLASS,
586-
attname TEXT,
587-
range_interval TEXT DEFAULT NULL)
588-
RETURNS BOOLEAN AS 'pg_pathman', 'add_to_pathman_config'
589-
LANGUAGE C;
590-
591597

592598
CREATE OR REPLACE FUNCTION @extschema@.on_create_partitions(
593599
relid REGCLASS)
@@ -619,40 +625,41 @@ CREATE OR REPLACE FUNCTION @extschema@.get_base_type(REGTYPE)
619625
RETURNS REGTYPE AS 'pg_pathman', 'get_base_type_pl'
620626
LANGUAGE C STRICT;
621627

622-
623628
/*
624-
* Checks if attribute is nullable
629+
* Returns attribute type name for relation.
625630
*/
626-
CREATE OR REPLACE FUNCTION @extschema@.is_attribute_nullable(
631+
CREATE OR REPLACE FUNCTION @extschema@.get_attribute_type(
627632
REGCLASS, TEXT)
628-
RETURNS BOOLEAN AS 'pg_pathman', 'is_attribute_nullable'
633+
RETURNS REGTYPE AS 'pg_pathman', 'get_attribute_type_pl'
629634
LANGUAGE C STRICT;
630635

631636
/*
632-
* Check if regclass is date or timestamp
637+
* Return tablespace name for specified relation.
633638
*/
634-
CREATE OR REPLACE FUNCTION @extschema@.is_date_type(
635-
typid REGTYPE)
636-
RETURNS BOOLEAN AS 'pg_pathman', 'is_date_type'
639+
CREATE OR REPLACE FUNCTION @extschema@.get_rel_tablespace_name(relation REGCLASS)
640+
RETURNS TEXT AS 'pg_pathman', 'get_rel_tablespace_name'
637641
LANGUAGE C STRICT;
638642

643+
639644
/*
640-
* Returns attribute type name for relation
645+
* Checks if attribute is nullable
641646
*/
642-
CREATE OR REPLACE FUNCTION @extschema@.get_attribute_type(
647+
CREATE OR REPLACE FUNCTION @extschema@.is_attribute_nullable(
643648
REGCLASS, TEXT)
644-
RETURNS REGTYPE AS 'pg_pathman', 'get_attribute_type_pl'
649+
RETURNS BOOLEAN AS 'pg_pathman', 'is_attribute_nullable'
645650
LANGUAGE C STRICT;
646651

647652
/*
648-
* Get parent of pg_pathman's partition.
653+
* Check if regclass is date or timestamp.
649654
*/
650-
CREATE OR REPLACE FUNCTION @extschema@.get_parent_of_partition(REGCLASS)
651-
RETURNS REGCLASS AS 'pg_pathman', 'get_parent_of_partition_pl'
655+
CREATE OR REPLACE FUNCTION @extschema@.is_date_type(
656+
typid REGTYPE)
657+
RETURNS BOOLEAN AS 'pg_pathman', 'is_date_type'
652658
LANGUAGE C STRICT;
653659

660+
654661
/*
655-
* Build check constraint name for a specified relation's column
662+
* Build check constraint name for a specified relation's column.
656663
*/
657664
CREATE OR REPLACE FUNCTION @extschema@.build_check_constraint_name(
658665
REGCLASS, INT2)
@@ -679,7 +686,22 @@ LANGUAGE C STRICT;
679686

680687

681688
/*
682-
* Lock partitioned relation to restrict concurrent modification of partitioning scheme.
689+
* Attach a previously partitioned table.
690+
*/
691+
CREATE OR REPLACE FUNCTION @extschema@.add_to_pathman_config(
692+
parent_relid REGCLASS,
693+
attname TEXT,
694+
range_interval TEXT DEFAULT NULL)
695+
RETURNS BOOLEAN AS 'pg_pathman', 'add_to_pathman_config'
696+
LANGUAGE C;
697+
698+
CREATE OR REPLACE FUNCTION @extschema@.invalidate_relcache(relid OID)
699+
RETURNS VOID AS 'pg_pathman' LANGUAGE C STRICT;
700+
701+
702+
/*
703+
* Lock partitioned relation to restrict concurrent
704+
* modification of partitioning scheme.
683705
*/
684706
CREATE OR REPLACE FUNCTION @extschema@.lock_partitioned_relation(
685707
REGCLASS)
@@ -702,18 +724,12 @@ CREATE OR REPLACE FUNCTION @extschema@.debug_capture()
702724
RETURNS VOID AS 'pg_pathman', 'debug_capture'
703725
LANGUAGE C STRICT;
704726

705-
/*
706-
* Return tablespace name for specified relation.
707-
*/
708-
CREATE OR REPLACE FUNCTION @extschema@.get_rel_tablespace_name(relation REGCLASS)
709-
RETURNS TEXT AS 'pg_pathman', 'get_rel_tablespace_name'
710-
LANGUAGE C STRICT;
711-
712727
/*
713728
* Checks that callback function meets specific requirements. Particularly it
714729
* must have the only JSONB argument and VOID return type.
715730
*/
716-
CREATE OR REPLACE FUNCTION @extschema@.validate_on_partition_created_callback(callback REGPROC)
731+
CREATE OR REPLACE FUNCTION @extschema@.validate_on_partition_created_callback(
732+
callback REGPROC)
717733
RETURNS VOID AS 'pg_pathman', 'validate_on_part_init_callback_pl'
718734
LANGUAGE C STRICT;
719735

src/pathman.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#define PATHMAN_CONFIG_interval_typmod -1
5353

5454
/*
55-
* Definitions for the "pathman_config_params" table
55+
* Definitions for the "pathman_config_params" table.
5656
*/
5757
#define PATHMAN_CONFIG_PARAMS "pathman_config_params"
5858
#define Natts_pathman_config_params 4
@@ -61,6 +61,19 @@
6161
#define Anum_pathman_config_params_auto 3 /* auto partitions creation */
6262
#define Anum_pathman_config_params_init_callback 4 /* partition action callback */
6363

64+
/*
65+
* Definitions for the "pathman_partition_list" view.
66+
*/
67+
#define PATHMAN_PARTITION_LIST "pathman_partition_list"
68+
#define Natts_pathman_partition_list 6
69+
#define Anum_pathman_pl_parent 1
70+
#define Anum_pathman_pl_partition 2
71+
#define Anum_pathman_pl_parttype 3
72+
#define Anum_pathman_pl_partattr 4
73+
#define Anum_pathman_pl_range_min 5
74+
#define Anum_pathman_pl_range_max 6
75+
76+
6477
/*
6578
* Cache current PATHMAN_CONFIG relid (set during load_config()).
6679
*/

src/pathman_workers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ cps_set_status(ConcurrentPartSlot *slot, ConcurrentPartSlotStatus status)
111111

112112

113113
/*
114-
* Definitions for the "pathman_concurrent_part_tasks" view
114+
* Definitions for the "pathman_concurrent_part_tasks" view.
115115
*/
116116
#define PATHMAN_CONCURRENT_PART_TASKS "pathman_concurrent_part_tasks"
117117
#define Natts_pathman_cp_tasks 6

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