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

Commit f2bc73c

Browse files
committed
some refactoring
1 parent 4511f8b commit f2bc73c

File tree

6 files changed

+236
-225
lines changed

6 files changed

+236
-225
lines changed

Makefile

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

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

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

expected/pathman_ri.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CREATE EXTENSION pg_pathman;
33
CREATE TABLE abc (id SERIAL);
44
CREATE TABLE xxx (id SERIAL, abc_id INT);
55
/* Cannot create FK if PK table isn't partitioned by pg_pathman */
6-
SELECT create_fk('xxx', 'abc_id', 'abc');
6+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
77
ERROR: table abc isn't partitioned by pg_pathman
88
/* Cannot create FK if there are no unique indexes */
99
SELECT create_range_partitions('abc', 'id', 1, 100, 3);
@@ -13,11 +13,11 @@ NOTICE: sequence "abc_seq" does not exist, skipping
1313
3
1414
(1 row)
1515

16-
SELECT create_fk('xxx', 'abc_id', 'abc');
16+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
1717
ERROR: there is no unique constraint matching given keys for referenced table "abc"
1818
/* Create index on parent but not on partitions. Expect an error */
1919
CREATE UNIQUE INDEX on abc(id);
20-
SELECT create_fk('xxx', 'abc_id', 'abc');
20+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
2121
ERROR: there is no unique constraint for partition "abc_1"
2222
/* Recreate partitioning setup with unique indexes */
2323
SELECT drop_partitions('abc');
@@ -38,13 +38,13 @@ SELECT create_range_partitions('abc', 'id', 1, 100, 3);
3838

3939
/* Existing row should violate FK constraint */
4040
INSERT INTO xxx (abc_id) VALUES (1);
41-
SELECT create_fk('xxx', 'abc_id', 'abc');
41+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
4242
ERROR: insert or update on table "xxx" violates foreign key constraint "xxx_abc_id_fkey"
4343
/* Expect successful execution */
4444
DELETE FROM xxx;
45-
SELECT create_fk('xxx', 'abc_id', 'abc');
46-
create_fk
47-
-----------
45+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
46+
create_foreign_key
47+
--------------------
4848

4949
(1 row)
5050

init.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,11 +932,11 @@ LANGUAGE C;
932932
/*
933933
* Referential integrity funcs and triggers
934934
*/
935-
CREATE OR REPLACE FUNCTION @extschema@.create_fk(
935+
CREATE OR REPLACE FUNCTION @extschema@.create_foreign_key(
936936
fk_table REGCLASS,
937937
fk_attr TEXT,
938938
pk_table REGCLASS)
939-
RETURNS VOID AS 'pg_pathman', 'create_fk_constraint'
939+
RETURNS VOID AS 'pg_pathman', 'create_foreign_key'
940940
LANGUAGE C STRICT;
941941

942942
CREATE OR REPLACE FUNCTION @extschema@.prepare_partition_drop(

sql/pathman_ri.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ CREATE TABLE abc (id SERIAL);
66
CREATE TABLE xxx (id SERIAL, abc_id INT);
77

88
/* Cannot create FK if PK table isn't partitioned by pg_pathman */
9-
SELECT create_fk('xxx', 'abc_id', 'abc');
9+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
1010

1111
/* Cannot create FK if there are no unique indexes */
1212
SELECT create_range_partitions('abc', 'id', 1, 100, 3);
13-
SELECT create_fk('xxx', 'abc_id', 'abc');
13+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
1414

1515
/* Create index on parent but not on partitions. Expect an error */
1616
CREATE UNIQUE INDEX on abc(id);
17-
SELECT create_fk('xxx', 'abc_id', 'abc');
17+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
1818

1919
/* Recreate partitioning setup with unique indexes */
2020
SELECT drop_partitions('abc');
@@ -23,11 +23,11 @@ SELECT create_range_partitions('abc', 'id', 1, 100, 3);
2323

2424
/* Existing row should violate FK constraint */
2525
INSERT INTO xxx (abc_id) VALUES (1);
26-
SELECT create_fk('xxx', 'abc_id', 'abc');
26+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
2727

2828
/* Expect successful execution */
2929
DELETE FROM xxx;
30-
SELECT create_fk('xxx', 'abc_id', 'abc');
30+
SELECT create_foreign_key('xxx', 'abc_id', 'abc');
3131

3232
/* PK violation */
3333
INSERT INTO xxx (id, abc_id) VALUES (100, 1);

src/include/ref_integrity.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* ref_integrity.c
4+
* Referential integrity for partitioned tables
5+
*
6+
* Copyright (c) 2016, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
10+
111
#include "postgres.h"
212

13+
314
void pathman_get_fkeys(Oid parent_relid, List **constraints, List **refrelids);
4-
void createSingleForeignKeyTrigger(Oid relOid, Oid refRelOid, List *funcname,
5-
char *trigname, int16 events, Oid constraintOid,
6-
Oid indexOid, bool is_internal);
715
void createPartitionForeignKeyTriggers(Oid partition,
8-
Oid fkrelid,
9-
AttrNumber attnum,
10-
Oid constraintOid,
11-
List *upd_funcname,
12-
List *del_funcname);
16+
Oid fkrelid,
17+
AttrNumber attnum,
18+
Oid constraintOid,
19+
List *upd_funcname,
20+
List *del_funcname);
21+
void createSingleForeignKeyTrigger(Oid relOid, Oid refRelOid, List *funcname,
22+
char *trigname, int16 events, Oid constraintOid,
23+
Oid indexOid, bool is_internal);
1324
HeapTuple get_index_for_key(Relation rel, AttrNumber attnum, Oid *index_id);
14-
List *get_ri_triggers_list(Oid relid, Oid constr);
15-
void ri_preparePartitionDrop(Oid parent,
16-
Relation partition,
17-
bool check_references);
1825
void ri_checkReferences(Relation partition, Oid constraintOid);
26+
List * get_ri_triggers_list(Oid relid, Oid constr);
27+
void ri_preparePartitionDrop(Oid parent,
28+
Relation partition,
29+
bool check_references);
1930
void enable_ri_triggers(void);
2031
void disable_ri_triggers(void);

0 commit comments

Comments
 (0)