Fix reorganize table without sorting.

Commit 5adff6ff0b separated the
data copy from creating table. This is a cause of bug that
pg_repack doesn't actually sort table during reorganization.
This commit fixes this issue by adding ORDER BY clause to Copy
SQL rather than CREATE TABLE SQL.

Reported by acmzero on issue #138.
This commit is contained in:
Masahiko Sawada
2017-08-05 02:31:47 +09:00
parent cac8179299
commit 33f4c30563
4 changed files with 130 additions and 12 deletions

View File

@ -81,6 +81,7 @@ CREATE TABLE tbl_with_mod_column_storage (
);
ALTER TABLE tbl_with_mod_column_storage ALTER c SET STORAGE MAIN;
CREATE TABLE tbl_order (c int primary key);
--
-- insert data
--
@ -126,6 +127,10 @@ SET client_min_messages = warning;
INSERT INTO tbl_idxopts VALUES (0, 'abc'), (1, 'aaa'), (2, NULL), (3, 'bbb');
-- Insert no-ordered data
INSERT INTO tbl_order SELECT generate_series(100, 51, -1);
CLUSTER tbl_order USING tbl_order_pkey;
INSERT INTO tbl_order SELECT generate_series(50, 1, -1);
--
-- before
--
@ -241,6 +246,19 @@ CREATE TABLE trg3 (id integer PRIMARY KEY);
CREATE TRIGGER repack_trigger_1 BEFORE UPDATE ON trg3 FOR EACH ROW EXECUTE PROCEDURE trgtest();
\! pg_repack --dbname=contrib_regression --table=trg3
--
-- Table re-organization using specific column
--
-- reorganize table using cluster key. Sort in ascending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
-- reorganize table using specific column order. Sort in descending order.
\! pg_repack --dbname=contrib_regression --table=tbl_order -o "c DESC"
SELECT ctid, c FROM tbl_order WHERE ctid <= '(0,10)';
--
-- Dry run
--