Skip to content

Commit 0b99585

Browse files
committed
Add DYNAMIC TABLE support to pg_dump.
Use pg_dump to dump Dynamic Tables. Authored-by: Zhang Mingli [email protected]
1 parent d63192b commit 0b99585

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,8 +2930,16 @@ refreshMatViewData(Archive *fout, const TableDataInfo *tdinfo)
29302930

29312931
q = createPQExpBuffer();
29322932

2933-
appendPQExpBuffer(q, "REFRESH MATERIALIZED VIEW %s;\n",
2934-
fmtQualifiedDumpable(tbinfo));
2933+
if (tbinfo->isdynamic)
2934+
{
2935+
appendPQExpBuffer(q, "REFRESH DYNAMIC TABLE %s;\n",
2936+
fmtQualifiedDumpable(tbinfo));
2937+
}
2938+
else
2939+
{
2940+
appendPQExpBuffer(q, "REFRESH MATERIALIZED VIEW %s;\n",
2941+
fmtQualifiedDumpable(tbinfo));
2942+
}
29352943

29362944
if (tdinfo->dobj.dump & DUMP_COMPONENT_DATA)
29372945
ArchiveEntry(fout,
@@ -2940,7 +2948,7 @@ refreshMatViewData(Archive *fout, const TableDataInfo *tdinfo)
29402948
ARCHIVE_OPTS(.tag = tbinfo->dobj.name,
29412949
.namespace = tbinfo->dobj.namespace->dobj.name,
29422950
.owner = tbinfo->rolname,
2943-
.description = "MATERIALIZED VIEW DATA",
2951+
.description = tbinfo->isdynamic ? "DYNAMIC TABLE DATA": "MATERIALIZED VIEW DATA",
29442952
.section = SECTION_POST_DATA,
29452953
.createStmt = q->data,
29462954
.deps = tdinfo->dobj.dependencies,
@@ -7415,6 +7423,7 @@ getTables(Archive *fout, int *numTables)
74157423
int i_amname;
74167424
int i_amoid;
74177425
int i_isivm;
7426+
int i_isdynamic;
74187427

74197428
/*
74207429
* Find all the tables and table-like objects.
@@ -7535,7 +7544,8 @@ getTables(Archive *fout, int *numTables)
75357544
"%s AS partkeydef, "
75367545
"%s AS ispartition, "
75377546
"%s AS partbound, "
7538-
"c.relisivm AS isivm "
7547+
"c.relisivm AS isivm, "
7548+
"c.relisdynamic AS isdynamic "
75397549
"FROM pg_class c "
75407550
"LEFT JOIN pg_depend d ON "
75417551
"(c.relkind = '%c' AND "
@@ -8106,6 +8116,7 @@ getTables(Archive *fout, int *numTables)
81068116
i_amname = PQfnumber(res, "amname");
81078117
i_amoid = PQfnumber(res, "amoid");
81088118
i_isivm = PQfnumber(res, "isivm");
8119+
i_isdynamic = PQfnumber(res, "isdynamic");
81098120

81108121
if (dopt->lockWaitTimeout)
81118122
{
@@ -8238,6 +8249,7 @@ getTables(Archive *fout, int *numTables)
82388249
tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0);
82398250
tblinfo[i].partbound = pg_strdup(PQgetvalue(res, i, i_partbound));
82408251
tblinfo[i].isivm = (strcmp(PQgetvalue(res, i, i_isivm), "t") == 0);
8252+
tblinfo[i].isdynamic = (strcmp(PQgetvalue(res, i, i_isdynamic), "t") == 0);
82418253

82428254
/* foreign server */
82438255
tblinfo[i].foreign_server = atooid(PQgetvalue(res, i, i_foreignserver));
@@ -18081,7 +18093,10 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
1808118093
break;
1808218094
}
1808318095
case RELKIND_MATVIEW:
18084-
reltypename = "MATERIALIZED VIEW";
18096+
if (tbinfo->isdynamic)
18097+
reltypename = "DYNAMIC TABLE";
18098+
else
18099+
reltypename = "MATERIALIZED VIEW";
1808518100
break;
1808618101
default:
1808718102
reltypename = "TABLE";
@@ -18154,14 +18169,22 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
1815418169
}
1815518170
}
1815618171

18157-
appendPQExpBuffer(q, "CREATE %s%s%s %s",
18158-
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
18159-
"UNLOGGED " : "",
18160-
tbinfo->relkind == RELKIND_MATVIEW && tbinfo->isivm ?
18161-
"INCREMENTAL " : "",
18162-
reltypename,
18163-
qualrelname);
18172+
if (tbinfo->relkind == RELKIND_MATVIEW && tbinfo->isdynamic)
18173+
{
18174+
/* We'r sure there is no UNLOGGED and this is a DYNAMIC TABLE. */
18175+
appendPQExpBuffer(q, "CREATE DYNAMIC TABLE %s", qualrelname);
18176+
}
18177+
else
18178+
{
18179+
appendPQExpBuffer(q, "CREATE %s%s%s %s",
18180+
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
18181+
"UNLOGGED " : "",
18182+
tbinfo->relkind == RELKIND_MATVIEW && tbinfo->isivm ?
18183+
"INCREMENTAL " : "",
18184+
reltypename,
18185+
qualrelname);
1816418186

18187+
}
1816518188
/*
1816618189
* Attach to type, if reloftype; except in case of a binary upgrade,
1816718190
* we dump the table normally and attach it to the type afterward.

src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ typedef struct _tableInfo
398398
int numTriggers; /* number of triggers for table */
399399
struct _triggerInfo *triggers; /* array of TriggerInfo structs */
400400
bool isivm; /* is incrementally maintainable materialized view? */
401+
bool isdynamic; /* is dynamic table? */
401402
} TableInfo;
402403

403404
typedef struct _tableAttachInfo

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,21 @@
21862186
unlike => { exclude_dump_test_schema => 1, },
21872187
},
21882188
2189+
'CREATE DYNAMIC TABLE dynamic_table' => {
2190+
create_order => 28,
2191+
create_sql => 'CREATE DYNAMIC TABLE dump_test.dynamic_table (col1) AS
2192+
SELECT col1 FROM dump_test.test_table;',
2193+
regexp => qr/^
2194+
\QCREATE DYNAMIC TABLE dump_test.dynamic_table AS\E
2195+
\n\s+\QSELECT test_table.col1\E
2196+
\n\s+\QFROM dump_test.test_table\E
2197+
\n\s+\QWITH NO DATA;\E
2198+
/xm,
2199+
like =>
2200+
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
2201+
unlike => { exclude_dump_test_schema => 1, },
2202+
},
2203+
21892204
'CREATE POLICY p1 ON test_table' => {
21902205
create_order => 22,
21912206
create_sql => 'CREATE POLICY p1 ON dump_test.test_table

0 commit comments

Comments
 (0)