Skip to content

Commit 55321b2

Browse files
committed
wrote a C version of merge_range_partitions() function
1 parent 194f29f commit 55321b2

File tree

10 files changed

+305
-61
lines changed

10 files changed

+305
-61
lines changed

hash.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ BEGIN
3838
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype)
3939
VALUES (parent_relid, attribute, 1);
4040

41+
IF array_length(relnames) != partitions_count THEN
42+
RAISE EXCEPTION 'Partition names array size must be equal the partitions count';
43+
END IF;
44+
45+
IF array_length(tablespaces) != partitions_count THEN
46+
RAISE EXCEPTION 'Partition tablespaces array size must be equal the partitions count';
47+
END IF;
48+
4149
/* Create partitions */
4250
PERFORM @extschema@.create_hash_partitions_internal(parent_relid,
4351
attribute,

range.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,13 @@ END
681681
$$ LANGUAGE plpgsql;
682682

683683

684+
CREATE OR REPLACE FUNCTION @extschema@.merge_range_partitions(
685+
parent REGCLASS,
686+
partitions REGCLASS[])
687+
RETURNS VOID AS 'pg_pathman', 'merge_range_partitions'
688+
LANGUAGE C STRICT;
689+
690+
684691
/*
685692
* Append new partition.
686693
*/

src/init.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -910,23 +910,6 @@ cmp_range_entries(const void *p1, const void *p2, void *arg)
910910
FmgrInfo *flinfo = (FmgrInfo *) arg;
911911

912912
return cmp_bounds(flinfo, &v1->min, &v2->min);
913-
914-
// /* If range is half open */
915-
// if (IsInfinite(&v1->min))
916-
// {
917-
// // if (IsInfinite(&v2->min))
918-
// // return Int32GetDatum(0);
919-
// return Int32GetDatum(-1);
920-
// }
921-
// if (IsInfinite(&v2->min))
922-
// {
923-
// return Int32GetDatum(1);
924-
// }
925-
926-
// /* Else if range is closed */
927-
// return OidFunctionCall2(cmp_proc_oid,
928-
// BoundGetValue(&v1->min),
929-
// BoundGetValue(&v2->min));
930913
}
931914

932915
/*

src/partition_creation.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static Constraint *make_constraint_common(char *name, Node *raw_expr);
8383
static Value make_string_value_struct(char *str);
8484
static Value make_int_value_struct(int int_val);
8585

86+
static RangeVar *makeRangeVarFromRelid(Oid relid);
87+
8688

8789
/*
8890
* ---------------------------------------
@@ -1426,6 +1428,40 @@ make_int_value_struct(int int_val)
14261428
return val;
14271429
}
14281430

1431+
void
1432+
drop_check_constraint(Oid relid, AttrNumber attnum)
1433+
{
1434+
char *constr_name;
1435+
AlterTableStmt *stmt;
1436+
AlterTableCmd *cmd;
1437+
1438+
/* Build a correct name for this constraint */
1439+
constr_name = build_check_constraint_name_relid_internal(relid, attnum);
1440+
1441+
stmt = makeNode(AlterTableStmt);
1442+
stmt->relation = makeRangeVarFromRelid(relid);
1443+
stmt->relkind = OBJECT_TABLE;
1444+
1445+
cmd = makeNode(AlterTableCmd);
1446+
cmd->subtype = AT_DropConstraint;
1447+
cmd->name = constr_name;
1448+
cmd->behavior = DROP_RESTRICT;
1449+
cmd->missing_ok = true;
1450+
1451+
stmt->cmds = list_make1(cmd);
1452+
1453+
AlterTable(relid, ShareUpdateExclusiveLock, stmt);
1454+
}
1455+
1456+
static RangeVar *
1457+
makeRangeVarFromRelid(Oid relid)
1458+
{
1459+
char *relname = get_rel_name(relid);
1460+
char *namespace = get_namespace_name(get_rel_namespace(relid));
1461+
1462+
return makeRangeVar(namespace, relname, -1);
1463+
}
1464+
14291465

14301466
/*
14311467
* ---------------------

src/partition_creation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Node * build_raw_hash_check_tree(char *attname,
7474
uint32 part_idx,
7575
uint32 part_count, Oid value_type);
7676

77+
void drop_check_constraint(Oid relid, AttrNumber attnum);
78+
7779

7880
/* Partitioning callback type */
7981
typedef enum

src/pl_funcs.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -779,25 +779,7 @@ prevent_relation_modification(PG_FUNCTION_ARGS)
779779
{
780780
Oid relid = PG_GETARG_OID(0);
781781

782-
/*
783-
* Check that isolation level is READ COMMITTED.
784-
* Else we won't be able to see new rows
785-
* which could slip through locks.
786-
*/
787-
if (!xact_is_level_read_committed())
788-
ereport(ERROR,
789-
(errmsg("Cannot perform blocking partitioning operation"),
790-
errdetail("Expected READ COMMITTED isolation level")));
791-
792-
/*
793-
* Check if table is being modified
794-
* concurrently in a separate transaction.
795-
*/
796-
if (!xact_lock_rel_exclusive(relid, true))
797-
ereport(ERROR,
798-
(errmsg("Cannot perform blocking partitioning operation"),
799-
errdetail("Table \"%s\" is being modified concurrently",
800-
get_rel_name_or_relid(relid))));
782+
(void) prevent_relation_modification_internal(relid);
801783

802784
PG_RETURN_VOID();
803785
}

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