12
12
* Portions Copyright (c) 1994, Regents of the University of California
13
13
*
14
14
* IDENTIFICATION
15
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.77 2005/01/26 23:20:21 tgl Exp $
15
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.78 2005/04/11 19:51:15 tgl Exp $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -416,18 +416,14 @@ DropDependentPortals(MemoryContext queryContext)
416
416
*
417
417
* Any holdable cursors created in this transaction need to be converted to
418
418
* materialized form, since we are going to close down the executor and
419
- * release locks. Remove all other portals created in this transaction.
420
- * Portals remaining from prior transactions should be left untouched.
419
+ * release locks. Other portals are not touched yet.
421
420
*
422
- * XXX This assumes that portals can be deleted in a random order, ie,
423
- * no portal has a reference to any other (at least not one that will be
424
- * exercised during deletion). I think this is okay at the moment, but
425
- * we've had bugs of that ilk in the past. Keep a close eye on cursor
426
- * references...
421
+ * Returns TRUE if any holdable cursors were processed, FALSE if not.
427
422
*/
428
- void
429
- AtCommit_Portals (void )
423
+ bool
424
+ CommitHoldablePortals (void )
430
425
{
426
+ bool result = false;
431
427
HASH_SEQ_STATUS status ;
432
428
PortalHashEnt * hentry ;
433
429
@@ -437,27 +433,9 @@ AtCommit_Portals(void)
437
433
{
438
434
Portal portal = hentry -> portal ;
439
435
440
- /*
441
- * Do not touch active portals --- this can only happen in the
442
- * case of a multi-transaction utility command, such as VACUUM.
443
- *
444
- * Note however that any resource owner attached to such a portal is
445
- * still going to go away, so don't leave a dangling pointer.
446
- */
447
- if (portal -> status == PORTAL_ACTIVE )
448
- {
449
- portal -> resowner = NULL ;
450
- continue ;
451
- }
452
-
453
- /*
454
- * Do nothing else to cursors held over from a previous
455
- * transaction.
456
- */
457
- if (portal -> createSubid == InvalidSubTransactionId )
458
- continue ;
459
-
436
+ /* Is it a holdable portal created in the current xact? */
460
437
if ((portal -> cursorOptions & CURSOR_OPT_HOLD ) &&
438
+ portal -> createSubid != InvalidSubTransactionId &&
461
439
portal -> status == PORTAL_READY )
462
440
{
463
441
/*
@@ -484,12 +462,60 @@ AtCommit_Portals(void)
484
462
* as not belonging to this transaction.
485
463
*/
486
464
portal -> createSubid = InvalidSubTransactionId ;
465
+
466
+ result = true;
487
467
}
488
- else
468
+ }
469
+
470
+ return result ;
471
+ }
472
+
473
+ /*
474
+ * Pre-commit processing for portals.
475
+ *
476
+ * Remove all non-holdable portals created in this transaction.
477
+ * Portals remaining from prior transactions should be left untouched.
478
+ *
479
+ * XXX This assumes that portals can be deleted in a random order, ie,
480
+ * no portal has a reference to any other (at least not one that will be
481
+ * exercised during deletion). I think this is okay at the moment, but
482
+ * we've had bugs of that ilk in the past. Keep a close eye on cursor
483
+ * references...
484
+ */
485
+ void
486
+ AtCommit_Portals (void )
487
+ {
488
+ HASH_SEQ_STATUS status ;
489
+ PortalHashEnt * hentry ;
490
+
491
+ hash_seq_init (& status , PortalHashTable );
492
+
493
+ while ((hentry = (PortalHashEnt * ) hash_seq_search (& status )) != NULL )
494
+ {
495
+ Portal portal = hentry -> portal ;
496
+
497
+ /*
498
+ * Do not touch active portals --- this can only happen in the
499
+ * case of a multi-transaction utility command, such as VACUUM.
500
+ *
501
+ * Note however that any resource owner attached to such a portal is
502
+ * still going to go away, so don't leave a dangling pointer.
503
+ */
504
+ if (portal -> status == PORTAL_ACTIVE )
489
505
{
490
- /* Zap all non-holdable portals */
491
- PortalDrop ( portal , true) ;
506
+ portal -> resowner = NULL ;
507
+ continue ;
492
508
}
509
+
510
+ /*
511
+ * Do nothing to cursors held over from a previous transaction
512
+ * (including holdable ones just frozen by CommitHoldablePortals).
513
+ */
514
+ if (portal -> createSubid == InvalidSubTransactionId )
515
+ continue ;
516
+
517
+ /* Zap all non-holdable portals */
518
+ PortalDrop (portal , true);
493
519
}
494
520
}
495
521
0 commit comments