]> granicus.if.org Git - postgresql/commitdiff
Defend against JOINs having more than 32K columns altogether. We cannot
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 5 Apr 2008 01:58:42 +0000 (01:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 5 Apr 2008 01:58:42 +0000 (01:58 +0000)
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.

src/backend/parser/parse_relation.c
src/include/access/attnum.h

index 1762782efa1175c1f09e7ca89cff99ddbf27b715..5f3e8e463ca85f003329d8f82af0dd38d5bd8041 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.116.2.2 2006/01/10 22:00:07 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/parse_relation.c,v 1.116.2.3 2008/04/05 01:58:42 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -935,6 +935,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;
index 7a4822e63f773875f3b46e9441fc61aac3248653..d129af0a876771ca3be6d19b71d6bb96eefa7dd3 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/access/attnum.h,v 1.21 2005/05/25 21:40:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/attnum.h,v 1.21.2.1 2008/04/05 01:58:42 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -21,6 +21,7 @@
 typedef int16 AttrNumber;
 
 #define InvalidAttrNumber              0
+#define MaxAttrNumber                  32767
 
 /* ----------------
  *             support macros