aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-04-05 01:58:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-04-05 01:58:20 +0000
commitceb5db69d4fbbd327a2ae2d589069008bbe57bb6 (patch)
tree31688c2cbdf620bfd1feb7c8434dd35a21d8f8a2 /src
parent2a1cf97c22933368c8747711da0f30c35f4bddcd (diff)
downloadpostgresql-ceb5db69d4fbbd327a2ae2d589069008bbe57bb6.tar.gz
postgresql-ceb5db69d4fbbd327a2ae2d589069008bbe57bb6.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/parse_relation.c12
-rw-r--r--src/include/access/attnum.h3
2 files changed, 13 insertions, 2 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 6d5fb189406..68855a70074 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.130 2008/01/01 19:45:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.131 2008/04/05 01:58:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -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 c1ec4947ffe..033f2ee786d 100644
--- a/src/include/access/attnum.h
+++ b/src/include/access/attnum.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/attnum.h,v 1.24 2008/01/01 19:45:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/attnum.h,v 1.25 2008/04/05 01:58:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,6 +21,7 @@
typedef int16 AttrNumber;
#define InvalidAttrNumber 0
+#define MaxAttrNumber 32767
/* ----------------
* support macros