Re: Removal of temp tables - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Removal of temp tables
Date
Msg-id 200106150006.f5F06R505374@candle.pha.pa.us
Whole thread Raw
In response to Re: Removal of temp tables  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> >> If you don't like pg_temp here, maybe post_temp?  pgsql_temp?
>
> > What if I call the directory tmp or pgsql_tmp and the files
> > pgsql_pid_#.#?
>
> Why are you so eager not to call temp files "temp"?  If you want to
> spell it "pgsql_tmp" or "pg_temporary" or something different from
> "pg_temp", that's fine, but I really think the files ought to clearly
> label themselves as temporary.  "pid" is not a clear label.  With a
> name like that, people might even think they are lock files.

OK, here is the new version with directories and files called pgsql_tmp.
That doesn't look like it holds temp tables.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: src/backend/catalog/aclchk.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/aclchk.c,v
retrieving revision 1.50
diff -c -r1.50 aclchk.c
*** src/backend/catalog/aclchk.c    2001/06/09 23:21:54    1.50
--- src/backend/catalog/aclchk.c    2001/06/15 00:01:48
***************
*** 32,37 ****
--- 32,38 ----
  #include "parser/parse_func.h"
  #include "utils/acl.h"
  #include "utils/syscache.h"
+ #include "utils/temprel.h"

  static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);

***************
*** 437,443 ****
       */
      if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
          !allowSystemTableMods && IsSystemRelationName(relname) &&
!         strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
          !((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
      {
  #ifdef ACLDEBUG
--- 438,444 ----
       */
      if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
          !allowSystemTableMods && IsSystemRelationName(relname) &&
!         !is_temp_relname(relname) &&
          !((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
      {
  #ifdef ACLDEBUG
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/heap.c,v
retrieving revision 1.167
diff -c -r1.167 heap.c
*** src/backend/catalog/heap.c    2001/06/12 05:55:49    1.167
--- src/backend/catalog/heap.c    2001/06/15 00:01:49
***************
*** 281,288 ****
           * replace relname of caller with a unique name for a temp
           * relation
           */
!         snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
!                  (int) MyProcPid, uniqueId++);
      }

      /*
--- 281,288 ----
           * replace relname of caller with a unique name for a temp
           * relation
           */
!         snprintf(relname, NAMEDATALEN, "%s_%d_%u",
!                 PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
      }

      /*
***************
*** 874,910 ****
  }


- /* ----------------------------------------------------------------
-  *        heap_drop_with_catalog    - removes all record of named relation from catalogs
-  *
-  *        1)    open relation, check for existence, etc.
-  *        2)    remove inheritance information
-  *        3)    remove indexes
-  *        4)    remove pg_class tuple
-  *        5)    remove pg_attribute tuples and related descriptions
-  *                6)        remove pg_description tuples
-  *        7)    remove pg_type tuples
-  *        8)    RemoveConstraints ()
-  *        9)    unlink relation
-  *
-  * old comments
-  *        Except for vital relations, removes relation from
-  *        relation catalog, and related attributes from
-  *        attribute catalog (needed?).  (Anything else?)
-  *
-  *        get proper relation from relation catalog (if not arg)
-  *        scan attribute catalog deleting attributes of reldesc
-  *                (necessary?)
-  *        delete relation from relation catalog
-  *        (How are the tuples of the relation discarded?)
-  *
-  *        XXX Must fix to work with indexes.
-  *        There may be a better order for doing things.
-  *        Problems with destroying a deleted database--cannot create
-  *        a struct reldesc without having an open file descriptor.
-  * ----------------------------------------------------------------
-  */
-
  /* --------------------------------
   *        RelationRemoveInheritance
   *
--- 874,879 ----
***************
*** 1334,1343 ****
      heap_close(pg_type_desc, RowExclusiveLock);
  }

! /* --------------------------------
!  *        heap_drop_with_catalog
   *
!  * --------------------------------
   */
  void
  heap_drop_with_catalog(const char *relname,
--- 1303,1337 ----
      heap_close(pg_type_desc, RowExclusiveLock);
  }

! /* ----------------------------------------------------------------
!  *        heap_drop_with_catalog    - removes all record of named relation from catalogs
   *
!  *        1)    open relation, check for existence, etc.
!  *        2)    remove inheritance information
!  *        3)    remove indexes
!  *        4)    remove pg_class tuple
!  *        5)    remove pg_attribute tuples and related descriptions
!  *                6)        remove pg_description tuples
!  *        7)    remove pg_type tuples
!  *        8)    RemoveConstraints ()
!  *        9)    unlink relation
!  *
!  * old comments
!  *        Except for vital relations, removes relation from
!  *        relation catalog, and related attributes from
!  *        attribute catalog (needed?).  (Anything else?)
!  *
!  *        get proper relation from relation catalog (if not arg)
!  *        scan attribute catalog deleting attributes of reldesc
!  *                (necessary?)
!  *        delete relation from relation catalog
!  *        (How are the tuples of the relation discarded?)
!  *
!  *        XXX Must fix to work with indexes.
!  *        There may be a better order for doing things.
!  *        Problems with destroying a deleted database--cannot create
!  *        a struct reldesc without having an open file descriptor.
!  * ----------------------------------------------------------------
   */
  void
  heap_drop_with_catalog(const char *relname,
***************
*** 1360,1367 ****
       * prevent deletion of system relations
       */
      /* allow temp of pg_class? Guess so. */
!     if (!istemp && !allow_system_table_mods &&
!         IsSystemRelationName(RelationGetRelationName(rel)))
          elog(ERROR, "System relation \"%s\" may not be dropped",
               RelationGetRelationName(rel));

--- 1354,1363 ----
       * prevent deletion of system relations
       */
      /* allow temp of pg_class? Guess so. */
!     if (!istemp &&
!         !allow_system_table_mods &&
!         IsSystemRelationName(RelationGetRelationName(rel)) &&
!         !is_temp_relname(RelationGetRelationName(rel)))
          elog(ERROR, "System relation \"%s\" may not be dropped",
               RelationGetRelationName(rel));

Index: src/backend/storage/file/fd.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/storage/file/fd.c,v
retrieving revision 1.81
diff -c -r1.81 fd.c
*** src/backend/storage/file/fd.c    2001/06/11 04:12:29    1.81
--- src/backend/storage/file/fd.c    2001/06/15 00:01:52
***************
*** 54,61 ****


  /* Filename components for OpenTemporaryFile */
! #define PG_TEMP_FILES_DIR "pg_tempfiles"
! #define PG_TEMP_FILE_PREFIX "pg_temp"


  /*
--- 54,61 ----


  /* Filename components for OpenTemporaryFile */
! #define PG_TEMP_FILES_DIR "pgsql_tmp"
! #define PG_TEMP_FILE_PREFIX "pgsql_tmp"


  /*
Index: src/backend/tcop/utility.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/tcop/utility.c,v
retrieving revision 1.113
diff -c -r1.113 utility.c
*** src/backend/tcop/utility.c    2001/06/09 23:21:54    1.113
--- src/backend/tcop/utility.c    2001/06/15 00:01:52
***************
*** 46,51 ****
--- 46,52 ----
  #include "utils/acl.h"
  #include "utils/ps_status.h"
  #include "utils/syscache.h"
+ #include "utils/temprel.h"
  #include "access/xlog.h"

  /*
***************
*** 120,126 ****
          elog(ERROR, "you do not own %s \"%s\"",
               rentry->name, name);

!     if (!allowSystemTableMods && IsSystemRelationName(name))
          elog(ERROR, "%s \"%s\" is a system %s",
               rentry->name, name, rentry->name);

--- 121,128 ----
          elog(ERROR, "you do not own %s \"%s\"",
               rentry->name, name);

!     if (!allowSystemTableMods && IsSystemRelationName(name) &&
!         !is_temp_relname(name))
          elog(ERROR, "%s \"%s\" is a system %s",
               rentry->name, name, rentry->name);

Index: src/include/utils/temprel.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/utils/temprel.h,v
retrieving revision 1.15
diff -c -r1.15 temprel.h
*** src/include/utils/temprel.h    2001/03/22 04:01:14    1.15
--- src/include/utils/temprel.h    2001/06/15 00:01:53
***************
*** 16,21 ****
--- 16,26 ----

  #include "access/htup.h"

+ #define PG_TEMP_REL_PREFIX "pg_temp"
+
+ #define is_temp_relname(relname) \
+         (strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)) == 0)
+
  extern void create_temp_relation(const char *relname,
                       HeapTuple pg_class_tuple);
  extern void remove_temp_rel_by_relid(Oid relid);

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Removal of temp tables
Next
From: Marko Kreen
Date:
Subject: switch for disabling ecpg & pgeasy