Skip to content

Commit d98a14b

Browse files
committed
Fixed index definition tokenization
In the previous commit skip_const was going ahead the space thus removing the starting quote. Also fixed (and tested) trailing part after the tablespace name, e.g. the WHERE clause.
1 parent 83fdb2a commit d98a14b

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

bin/expected/tablespace.out

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
1212

1313
-- If the query above failed you must create the 'testts' tablespace;
1414
CREATE TABLE testts1 (id serial primary key, data text);
15+
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
1516
INSERT INTO testts1 (data) values ('a');
1617
INSERT INTO testts1 (data) values ('b');
1718
INSERT INTO testts1 (data) values ('c');
1819
-- can move the tablespace from default
1920
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts
2021
SELECT relname, spcname
2122
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
22-
WHERE relname ~ '^testts1';
23+
WHERE relname ~ '^testts1'
24+
ORDER BY relname;
2325
relname | spcname
2426
---------+---------
2527
testts1 | testts
@@ -37,7 +39,8 @@ SELECT * from testts1 order by id;
3739
\! pg_repack --dbname=contrib_regression --no-order --table=testts1
3840
SELECT relname, spcname
3941
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
40-
WHERE relname ~ '^testts1';
42+
WHERE relname ~ '^testts1'
43+
ORDER BY relname;
4144
relname | spcname
4245
---------+---------
4346
testts1 | testts
@@ -47,7 +50,8 @@ WHERE relname ~ '^testts1';
4750
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
4851
SELECT relname, spcname
4952
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
50-
WHERE relname ~ '^testts1';
53+
WHERE relname ~ '^testts1'
54+
ORDER BY relname;
5155
relname | spcname
5256
---------+---------
5357
(0 rows)
@@ -56,12 +60,14 @@ WHERE relname ~ '^testts1';
5660
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
5761
SELECT relname, spcname
5862
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
59-
WHERE relname ~ '^testts1';
60-
relname | spcname
61-
--------------+---------
62-
testts1 | testts
63-
testts1_pkey | testts
64-
(2 rows)
63+
WHERE relname ~ '^testts1'
64+
ORDER BY relname;
65+
relname | spcname
66+
---------------------+---------
67+
testts1 | testts
68+
testts1_partial_idx | testts
69+
testts1_pkey | testts
70+
(3 rows)
6571

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

bin/sql/tablespace.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SELECT spcname FROM pg_tablespace WHERE spcname = 'testts';
1010
-- If the query above failed you must create the 'testts' tablespace;
1111

1212
CREATE TABLE testts1 (id serial primary key, data text);
13+
CREATE INDEX testts1_partial_idx on testts1 (id) where (id > 0);
1314
INSERT INTO testts1 (data) values ('a');
1415
INSERT INTO testts1 (data) values ('b');
1516
INSERT INTO testts1 (data) values ('c');
@@ -19,7 +20,8 @@ INSERT INTO testts1 (data) values ('c');
1920

2021
SELECT relname, spcname
2122
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
22-
WHERE relname ~ '^testts1';
23+
WHERE relname ~ '^testts1'
24+
ORDER BY relname;
2325

2426
SELECT * from testts1 order by id;
2527

@@ -28,21 +30,24 @@ SELECT * from testts1 order by id;
2830

2931
SELECT relname, spcname
3032
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
31-
WHERE relname ~ '^testts1';
33+
WHERE relname ~ '^testts1'
34+
ORDER BY relname;
3235

3336
-- can move the ts back to default
3437
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 -s pg_default
3538

3639
SELECT relname, spcname
3740
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
38-
WHERE relname ~ '^testts1';
41+
WHERE relname ~ '^testts1'
42+
ORDER BY relname;
3943

4044
-- can move the table together with the indexes
4145
\! pg_repack --dbname=contrib_regression --no-order --table=testts1 --tablespace testts --moveidx
4246

4347
SELECT relname, spcname
4448
FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace
45-
WHERE relname ~ '^testts1';
49+
WHERE relname ~ '^testts1'
50+
ORDER BY relname;
4651

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

lib/repack.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,25 +653,22 @@ repack_indexdef(PG_FUNCTION_ARGS)
653653
}
654654
else
655655
{
656-
const char *pos;
657-
if (NULL == (pos = strstr(stmt.options, " TABLESPACE ")))
656+
if (NULL == strstr(stmt.options, "TABLESPACE"))
658657
{
659658
/* tablespace is to append */
660659
appendStringInfoString(&str, " TABLESPACE ");
661660
appendStringInfoString(&str, NameStr(*tablespace));
662661
}
663662
else
664663
{
665-
char *tmp;
666-
667664
/* tablespace is to replace */
668-
tmp = skip_const(index, stmt.options, " TABLESPACE ", NULL);
665+
char *tmp;
666+
tmp = skip_const(index, stmt.options, " TABLESPACE", NULL);
669667
appendStringInfoString(&str, stmt.options);
670-
appendStringInfoString(&str, NameStr(*tablespace));
671-
/* FIXME: not working if original ts has a space. But skip_ident
672-
* should deal with that. Stupid mistake somewhere? */
668+
appendStringInfo(&str, " %s", NameStr(*tablespace));
673669
tmp = skip_ident(index, tmp);
674-
appendStringInfoString(&str, tmp);
670+
if (*tmp)
671+
appendStringInfo(&str, " %s", tmp);
675672
}
676673
}
677674

0 commit comments

Comments
 (0)