8000 Reimplement nodeMaterial to use a temporary BufFile (or even memory, … · postgrespro/postgres_cluster@1ee26b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ee26b7

Browse files
committed
Reimplement nodeMaterial to use a temporary BufFile (or even memory, if the
materialized tupleset is small enough) instead of a temporary relation. This was something I was thinking of doing anyway for performance, and Jan says he needs it for TOAST because he doesn't want to cope with toasting noname relations. With this change, the 'noname table' support in heap.c is dead code, and I have accordingly removed it. Also clean up 'noname' plan handling in planner --- nonames are either sort or materialize plans, and it seems less confusing to handle them separately under those names.
1 parent 2c0edb3 commit 1ee26b7

File tree

32 files changed

+1066
-958
lines changed
  • optimizer
  • utils
  • 32 files changed

    +1066
    -958
    lines changed

    src/backend/access/transam/xact.c

    Lines changed: 1 addition & 11 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@
    88
    *
    99
    *
    1010
    * IDENTIFICATION
    11-
    * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.66 2000/06/08 22:36:54 momjian Exp $
    11+
    * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.67 2000/06/18 22:43:51 tgl Exp $
    1212
    *
    1313
    * NOTES
    1414
    * Transaction aborts can now occur two ways:
    @@ -878,14 +878,6 @@ StartTransaction()
    878878
    AtStart_Locks();
    879879
    AtStart_Memory();
    880880

    881-
    /* --------------
    882-
    initialize temporary relations list
    883-
    the tempRelList is a list of temporary relations that
    884-
    are created in the course of the transactions
    885-
    they need to be destroyed properly at the end of the transactions
    886-
    */
    887-
    InitNoNameRelList();
    888-
    889881
    /* ----------------
    890882
    * Tell the trigger manager to we're starting a transaction
    891883
    * ----------------
    @@ -960,7 +952,6 @@ CommitTransaction()
    960952
    AtCommit_Notify();
    961953

    962954
    CloseSequences();
    963-
    DropNoNameRels();
    964955
    AtEOXact_portals();
    965956
    RecordTransactionCommit();
    966957

    @@ -1056,7 +1047,6 @@ AbortTransaction()
    10561047
    CommonSpecialPortalClose();
    10571048
    RecordTransactionAbort();
    10581049
    RelationPurgeLocalRelation(false);
    1059-
    DropNoNameRels();
    10601050
    invalidate_temp_relations();
    10611051
    AtEOXact_nbtree();
    10621052
    AtAbort_Cache();

    src/backend/bootstrap/bootparse.y

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,7 +9,7 @@
    99
    *
    1010
    *
    1111
    * IDENTIFICATION
    12-
    * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.29 2000/01/26 05:56:07 momjian Exp $
    12+
    * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.30 2000/06/18 22:43:51 tgl Exp $
    1313
    *
    1414
    *-------------------------------------------------------------------------
    1515
    */
    @@ -166,7 +166,7 @@ Boot_CreateStmt:
    166166
    puts("creating bootstrap relation");
    167167
    tupdesc = CreateTupleDesc(numattr,attrtypes);
    168168
    reldesc = heap_create(LexIDStr($3), tupdesc,
    169-
    false, false, true);
    169+
    false, true);
    170170
    if (DebugMode)
    171171
    puts("bootstrap relation created ok");
    172172
    }

    src/backend/catalog/heap.c

    Lines changed: 15 additions & 181 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@
    88
    *
    99
    *
    1010
    * IDENTIFICATION
    11-
    * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.132 2000/06/17 23:41:31 tgl Exp $
    11+
    * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.133 2000/06/18 22:43:55 tgl Exp $
    1212
    *
    1313
    *
    1414
    * INTERFACE ROUTINES
    @@ -70,14 +70,11 @@ static void AddNewRelationTuple(Relation pg_class_desc,
    7070
    Relation new_rel_desc, Oid new_rel_oid,
    7171
    int natts,
    7272
    char relkind, char *temp_relname);
    73-
    static void AddToNoNameRelList(Relation r);
    74-
    7573
    static void DeleteAttributeTuples(Relation rel);
    7674
    static void DeleteRelationTuple(Relation rel);
    7775
    static void DeleteTypeTuple(Relation rel);
    7876
    static void RelationRemoveIndexes(Relation relation);
    7977
    static void RelationRemoveInheritance(Relation relation);
    80-
    static void RemoveFromNoNameRelList(Relation r);
    8178
    static void AddNewRelationType(char *typeName, Oid new_rel_oid);
    8279
    static void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin,
    8380
    bool updatePgAttribute);
    @@ -141,22 +138,6 @@ static Form_pg_attribute HeapAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6};
    141138
    * ----------------------------------------------------------------
    142139
    */
    143140

    144-
    /* the tempRelList holds
    145-
    the list of temporary uncatalogued relations that are created.
    146-
    these relations should be destroyed at the end of transactions
    147-
    */
    148-
    typedef struct tempRelList
    149-
    {
    150-
    Relation *rels; /* array of relation descriptors */
    151-
    int num; /* number of temporary relations */
    152-
    int size; /* size of space allocated for the rels
    153-
    * array */
    154-
    } TempRelList;
    155-
    156-
    #define NONAME_REL_LIST_SIZE 32
    157-
    158-
    static TempRelList *tempRels = NULL;
    159-
    160141

    161142
    /* ----------------------------------------------------------------
    162143
    * heap_create - Create an uncataloged heap relation
    @@ -170,15 +151,16 @@ static TempRelList *tempRels = NULL;
    170151
    * Eventually, must place information about this temporary relation
    171152
    * into the transaction context block.
    172153
    *
    154+
    * NOTE: if istemp is TRUE then heap_create will overwrite relname with
    155+
    * the unique "real" name chosen for the temp relation.
    173156
    *
    174-
    * if heap_create is called with "" as the name, then heap_create will create
    175-
    * a temporary name "pg_noname.$PID.$SEQUENCE" for the relation
    157+
    * If storage_create is TRUE then heap_storage_create is called here,
    158+
    * else caller must call heap_storage_create later.
    176159
    * ----------------------------------------------------------------
    177160
    */
    178161
    Relation
    179162
    heap_create(char *relname,
    180163
    TupleDesc tupDesc,
    181-
    bool isnoname,
    182164
    bool istemp,
    183165
    bool storage_create)
    184166
    {
    @@ -245,18 +227,11 @@ heap_create(char *relname,
    245227
    else
    246228
    relid = newoid();
    247229

    248-
    if (isnoname)
    249-
    {
    250-
    Assert(!relname);
    251-
    relname = palloc(NAMEDATALEN);
    252-
    snprintf(relname, NAMEDATALEN, "pg_noname.%d.%u",
    253-
    (int) MyProcPid, uniqueId++);
    254-
    }
    255-
    256230
    if (istemp)
    257231
    {
    258-
    /* replace relname of caller */
    259-
    snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u", MyProcPid, uniqueId++);
    232+
    /* replace relname of caller with a unique name for a temp relation */
    233+
    snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
    234+
    (int) MyProcPid, uniqueId++);
    260235
    }
    261236

    262237
    /* ----------------
    @@ -268,7 +243,7 @@ heap_create(char *relname,
    268243
    rel = (Relation) palloc(len);
    269244
    MemSet((char *) rel, 0, len);
    270245
    rel->rd_fd = -1; /* table is not open */
    271-
    rel->rd_unlinked = TRUE; /* table is not created yet */
    246+
    rel->rd_unlinked = true; /* table is not created yet */
    272247

    273248
    /*
    274249
    * create a new tuple descriptor from the one passed in
    @@ -310,12 +285,6 @@ heap_create(char *relname,
    310285
    rel->rd_rel->reltype = relid;
    311286
    }
    312287

    313-
    /* ----------------
    314-
    * remember if this is a noname relation
    315-
    * ----------------
    316-
    */
    317-
    rel->rd_isnoname = isnoname;
    318-
    319288
    /* ----------------
    320289
    * have the storage manager create the relation.
    321290
    * ----------------
    @@ -329,13 +298,6 @@ heap_create(char *relname,
    329298

    330299
    MemoryContextSwitchTo(oldcxt);
    331300

    332-
    /*
    333-
    * add all noname relations to the tempRels list so they can be
    334-
    * properly disposed of at the end of transaction
    335-
    */
    336-
    if (isnoname)
    337-
    AddToNoNameRelList(rel);
    338-
    339301
    return rel;
    340302
    }
    341303

    @@ -347,7 +309,7 @@ heap_storage_create(Relation rel)
    347309
    if (rel->rd_unlinked)
    348310
    {
    349311
    rel->rd_fd = (File) smgrcreate(DEFAULT_SMGR, rel);
    350-
    rel->rd_unlinked = FALSE;
    312+
    rel->rd_unlinked = false;
    351313
    smgrcall = true;
    352314
    }
    353315
    return smgrcall;
    @@ -810,7 +772,7 @@ heap_create_with_catalog(char *relname,
    810772
    * get_temp_rel_by_username() couldn't check the simultaneous
    811773
    * creation. Uniqueness will be really checked by unique
    812774
    * indexes of system tables but we couldn't check it here.
    813-
    * We have to pospone to create the disk file for this
    775+
    * We have to postpone creating the disk file for this
    814776
    * relation.
    815777
    * Another boolean parameter "storage_create" was added
    816778
    * to heap_create() function. If the parameter is false
    @@ -821,12 +783,12 @@ heap_create_with_catalog(char *relname,
    821783
    * relation descriptor.
    822784
    *
    823785
    * Note: The call to heap_create() changes relname for
    824-
    * noname and temp tables.
    786+
    * temp tables; it becomes the true physical relname.
    825787
    * The call to heap_storage_create() does all the "real"
    826788
    * work of creating the disk file for the relation.
    827789
    * ----------------
    828790
    */
    829-
    new_rel_desc = heap_create(relname, tupdesc, false, istemp, false);
    791+
    new_rel_desc = heap_create(relname, tupdesc, istemp, false);
    830792

    831793
    new_rel_oid = new_rel_desc->rd_att->attrs[0]->attrelid;
    832794

    @@ -1546,10 +1508,9 @@ heap_drop_with_catalog(const char *relname)
    15461508
    * unlink the relation's physical file and finish up.
    15471509
    * ----------------
    15481510
    */
    1549-
    if (!(rel->rd_isnoname) || !(rel->rd_unlinked))
    1511+
    if (! rel->rd_unlinked)
    15501512
    smgrunlink(DEFAULT_SMGR, rel);
    1551-
    1552-
    rel->rd_unlinked = TRUE;
    1513+
    rel->rd_unlinked = true;
    15531514

    15541515
    /*
    15551516
    * Close relcache entry, but *keep* AccessExclusiveLock on the
    @@ -1568,133 +1529,6 @@ heap_drop_with_catalog(const char *relname)
    15681529
    remove_temp_relation(rid);
    15691530
    }
    15701531

    1571-
    /*
    1572-
    * heap_drop
    1573-
    * destroy and close temporary relations
    1574-
    *
    1575-
    */
    1576-
    1577-
    void
    1578-
    heap_drop(Relation rel)
    1579-
    {
    1580-
    Oid rid = RelationGetRelid(rel);
    1581-
    1582-
    ReleaseRelationBuffers(rel);
    1583-
    if (!(rel->rd_isnoname) || !(rel->rd_unlinked))
    1584-
    smgrunlink(DEFAULT_SMGR, rel);
    1585-
    rel->rd_unlinked = TRUE;
    1586-
    heap_close(rel, NoLock);
    1587-
    RemoveFromNoNameRelList(rel);
    1588-
    RelationForgetRelation(rid);
    1589-
    }
    1590-
    1591-
    1592-
    /**************************************************************
    1593-
    functions to deal with the list of temporary relations
    1594-
    **************************************************************/
    1595-
    1596-
    /* --------------
    1597-
    InitTempRellist():
    1598-
    1599-
    initialize temporary relations list
    1600-
    the tempRelList is a list of temporary relations that
    1601-
    are created in the course of the transactions
    1602-
    they need to be destroyed properly at the end of the transactions
    1603-
    1604-
    MODIFIES the global variable tempRels
    1605-
    1606-
    >> NOTE <<
    1607-
    1608-
    malloc is used instead of palloc because we KNOW when we are
    1609-
    going to free these things. Keeps us away from the memory context
    1610-
    hairyness
    1611-
    1612-
    */
    1613-
    void
    1614-
    InitNoNameRelList(void)
    1615-
    {
    1616-
    if (tempRels)
    1617-
    {
    1618-
    free(tempRels->rels);
    1619-
    free(tempRels);
    1620-
    }
    1621-
    1622-
    tempRels = (TempRelList *) malloc(sizeof(TempRelList));
    1623-
    tempRels->size = NONAME_REL_LIST_SIZE;
    1624-
    tempRels->rels = (Relation *) malloc(sizeof(Relation) * tempRels->size);
    1625-
    MemSet(tempRels->rels, 0, sizeof(Relation) * tempRels->size);
    1626-
    tempRels->num = 0;
    1627-
    }
    1628-
    1629-
    /*
    1630-
    removes a relation from the TempRelList
    1631-
    1632-
    MODIFIES the global variable tempRels
    1633-
    we don't really remove it, just mark it as NULL
    1634-
    and DropNoNameRels will look for NULLs
    1635-
    */
    1636-
    static void
    1637-
    RemoveFromNoNameRelList(Relation r)
    1638-
    {
    1639-
    int i;
    1640-
    1641-
    if (!tempRels)
    1642-
    return;
    1643-
    1644-
    for (i = 0; i < tempRels->num; i++)
    1645-
    {
    1646-
    if (tempRels->rels[i] == r)
    1647-
    {
    1648-
    tempRels->rels[i] = NULL;
    1649-
    break;
    1650-
    }
    1651-
    }
    1652-
    }
    1653-
    1654-
    /*
    1655-
    add a temporary relation to the TempRelList
    1656-
    1657-
    MODIFIES the global variable tempRels
    1658-
    */
    1659-
    static void
    1660-
    AddToNoNameRelList(Relation r)
    1661-
    {
    1662-
    if (!tempRels)
    1663-
    return;
    1664-
    1665-
    if (tempRels->num == tempRels->size)
    1666-
    {
    1667-
    tempRels->size += NONAME_REL_LIST_SIZE;
    1668-
    tempRels->rels = realloc(tempRels->rels,
    1669-
    sizeof(Relation) * tempRels->size);
    1670-
    }
    1671-
    tempRels->rels[tempRels->num] = r;
    1672-
    tempRels->num++;
    1673-
    }
    1674-
    1675-
    /*
    1676-
    go through the tempRels list and destroy each of the relations
    1677-
    */
    1678-
    void
    1679-
    DropNoNameRels(void)
    1680-
    {
    1681-
    int i;
    1682-
    Relation rel;
    1683-
    1684-
    if (!tempRels)
    1685-
    return;
    1686-
    1687-
    for (i = 0; i < tempRels->num; i++)
    1688-
    {
    1689-
    rel = tempRels->rels[i];
    1690-
    /* rel may be NULL if it has been removed from the list already */
    1691-
    if (rel)
    1692-
    heap_drop(rel);
    1693-
    }
    1694-
    free(tempRels->rels);
    1695-
    free(tempRels);
    1696-
    tempRels = NULL;
    1697-
    }
    16981532

    16991533
    /*
    17001534
    * Store a default expression for column attnum of relation rel.

    src/backend/catalog/index.c

    Lines changed: 3 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@
    88
    *
    99
    *
    1010
    * IDENTIFICATION
    11-
    * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.118 2000/06/17 23:41:34 tgl Exp $
    11+
    * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.119 2000/06/18 22:43:55 tgl Exp $
    1212
    *
    1313
    *
    1414
    * INTERFACE ROUTINES
    @@ -976,7 +976,6 @@ index_create(char *heapRelationName,
    976976

    977977
    /* ----------------
    978978
    * get heap relation oid and open the heap relation
    979-
    * XXX ADD INDEXING
    980979
    * ----------------
    981980
    */
    982981
    heapoid = GetHeapRelationOid(heapRelationName, indexRelationName, istemp);
    @@ -1012,8 +1011,8 @@ index_create(char *heapRelationName,
    10121011
    * create the index relation
    10131012
    * ----------------
    10141013
    */
    1015-
    indexRelation = heap_create(indexRelationName,
    1016-
    indexTupDesc, false, istemp, false);
    1014+
    indexRelation = heap_create(indexRelationName, indexTupDesc,
    1015+
    istemp, false);
    10171016

    10181017
    /* ----------------
    10191018
    * construct the index relation descriptor

    0 commit comments

    Comments
     (0)
    0