Skip to content

Commit 3bc9643

Browse files
committed
Merge branch 'master' into rel_1_3_beta
2 parents 04b1b20 + 592efd0 commit 3bc9643

12 files changed

+331
-96
lines changed

expected/pathman_calamity.out

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,127 @@ SELECT debug_capture();
1212
set client_min_messages = NOTICE;
1313
/* create table to be partitioned */
1414
CREATE TABLE calamity.part_test(val serial);
15+
/* test pg_pathman's cache */
16+
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
17+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
18+
NOTICE: sequence "part_test_seq" does not exist, skipping
19+
create_range_partitions
20+
-------------------------
21+
3
22+
(1 row)
23+
24+
SELECT drop_partitions('calamity.part_test');
25+
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
26+
NOTICE: 10 rows copied from calamity.part_test_1
27+
NOTICE: 10 rows copied from calamity.part_test_2
28+
NOTICE: 10 rows copied from calamity.part_test_3
29+
drop_partitions
30+
-----------------
31+
3
32+
(1 row)
33+
34+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
35+
create_range_partitions
36+
-------------------------
37+
3
38+
(1 row)
39+
40+
SELECT drop_partitions('calamity.part_test');
41+
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
42+
NOTICE: 10 rows copied from calamity.part_test_1
43+
NOTICE: 10 rows copied from calamity.part_test_2
44+
NOTICE: 10 rows copied from calamity.part_test_3
45+
drop_partitions
46+
-----------------
47+
3
48+
(1 row)
49+
50+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
51+
create_range_partitions
52+
-------------------------
53+
3
54+
(1 row)
55+
56+
SELECT append_range_partition('calamity.part_test');
57+
append_range_partition
58+
------------------------
59+
calamity.part_test_4
60+
(1 row)
61+
62+
SELECT drop_partitions('calamity.part_test');
63+
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
64+
NOTICE: 10 rows copied from calamity.part_test_1
65+
NOTICE: 10 rows copied from calamity.part_test_2
66+
NOTICE: 10 rows copied from calamity.part_test_3
67+
NOTICE: 0 rows copied from calamity.part_test_4
68+
drop_partitions
69+
-----------------
70+
4
71+
(1 row)
72+
73+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
74+
create_range_partitions
75+
-------------------------
76+
3
77+
(1 row)
78+
79+
SELECT append_range_partition('calamity.part_test');
80+
append_range_partition
81+
------------------------
82+
calamity.part_test_4
83+
(1 row)
84+
85+
SELECT drop_partitions('calamity.part_test');
86+
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
87+
NOTICE: 10 rows copied from calamity.part_test_1
88+
NOTICE: 10 rows copied from calamity.part_test_2
89+
NOTICE: 10 rows copied from calamity.part_test_3
90+
NOTICE: 0 rows copied from calamity.part_test_4
91+
drop_partitions
92+
-----------------
93+
4
94+
(1 row)
95+
96+
SELECT count(*) FROM calamity.part_test;
97+
count
98+
-------
99+
30
100+
(1 row)
101+
102+
DELETE FROM calamity.part_test;
103+
/* test stub 'enable_parent' value for PATHMAN_CONFIG_PARAMS */
104+
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
105+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
106+
create_range_partitions
107+
-------------------------
108+
3
109+
(1 row)
110+
111+
DELETE FROM pathman_config_params WHERE partrel = 'calamity.part_test'::regclass;
112+
SELECT append_range_partition('calamity.part_test');
113+
append_range_partition
114+
------------------------
115+
calamity.part_test_4
116+
(1 row)
117+
118+
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_test;
119+
QUERY PLAN
120+
-------------------------------
121+
Append
122+
-> Seq Scan on part_test_1
123+
-> Seq Scan on part_test_2
124+
-> Seq Scan on part_test_3
125+
-> Seq Scan on part_test_4
126+
(5 rows)
127+
128+
SELECT drop_partitions('calamity.part_test', true);
129+
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
130+
drop_partitions
131+
-----------------
132+
4
133+
(1 row)
134+
135+
DELETE FROM calamity.part_test;
15136
/* check function build_hash_condition() */
16137
SELECT build_hash_condition('int4', 'val', 10, 1);
17138
build_hash_condition
@@ -210,6 +331,9 @@ SELECT build_update_trigger_func_name(NULL) IS NULL;
210331
t
211332
(1 row)
212333

334+
/* check function stop_concurrent_part_task() */
335+
SELECT stop_concurrent_part_task(1::regclass);
336+
ERROR: cannot find worker for relation "1"
213337
/* check invoke_on_partition_created_callback() for RANGE */
214338
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, NULL, NULL::int);
215339
ERROR: both bounds must be provided for RANGE partition
@@ -383,5 +507,5 @@ SELECT count(*) FROM pathman_config_params WHERE partrel = 'calamity.to_be_disab
383507
(1 row)
384508

385509
DROP SCHEMA calamity CASCADE;
386-
NOTICE: drop cascades to 15 other objects
510+
NOTICE: drop cascades to 16 other objects
387511
DROP EXTENSION pg_pathman;

init.sql

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ CREATE OR REPLACE FUNCTION @extschema@.partition_data(
314314
OUT p_total BIGINT)
315315
AS
316316
$$
317-
DECLARE
318-
relname TEXT;
319-
rec RECORD;
320-
cnt BIGINT := 0;
321-
322317
BEGIN
323318
p_total := 0;
324319

@@ -718,13 +713,13 @@ LANGUAGE C STRICT;
718713
*/
719714
CREATE OR REPLACE FUNCTION @extschema@.build_check_constraint_name(
720715
partition_relid REGCLASS,
721-
attribute INT2)
716+
attribute INT2)
722717
RETURNS TEXT AS 'pg_pathman', 'build_check_constraint_name_attnum'
723718
LANGUAGE C STRICT;
724719

725720
CREATE OR REPLACE FUNCTION @extschema@.build_check_constraint_name(
726721
partition_relid REGCLASS,
727-
attribute TEXT)
722+
attribute TEXT)
728723
RETURNS TEXT AS 'pg_pathman', 'build_check_constraint_name_attname'
729724
LANGUAGE C STRICT;
730725

sql/pathman_calamity.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ set client_min_messages = NOTICE;
1414
CREATE TABLE calamity.part_test(val serial);
1515

1616

17+
/* test pg_pathman's cache */
18+
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
19+
20+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
21+
SELECT drop_partitions('calamity.part_test');
22+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
23+
SELECT drop_partitions('calamity.part_test');
24+
25+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
26+
SELECT append_range_partition('calamity.part_test');
27+
SELECT drop_partitions('calamity.part_test');
28+
29+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
30+
SELECT append_range_partition('calamity.part_test');
31+
SELECT drop_partitions('calamity.part_test');
32+
33+
SELECT count(*) FROM calamity.part_test;
34+
35+
DELETE FROM calamity.part_test;
36+
37+
38+
/* test stub 'enable_parent' value for PATHMAN_CONFIG_PARAMS */
39+
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
40+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
41+
DELETE FROM pathman_config_params WHERE partrel = 'calamity.part_test'::regclass;
42+
SELECT append_range_partition('calamity.part_test');
43+
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_test;
44+
SELECT drop_partitions('calamity.part_test', true);
45+
DELETE FROM calamity.part_test;
46+
47+
1748
/* check function build_hash_condition() */
1849
SELECT build_hash_condition('int4', 'val', 10, 1);
1950
SELECT build_hash_condition('text', 'val', 10, 1);
@@ -72,6 +103,9 @@ SELECT build_update_trigger_name(NULL) IS NULL;
72103
SELECT build_update_trigger_func_name('calamity.part_test');
73104
SELECT build_update_trigger_func_name(NULL) IS NULL;
74105

106+
/* check function stop_concurrent_part_task() */
107+
SELECT stop_concurrent_part_task(1::regclass);
108+
75109
/* check invoke_on_partition_created_callback() for RANGE */
76110
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, NULL, NULL::int);
77111
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, 1, NULL);

src/init.c

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -504,25 +504,28 @@ find_inheritance_children_array(Oid parentrelId,
504504
SysScanDesc scan;
505505
ScanKeyData key[1];
506506
HeapTuple inheritsTuple;
507-
Oid inhrelid;
507+
508508
Oid *oidarr;
509509
uint32 maxoids,
510-
numoids,
511-
i;
510+
numoids;
511+
512+
Oid *result = NULL;
513+
uint32 nresult = 0;
514+
515+
uint32 i;
516+
517+
Assert(lockmode != NoLock);
518+
519+
/* Init safe return values */
520+
*children_size = 0;
521+
*children = NULL;
512522

513523
/*
514-
* Can skip the scan if pg_class shows the relation has never had a
515-
* subclass.
524+
* Can skip the scan if pg_class shows the
525+
* relation has never had a subclass.
516526
*/
517527
if (!has_subclass(parentrelId))
518-
{
519-
/* Init return values */
520-
*children_size = 0;
521-
children = NULL;
522-
523-
/* Ok, could not find any children */
524528
return FCS_NO_CHILDREN;
525-
}
526529

527530
/*
528531
* Scan pg_inherits and build a working array of subclass OIDs.
@@ -543,6 +546,8 @@ find_inheritance_children_array(Oid parentrelId,
543546

544547
while ((inheritsTuple = systable_getnext(scan)) != NULL)
545548
{
549+
Oid inhrelid;
550+
546551
inhrelid = ((Form_pg_inherits) GETSTRUCT(inheritsTuple))->inhrelid;
547552
if (numoids >= maxoids)
548553
{
@@ -565,12 +570,10 @@ find_inheritance_children_array(Oid parentrelId,
565570
if (numoids > 1)
566571
qsort(oidarr, numoids, sizeof(Oid), oid_cmp);
567572

568-
/*
569-
* Acquire locks and build the result list.
570-
*/
573+
/* Acquire locks and build the result list */
571574
for (i = 0; i < numoids; i++)
572575
{
573-
inhrelid = oidarr[i];
576+
Oid inhrelid = oidarr[i];
574577

575578
if (lockmode != NoLock)
576579
{
@@ -585,9 +588,7 @@ find_inheritance_children_array(Oid parentrelId,
585588
for (j = 0; j < i; j++)
586589
UnlockRelationOid(oidarr[j], lockmode);
587590

588-
/* Init return values */
589-
*children_size = numoids;
590-
*children = oidarr;
591+
pfree(oidarr);
591592

592593
/* We couldn't lock this child, retreat! */
593594
return FCS_COULD_NOT_LOCK;
@@ -604,18 +605,28 @@ find_inheritance_children_array(Oid parentrelId,
604605
{
605606
/* Release useless lock */
606607
UnlockRelationOid(inhrelid, lockmode);
608+
607609
/* And ignore this relation */
608610
continue;
609611
}
610612
}
613+
614+
/* Alloc array if it's the first time */
615+
if (nresult == 0)
616+
result = palloc(numoids * sizeof(Oid));
617+
618+
/* Save Oid of the existing relation */
619+
result[nresult++] = inhrelid;
611620
}
612621

613-
/* Init return values */
614-
*children_size = numoids;
615-
*children = oidarr;
622+
/* Set return values */
623+
*children_size = nresult;
624+
*children = result;
625+
626+
pfree(oidarr);
616627

617-
/* Ok, we have children */
618-
return FCS_FOUND;
628+
/* Do we have children? */
629+
return nresult > 0 ? FCS_FOUND : FCS_NO_CHILDREN;
619630
}
620631

621632
/*

src/init.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ extern PathmanInitState pg_pathman_init_state;
9797

9898
/* Lowest version of Pl/PgSQL frontend compatible with internals (0xAA_BB_CC) */
9999
#define LOWEST_COMPATIBLE_FRONT 0x010200
100-
#define CURRENT_LIB_VERSION 0x010200
100+
101+
/* Current version on native C library (0xAA_BB_CC) */
102+
#define CURRENT_LIB_VERSION 0x010201
101103

102104

103105
/*

src/partition_creation.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*-------------------------------------------------------------------------
1+
/*-------------------------------------------------------------------------
22
*
33
* partition_creation.c
44
* Various functions for partition creation.
@@ -236,11 +236,6 @@ create_partitions_for_value(Oid relid, Datum value, Oid value_type)
236236
/* Check that table is partitioned and fetch xmin */
237237
if (pathman_config_contains_relation(relid, NULL, NULL, &rel_xmin))
238238
{
239-
/* Was table partitioned in some previous transaction? */
240-
bool part_in_prev_xact =
241-
TransactionIdPrecedes(rel_xmin, GetCurrentTransactionId()) ||
242-
TransactionIdEquals(rel_xmin, FrozenTransactionId);
243-
244239
/* Take default values */
245240
bool spawn_using_bgw = DEFAULT_SPAWN_USING_BGW,
246241
enable_auto = DEFAULT_AUTO;
@@ -264,7 +259,8 @@ create_partitions_for_value(Oid relid, Datum value, Oid value_type)
264259
* If table has been partitioned in some previous xact AND
265260
* we don't hold any conflicting locks, run BGWorker.
266261
*/
267-
if (spawn_using_bgw && part_in_prev_xact &&
262+
if (spawn_using_bgw &&
263+
xact_object_is_visible(rel_xmin) &&
268264
!xact_bgw_conflicting_lock_exists(relid))
269265
{
270266
elog(DEBUG2, "create_partitions(): chose BGWorker [%u]", MyProcPid);
@@ -686,7 +682,9 @@ choose_range_partition_name(Oid parent_relid, Oid parent_nsp)
686682
if (need_priv_escalation)
687683
SetUserIdAndSecContext(save_userid, save_sec_context);
688684

689-
return psprintf("%s_%u", get_rel_name(parent_relid), DatumGetInt32(part_num));
685+
return psprintf("%s_" UINT64_FORMAT,
686+
get_rel_name(parent_relid),
687+
(uint64) DatumGetInt64(part_num)); /* can't use UInt64 on 9.5 */
690688
}
691689

692690
/* Choose a good name for a HASH partition */

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