Skip to content

Commit 25a6fa7

Browse files
committed
bugfix for PARTITION BY HASH with no relnames and tablespaces specified
1 parent a9e03f6 commit 25a6fa7

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

contrib/test_partitioning/expected/partition.out

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ SELECT * FROM pathman_partition_list;
2424
abc | abc_200 | 2 | id | 200 | 400
2525
(3 rows)
2626

27-
/* Check that we can omit optional INTO parameter */
28-
ALTER TABLE abc SPLIT PARTITION abc_200 AT (300);
29-
ALTER TABLE abc MERGE PARTITIONS abc_200, abc_1;
27+
ALTER TABLE abc ADD PARTITION abc_400 VALUES LESS THAN (500);
28+
ALTER TABLE abc DROP PARTITION abc_200;
3029
SELECT * FROM pathman_partition_list;
3130
parent | partition | parttype | partattr | range_min | range_max
3231
--------+-----------+----------+----------+-----------+-----------
3332
abc | abc_inf | 2 | id | NULL | 100
3433
abc | abc_100 | 2 | id | 100 | 200
35-
abc | abc_200 | 2 | id | 200 | 400
34+
abc | abc_400 | 2 | id | 200 | 500
3635
(3 rows)
3736

3837
/* Inserting values into area not covered by partitions should create new partition */
@@ -42,12 +41,11 @@ SELECT * FROM pathman_partition_list;
4241
--------+-----------+----------+----------+-----------+-----------
4342
abc | abc_inf | 2 | id | NULL | 100
4443
abc | abc_100 | 2 | id | 100 | 200
45-
abc | abc_200 | 2 | id | 200 | 400
46-
abc | abc_2 | 2 | id | 400 | 500
47-
(4 rows)
44+
abc | abc_400 | 2 | id | 200 | 500
45+
(3 rows)
4846

4947
DROP TABLE abc CASCADE;
50-
NOTICE: drop cascades to 4 other objects
48+
NOTICE: drop cascades to 3 other objects
5149
/*
5250
* Create range partitioned table (in contrast to interval-partitioned in terms
5351
* of Oracle)
@@ -58,7 +56,7 @@ PARTITION BY RANGE(id)
5856
PARTITION abc_inf VALUES LESS THAN (100),
5957
PARTITION abc_100 VALUES LESS THAN (200)
6058
);
61-
/* Inserting should produce an error */
59+
/* Inserting should produce an error because interval hasn't been set */
6260
INSERT INTO abc VALUES (250);
6361
ERROR: could not create new partitions for relation "abc"
6462
DROP TABLE abc CASCADE;

contrib/test_partitioning/sql/partition.sql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ ALTER TABLE abc SPLIT PARTITION abc_200 AT (300) INTO (PARTITION abc_200, PARTIT
2020
ALTER TABLE abc MERGE PARTITIONS abc_200, abc_300 INTO PARTITION abc_200;
2121
SELECT * FROM pathman_partition_list;
2222

23-
/* Check that we can omit optional INTO parameter */
24-
ALTER TABLE abc SPLIT PARTITION abc_200 AT (300);
25-
ALTER TABLE abc MERGE PARTITIONS abc_200, abc_1;
23+
ALTER TABLE abc ADD PARTITION abc_400 VALUES LESS THAN (500);
24+
ALTER TABLE abc DROP PARTITION abc_200;
2625
SELECT * FROM pathman_partition_list;
2726

2827
/* Inserting values into area not covered by partitions should create new partition */
@@ -42,7 +41,7 @@ PARTITION BY RANGE(id)
4241
PARTITION abc_100 VALUES LESS THAN (200)
4342
);
4443

45-
/* Inserting should produce an error */
44+
/* Inserting should produce an error because interval hasn't been set */
4645
INSERT INTO abc VALUES (250);
4746
DROP TABLE abc CASCADE;
4847

src/backend/commands/partition.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ static void create_range_partitions(CreateStmt *stmt, Oid relid, const char *att
3434
static Node *cookPartitionKeyValue(Oid relid, const char *raw, Node *raw_value);
3535
static char *RangeVarGetString(const RangeVar *rangevar);
3636
static Oid RangeVarGetNamespaceId(const RangeVar *rangevar);
37-
static List* makeNameListFromRangeVar(const RangeVar *rangevar);
3837

3938
#define equalstr(a, b) \
4039
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
@@ -74,7 +73,7 @@ create_hash_partitions(CreateStmt *stmt, Oid relid, const char* attname)
7473
char **relnames = NULL;
7574
char **tablespaces = NULL;
7675

77-
if (pinfo->partitions_count > 0)
76+
if (list_length(pinfo->partitions) > 0)
7877
{
7978
ListCell *lc;
8079
int i = 0;
@@ -100,7 +99,11 @@ create_hash_partitions(CreateStmt *stmt, Oid relid, const char* attname)
10099
relnames,
101100
tablespaces);
102101

103-
pfree(relnames);
102+
/* Free allocated resources */
103+
if (relnames)
104+
pfree(relnames);
105+
if (tablespaces)
106+
pfree(tablespaces);
104107
}
105108

106109

@@ -519,16 +522,3 @@ RangeVarGetNamespaceId(const RangeVar *rangevar)
519522

520523
return namespace_id;
521524
}
522-
523-
524-
/*
525-
* This is the inverse function for makeRangeVarFromNameList()
526-
*/
527-
static List*
528-
makeNameListFromRangeVar(const RangeVar *rangevar)
529-
{
530-
Oid namespace_id = RangeVarGetNamespaceId(rangevar);
531-
532-
return list_make2(makeString(get_namespace_name(namespace_id)),
533-
makeString(rangevar->relname));
534-
}

src/backend/parser/gram.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,7 @@ partitionType: HASH '(' a_expr ')' PARTITIONS '(' Iconst ')'
30303030
PartitionInfo *n = (PartitionInfo *) palloc(sizeof(PartitionInfo));
30313031
n->partition_type = P_HASH;
30323032
n->key = $3;
3033+
n->partitions = NIL;
30333034
n->partitions_count = $7;
30343035
$$ = (PartitionInfo *)n;
30353036
}

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