This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit b1cf523f7435fbfad61b4e0b7f231733f92c8e6a
Author: Brent Doil <[email protected]>
AuthorDate: Fri Jul 22 18:22:07 2022 -0400

    pg_dump: Lock all interesting tables in single statement.
    
    This reduces the potentially significant command and
    communication overhead between frontend and backend
    when sending a LOCK TABLE query for each table.
    
    Discussion: 
https://www.postgresql.org/message-id/20120530.180620.600165924826262795.t-ishii%40sraoss.co.jp
    
    Authored-by: Brent Doil <[email protected]>
---
 src/bin/pg_dump/pg_dump.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2d77da17d2..cb4b6e1db4 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -7256,6 +7256,7 @@ getTables(Archive *fout, int *numTables)
        int                     i;
        PQExpBuffer query = createPQExpBuffer();
        TableInfo  *tblinfo;
+       bool            lockTableDumped = false;
        int                     i_reltableoid;
        int                     i_reloid;
        int                     i_relname;
@@ -7963,6 +7964,8 @@ getTables(Archive *fout, int *numTables)
                ExecuteSqlStatement(fout, query->data);
        }
 
+       resetPQExpBuffer(query);
+
        for (i = 0; i < ntups; i++)
        {
                tblinfo[i].dobj.objType = DO_TABLE;
@@ -8098,6 +8101,11 @@ getTables(Archive *fout, int *numTables)
                 *
                 * We only need to lock the table for certain components; see
                 * pg_dump.h
+                * 
+                * GPDB: Build a single LOCK TABLE statement to lock all 
interesting tables.
+                * This is more performant than issuing a separate LOCK TABLE 
statement for each table,
+                * with considerable savings in FE/BE overhead. It does come at 
the cost of some increased
+                * memory usage in both FE and BE, which we will be able to 
tolerate.
                 */
                /* GPDB_14_MERGE_FIXME: GPDB_96_MERGE_FIXME: Is the parrelid 
check still needed? */
                if (tblinfo[i].dobj.dump &&
@@ -8106,11 +8114,15 @@ getTables(Archive *fout, int *numTables)
                        tblinfo[i].parrelid == 0 &&
                        (tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK))
                {
-                       resetPQExpBuffer(query);
-                       appendPQExpBuffer(query,
-                                                         "LOCK TABLE %s IN 
ACCESS SHARE MODE",
-                                                         
fmtQualifiedDumpable(&tblinfo[i]));
-                       ExecuteSqlStatement(fout, query->data);
+                       if (!lockTableDumped)
+                               appendPQExpBuffer(query,
+                                               "LOCK TABLE %s ",
+                                               
fmtQualifiedDumpable(&tblinfo[i]));
+                       else
+                               appendPQExpBuffer(query,
+                                               ",%s ",
+                                               
fmtQualifiedDumpable(&tblinfo[i]));
+                       lockTableDumped = true;
                }
 
                /* Emit notice if join for owner failed */
@@ -8118,6 +8130,13 @@ getTables(Archive *fout, int *numTables)
                        pg_log_warning("owner of table \"%s\" appears to be 
invalid",
                                                   tblinfo[i].dobj.name);
        }
+       /* Are there any tables to lock? */
+       if (lockTableDumped)
+       {
+       appendPQExpBuffer(query,
+                       "IN ACCESS SHARE MODE");
+       ExecuteSqlStatement(fout, query->data);
+       }
 
        if (dopt->lockWaitTimeout)
        {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to