pg_repack.git / summary / log / commit / refs
commit cc2abf4b25360e4ea4109ec79cfe38c9ddf10a1b
Author: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Date: Thu May 02 22:32:30 2013 +0000
Fixed tablespace assignment in index with WITH clause
Reported by Beena Emerson.
bin/expected/tablespace.out | 4 +++-
bin/sql/tablespace.sql | 1 +
lib/repack.c | 20 +++++++++++++++++++-
3 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/bin/expected/tablespace.out b/bin/expected/tablespace.out
index 7a7a769..15f69c2 100644
--- a/bin/expected/tablespace.out
+++ b/bin/expected/tablespace.out
@@ -13,6 +13,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
-- If the query above failed you must create the 'testts' tablespace;
CREATE TABLE testts1 (id serial primary key, data text);
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
+CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80);
INSERT INTO testts1 (data) values ('a');
INSERT INTO testts1 (data) values ('b');
INSERT INTO testts1 (data) values ('c');
@@ -71,7 +72,8 @@ ORDER BY relname;
testts1 | testts
testts1_partial_idx | testts
testts1_pkey | testts
-(3 rows)
+ testts1_with_idx | testts
+(4 rows)
-- can't specify --moveidx without --tablespace
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --moveidx
diff --git a/bin/sql/tablespace.sql b/bin/sql/tablespace.sql
index 1f2c46a..7fa2ce8 100644
--- a/bin/sql/tablespace.sql
+++ b/bin/sql/tablespace.sql
@@ -11,6 +11,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
CREATE TABLE testts1 (id serial primary key, data text);
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
+CREATE INDEX testts1_with_idx on testts1 (id) with (fillfactor=80);
INSERT INTO testts1 (data) values ('a');
INSERT INTO testts1 (data) values ('b');
INSERT INTO testts1 (data) values ('c');
diff --git a/lib/repack.c b/lib/repack.c
index 125acce..34fdcf9 100644
--- a/lib/repack.c
+++ b/lib/repack.c
@@ -346,6 +346,24 @@ skip_const(Oid index, char *sql, const char *arg1, const char *arg2)
return parse_error(index);
}
+static char *
+skip_until_const(Oid index, char *sql, const char *what)
+{
+ char *pos;
+
+ if ((pos = strstr(sql, what)))
+ {
+ size_t len;
+
+ len = strlen(what);
+ pos[len] = '\0';
+ return pos + len + 1;
+ }
+
+ /* error */
+ return parse_error(index);
+}
+
static char *
skip_ident(Oid index, char *sql)
{
@@ -664,7 +682,7 @@ repack_indexdef(PG_FUNCTION_ARGS)
/* tablespace is to replace */
char *tmp, *limit;
limit = strchr(stmt.options, '\0');
- tmp = skip_const(index, stmt.options, " TABLESPACE", NULL);
+ tmp = skip_until_const(index, stmt.options, " TABLESPACE");
appendStringInfoString(&str, stmt.options);
appendStringInfo(&str, " %s", NameStr(*tablespace));
tmp = skip_ident(index, tmp);
[parent: f886e0dba66d]