summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2008-04-05 01:59:01 +0000
committerTom Lane2008-04-05 01:59:01 +0000
commit4b73fed4b32fa5a02fac9a28485f5b83b10a5e76 (patch)
tree1745e0b9966b9d7074a0296d2f7dc75b13281741
parent550057a0b7826c7849eefa565e51d892cae0b5a1 (diff)
Defend against JOINs having more than 32K columns altogether. We cannot
currently support this because we must be able to build Vars referencing join columns, and varattno is only 16 bits wide. Perhaps this should be improved in future, but considering that it never came up before, I'm not sure the problem is worth much effort. Per bug #4070 from Marcello Ceschia. The problem seems largely academic in 8.0 and 7.4, because they have (different) O(N^2) performance issues with such wide joins, but back-patch all the way anyway.
-rw-r--r--src/backend/parser/parse_relation.c10
-rw-r--r--src/include/access/attnum.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 893bb006b3..737b093a1b 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -1025,6 +1025,16 @@ addRangeTableEntryForJoin(ParseState *pstate,
Alias *eref;
int numaliases;
+ /*
+ * Fail if join has too many columns --- we must be able to reference
+ * any of the columns with an AttrNumber.
+ */
+ if (list_length(aliasvars) > MaxAttrNumber)
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("joins can have at most %d columns",
+ MaxAttrNumber)));
+
rte->rtekind = RTE_JOIN;
rte->relid = InvalidOid;
rte->subquery = NULL;
diff --git a/src/include/access/attnum.h b/src/include/access/attnum.h
index 3050348ed3..e479e5479a 100644
--- a/src/include/access/attnum.h
+++ b/src/include/access/attnum.h
@@ -21,6 +21,7 @@
typedef int16 AttrNumber;
#define InvalidAttrNumber 0
+#define MaxAttrNumber 32767
/* ----------------
* support macros