This patch fixes a bug I introduced in the recent CREATE TABLE AS / WITH
OIDS work. The patch should be pretty straight-forward.
The only question I have is whether analyze.c (and therefore
analyze.h) is the right place to put the new utility function
interpretOidsOption() -- can anyone suggest a better location?
Unless anyone objects, I plan to apply this within 24 hours.
-Neil
Index: src/backend/commands/tablecmds.c
===================================================================
RCS file: /Users/neilc/local/cvs/pgsql-server/src/backend/commands/tablecmds.c,v
retrieving revision 1.95
diff -c -r1.95 tablecmds.c
*** src/backend/commands/tablecmds.c 10 Jan 2004 23:28:44 -0000 1.95
--- src/backend/commands/tablecmds.c 22 Jan 2004 20:32:28 -0000
***************
*** 38,43 ****
--- 38,44 ----
#include "optimizer/clauses.h"
#include "optimizer/plancat.h"
#include "optimizer/prep.h"
+ #include "parser/analyze.h"
#include "parser/gramparse.h"
#include "parser/parse_coerce.h"
#include "parser/parse_expr.h"
***************
*** 47,53 ****
#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"
--- 48,53 ----
***************
*** 189,210 ****
if (parentHasOids)
descriptor->tdhasoid = true;
else
! {
! switch (stmt->hasoids)
! {
! case MUST_HAVE_OIDS:
! descriptor->tdhasoid = true;
! break;
!
! case MUST_NOT_HAVE_OIDS:
! descriptor->tdhasoid = false;
! break;
!
! case DEFAULT_OIDS:
! descriptor->tdhasoid = default_with_oids;
! break;
! }
! }
if (old_constraints != NIL)
{
--- 189,195 ----
if (parentHasOids)
descriptor->tdhasoid = true;
else
! descriptor->tdhasoid = interpretOidsOption(stmt->hasoids);
if (old_constraints != NIL)
{
Index: src/backend/parser/analyze.c
===================================================================
RCS file: /Users/neilc/local/cvs/pgsql-server/src/backend/parser/analyze.c,v
retrieving revision 1.296
diff -c -r1.296 analyze.c
*** src/backend/parser/analyze.c 14 Jan 2004 23:01:55 -0000 1.296
--- src/backend/parser/analyze.c 22 Jan 2004 20:32:28 -0000
***************
*** 859,865 ****
cxt.stmtType = "CREATE TABLE";
cxt.relation = stmt->relation;
cxt.inhRelations = stmt->inhRelations;
- cxt.hasoids = stmt->hasoids;
cxt.relOid = InvalidOid;
cxt.columns = NIL;
cxt.ckconstraints = NIL;
--- 859,864 ----
***************
*** 868,873 ****
--- 867,873 ----
cxt.blist = NIL;
cxt.alist = NIL;
cxt.pkey = NULL;
+ cxt.hasoids = interpretOidsOption(stmt->hasoids);
/*
* Run through each primary element in the table creation clause.
***************
*** 1979,1998 ****
if (stmt->intoColNames)
applyColumnNames(qry->targetList, stmt->intoColNames);
! switch (stmt->intoHasOids)
! {
! case MUST_HAVE_OIDS:
! qry->intoHasOids = true;
! break;
!
! case MUST_NOT_HAVE_OIDS:
! qry->intoHasOids = false;
! break;
!
! case DEFAULT_OIDS:
! qry->intoHasOids = default_with_oids;
! break;
! }
/* mark column origins */
markTargetListOrigins(pstate, qry->targetList);
--- 1979,1985 ----
if (stmt->intoColNames)
applyColumnNames(qry->targetList, stmt->intoColNames);
! qry->intoHasOids = interpretOidsOption(stmt->intoHasOids);
/* mark column origins */
markTargetListOrigins(pstate, qry->targetList);
***************
*** 3338,3341 ****
--- 3325,3355 ----
}
return expression_tree_walker(node, check_parameter_resolution_walker,
(void *) context);
+ }
+
+ /*
+ * Given an enum that specifies whether WITH / WITHOUT OIDS was
+ * specified by the user, return true iff the specified table/result
+ * set should be created with OIDs. This needs to be done after
+ * parsing because it can depend upon the value of the
+ * default_with_oids GUC var.
+ */
+ bool
+ interpretOidsOption(ContainsOids opt)
+ {
+ switch (opt)
+ {
+ case MUST_HAVE_OIDS:
+ return true;
+
+ case MUST_NOT_HAVE_OIDS:
+ return false;
+
+ case DEFAULT_OIDS:
+ return default_with_oids;
+ }
+
+ /* keep the compiler quiet; never reached */
+ Assert(false);
+ return false;
}
Index: src/include/parser/analyze.h
===================================================================
RCS file: /Users/neilc/local/cvs/pgsql-server/src/include/parser/analyze.h,v
retrieving revision 1.24
diff -c -r1.24 analyze.h
*** src/include/parser/analyze.h 29 Nov 2003 22:41:09 -0000 1.24
--- src/include/parser/analyze.h 22 Jan 2004 20:39:25 -0000
***************
*** 24,30 ****
extern void CheckSelectForUpdate(Query *qry);
! /* This was exported to allow ADD CONSTRAINT to make use of it */
extern char *makeObjectName(char *name1, char *name2, char *typename);
#endif /* ANALYZE_H */
--- 24,32 ----
extern void CheckSelectForUpdate(Query *qry);
! /* This is exported to allow ADD CONSTRAINT to make use of it */
extern char *makeObjectName(char *name1, char *name2, char *typename);
+
+ extern bool interpretOidsOption(ContainsOids opt);
#endif /* ANALYZE_H */
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match