You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for pg_dump to dump tables in cluster order if a clustered index is defined on the table, a little hacked in with how the data is passed around and how the order is pulled out of the db. The latter is the only semi-problematic part as you might be able to generate (very odd) table column names that would break the regex used there which would cause the sql query to be invalid and therefore not dump data for that table. But as long as you don't name an clustered column/function something like "foo ) WHERE" or the like should be ok.
Pulled from REL9_1_2_P and fixed some merge conflicts
Conflicts:
src/bin/pg_dump/pg_dump.c
@@ -4473,6 +4482,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4473
4482
i_oid,
4474
4483
i_indexname,
4475
4484
i_indexdef,
4485
+
i_indexdeforderclause,
4476
4486
i_indnkeys,
4477
4487
i_indkey,
4478
4488
i_indisclustered,
@@ -4528,6 +4538,14 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4528
4538
"SELECT t.tableoid, t.oid, "
4529
4539
"t.relname AS indexname, "
4530
4540
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
4541
+
/*
4542
+
* FIXME - regex is not the best way to to do this, but
4543
+
* indexdef is consistent enough that it should work
4544
+
* Any missing corner cases worth worrying about?
4545
+
* A column named "foo ) WITH" would be problematic...
4546
+
* but would need a parser to cover all possible cases
4547
+
*/
4548
+
"CASE WHEN i.indisclustered THEN 'ORDER BY ' || regexp_replace(pg_catalog.pg_get_indexdef(i.indexrelid), E'^CREATE (UNIQUE )?INDEX (CONCURRENTLY )?.* ON .* USING [^\\\\(]*\\\\((.*?)\\\\)($| WITH .*| WHERE .*| TABLESPACE .*)', E'\\\\3') ELSE NULL END AS indexdeforderclause, "
4531
4549
"t.relnatts AS indnkeys, "
4532
4550
"i.indkey, i.indisclustered, "
4533
4551
"c.contype, c.conname, "
@@ -4554,6 +4572,14 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4554
4572
"SELECT t.tableoid, t.oid, "
4555
4573
"t.relname AS indexname, "
4556
4574
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
4575
+
/*
4576
+
* FIXME - regex is not the best way to to do this, but
4577
+
* indexdef is consistent enough that it should work
4578
+
* Any missing corner cases worth worrying about?
4579
+
* A column named "foo ) WITH" would be problematic...
4580
+
* but would need a parser to cover all possible cases
4581
+
*/
4582
+
"CASE WHEN i.indisclustered THEN 'ORDER BY ' || regexp_replace(pg_catalog.pg_get_indexdef(i.indexrelid), E'^CREATE (UNIQUE )?INDEX (CONCURRENTLY )?.* ON .* USING [^\\\\(]*\\\\((.*?)\\\\)($| WITH .*| WHERE .*| TABLESPACE .*)', E'\\\\3') ELSE NULL END AS indexdeforderclause, "
4557
4583
"t.relnatts AS indnkeys, "
4558
4584
"i.indkey, i.indisclustered, "
4559
4585
"c.contype, c.conname, "
@@ -4583,6 +4609,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4583
4609
"SELECT t.tableoid, t.oid, "
4584
4610
"t.relname AS indexname, "
4585
4611
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
4612
+
"NULL AS indexdeforderclause, "
4586
4613
"t.relnatts AS indnkeys, "
4587
4614
"i.indkey, i.indisclustered, "
4588
4615
"c.contype, c.conname, "
@@ -4611,6 +4638,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4611
4638
"SELECT t.tableoid, t.oid, "
4612
4639
"t.relname AS indexname, "
4613
4640
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
4641
+
"NULL AS indexdeforderclause, "
4614
4642
"t.relnatts AS indnkeys, "
4615
4643
"i.indkey, i.indisclustered, "
4616
4644
"c.contype, c.conname, "
@@ -4639,6 +4667,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4639
4667
"SELECT t.tableoid, t.oid, "
4640
4668
"t.relname AS indexname, "
4641
4669
"pg_get_indexdef(i.indexrelid) AS indexdef, "
4670
+
"NULL AS indexdeforderclause, "
4642
4671
"t.relnatts AS indnkeys, "
4643
4672
"i.indkey, false AS indisclustered, "
4644
4673
"CASE WHEN i.indisprimary THEN 'p'::char "
@@ -4665,6 +4694,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
4665
4694
"t.oid, "
4666
4695
"t.relname AS indexname, "
4667
4696
"pg_get_indexdef(i.indexrelid) AS indexdef, "
4697
+
"NULL AS indexdeforderclause, "
4668
4698
"t.relnatts AS indnkeys, "
4669
4699
"i.indkey, false AS indisclustered, "
4670
4700
"CASE WHEN i.indisprimary THEN 'p'::char "
@@ -4692,6 +4722,7 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Copy file name to clipboardExpand all lines: src/bin/pg_dump/pg_dump.h
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -291,6 +291,7 @@ typedef struct _tableInfo
291
291
intnumParents; /* number of (immediate) parent tables */
292
292
struct_tableInfo**parents; /* TableInfos of immediate parents */
293
293
struct_tableDataInfo*dataObj; /* TableDataInfo, if dumping its data */
294
+
char*ordercond; /* ORDER condition to order dumped rows, should prob. be in dataObj, but we find it out from the indexes before that's created (though arguably should do it's own query since that's the only way to support --data-only with --cluster-order) */
0 commit comments