Thread: Add GUC setting to make created tables default to WITHOUT

Add GUC setting to make created tables default to WITHOUT

From
Hans-Jürgen Schönig
Date:
I have attaches a patch against 7.4.0 which contains the implementation
of the following todo item.


 > Log message:
 >    Add:
 >
 >    > * Add GUC setting to make created tables
 >           default to WITHOUT OIDS


    Cheers,

        Hans


--
Cybertec Geschwinde u Schoenig
Ludo-Hartmannplatz 1/14, A-1160 Vienna, Austria
Tel: +43/2952/30706 or +43/660/816 40 77
www.cybertec.at, www.postgresql.at, kernel.cybertec.at

*** ./doc/src/sgml/ref/create_table.sgml.orig    2003-11-19 18:28:41.000000000 +0100
--- ./doc/src/sgml/ref/create_table.sgml    2003-11-19 18:30:12.000000000 +0100
***************
*** 243,252 ****
      <listitem>
       <para>
        This optional clause specifies whether rows of the new table
!       should have OIDs (object identifiers) assigned to them.  The
!       default is to have OIDs.  (If the new table inherits from any
        tables that have OIDs, then <literal>WITH OIDS</> is forced even
!       if the command says <literal>WITHOUT OIDS</>.)
       </para>

       <para>
--- 243,254 ----
      <listitem>
       <para>
        This optional clause specifies whether rows of the new table
!       should have OIDs (object identifiers) assigned to them. The
!       default behaviour of PostgrSQL can be defined with the help of a
!       runtime variable (table_with_oid).
!       If the new table inherits from any
        tables that have OIDs, then <literal>WITH OIDS</> is forced even
!       if the command says <literal>WITHOUT OIDS</>.
       </para>

       <para>
*** ./src/backend/commands/tablecmds.c.orig    2003-11-19 10:24:13.000000000 +0100
--- ./src/backend/commands/tablecmds.c    2003-11-19 18:23:13.000000000 +0100
***************
*** 52,57 ****
--- 52,58 ----
  #include "utils/acl.h"
  #include "utils/builtins.h"
  #include "utils/fmgroids.h"
+ #include "utils/guc.h"
  #include "utils/inval.h"
  #include "utils/lsyscache.h"
  #include "utils/relcache.h"
***************
*** 250,257 ****
       */
      descriptor = BuildDescForRelation(schema);

!     descriptor->tdhasoid = (stmt->hasoids || parentHasOids);
!
      if (old_constraints != NIL)
      {
          ConstrCheck *check = (ConstrCheck *) palloc(length(old_constraints) *
--- 251,273 ----
       */
      descriptor = BuildDescForRelation(schema);

!     /* it is time to decide whether the table we are about to
!      * generate contains an OID or not. several cases have to be
!      * taken into consideration. we will need an oid if:
!      *  a. the parent table has an oid
!      *  b. the user has not defined WITH/OUT OID explicity but has
!      *     set "table_with_oid" to "true"
!      *  c. the user tells us to use an OID - no matter if
!      *     table_with_oid is set or not
!      */
!     if    (parentHasOids || stmt->hasoids == WITH_OID ||
!         (stmt->hasoids == EMPTY_OID && table_with_oid == true))
!     {
!         descriptor->tdhasoid = true;
!     }
!     else
!         descriptor->tdhasoid = false;
!
      if (old_constraints != NIL)
      {
          ConstrCheck *check = (ConstrCheck *) palloc(length(old_constraints) *
*** ./src/backend/nodes/outfuncs.c.orig    2003-11-19 10:37:59.000000000 +0100
--- ./src/backend/nodes/outfuncs.c    2003-11-19 10:38:14.000000000 +0100
***************
*** 1101,1107 ****
      WRITE_NODE_FIELD(tableElts);
      WRITE_NODE_FIELD(inhRelations);
      WRITE_NODE_FIELD(constraints);
!     WRITE_BOOL_FIELD(hasoids);
      WRITE_ENUM_FIELD(oncommit, OnCommitAction);
  }

--- 1101,1107 ----
      WRITE_NODE_FIELD(tableElts);
      WRITE_NODE_FIELD(inhRelations);
      WRITE_NODE_FIELD(constraints);
!     WRITE_INT_FIELD(hasoids);
      WRITE_ENUM_FIELD(oncommit, OnCommitAction);
  }

*** ./src/backend/parser/gram.y.orig    2003-11-19 10:54:02.000000000 +0100
--- ./src/backend/parser/gram.y    2003-11-19 16:21:17.000000000 +0100
***************
*** 234,240 ****
  %type <defelt>    createfunc_opt_item
  %type <typnam>    func_arg func_return func_type aggr_argtype

! %type <boolean> opt_arg TriggerForType OptTemp OptWithOids
  %type <oncommit>    OnCommitOption

  %type <list>    for_update_clause opt_for_update_clause update_list
--- 234,241 ----
  %type <defelt>    createfunc_opt_item
  %type <typnam>    func_arg func_return func_type aggr_argtype

! %type <ival> OptWithOids
! %type <boolean> opt_arg TriggerForType OptTemp
  %type <oncommit>    OnCommitOption

  %type <list>    for_update_clause opt_for_update_clause update_list
***************
*** 1840,1848 ****
          ;

  OptWithOids:
!             WITH OIDS                                { $$ = TRUE; }
!             | WITHOUT OIDS                            { $$ = FALSE; }
!             | /*EMPTY*/                                { $$ = TRUE; }
          ;

  OnCommitOption:  ON COMMIT DROP                { $$ = ONCOMMIT_DROP; }
--- 1841,1849 ----
          ;

  OptWithOids:
!             WITH OIDS                                { $$ = WITH_OID; }
!             | WITHOUT OIDS                            { $$ = WITHOUT_OID; }
!             | /*EMPTY*/                                { $$ = EMPTY_OID; }
          ;

  OnCommitOption:  ON COMMIT DROP                { $$ = ONCOMMIT_DROP; }
*** ./src/backend/utils/misc/guc.c.orig    2003-11-19 12:19:19.000000000 +0100
--- ./src/backend/utils/misc/guc.c    2003-11-19 18:36:31.000000000 +0100
***************
*** 103,108 ****
--- 103,111 ----
  #ifdef USE_ASSERT_CHECKING
  bool        assert_enabled = true;
  #endif
+
+ bool        table_with_oid = true;
+
  bool        log_statement = false;
  bool        log_duration = false;
  bool        Debug_print_plan = false;
***************
*** 481,486 ****
--- 484,497 ----
          false, NULL, NULL
      },
      {
+         {"table_with_oid", PGC_USERSET, CLIENT_CONN_STATEMENT,
+             gettext_noop("Tells us whether we want OIDs or not."),
+             NULL
+         },
+         &table_with_oid,
+         false, NULL, NULL
+     },
+     {
          {"log_connections", PGC_BACKEND, LOGGING_WHAT,
              gettext_noop("Logs each successful connection."),
              NULL
*** ./src/backend/utils/misc/postgresql.conf.sample.orig    2003-11-19 18:37:24.000000000 +0100
--- ./src/backend/utils/misc/postgresql.conf.sample    2003-11-19 18:37:33.000000000 +0100
***************
*** 210,215 ****
--- 210,216 ----
  #default_transaction_isolation = 'read committed'
  #default_transaction_read_only = false
  #statement_timeout = 0        # 0 is disabled, in milliseconds
+ #table_with_oid = true

  # - Locale and Formatting -

*** ./src/bin/psql/tab-complete.c.orig    2003-11-19 12:29:38.000000000 +0100
--- ./src/bin/psql/tab-complete.c    2003-11-19 12:29:46.000000000 +0100
***************
*** 562,567 ****
--- 562,568 ----
          "syslog",
          "syslog_facility",
          "syslog_ident",
+         "table_with_oid",
          "tcpip_socket",
          "TimeZone",
          "trace_notify",
*** ./src/include/nodes/parsenodes.h.orig    2003-11-19 12:03:19.000000000 +0100
--- ./src/include/nodes/parsenodes.h    2003-11-19 16:20:02.000000000 +0100
***************
*** 916,921 ****
--- 916,926 ----
      OnCommitAction oncommit;    /* what do we do at COMMIT? */
  } CreateStmt;

+ /* needed for WITH/OUT OIDs in CREATE TABLE statements */
+ #define    WITHOUT_OID    0
+ #define    EMPTY_OID    1
+ #define    WITH_OID    2
+
  /* ----------
   * Definitions for plain (non-FOREIGN KEY) constraints in CreateStmt
   *
*** ./src/include/utils/guc.h.orig    2003-11-19 12:18:50.000000000 +0100
--- ./src/include/utils/guc.h    2003-11-19 13:18:57.000000000 +0100
***************
*** 106,111 ****
--- 106,112 ----
  extern bool log_statement_stats;
  extern bool log_btree_build_stats;

+ extern bool table_with_oid;
  extern bool SQL_inheritance;
  extern bool Australian_timezones;


Re: Add GUC setting to make created tables default to

From
Neil Conway
Date:
Hans-Jürgen Schönig <postgres@cybertec.at> writes:
> I have attaches a patch against 7.4.0 which contains the
> implementation of the following todo item.

I sent a proposal for this functionality to -hackers a month or so
ago, and implemented it a couple days later -- it was sent to
pgsql-patches, and is in the queue of items to be applied to 7.5.

-Neil


Re: Add GUC setting to make created tables default to

From
Hans-Jürgen Schönig
Date:
Neil Conway wrote:
> Hans-Jürgen Schönig <postgres@cybertec.at> writes:
>
>>I have attaches a patch against 7.4.0 which contains the
>>implementation of the following todo item.
>
>
> I sent a proposal for this functionality to -hackers a month or so
> ago, and implemented it a couple days later -- it was sent to
> pgsql-patches, and is in the queue of items to be applied to 7.5.
>
> -Neil

oops, I haven't seen that since it was still an open item.
I haven't checked the pending patches. I must have missed it on the list.

    Cheers,

        Hans

--
Cybertec Geschwinde u Schoenig
Ludo-Hartmannplatz 1/14, A-1160 Vienna, Austria
Tel: +43/2952/30706 or +43/660/816 40 77
www.cybertec.at, www.postgresql.at, kernel.cybertec.at