Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 81a23dd

Browse filesBrowse files
committed
Avoid unnecessary table open/close in TRUNCATE command.
ExecuteTruncate() filters out the duplicate tables specified in the TRUNCATE command, for example in the case where "TRUNCATE foo, foo" is executed. Such duplicate tables obviously don't need to be opened and closed because they are skipped. But previously it always opened the tables before checking whether they were duplicated ones or not, and then closed them if they were. That is, the duplicated tables were opened and closed unnecessarily. This commit changes ExecuteTruncate() so that it opens the table after it confirms that table is not duplicated one, which leads to avoid unnecessary table open/close. Do not back-patch because such unnecessary table open/close is not a bug though it exists in older versions. Author: Bharath Rupireddy Reviewed-by: Amul Sul, Fujii Masao Discussion: https://postgr.es/m/CALj2ACUdBO_sXJTa08OZ0YT0qk7F_gAmRa9hT4dxRcgPS4nsZA@mail.gmail.com
1 parent 08aa89b commit 81a23dd
Copy full SHA for 81a23dd

File tree

Expand file treeCollapse file tree

1 file changed

+3
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-6
lines changed

‎src/backend/commands/tablecmds.c

Copy file name to clipboardExpand all lines: src/backend/commands/tablecmds.c
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,15 +1639,12 @@ ExecuteTruncate(TruncateStmt *stmt)
16391639
0, RangeVarCallbackForTruncate,
16401640
NULL);
16411641

1642-
/* open the relation, we already hold a lock on it */
1643-
rel = table_open(myrelid, NoLock);
1644-
16451642
/* don't throw error for "TRUNCATE foo, foo" */
16461643
if (list_member_oid(relids, myrelid))
1647-
{
1648-
table_close(rel, lockmode);
16491644
continue;
1650-
}
1645+
1646+
/* open the relation, we already hold a lock on it */
1647+
rel = table_open(myrelid, NoLock);
16511648

16521649
/*
16531650
* RangeVarGetRelidExtended() has done most checks with its callback,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.