|
30 | 30 | * |
31 | 31 | * HeapTupleSatisfiesMVCC() |
32 | 32 | * visible to supplied snapshot, excludes current command |
33 | | - * HeapTupleSatisfiesNow() |
34 | | - * visible to instant snapshot, excludes current command |
35 | 33 | * HeapTupleSatisfiesUpdate() |
36 | | - *like HeapTupleSatisfiesNow(), but with user-supplied command |
| 34 | + *visible to instant snapshot, with user-supplied command |
37 | 35 | * counter and more complex result |
38 | 36 | * HeapTupleSatisfiesSelf() |
39 | 37 | * visible to instant snapshot and current command |
|
68 | 66 |
|
69 | 67 |
|
70 | 68 | /* Static variables representing various special snapshot semantics */ |
71 | | -SnapshotDataSnapshotNowData= {HeapTupleSatisfiesNow}; |
72 | 69 | SnapshotDataSnapshotSelfData= {HeapTupleSatisfiesSelf}; |
73 | 70 | SnapshotDataSnapshotAnyData= {HeapTupleSatisfiesAny}; |
74 | 71 | SnapshotDataSnapshotToastData= {HeapTupleSatisfiesToast}; |
@@ -323,212 +320,6 @@ HeapTupleSatisfiesSelf(HeapTuple htup, Snapshot snapshot, Buffer buffer) |
323 | 320 | return false; |
324 | 321 | } |
325 | 322 |
|
326 | | -/* |
327 | | - * HeapTupleSatisfiesNow |
328 | | - *True iff heap tuple is valid "now". |
329 | | - * |
330 | | - *Here, we consider the effects of: |
331 | | - *all committed transactions (as of the current instant) |
332 | | - *previous commands of this transaction |
333 | | - * |
334 | | - * Note we do _not_ include changes made by the current command. This |
335 | | - * solves the "Halloween problem" wherein an UPDATE might try to re-update |
336 | | - * its own output tuples, http://en.wikipedia.org/wiki/Halloween_Problem. |
337 | | - * |
338 | | - * Note: |
339 | | - *Assumes heap tuple is valid. |
340 | | - * |
341 | | - * The satisfaction of "now" requires the following: |
342 | | - * |
343 | | - * ((Xmin == my-transaction &&inserted by the current transaction |
344 | | - * Cmin < my-command &&before this command, and |
345 | | - * (Xmax is null ||the row has not been deleted, or |
346 | | - * (Xmax == my-transaction &&it was deleted by the current transaction |
347 | | - * Cmax >= my-command)))but not before this command, |
348 | | - * ||or |
349 | | - *(Xmin is committed &&the row was inserted by a committed transaction, and |
350 | | - *(Xmax is null ||the row has not been deleted, or |
351 | | - * (Xmax == my-transaction &&the row is being deleted by this transaction |
352 | | - * Cmax >= my-command) ||but it's not deleted "yet", or |
353 | | - * (Xmax != my-transaction &&the row was deleted by another transaction |
354 | | - * Xmax is not committed))))that has not been committed |
355 | | - * |
356 | | - */ |
357 | | -bool |
358 | | -HeapTupleSatisfiesNow(HeapTuplehtup,Snapshotsnapshot,Bufferbuffer) |
359 | | -{ |
360 | | -HeapTupleHeadertuple=htup->t_data; |
361 | | -Assert(ItemPointerIsValid(&htup->t_self)); |
362 | | -Assert(htup->t_tableOid!=InvalidOid); |
363 | | - |
364 | | -if (!(tuple->t_infomask&HEAP_XMIN_COMMITTED)) |
365 | | -{ |
366 | | -if (tuple->t_infomask&HEAP_XMIN_INVALID) |
367 | | -return false; |
368 | | - |
369 | | -/* Used by pre-9.0 binary upgrades */ |
370 | | -if (tuple->t_infomask&HEAP_MOVED_OFF) |
371 | | -{ |
372 | | -TransactionIdxvac=HeapTupleHeaderGetXvac(tuple); |
373 | | - |
374 | | -if (TransactionIdIsCurrentTransactionId(xvac)) |
375 | | -return false; |
376 | | -if (!TransactionIdIsInProgress(xvac)) |
377 | | -{ |
378 | | -if (TransactionIdDidCommit(xvac)) |
379 | | -{ |
380 | | -SetHintBits(tuple,buffer,HEAP_XMIN_INVALID, |
381 | | -InvalidTransactionId); |
382 | | -return false; |
383 | | -} |
384 | | -SetHintBits(tuple,buffer,HEAP_XMIN_COMMITTED, |
385 | | -InvalidTransactionId); |
386 | | -} |
387 | | -} |
388 | | -/* Used by pre-9.0 binary upgrades */ |
389 | | -elseif (tuple->t_infomask&HEAP_MOVED_IN) |
390 | | -{ |
391 | | -TransactionIdxvac=HeapTupleHeaderGetXvac(tuple); |
392 | | - |
393 | | -if (!TransactionIdIsCurrentTransactionId(xvac)) |
394 | | -{ |
395 | | -if (TransactionIdIsInProgress(xvac)) |
396 | | -return false; |
397 | | -if (TransactionIdDidCommit(xvac)) |
398 | | -SetHintBits(tuple,buffer,HEAP_XMIN_COMMITTED, |
399 | | -InvalidTransactionId); |
400 | | -else |
401 | | -{ |
402 | | -SetHintBits(tuple,buffer,HEAP_XMIN_INVALID, |
403 | | -InvalidTransactionId); |
404 | | -return false; |
405 | | -} |
406 | | -} |
407 | | -} |
408 | | -elseif (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tuple))) |
409 | | -{ |
410 | | -if (HeapTupleHeaderGetCmin(tuple) >=GetCurrentCommandId(false)) |
411 | | -return false;/* inserted after scan started */ |
412 | | - |
413 | | -if (tuple->t_infomask&HEAP_XMAX_INVALID)/* xid invalid */ |
414 | | -return true; |
415 | | - |
416 | | -if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))/* not deleter */ |
417 | | -return true; |
418 | | - |
419 | | -if (tuple->t_infomask&HEAP_XMAX_IS_MULTI) |
420 | | -{ |
421 | | -TransactionIdxmax; |
422 | | - |
423 | | -xmax=HeapTupleGetUpdateXid(tuple); |
424 | | -if (!TransactionIdIsValid(xmax)) |
425 | | -return true; |
426 | | - |
427 | | -/* updating subtransaction must have aborted */ |
428 | | -if (!TransactionIdIsCurrentTransactionId(xmax)) |
429 | | -return true; |
430 | | -else |
431 | | -return false; |
432 | | -} |
433 | | - |
434 | | -if (!TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple))) |
435 | | -{ |
436 | | -/* deleting subtransaction must have aborted */ |
437 | | -SetHintBits(tuple,buffer,HEAP_XMAX_INVALID, |
438 | | -InvalidTransactionId); |
439 | | -return true; |
440 | | -} |
441 | | - |
442 | | -if (HeapTupleHeaderGetCmax(tuple) >=GetCurrentCommandId(false)) |
443 | | -return true;/* deleted after scan started */ |
444 | | -else |
445 | | -return false;/* deleted before scan started */ |
446 | | -} |
447 | | -elseif (TransactionIdIsInProgress(HeapTupleHeaderGetXmin(tuple))) |
448 | | -return false; |
449 | | -elseif (TransactionIdDidCommit(HeapTupleHeaderGetXmin(tuple))) |
450 | | -SetHintBits(tuple,buffer,HEAP_XMIN_COMMITTED, |
451 | | -HeapTupleHeaderGetXmin(tuple)); |
452 | | -else |
453 | | -{ |
454 | | -/* it must have aborted or crashed */ |
455 | | -SetHintBits(tuple,buffer,HEAP_XMIN_INVALID, |
456 | | -InvalidTransactionId); |
457 | | -return false; |
458 | | -} |
459 | | -} |
460 | | - |
461 | | -/* by here, the inserting transaction has committed */ |
462 | | - |
463 | | -if (tuple->t_infomask&HEAP_XMAX_INVALID)/* xid invalid or aborted */ |
464 | | -return true; |
465 | | - |
466 | | -if (tuple->t_infomask&HEAP_XMAX_COMMITTED) |
467 | | -{ |
468 | | -if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) |
469 | | -return true; |
470 | | -return false; |
471 | | -} |
472 | | - |
473 | | -if (tuple->t_infomask&HEAP_XMAX_IS_MULTI) |
474 | | -{ |
475 | | -TransactionIdxmax; |
476 | | - |
477 | | -if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) |
478 | | -return true; |
479 | | - |
480 | | -xmax=HeapTupleGetUpdateXid(tuple); |
481 | | -if (!TransactionIdIsValid(xmax)) |
482 | | -return true; |
483 | | -if (TransactionIdIsCurrentTransactionId(xmax)) |
484 | | -{ |
485 | | -if (HeapTupleHeaderGetCmax(tuple) >=GetCurrentCommandId(false)) |
486 | | -return true;/* deleted after scan started */ |
487 | | -else |
488 | | -return false;/* deleted before scan started */ |
489 | | -} |
490 | | -if (TransactionIdIsInProgress(xmax)) |
491 | | -return true; |
492 | | -if (TransactionIdDidCommit(xmax)) |
493 | | -return false; |
494 | | -return true; |
495 | | -} |
496 | | - |
497 | | -if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple))) |
498 | | -{ |
499 | | -if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) |
500 | | -return true; |
501 | | -if (HeapTupleHeaderGetCmax(tuple) >=GetCurrentCommandId(false)) |
502 | | -return true;/* deleted after scan started */ |
503 | | -else |
504 | | -return false;/* deleted before scan started */ |
505 | | -} |
506 | | - |
507 | | -if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple))) |
508 | | -return true; |
509 | | - |
510 | | -if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple))) |
511 | | -{ |
512 | | -/* it must have aborted or crashed */ |
513 | | -SetHintBits(tuple,buffer,HEAP_XMAX_INVALID, |
514 | | -InvalidTransactionId); |
515 | | -return true; |
516 | | -} |
517 | | - |
518 | | -/* xmax transaction committed */ |
519 | | - |
520 | | -if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask)) |
521 | | -{ |
522 | | -SetHintBits(tuple,buffer,HEAP_XMAX_INVALID, |
523 | | -InvalidTransactionId); |
524 | | -return true; |
525 | | -} |
526 | | - |
527 | | -SetHintBits(tuple,buffer,HEAP_XMAX_COMMITTED, |
528 | | -HeapTupleHeaderGetRawXmax(tuple)); |
529 | | -return false; |
530 | | -} |
531 | | - |
532 | 323 | /* |
533 | 324 | * HeapTupleSatisfiesAny |
534 | 325 | *Dummy "satisfies" routine: any tuple satisfies SnapshotAny. |
@@ -614,10 +405,10 @@ HeapTupleSatisfiesToast(HeapTuple htup, Snapshot snapshot, |
614 | 405 | /* |
615 | 406 | * HeapTupleSatisfiesUpdate |
616 | 407 | * |
617 | | - *Same logic as HeapTupleSatisfiesNow, butreturns a more detailed result |
618 | | - *code, since UPDATE needs to know more than "is it visible?". Also, |
619 | | - *tuples of my own xact are tested against the passedCommandIdnot |
620 | | - *CurrentCommandId. |
| 408 | + *This functionreturns a more detailed result code than most of the |
| 409 | + *functions in this file, since UPDATE needs to know more than "is it |
| 410 | + *visible?". It also allows for user-suppliedCommandIdrather than |
| 411 | + *relying onCurrentCommandId. |
621 | 412 | * |
622 | 413 | *The possible return codes are: |
623 | 414 | * |
@@ -1051,10 +842,6 @@ HeapTupleSatisfiesDirty(HeapTuple htup, Snapshot snapshot, |
1051 | 842 | *transactions started after the snapshot was taken |
1052 | 843 | *changes made by the current command |
1053 | 844 | * |
1054 | | - * This is the same as HeapTupleSatisfiesNow, except that transactions that |
1055 | | - * were in progress or as yet unstarted when the snapshot was taken will |
1056 | | - * be treated as uncommitted, even if they have committed by now. |
1057 | | - * |
1058 | 845 | * (Notice, however, that the tuple status hint bits will be updated on the |
1059 | 846 | * basis of the true state of the transaction, even if we then pretend we |
1060 | 847 | * can't see it.) |
|