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

Commit3007f79

Browse files
committed
auto partitions creation parameter added
1 parentbea88a9 commit3007f79

File tree

8 files changed

+113
-25
lines changed

8 files changed

+113
-25
lines changed

‎expected/pg_pathman.out

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,46 @@ CREATE TABLE test.range_rel_test2 (
11091109
dt TIMESTAMP);
11101110
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
11111111
ERROR: Partition must have the exact same structure as parent
1112+
/*
1113+
* Zero partitions count and adding partitions with specified name
1114+
*/
1115+
CREATE TABLE test.zero(
1116+
idSERIAL PRIMARY KEY,
1117+
valueINT NOT NULL);
1118+
INSERT INTO test.zero SELECT g, g FROM generate_series(1, 100) as g;
1119+
SELECT pathman.create_range_partitions('test.zero', 'value', 50, 10, 0);
1120+
NOTICE: sequence "zero_seq" does not exist, skipping
1121+
create_range_partitions
1122+
-------------------------
1123+
0
1124+
(1 row)
1125+
1126+
SELECT pathman.append_range_partition('test.zero', 'test.zero_0');
1127+
ERROR: Cannot append to empty partitions set
1128+
SELECT pathman.prepend_range_partition('test.zero', 'test.zero_1');
1129+
ERROR: Cannot prepend to empty partitions set
1130+
SELECT pathman.add_range_partition('test.zero', 50, 70, 'test.zero_50');
1131+
add_range_partition
1132+
---------------------
1133+
test.zero_50
1134+
(1 row)
1135+
1136+
SELECT pathman.append_range_partition('test.zero', 'test.zero_appended');
1137+
ERROR: Partition #-1 does not exist (total amount is 1)
1138+
SELECT pathman.prepend_range_partition('test.zero', 'test.zero_prepended');
1139+
prepend_range_partition
1140+
-------------------------
1141+
test.zero_prepended
1142+
(1 row)
1143+
1144+
SELECT pathman.split_range_partition('test.zero_50', 60, 'test.zero_60');
1145+
split_range_partition
1146+
-----------------------
1147+
{50,70}
1148+
(1 row)
1149+
1150+
DROP TABLE test.zero CASCADE;
1151+
NOTICE: drop cascades to 3 other objects
11121152
/*
11131153
* Check that altering table columns doesn't break trigger
11141154
*/

‎init.sql

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
2929

3030
CREATETABLEIF NOT EXISTS @extschema@.pathman_config_params (
3131
partrelREGCLASSNOT NULL,
32-
enable_parentBOOLEANNOT NULL DEFAULT TRUE
32+
enable_parentBOOLEANNOT NULL DEFAULT TRUE,
33+
autoBOOLEANNOT NULL DEFAULT TRUE
3334
);
3435
CREATEUNIQUE INDEXi_pathman_config_params
3536
ON @extschema@.pathman_config_params(partrel);
@@ -81,32 +82,73 @@ END
8182
$$
8283
LANGUAGE plpgsql;
8384

84-
/* Include parent relation into query plan's for specified relation*/
85+
/*
86+
* Set additional param
87+
*/
88+
CREATEOR REPLACE FUNCTION @extschema@.pathman_set_param(
89+
relationREGCLASS,
90+
paramTEXT,
91+
valueBOOLEAN)
92+
RETURNS VOIDAS
93+
$$
94+
BEGIN
95+
EXECUTE format(
96+
'INSERT INTO @extschema@.pathman_config_params (partrel, %1$s)
97+
VALUES ($1, $2)
98+
ON CONFLICT (partrel) DO
99+
UPDATE SET %1$s = $2',
100+
param)
101+
USING
102+
relation,
103+
value;
104+
END
105+
$$
106+
LANGUAGE plpgsql;
107+
108+
/*
109+
* Include parent relation into query plan's for specified relation
110+
*/
85111
CREATEOR REPLACE FUNCTION @extschema@.enable_parent(relation REGCLASS)
86112
RETURNS VOIDAS
87113
$$
88114
BEGIN
89-
INSERT INTO @extschema@.pathman_config_paramsvalues (relation, True)
90-
ON CONFLICT (partrel) DO
91-
UPDATESET enable_parent= True;
115+
PERFORM @extschema@.pathman_set_param(relation,'enable_parent', True);
116+
END
117+
$$
118+
LANGUAGE plpgsql;
92119

93-
-- PERFORM @extschema@.invalidate_relcache(relation::oid);
94-
-- PERFORM @extschema@.on_enable_parent(relation::oid);
120+
/*
121+
* Do not include parent relation into query plan's for specified relation
122+
*/
123+
CREATEOR REPLACE FUNCTION @extschema@.disable_parent(relation REGCLASS)
124+
RETURNS VOIDAS
125+
$$
126+
BEGIN
127+
PERFORM @extschema@.pathman_set_param(relation,'enable_parent', False);
95128
END
96129
$$
97130
LANGUAGE plpgsql;
98131

99-
/* Do not include parent relation into query plan's for specified relation*/
100-
CREATEOR REPLACE FUNCTION @extschema@.disable_parent(relation REGCLASS)
132+
/*
133+
* Enable auto partition creation
134+
*/
135+
CREATEOR REPLACE FUNCTION @extschema@.enable_auto(relation REGCLASS)
101136
RETURNS VOIDAS
102137
$$
103138
BEGIN
104-
INSERT INTO @extschema@.pathman_config_paramsvalues (relation, False)
105-
ON CONFLICT (partrel) DO
106-
UPDATESET enable_parent= False;
139+
PERFORM @extschema@.pathman_set_param(relation,'auto', True);
140+
END
141+
$$
142+
LANGUAGE plpgsql;
107143

108-
-- PERFORM @extschema@.invalidate_relcache(relation::oid);
109-
-- PERFORM @extschema@.on_disable_parent(relation::oid);
144+
/*
145+
* Disable auto partition creation
146+
*/
147+
CREATEOR REPLACE FUNCTION @extschema@.disable_auto(relation REGCLASS)
148+
RETURNS VOIDAS
149+
$$
150+
BEGIN
151+
PERFORM @extschema@.pathman_set_param(relation,'auto', False);
110152
END
111153
$$
112154
LANGUAGE plpgsql;

‎sql/pg_pathman.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ SELECT pathman.add_range_partition('test.zero', 50, 70, 'test.zero_50');
485485
SELECTpathman.append_range_partition('test.zero','test.zero_appended');
486486
SELECTpathman.prepend_range_partition('test.zero','test.zero_prepended');
487487
SELECTpathman.split_range_partition('test.zero_50',60,'test.zero_60');
488+
DROPTABLEtest.zero CASCADE;
488489

489490
/*
490491
* Check that altering table columns doesn't break trigger

‎src/init.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
570570
* Return 'enable_parent' parameter of relation
571571
*/
572572
bool
573-
read_enable_parent_parameter(Oidrelid)
573+
read_pathman_params(Oidrelid,Datum*values,bool*isnull)
574574
{
575575
Relationrel;
576576
HeapScanDescscan;
@@ -590,12 +590,9 @@ read_enable_parent_parameter(Oid relid)
590590

591591
if ((htup=heap_getnext(scan,ForwardScanDirection))!=NULL)
592592
{
593-
Datumvalues[Natts_pathman_config_params];
594-
boolisnull[Natts_pathman_config_params];
595-
596593
/* Extract data if necessary */
597594
heap_deform_tuple(htup,RelationGetDescr(rel),values,isnull);
598-
result=values[Anum_pathman_config_params_enable_parent-1];
595+
result=true;
599596
}
600597

601598
/* Clean resources */

‎src/init.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ bool pathman_config_contains_relation(Oid relid,
4747
bool*isnull,
4848
TransactionId*xmin);
4949

50-
boolread_enable_parent_parameter(Oidrelid);
50+
boolread_pathman_params(Oidrelid,
51+
Datum*values,
52+
bool*isnull);
5153

5254
#endif

‎src/pathman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
* Definitions for the "pathman_config_params" table
5858
*/
5959
#definePATHMAN_CONFIG_PARAMS"pathman_config_params"
60-
// #define PATHMAN_CONFIG_PARAMS_INDEX"i_pathman_config_params"
61-
#defineNatts_pathman_config_params2
60+
#defineNatts_pathman_config_params3
6261
#defineAnum_pathman_config_params_partrel1/* primary key */
6362
#defineAnum_pathman_config_params_enable_parent2/* include parent into plan */
63+
#defineAnum_pathman_config_params_auto3/* auto partitions creation */
6464

6565
/*
6666
* Cache current PATHMAN_CONFIG relid (set during load_config()).

‎src/relation_info.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ refresh_pathman_relation_info(Oid relid,
7474
i;
7575
boolfound;
7676
PartRelationInfo*prel;
77+
Datumparam_values[Natts_pathman_config_params];
78+
boolparam_isnull[Natts_pathman_config_params];
7779

7880
prel= (PartRelationInfo*)hash_search(partitioned_rels,
7981
(constvoid*)&relid,
@@ -158,10 +160,13 @@ refresh_pathman_relation_info(Oid relid,
158160
pfree(prel_children);
159161

160162
/*
161-
* Read additional parameter ('enable_parent' is the only one at
162-
* the moment)
163+
* Read additional parameters ('enable_parent' and 'auto' at the moment)
163164
*/
164-
prel->enable_parent=read_enable_parent_parameter(relid);
165+
if (read_pathman_params(relid,param_values,param_isnull))
166+
{
167+
prel->enable_parent=param_values[Anum_pathman_config_params_enable_parent-1];
168+
prel->auto_partition=param_values[Anum_pathman_config_params_auto-1];
169+
}
165170

166171
/* We've successfully built a cache entry */
167172
prel->valid= true;

‎src/relation_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct
4848
Oidkey;/* partitioned table's Oid */
4949
boolvalid;/* is this entry valid? */
5050
boolenable_parent;/* include parent to the plan */
51+
boolauto_partition;/* auto partition creation */
5152

5253
uint32children_count;
5354
Oid*children;/* Oids of child partitions */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp