From 924ccdcea246eb7c5ebbe7909ce5618fe723a372 Mon Sep 17 00:00:00 2001 From: Paul Guo Date: Thu, 17 May 2018 11:24:37 +0800 Subject: [PATCH] Use access() to check file existence in GetNewRelFileNode(). Previous code use BasicOpenFile() + close(). access() should be faster than BasicOpenFile()+close() and access() should be more correct since BasicOpenFile() could fail for various cases (e.g. due to file permission, etc) even the file exists. --- src/backend/catalog/catalog.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index 2292deb703..e516055a2b 100644 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -397,7 +397,6 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) { RelFileNodeBackend rnode; char *rpath; - int fd; bool collides; BackendId backend; @@ -445,12 +444,10 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence) /* Check for existing file of same name */ rpath = relpath(rnode, MAIN_FORKNUM); - fd = BasicOpenFile(rpath, O_RDONLY | PG_BINARY); - if (fd >= 0) + if (access(rpath, F_OK) == 0) { /* definite collision */ - close(fd); collides = true; } else -- 2.15.1 (Apple Git-101)