Skip to content

Commit cc2abf4

Browse files
committed
Fixed tablespace assignment in index with WITH clause
Reported by Beena Emerson.
1 parent f886e0d commit cc2abf4

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

bin/expected/tablespace.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
1313
-- If the query above failed you must create the 'testts' tablespace;
1414
CREATE TABLE testts1 (id serial primary key, data text);
1515
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
16+
CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80);
1617
INSERT INTO testts1 (data) values ('a');
1718
INSERT INTO testts1 (data) values ('b');
1819
INSERT INTO testts1 (data) values ('c');
@@ -71,7 +72,8 @@ ORDER BY relname;
7172
testts1 | testts
7273
testts1_partial_idx | testts
7374
testts1_pkey | testts
74-
(3 rows)
75+
testts1_with_idx | testts
76+
(4 rows)
7577

7678
-- can't specify --moveidx without --tablespace
7779
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx

bin/sql/tablespace.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
1111

1212
CREATE TABLE testts1 (id serial primary key, data text);
1313
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
14+
CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80);
1415
INSERT INTO testts1 (data) values ('a');
1516
INSERT INTO testts1 (data) values ('b');
1617
INSERT INTO testts1 (data) values ('c');

lib/repack.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,24 @@ skip_const(Oid index, char *sql, const char *arg1, const char *arg2)
346346
return parse_error(index);
347347
}
348348

349+
static char *
350+
skip_until_const(Oid index, char *sql, const char *what)
351+
{
352+
char *pos;
353+
354+
if ((pos = strstr(sql, what)))
355+
{
356+
size_t len;
357+
358+
len = strlen(what);
359+
pos[len] = '\0';
360+
return pos + len + 1;
361+
}
362+
363+
/* error */
364+
return parse_error(index);
365+
}
366+
349367
static char *
350368
skip_ident(Oid index, char *sql)
351369
{
@@ -664,7 +682,7 @@ repack_indexdef(PG_FUNCTION_ARGS)
664682
/* tablespace is to replace */
665683
char *tmp, *limit;
666684
limit = strchr(stmt.options, '\0');
667-
tmp = skip_const(index, stmt.options, " TABLESPACE", NULL);
685+
tmp = skip_until_const(index, stmt.options, " TABLESPACE");
668686
appendStringInfoString(&str, stmt.options);
669687
appendStringInfo(&str, " %s", NameStr(*tablespace));
670688
tmp = skip_ident(index, tmp);

0 commit comments

Comments
 (0)