|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.139 2004/11/05 19:15:57 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.140 2004/11/16 23:34:22 neilc Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -680,6 +680,23 @@ MergeAttributes(List *schema, List *supers, bool istemp,
|
680 | 680 | * defaults */
|
681 | 681 | int child_attno;
|
682 | 682 |
|
| 683 | + /* |
| 684 | + * Check for and reject tables with too many columns. We perform |
| 685 | + * this check relatively early for two reasons: (a) we don't run |
| 686 | + * the risk of overflowing an AttrNumber in subsequent code (b) an |
| 687 | + * O(n^2) algorithm is okay if we're processing <= 1600 columns, |
| 688 | + * but could take minutes to execute if the user attempts to |
| 689 | + * create a table with hundreds of thousands of columns. |
| 690 | + * |
| 691 | + * Note that we also need to check that any we do not exceed this |
| 692 | + * figure after including columns from inherited relations. |
| 693 | + */ |
| 694 | + if (list_length(schema) > MaxHeapAttributeNumber) |
| 695 | + ereport(ERROR, |
| 696 | + (errcode(ERRCODE_TOO_MANY_COLUMNS), |
| 697 | + errmsg("tables can have at most %d columns", |
| 698 | + MaxHeapAttributeNumber))); |
| 699 | + |
683 | 700 | /*
|
684 | 701 | * Check for duplicate names in the explicit list of attributes.
|
685 | 702 | *
|
@@ -979,6 +996,16 @@ MergeAttributes(List *schema, List *supers, bool istemp,
|
979 | 996 | }
|
980 | 997 |
|
981 | 998 | schema = inhSchema;
|
| 999 | + |
| 1000 | + /* |
| 1001 | + * Check that we haven't exceeded the legal # of columns after |
| 1002 | + * merging in inherited columns. |
| 1003 | + */ |
| 1004 | + if (list_length(schema) > MaxHeapAttributeNumber) |
| 1005 | + ereport(ERROR, |
| 1006 | + (errcode(ERRCODE_TOO_MANY_COLUMNS), |
| 1007 | + errmsg("tables can have at most %d columns", |
| 1008 | + MaxHeapAttributeNumber))); |
982 | 1009 | }
|
983 | 1010 |
|
984 | 1011 | /*
|
|
0 commit comments