From f0a6e5ba4bcc67fdcfe83d8599fdf2572130f366 Mon Sep 17 00:00:00 2001 From: Artur Zakirov Date: Mon, 11 Mar 2024 14:47:02 +0100 Subject: [PATCH 1/3] Issue 386: Do not call quote_ident() within repack_one_database() --- .github/workflows/regression.yml | 5 ++++- bin/pg_repack.c | 2 +- regress/expected/tablespace.out | 15 +++++++++++++++ regress/expected/tablespace_1.out | 15 +++++++++++++++ regress/expected/tablespace_2.out | 15 +++++++++++++++ regress/expected/tablespace_3.out | 15 +++++++++++++++ regress/expected/tablespace_4.out | 15 +++++++++++++++ regress/sql/tablespace.sql | 8 ++++++++ 8 files changed, 88 insertions(+), 2 deletions(-) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 003ae00c..14b401c8 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -35,11 +35,14 @@ jobs: run: echo "$PWD/bin" >> $GITHUB_PATH - name: Create testts directory - run: sudo -u postgres mkdir /tmp/testts + run: sudo -u postgres mkdir /tmp/testts /tmp/1testts - name: Create testts tablespace run: sudo -u postgres psql -c "CREATE TABLESPACE testts LOCATION '/tmp/testts'" + - name: Create 1testts tablespace + run: sudo -u postgres psql -c "CREATE TABLESPACE 1testts LOCATION '/tmp/1testts'" + - name: Test on PostgreSQL ${{ matrix.pg }} run: pg-build-test diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 37b6ae7e..6feae8d7 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -783,7 +783,7 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize) "SELECT t.*," " coalesce(v.tablespace, t.tablespace_orig) as tablespace_dest" " FROM repack.tables t, " - " (VALUES (quote_ident($1::text))) as v (tablespace)" + " (VALUES ($1::text)) as v (tablespace)" " WHERE "); params[iparam++] = tablespace; diff --git a/regress/expected/tablespace.out b/regress/expected/tablespace.out index 11c7e106..819dcfe9 100644 --- a/regress/expected/tablespace.out +++ b/regress/expected/tablespace.out @@ -245,3 +245,18 @@ ORDER BY relname; --using --indexes-only and --index option together \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey ERROR: cannot specify --index (-i) and --table (-t) +--check quote_ident() with 1testts tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | 1testts + testts1_partial_idx | 1testts + testts1_pkey | 1testts + testts1_with_idx | 1testts +(4 rows) + diff --git a/regress/expected/tablespace_1.out b/regress/expected/tablespace_1.out index 4ef2d04a..177505ec 100644 --- a/regress/expected/tablespace_1.out +++ b/regress/expected/tablespace_1.out @@ -245,3 +245,18 @@ ORDER BY relname; --using --indexes-only and --index option together \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey ERROR: cannot specify --index (-i) and --table (-t) +--check quote_ident() with 1testts tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | 1testts + testts1_partial_idx | 1testts + testts1_pkey | 1testts + testts1_with_idx | 1testts +(4 rows) + diff --git a/regress/expected/tablespace_2.out b/regress/expected/tablespace_2.out index 521f82a6..e06c3715 100644 --- a/regress/expected/tablespace_2.out +++ b/regress/expected/tablespace_2.out @@ -245,3 +245,18 @@ ORDER BY relname; --using --indexes-only and --index option together \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey ERROR: cannot specify --index (-i) and --table (-t) +--check quote_ident() with 1testts tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | 1testts + testts1_partial_idx | 1testts + testts1_pkey | 1testts + testts1_with_idx | 1testts +(4 rows) + diff --git a/regress/expected/tablespace_3.out b/regress/expected/tablespace_3.out index a3d023c6..6a898d32 100644 --- a/regress/expected/tablespace_3.out +++ b/regress/expected/tablespace_3.out @@ -245,3 +245,18 @@ ORDER BY relname; --using --indexes-only and --index option together \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey ERROR: cannot specify --index (-i) and --table (-t) +--check quote_ident() with 1testts tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | 1testts + testts1_partial_idx | 1testts + testts1_pkey | 1testts + testts1_with_idx | 1testts +(4 rows) + diff --git a/regress/expected/tablespace_4.out b/regress/expected/tablespace_4.out index cc6495f8..ddcec3be 100644 --- a/regress/expected/tablespace_4.out +++ b/regress/expected/tablespace_4.out @@ -245,3 +245,18 @@ ORDER BY relname; --using --indexes-only and --index option together \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey ERROR: cannot specify --index (-i) and --table (-t) +--check quote_ident() with 1testts tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | 1testts + testts1_partial_idx | 1testts + testts1_pkey | 1testts + testts1_with_idx | 1testts +(4 rows) + diff --git a/regress/sql/tablespace.sql b/regress/sql/tablespace.sql index 78790d87..52a1b4dc 100644 --- a/regress/sql/tablespace.sql +++ b/regress/sql/tablespace.sql @@ -147,3 +147,11 @@ ORDER BY relname; --using --indexes-only and --index option together \! pg_repack --dbname=contrib_regression --table=testts1 --only-indexes --index=testts1_pkey + +--check quote_ident() with 1testts tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace=1testts --moveidx + +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; From d6912c92e0da247c5548fcc8dcb703fddcaf4848 Mon Sep 17 00:00:00 2001 From: Artur Zakirov Date: Mon, 11 Mar 2024 14:52:48 +0100 Subject: [PATCH 2/3] Fix tablespace name in the workflow --- .github/workflows/regression.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 14b401c8..467efaf4 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -41,7 +41,7 @@ jobs: run: sudo -u postgres psql -c "CREATE TABLESPACE testts LOCATION '/tmp/testts'" - name: Create 1testts tablespace - run: sudo -u postgres psql -c "CREATE TABLESPACE 1testts LOCATION '/tmp/1testts'" + run: sudo -u postgres psql -c "CREATE TABLESPACE \"1testts\" LOCATION '/tmp/1testts'" - name: Test on PostgreSQL ${{ matrix.pg }} run: pg-build-test From 9a96bfad01784aa3535b2c754b712be2b82ffc87 Mon Sep 17 00:00:00 2001 From: Artur Zakirov Date: Mon, 11 Mar 2024 16:41:48 +0100 Subject: [PATCH 3/3] Adding more unusual tablespaces names per @andreasscherbaum --- .github/workflows/regression.yml | 10 ++-------- regress/create_tablespaces.sh | 8 ++++++++ regress/expected/tablespace.out | 30 ++++++++++++++++++++++++++++++ regress/expected/tablespace_1.out | 30 ++++++++++++++++++++++++++++++ regress/expected/tablespace_2.out | 30 ++++++++++++++++++++++++++++++ regress/expected/tablespace_3.out | 30 ++++++++++++++++++++++++++++++ regress/expected/tablespace_4.out | 30 ++++++++++++++++++++++++++++++ regress/sql/tablespace.sql | 16 ++++++++++++++++ 8 files changed, 176 insertions(+), 8 deletions(-) create mode 100755 regress/create_tablespaces.sh diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 467efaf4..5fb62544 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -34,14 +34,8 @@ jobs: - name: Put pg_repack on PATH run: echo "$PWD/bin" >> $GITHUB_PATH - - name: Create testts directory - run: sudo -u postgres mkdir /tmp/testts /tmp/1testts - - - name: Create testts tablespace - run: sudo -u postgres psql -c "CREATE TABLESPACE testts LOCATION '/tmp/testts'" - - - name: Create 1testts tablespace - run: sudo -u postgres psql -c "CREATE TABLESPACE \"1testts\" LOCATION '/tmp/1testts'" + - name: Create tablespaces + run: bash regress/create_tablespaces.sh - name: Test on PostgreSQL ${{ matrix.pg }} run: pg-build-test diff --git a/regress/create_tablespaces.sh b/regress/create_tablespaces.sh new file mode 100755 index 00000000..e9e64e34 --- /dev/null +++ b/regress/create_tablespaces.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +sudo -u postgres mkdir /tmp/testts /tmp/1testts /tmp/test\ ts /tmp/test\"ts + +sudo -u postgres psql -c "CREATE TABLESPACE testts LOCATION '/tmp/testts'" +sudo -u postgres psql -c "CREATE TABLESPACE \"1testts\" LOCATION '/tmp/1testts'" +sudo -u postgres psql -c "CREATE TABLESPACE \"test ts\" LOCATION '/tmp/test ts'" +sudo -u postgres psql -c "CREATE TABLESPACE \"test\"\"ts\" LOCATION '/tmp/test\"ts'" diff --git a/regress/expected/tablespace.out b/regress/expected/tablespace.out index 819dcfe9..164c6f37 100644 --- a/regress/expected/tablespace.out +++ b/regress/expected/tablespace.out @@ -260,3 +260,33 @@ ORDER BY relname; testts1_with_idx | 1testts (4 rows) +--check quote_ident() with "test ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test ts + testts1_partial_idx | test ts + testts1_pkey | test ts + testts1_with_idx | test ts +(4 rows) + +--check quote_ident() with "test""ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test"ts + testts1_partial_idx | test"ts + testts1_pkey | test"ts + testts1_with_idx | test"ts +(4 rows) + diff --git a/regress/expected/tablespace_1.out b/regress/expected/tablespace_1.out index 177505ec..007dac4f 100644 --- a/regress/expected/tablespace_1.out +++ b/regress/expected/tablespace_1.out @@ -260,3 +260,33 @@ ORDER BY relname; testts1_with_idx | 1testts (4 rows) +--check quote_ident() with "test ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test ts + testts1_partial_idx | test ts + testts1_pkey | test ts + testts1_with_idx | test ts +(4 rows) + +--check quote_ident() with "test""ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test"ts + testts1_partial_idx | test"ts + testts1_pkey | test"ts + testts1_with_idx | test"ts +(4 rows) + diff --git a/regress/expected/tablespace_2.out b/regress/expected/tablespace_2.out index e06c3715..f5a56a72 100644 --- a/regress/expected/tablespace_2.out +++ b/regress/expected/tablespace_2.out @@ -260,3 +260,33 @@ ORDER BY relname; testts1_with_idx | 1testts (4 rows) +--check quote_ident() with "test ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test ts + testts1_partial_idx | test ts + testts1_pkey | test ts + testts1_with_idx | test ts +(4 rows) + +--check quote_ident() with "test""ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test"ts + testts1_partial_idx | test"ts + testts1_pkey | test"ts + testts1_with_idx | test"ts +(4 rows) + diff --git a/regress/expected/tablespace_3.out b/regress/expected/tablespace_3.out index 6a898d32..4ff1bc43 100644 --- a/regress/expected/tablespace_3.out +++ b/regress/expected/tablespace_3.out @@ -260,3 +260,33 @@ ORDER BY relname; testts1_with_idx | 1testts (4 rows) +--check quote_ident() with "test ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test ts + testts1_partial_idx | test ts + testts1_pkey | test ts + testts1_with_idx | test ts +(4 rows) + +--check quote_ident() with "test""ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test"ts + testts1_partial_idx | test"ts + testts1_pkey | test"ts + testts1_with_idx | test"ts +(4 rows) + diff --git a/regress/expected/tablespace_4.out b/regress/expected/tablespace_4.out index ddcec3be..d9970294 100644 --- a/regress/expected/tablespace_4.out +++ b/regress/expected/tablespace_4.out @@ -260,3 +260,33 @@ ORDER BY relname; testts1_with_idx | 1testts (4 rows) +--check quote_ident() with "test ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test ts + testts1_partial_idx | test ts + testts1_pkey | test ts + testts1_with_idx | test ts +(4 rows) + +--check quote_ident() with "test""ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx +INFO: repacking table "public.testts1" +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + relname | spcname +---------------------+--------- + testts1 | test"ts + testts1_partial_idx | test"ts + testts1_pkey | test"ts + testts1_with_idx | test"ts +(4 rows) + diff --git a/regress/sql/tablespace.sql b/regress/sql/tablespace.sql index 52a1b4dc..8f770fdf 100644 --- a/regress/sql/tablespace.sql +++ b/regress/sql/tablespace.sql @@ -155,3 +155,19 @@ SELECT relname, spcname FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace WHERE relname ~ '^testts1' ORDER BY relname; + +--check quote_ident() with "test ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test ts" --moveidx + +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname; + +--check quote_ident() with "test""ts" tablespace +\! pg_repack --dbname=contrib_regression --table=testts1 --tablespace="test\"ts" --moveidx + +SELECT relname, spcname +FROM pg_class JOIN pg_tablespace ts ON ts.oid = reltablespace +WHERE relname ~ '^testts1' +ORDER BY relname;