Обсуждение: bug with long serial names

Поиск
Список
Период
Сортировка

bug with long serial names

От
"Nat Howard"
Дата:
Apologies if this has been raised before.

This:

create table a12345678901234567890 ( b1234567890  serial );

causes this:

pqReadData() -- backend closed the channel unexpectedly.       This probably means the backend terminated abnormally
beforeor
 
while processing the request.
We have lost the connection to the backend, so further processing is
impossible.  Terminating.


This is on postgres 6.4.1 (the "fixed" 6.4.1, not the accidental
snapshot) on BSDI.

The same problem exists in 6.4 on FreeBSD.



Re: [HACKERS] bug with long serial names

От
"Thomas G. Lockhart"
Дата:
> create table a12345678901234567890 ( b1234567890  serial );
> causes this:
> pqReadData() -- backend closed the channel unexpectedly.

I hadn't heard about this. Will look at it. In the meantime, don't do
that :)

The upper limit on names is probably something like
  <table name length> + <column name length> + 5 <= 31
                     - Tom


Re: [HACKERS] bug with long serial names

От
"Thomas G. Lockhart"
Дата:
> > create table a12345678901234567890 ( b1234567890  serial );
> > causes this:
> > pqReadData() -- backend closed the channel unexpectedly.
> The upper limit on names is probably something like
>    <table name length> + <column name length> + 5 <= 31

Here is a patch which should catch the problem:

pg=> create table a12345678901234567890 ( b1234567890  serial );
ERROR:  CREATE TABLE/SERIAL implicit sequence name must be less than 32
characters
        Sum of lengths of 'a12345678901234567890' and 'b1234567890' must
be less than 27

Will be in the next release. Apply the patch by putting it into the
backend/parser/ directory, then typing:

  patch < analyze.c.patch

btw, the patch should apply cleanly but with offsets since my source
code has some other changes you will not want (yet).

                       - Tom*** analyze.c.orig    Wed Dec  9 05:22:34 1998
--- analyze.c    Tue Dec 29 18:24:44 1998
***************
*** 535,540 ****
--- 533,542 ----
                      CreateSeqStmt *sequence;

                      sname = makeTableName(stmt->relname, column->colname, "seq", NULL);
+                     if (sname == NULL)
+                         elog(ERROR, "CREATE TABLE/SERIAL implicit sequence name must be less than %d characters"
+                              "\n\tSum of lengths of '%s' and '%s' must be less than %d",
+                              NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-5));

                      constraint = makeNode(Constraint);
                      constraint->contype = CONSTR_DEFAULT;
***************
*** 563,568 ****
--- 565,574 ----
                          constraint = makeNode(Constraint);
                          constraint->contype = CONSTR_UNIQUE;
                          constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
+                         if (constraint->name == NULL)
+                             elog(ERROR, "CREATE TABLE/SERIAL implicit index name must be less than %d characters"
+                                  "\n\tSum of lengths of '%s' and '%s' must be less than %d",
+                                  NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-5));
                          column->constraints = lappend(column->constraints, constraint);
                      }

***************
*** 584,589 ****
--- 590,605 ----
                          constraint = lfirst(clist);
                          switch (constraint->contype)
                          {
+                             case CONSTR_NULL:
+                                 /* We should mark this explicitly,
+                                  * so we can tell if NULL and NOT NULL are both specified
+                                  */
+                                 if (column->is_not_null)
+                                     elog(ERROR, "CREATE TABLE/(NOT) NULL conflicting declaration"
+                                          " for %s.%s", stmt->relname, column->colname);
+                                 column->is_not_null = FALSE;
+                                 break;
+
                              case CONSTR_NOTNULL:
                                  if (column->is_not_null)
                                      elog(ERROR, "CREATE TABLE/NOT NULL already specified"
***************
*** 601,606 ****
--- 617,626 ----
                              case CONSTR_PRIMARY:
                                  if (constraint->name == NULL)
                                      constraint->name = makeTableName(stmt->relname, "pkey", NULL);
+                                 if (constraint->name == NULL)
+                                     elog(ERROR, "CREATE TABLE/PRIMARY KEY implicit index name must be less than %d
characters"
+                                          "\n\tLength of '%s' must be less than %d",
+                                          NAMEDATALEN, stmt->relname, (NAMEDATALEN-6));
                                  if (constraint->keys == NIL)
                                      constraint->keys = lappend(constraint->keys, column);
                                  dlist = lappend(dlist, constraint);
***************
*** 609,614 ****
--- 629,638 ----
                              case CONSTR_UNIQUE:
                                  if (constraint->name == NULL)
                                      constraint->name = makeTableName(stmt->relname, column->colname, "key", NULL);
+                                 if (constraint->name == NULL)
+                                     elog(ERROR, "CREATE TABLE/UNIQUE implicit index name must be less than %d
characters"
+                                          "\n\tLength of '%s' must be less than %d",
+                                          NAMEDATALEN, stmt->relname, (NAMEDATALEN-5));
                                  if (constraint->keys == NIL)
                                      constraint->keys = lappend(constraint->keys, column);
                                  dlist = lappend(dlist, constraint);
***************
*** 618,623 ****
--- 642,651 ----
                                  constraints = lappend(constraints, constraint);
                                  if (constraint->name == NULL)
                                      constraint->name = makeTableName(stmt->relname, column->colname, NULL);
+                                 if (constraint->name == NULL)
+                                     elog(ERROR, "CREATE TABLE/CHECK implicit constraint name must be less than %d
characters"
+                                          "\n\tSum of lengths of '%s' and '%s' must be less than %d",
+                                          NAMEDATALEN, stmt->relname, column->colname, (NAMEDATALEN-1));
                                  break;

                              default:
***************
*** 636,641 ****
--- 664,673 ----
                      case CONSTR_PRIMARY:
                          if (constraint->name == NULL)
                              constraint->name = makeTableName(stmt->relname, "pkey", NULL);
+                         if (constraint->name == NULL)
+                             elog(ERROR, "CREATE TABLE/PRIMARY KEY implicit index name must be less than %d
characters"
+                                  "\n\tLength of '%s' must be less than %d",
+                                  NAMEDATALEN, stmt->relname, (NAMEDATALEN-5));
                          dlist = lappend(dlist, constraint);
                          break;

***************
*** 709,714 ****
--- 741,750 ----

              have_pkey = TRUE;
              index->idxname = makeTableName(stmt->relname, "pkey", NULL);
+             if (index->idxname == NULL)
+                 elog(ERROR, "CREATE TABLE/PRIMARY KEY implicit index name must be less than %d characters"
+                      "\n\tLength of '%s' must be less than %d",
+                      NAMEDATALEN, stmt->relname, (NAMEDATALEN-5));
          }
          else
              index->idxname = NULL;