Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bd1085a

Browse files
committed
rewrite split_range_partition() function in C; fix merge_range_partitions() func; fix drop_range_partition_expand_next(); tests added
1 parent a79da22 commit bd1085a

File tree

13 files changed

+325
-130
lines changed

13 files changed

+325
-130
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ REGRESS = pathman_basic \
4141
pathman_calamity \
4242
pathman_ri
4343

44+
# REGRESS = pathman_ri
45+
# REGRESS = pathman_basic
46+
4447
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
4548

4649
EXTRA_CLEAN = pg_pathman--$(EXTVERSION).sql ./isolation_output

expected/pathman_basic.out

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ NOTICE: drop cascades to 4 other objects
943943
SELECT pathman.split_range_partition('test.num_range_rel_1', 500);
944944
split_range_partition
945945
-----------------------
946-
{0,1000}
946+
test.num_range_rel_5
947947
(1 row)
948948

949949
EXPLAIN (COSTS OFF) SELECT * FROM test.num_range_rel WHERE id BETWEEN 100 AND 700;
@@ -957,9 +957,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.num_range_rel WHERE id BETWEEN 100 AND 70
957957
(5 rows)
958958

959959
SELECT pathman.split_range_partition('test.range_rel_1', '2015-01-15'::DATE);
960-
split_range_partition
961-
-------------------------
962-
{01-01-2015,02-01-2015}
960+
split_range_partition
961+
-----------------------
962+
test.range_rel_5
963963
(1 row)
964964

965965
/* Merge two partitions into one */
@@ -1242,7 +1242,7 @@ SELECT pathman.prepend_range_partition('test.zero', 'test.zero_prepended');
12421242
SELECT pathman.split_range_partition('test.zero_50', 60, 'test.zero_60');
12431243
split_range_partition
12441244
-----------------------
1245-
{50,70}
1245+
test.zero_60
12461246
(1 row)
12471247

12481248
DROP TABLE test.zero CASCADE;
@@ -1567,9 +1567,9 @@ SELECT pathman.merge_range_partitions('test."RangeRel_1"', 'test."RangeRel_' ||
15671567
(1 row)
15681568

15691569
SELECT pathman.split_range_partition('test."RangeRel_1"', '2015-01-01'::DATE);
1570-
split_range_partition
1571-
-------------------------
1572-
{12-31-2014,01-02-2015}
1570+
split_range_partition
1571+
-----------------------
1572+
test."RangeRel_6"
15731573
(1 row)
15741574

15751575
SELECT pathman.drop_partitions('test."RangeRel"');
@@ -1669,9 +1669,9 @@ SELECT merge_range_partitions('test.range_rel_1', 'test.range_rel_2');
16691669
(1 row)
16701670

16711671
SELECT split_range_partition('test.range_rel_1', '2010-02-15'::date);
1672-
split_range_partition
1673-
-------------------------
1674-
{01-01-2010,03-01-2010}
1672+
split_range_partition
1673+
-----------------------
1674+
test.range_rel_13
16751675
(1 row)
16761676

16771677
SELECT append_range_partition('test.range_rel');

expected/pathman_domains.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SELECT merge_range_partitions('domains.dom_table_1', 'domains.dom_table_2');
4747
SELECT split_range_partition('domains.dom_table_1', 50);
4848
split_range_partition
4949
-----------------------
50-
{1,201}
50+
domains.dom_table_14
5151
(1 row)
5252

5353
INSERT INTO domains.dom_table VALUES(1101);

expected/pathman_ri.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ SELECT append_range_partition('abc');
7777

7878
INSERT INTO abc VALUES (350);
7979
INSERT INTO xxx (abc_id) VALUES (350);
80+
/* Partition cannot be dropped unless there are references from FK table */
8081
DROP TABLE abc_4;
82+
ERROR: update or delete on table "abc_4" violates foreign key constraint "xxx_abc_id_fkey" on table "xxx"
83+
/* Successful partition drop */
84+
DELETE FROM xxx WHERE abc_id = 350;
85+
DROP TABLE abc_4;
86+
/* Quick check for essential pg_pathman's functions */
87+
SELECT merge_range_partitions('abc_2', 'abc_3');
88+
merge_range_partitions
89+
------------------------
90+
91+
(1 row)
92+
93+
SELECT split_range_partition('abc_2', 200);
94+
split_range_partition
95+
-----------------------
96+
abc_5
97+
(1 row)
98+
99+
SELECT add_range_partition('abc', 301, 401, 'abc_x');
100+
add_range_partition
101+
---------------------
102+
abc_x
103+
(1 row)
104+
81105
DROP EXTENSION pg_pathman CASCADE;
82106
NOTICE: drop cascades to constraint xxx_abc_id_fkey on table xxx

range.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,15 @@ LANGUAGE C;
494494
* Split RANGE partition
495495
*/
496496
CREATE OR REPLACE FUNCTION @extschema@.split_range_partition(
497+
partition_relid REGCLASS,
498+
split_value ANYELEMENT,
499+
partition_name TEXT DEFAULT NULL,
500+
tablespace TEXT DEFAULT NULL)
501+
RETURNS REGCLASS AS 'pg_pathman', 'split_range_partitions'
502+
LANGUAGE C;
503+
504+
505+
CREATE OR REPLACE FUNCTION @extschema@._split_range_partition(
497506
partition_relid REGCLASS,
498507
split_value ANYELEMENT,
499508
partition_name TEXT DEFAULT NULL,

sql/pathman_ri.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ DROP INDEX abc_1_id_idx;
5454
SELECT append_range_partition('abc');
5555
INSERT INTO abc VALUES (350);
5656
INSERT INTO xxx (abc_id) VALUES (350);
57+
58+
/* Partition cannot be dropped unless there are references from FK table */
59+
DROP TABLE abc_4;
60+
61+
/* Successful partition drop */
62+
DELETE FROM xxx WHERE abc_id = 350;
5763
DROP TABLE abc_4;
5864

65+
/* Quick check for essential pg_pathman's functions */
66+
SELECT merge_range_partitions('abc_2', 'abc_3');
67+
SELECT split_range_partition('abc_2', 200);
68+
SELECT add_range_partition('abc', 301, 401, 'abc_x');
69+
5970
DROP EXTENSION pg_pathman CASCADE;

src/hooks.c

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ post_parse_analyze_hook_type post_parse_analyze_hook_next = NULL;
4949
shmem_startup_hook_type shmem_startup_hook_next = NULL;
5050
ProcessUtility_hook_type process_utility_hook_next = NULL;
5151

52-
static void pathman_drop_fkeys(Node *parsetree);
52+
static void pathman_prepare_drop(Node *parsetree);
5353

5454

5555
/* Take care of joins */
@@ -729,10 +729,11 @@ pathman_process_utility_hook(Node *parsetree,
729729
break;
730730
case T_DropStmt:
731731
/*
732-
* Check if there are pg_pathman's tables involved and drop
733-
* foreign key constraints if exist
732+
* Check if there are pg_pathman's tables involved:
733+
* if partitioned table involved then drop FK constraints
734+
* if partition then drop dependencies and check for references
734735
*/
735-
pathman_drop_fkeys(parsetree);
736+
pathman_prepare_drop(parsetree);
736737
break;
737738
default:
738739
; /* skip */
@@ -752,10 +753,10 @@ pathman_process_utility_hook(Node *parsetree,
752753
}
753754

754755
/*
755-
* Drop foreign key constraints referencing pg_pathman's tables being dropped
756+
* Prepare partitioned table or partition to be dropped
756757
*/
757758
static void
758-
pathman_drop_fkeys(Node *parsetree)
759+
pathman_prepare_drop(Node *parsetree)
759760
{
760761
DropStmt *drop_stmt = (DropStmt *) parsetree;
761762
ListCell *cell;
@@ -789,7 +790,7 @@ pathman_drop_fkeys(Node *parsetree)
789790
rv->relname)));
790791
}
791792

792-
/* Is it pg_pathman's table? */
793+
/* Is it pg_pathman's partitioned table? */
793794
if (get_pathman_relation_info(relid) != NULL)
794795
{
795796
List *ri_constr = NIL,
@@ -817,46 +818,14 @@ pathman_drop_fkeys(Node *parsetree)
817818
{
818819
PartParentSearch parent_search;
819820
Oid parent_relid;
820-
// Relation relation = heap_open(relid, NoLock);
821821

822822
/* Try fetching parent of this table */
823823
parent_relid = get_parent_of_partition(relid, &parent_search);
824824
if (parent_search == PPS_ENTRY_PART_PARENT)
825825
{
826-
ri_removePartitionDependencies(parent_relid, rel);
827-
// ri_removeTriggersDependency(parent_relid, relid);
826+
ri_preparePartitionDrop(parent_relid, rel, true);
828827
CommandCounterIncrement();
829-
830-
// {
831-
// const PartRelationInfo *prel;
832-
// const char * attname;
833-
// AttrNumber attnum;
834-
// Oid indexOid;
835-
// HeapTuple indexTuple;
836-
837-
// if ((prel = get_pathman_relation_info(parent_relid)) == NULL)
838-
// {
839-
// heap_close(relation, NoLock);
840-
// continue;
841-
// }
842-
843-
// attname = get_attname(parent_relid, prel->attnum);
844-
// attnum = get_attnum(relid, attname);
845-
// indexTuple = get_index_for_key(relation, attnum, &indexOid);
846-
847-
// /* If there is an index remove dependency */
848-
// if (HeapTupleIsValid(indexTuple))
849-
// {
850-
// deleteDependencyRecordsRef(RelationRelationId, indexOid);
851-
// ReleaseSysCache(indexTuple);
852-
853-
// /* Make changes visible */
854-
// CommandCounterIncrement();
855-
// }
856-
// }
857828
}
858-
859-
// heap_close(relation, NoLock);
860829
}
861830
heap_close(rel, lockmode);
862831
}

src/include/ref_integrity.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ void createPartitionForeignKeyTriggers(Oid partition,
1212
List *del_funcname);
1313
HeapTuple get_index_for_key(Relation rel, AttrNumber attnum, Oid *index_id);
1414
List *get_ri_triggers_list(Oid relid, Oid constr);
15-
void ri_removePartitionDependencies(Oid parent, Relation partition);
16-
void ri_checkReferences(Relation partition, Oid constraintOid);
15+
void ri_preparePartitionDrop(Oid parent,
16+
Relation partition,
17+
bool check_referencies);
18+
void ri_checkReferences(Relation partition, Oid constraintOid);
19+
void enable_ri_triggers(void);
20+
void disable_ri_triggers(void);

src/include/relation_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ typedef struct
3636
#define IsPlusInfinity(i) ( (i)->is_infinite == PLUS_INFINITY )
3737
#define IsMinusInfinity(i) ( (i)->is_infinite == MINUS_INFINITY )
3838

39+
#define BoundAsString(i, type) \
40+
( !IsInfinite(i) ? datum_to_cstring(BoundGetValue(i), (type)) : "NULL" )
41+
3942

4043
inline static Bound
4144
CopyBound(const Bound *src, bool byval, int typlen)

src/include/utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,5 @@ RangeVar ** qualified_relnames_to_rangevars(char **relnames, size_t nrelnames);
7070
*/
7171
long deleteDependencyRecords(Oid classId, Oid objId,
7272
Oid refClassId, Oid refObjId);
73-
long deleteDependencyRecordsRef(Oid classId, Oid objectId);
74-
7573

7674
#endif /* PATHMAN_UTILS_H */

0 commit comments

Comments
 (0)