~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/backend/catalog/heap.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-04-20 15:57:49 UTC
  • mfrom: (1.3.2 upstream) (12.1.2 lucid-security)
  • Revision ID: james.westby@ubuntu.com-20110420155749-t2nm8kb8pzf2nplc
Tags: 8.4.8-0ubuntu0.10.04
* New upstream bug fix release: (LP: #767165)
  - If your installation was upgraded from a previous major release by
    running pg_upgrade, you should take action to prevent possible data loss
    due to a now-fixed bug in pg_upgrade. The recommended solution is to run
    "VACUUM FREEZE" on all TOAST tables.  More information is available at
    http://wiki.postgresql.org/wiki/20110408pg_upgrade_fix.
  - Fix pg_upgrade's handling of TOAST tables.
    This error poses a significant risk of data loss for installations
    that have been upgraded with pg_upgrade. This patch corrects the
    problem for future uses of pg_upgrade, but does not in itself cure
    the issue in installations that have been processed with a buggy
    version of pg_upgrade.
  - Suppress incorrect "PD_ALL_VISIBLE flag was incorrectly set"
    warning.
  - Disallow including a composite type in itself.
  - Avoid potential deadlock during catalog cache initialization.
  - Fix dangling-pointer problem in BEFORE ROW UPDATE trigger handling
    when there was a concurrent update to the target tuple.
  - Disallow "DROP TABLE" when there are pending deferred trigger
    events for the table.
    Formerly the "DROP" would go through, leading to "could not open
    relation with OID nnn" errors when the triggers were eventually
    fired.
  - Prevent crash triggered by constant-false WHERE conditions during
    GEQO optimization.
  - Improve planner's handling of semi-join and anti-join cases.
  - Fix selectivity estimation for text search to account for NULLs.
  - Improve PL/pgSQL's ability to handle row types with dropped columns.
  - Fix PL/Python memory leak involving array slices.
  - Fix pg_restore to cope with long lines (over 1KB) in TOC files.
  - Put in more safeguards against crashing due to division-by-zero
    with overly enthusiastic compiler optimization. (Closes: #616180)

Show diffs side-by-side

added added

removed removed

Lines of Context:
403
403
        for (i = 0; i < natts; i++)
404
404
        {
405
405
                CheckAttributeType(NameStr(tupdesc->attrs[i]->attname),
406
 
                                                   tupdesc->attrs[i]->atttypid);
 
406
                                                   tupdesc->attrs[i]->atttypid,
 
407
                                                   NIL /* assume we're creating a new rowtype */);
407
408
        }
408
409
}
409
410
 
411
412
 *              CheckAttributeType
412
413
 *
413
414
 *              Verify that the proposed datatype of an attribute is legal.
414
 
 *              This is needed because there are types (and pseudo-types)
 
415
 *              This is needed mainly because there are types (and pseudo-types)
415
416
 *              in the catalogs that we do not support as elements of real tuples.
 
417
 *              We also check some other properties required of a table column.
 
418
 *
 
419
 * If the attribute is being proposed for addition to an existing table or
 
420
 * composite type, pass a one-element list of the rowtype OID as
 
421
 * containing_rowtypes.  When checking a to-be-created rowtype, it's
 
422
 * sufficient to pass NIL, because there could not be any recursive reference
 
423
 * to a not-yet-existing rowtype.
416
424
 * --------------------------------
417
425
 */
418
426
void
419
 
CheckAttributeType(const char *attname, Oid atttypid)
 
427
CheckAttributeType(const char *attname, Oid atttypid,
 
428
                                   List *containing_rowtypes)
420
429
{
421
430
        char            att_typtype = get_typtype(atttypid);
 
431
        Oid                     att_typelem;
422
432
 
423
433
        if (atttypid == UNKNOWNOID)
424
434
        {
454
464
                TupleDesc       tupdesc;
455
465
                int                     i;
456
466
 
 
467
                /*
 
468
                 * Check for self-containment.  Eventually we might be able to allow
 
469
                 * this (just return without complaint, if so) but it's not clear how
 
470
                 * many other places would require anti-recursion defenses before it
 
471
                 * would be safe to allow tables to contain their own rowtype.
 
472
                 */
 
473
                if (list_member_oid(containing_rowtypes, atttypid))
 
474
                        ereport(ERROR,
 
475
                                        (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
 
476
                                         errmsg("composite type %s cannot be made a member of itself",
 
477
                                                        format_type_be(atttypid))));
 
478
 
 
479
                containing_rowtypes = lcons_oid(atttypid, containing_rowtypes);
 
480
 
457
481
                relation = relation_open(get_typ_typrelid(atttypid), AccessShareLock);
458
482
 
459
483
                tupdesc = RelationGetDescr(relation);
464
488
 
465
489
                        if (attr->attisdropped)
466
490
                                continue;
467
 
                        CheckAttributeType(NameStr(attr->attname), attr->atttypid);
 
491
                        CheckAttributeType(NameStr(attr->attname), attr->atttypid,
 
492
                                                           containing_rowtypes);
468
493
                }
469
494
 
470
495
                relation_close(relation, AccessShareLock);
 
496
 
 
497
                containing_rowtypes = list_delete_first(containing_rowtypes);
 
498
        }
 
499
        else if (OidIsValid((att_typelem = get_element_type(atttypid))))
 
500
        {
 
501
                /*
 
502
                 * Must recurse into array types, too, in case they are composite.
 
503
                 */
 
504
                CheckAttributeType(attname, att_typelem,
 
505
                                                   containing_rowtypes);
471
506
        }
472
507
}
473
508
 
1426
1461
 
1427
1462
        /*
1428
1463
         * There can no longer be anyone *else* touching the relation, but we
1429
 
         * might still have open queries or cursors in our own session.
 
1464
         * might still have open queries or cursors, or pending trigger events,
 
1465
         * in our own session.
1430
1466
         */
1431
 
        if (rel->rd_refcnt != 1)
1432
 
                ereport(ERROR,
1433
 
                                (errcode(ERRCODE_OBJECT_IN_USE),
1434
 
                                 errmsg("cannot drop \"%s\" because "
1435
 
                                                "it is being used by active queries in this session",
1436
 
                                                RelationGetRelationName(rel))));
 
1467
        CheckTableNotInUse(rel, "DROP TABLE");
1437
1468
 
1438
1469
        /*
1439
1470
         * Schedule unlinking of the relation's physical files at commit.