~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/access/gin/gininsert.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-01 17:41:41 UTC
  • mfrom: (1.1.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20090701174141-jfmn9tt8e69m950x
Tags: 8.4.0-1
* Final 8.4.0 release. Major enhancements:
  - Windowing Functions
  - Common Table Expressions and Recursive Queries
  - Default and variadic parameters for functions
  - Parallel Restore
  - Column Permissions
  - Per-database locale settings
  - Improved hash indexes
  - Improved join performance for EXISTS and NOT EXISTS queries
  - Easier-to-use Warm Standby
  - Automatic sizing of the Free Space Map
  - Visibility Map (greatly reduces vacuum overhead for slowly-changing
    tables)
  - Version-aware psql (backslash commands work against older servers)
  - Support SSL certificates for user authentication
  - Per-function runtime statistics
  - Easy editing of functions in psql
  - New contrib modules: pg_stat_statements, auto_explain, citext,
    btree_gin 
  Upload to unstable, 8.4 is the new default. 
* debian/control: Build the versionless metapackages and have them point to
  8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *                      $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.20 2009/03/24 22:06:03 tgl Exp $
 
11
 *                      $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.22 2009/06/11 14:48:53 momjian Exp $
12
12
 *-------------------------------------------------------------------------
13
13
 */
14
14
 
100
100
addItemPointersToTuple(Relation index, GinState *ginstate, GinBtreeStack *stack,
101
101
                  IndexTuple old, ItemPointerData *items, uint32 nitem, bool isBuild)
102
102
{
103
 
        Datum                   key = gin_index_getattr(ginstate, old);
104
 
        OffsetNumber    attnum = gintuple_get_attrnum(ginstate, old);
105
 
        IndexTuple              res = GinFormTuple(ginstate, attnum, key, NULL, nitem + GinGetNPosting(old));
 
103
        Datum           key = gin_index_getattr(ginstate, old);
 
104
        OffsetNumber attnum = gintuple_get_attrnum(ginstate, old);
 
105
        IndexTuple      res = GinFormTuple(ginstate, attnum, key,
 
106
                                                                   NULL, nitem + GinGetNPosting(old));
106
107
 
107
108
        if (res)
108
109
        {
109
110
                /* good, small enough */
110
 
                MergeItemPointers(GinGetPosting(res),
111
 
                                                  GinGetPosting(old), GinGetNPosting(old),
112
 
                                                  items, nitem
113
 
                        );
 
111
                uint32          newnitem;
114
112
 
115
 
                GinSetNPosting(res, nitem + GinGetNPosting(old));
 
113
                newnitem = MergeItemPointers(GinGetPosting(res),
 
114
                                                                         GinGetPosting(old), GinGetNPosting(old),
 
115
                                                                         items, nitem);
 
116
                /* merge might have eliminated some duplicate items */
 
117
                GinShortenTuple(res, newnitem);
116
118
        }
117
119
        else
118
120
        {
234
236
{
235
237
        GinBuildState *buildstate = (GinBuildState *) state;
236
238
        MemoryContext oldCtx;
237
 
        int               i;
 
239
        int                     i;
238
240
 
239
241
        oldCtx = MemoryContextSwitchTo(buildstate->tmpCtx);
240
242
 
241
 
        for(i=0; i<buildstate->ginstate.origTupdesc->natts;i++)
242
 
                if ( !isnull[i] )
243
 
                        buildstate->indtuples += ginHeapTupleBulkInsert(buildstate, 
244
 
                                                                                                                (OffsetNumber)(i+1), values[i], 
245
 
                                                                                                                &htup->t_self);
 
243
        for (i = 0; i < buildstate->ginstate.origTupdesc->natts; i++)
 
244
                if (!isnull[i])
 
245
                        buildstate->indtuples += ginHeapTupleBulkInsert(buildstate,
 
246
                                                                                   (OffsetNumber) (i + 1), values[i],
 
247
                                                                                                                        &htup->t_self);
246
248
 
247
249
        /* If we've maxed out our available memory, dump everything to the index */
248
250
        /* Also dump if the tree seems to be getting too unbalanced */
252
254
                ItemPointerData *list;
253
255
                Datum           entry;
254
256
                uint32          nlist;
255
 
                OffsetNumber  attnum;
 
257
                OffsetNumber attnum;
256
258
 
257
259
                while ((list = ginGetEntry(&buildstate->accum, &attnum, &entry, &nlist)) != NULL)
258
260
                {
277
279
        IndexBuildResult *result;
278
280
        double          reltuples;
279
281
        GinBuildState buildstate;
280
 
        Buffer          RootBuffer, MetaBuffer;
 
282
        Buffer          RootBuffer,
 
283
                                MetaBuffer;
281
284
        ItemPointerData *list;
282
285
        Datum           entry;
283
286
        uint32          nlist;
314
317
                rdata.next = NULL;
315
318
 
316
319
                recptr = XLogInsert(RM_GIN_ID, XLOG_GIN_CREATE_INDEX, &rdata);
317
 
                
 
320
 
318
321
                page = BufferGetPage(RootBuffer);
319
322
                PageSetLSN(page, recptr);
320
323
                PageSetTLI(page, ThisTimeLineID);
418
421
        MemoryContext oldCtx;
419
422
        MemoryContext insertCtx;
420
423
        uint32          res = 0;
421
 
        int             i;
 
424
        int                     i;
422
425
 
423
426
        insertCtx = AllocSetContextCreate(CurrentMemoryContext,
424
427
                                                                          "Gin insert temporary context",
430
433
 
431
434
        initGinState(&ginstate, index);
432
435
 
433
 
        if ( GinGetUseFastUpdate(index) )
 
436
        if (GinGetUseFastUpdate(index))
434
437
        {
435
 
                GinTupleCollector       collector;
 
438
                GinTupleCollector collector;
436
439
 
437
440
                memset(&collector, 0, sizeof(GinTupleCollector));
438
 
                for(i=0; i<ginstate.origTupdesc->natts;i++)
439
 
                        if ( !isnull[i] )
 
441
                for (i = 0; i < ginstate.origTupdesc->natts; i++)
 
442
                        if (!isnull[i])
440
443
                                res += ginHeapTupleFastCollect(index, &ginstate, &collector,
441
 
                                                                                                (OffsetNumber)(i+1), values[i], ht_ctid);
 
444
                                                                 (OffsetNumber) (i + 1), values[i], ht_ctid);
442
445
 
443
446
                ginHeapTupleFastInsert(index, &ginstate, &collector);
444
447
        }
445
448
        else
446
449
        {
447
 
                for(i=0; i<ginstate.origTupdesc->natts;i++)
448
 
                        if ( !isnull[i] ) 
449
 
                                res += ginHeapTupleInsert(index, &ginstate, 
450
 
                                                                                                (OffsetNumber)(i+1), values[i], ht_ctid);
 
450
                for (i = 0; i < ginstate.origTupdesc->natts; i++)
 
451
                        if (!isnull[i])
 
452
                                res += ginHeapTupleInsert(index, &ginstate,
 
453
                                                                 (OffsetNumber) (i + 1), values[i], ht_ctid);
451
454
 
452
455
        }
453
456