81 bool all_visible_cleared,
bool new_all_visible_cleared);
89 bool *have_tuple_lock);
161 #define LOCKMODE_from_mxstatus(status) \
162 (tupleLockExtraInfo[TUPLOCK_from_mxstatus((status))].hwlock)
169 #define LockTupleTuplock(rel, tup, mode) \
170 LockTuple((rel), (tup), tupleLockExtraInfo[mode].hwlock)
171 #define UnlockTupleTuplock(rel, tup, mode) \
172 UnlockTuple((rel), (tup), tupleLockExtraInfo[mode].hwlock)
173 #define ConditionalLockTupleTuplock(rel, tup, mode) \
174 ConditionalLockTuple((rel), (tup), tupleLockExtraInfo[mode].hwlock)
187 } IndexDeletePrefetchState;
191 #define BOTTOMUP_MAX_NBLOCKS 6
192 #define BOTTOMUP_TOLERANCE_NBLOCKS 3
220 #define TUPLOCK_from_mxstatus(status) \
221 (MultiXactStatusLock[(status)])
277 allow_strat = allow_sync =
false;
300 else if (keep_startblock)
363 Assert(startBlk == 0 || startBlk < scan->rs_nblocks);
388 Assert(block < scan->rs_nblocks);
474 &loctup, buffer, snapshot);
616 *linesleft = *lineoff;
787 while (linesleft > 0)
808 if (valid &&
key != NULL)
927 linesleft = scan->rs_ntuples;
929 scan->rs_inited =
true;
951 while (linesleft > 0)
1013 linesleft = scan->rs_ntuples;
1015 lineindex = linesleft - 1;
1094 if (parallel_scan != NULL)
1115 bool allow_strat,
bool allow_sync,
bool allow_pagemode)
1197 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1208 elog(
ERROR,
"unexpected heap_getnext call during logical decoding");
1566 bool *all_dead,
bool first_call)
1572 bool at_chain_start;
1579 *all_dead = first_call;
1583 at_chain_start = first_call;
1609 at_chain_start =
false;
1676 if (all_dead && *all_dead)
1694 at_chain_start =
false;
1921 bool all_visible_cleared =
false;
1968 all_visible_cleared =
true;
2019 if (all_visible_cleared)
2113 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
2114 errmsg(
"cannot insert tuples in a parallel worker")));
2131 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2132 relation->
rd_rel->relkind != RELKIND_MATVIEW)
2180 for (
i = 0;
i < ntuples;
i++)
2217 while (ndone < ntuples)
2220 bool starting_with_empty_page;
2221 bool all_visible_cleared =
false;
2222 bool all_frozen_set =
false;
2242 all_frozen_set =
true;
2257 if (needwal && need_cids)
2260 for (nthispage = 1; ndone + nthispage < ntuples; nthispage++)
2262 HeapTuple heaptup = heaptuples[ndone + nthispage];
2273 if (needwal && need_cids)
2286 all_visible_cleared =
true;
2292 else if (all_frozen_set)
2309 char *scratchptr = scratch.
data;
2317 init = starting_with_empty_page;
2333 tupledata = scratchptr;
2336 Assert(!(all_visible_cleared && all_frozen_set));
2339 if (all_visible_cleared)
2350 for (
i = 0;
i < nthispage;
i++)
2372 scratchptr += datalen;
2374 totaldatalen = scratchptr - tupledata;
2375 Assert((scratchptr - scratch.
data) < BLCKSZ);
2377 if (need_tuple_data)
2385 if (ndone + nthispage == ntuples)
2398 if (need_tuple_data)
2475 for (
i = 0;
i < ntuples;
i++)
2480 for (
i = 0;
i < ntuples;
i++)
2481 slots[
i]->tts_tid = heaptuples[
i]->t_self;
2533 const uint16 interesting =
2536 if ((new_infomask & interesting) != (old_infomask & interesting))
2569 bool have_tuple_lock =
false;
2571 bool all_visible_cleared =
false;
2573 bool old_key_copied =
false;
2584 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
2585 errmsg(
"cannot delete tuples during a parallel operation")));
2631 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2632 errmsg(
"attempted to delete invisible tuple")));
2658 bool current_is_member =
false;
2669 if (!current_is_member)
2755 if (result !=
TM_Ok)
2771 if (have_tuple_lock)
2811 &new_xmax, &new_infomask, &new_infomask2);
2826 all_visible_cleared =
true;
2869 if (all_visible_cleared)
2876 xlrec.
xmax = new_xmax;
2878 if (old_key_tuple != NULL)
2880 if (relation->
rd_rel->relreplident == REPLICA_IDENTITY_FULL)
2894 if (old_key_tuple != NULL)
2903 old_key_tuple->
t_len
2928 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
2929 relation->
rd_rel->relkind != RELKIND_MATVIEW)
2950 if (have_tuple_lock)
2955 if (old_key_tuple != NULL && old_key_copied)
2983 elog(
ERROR,
"tuple already updated by self");
2991 elog(
ERROR,
"tuple concurrently updated");
2995 elog(
ERROR,
"tuple concurrently deleted");
2999 elog(
ERROR,
"unrecognized heap_delete status: %u", result);
3031 bool old_key_copied =
false;
3042 bool have_tuple_lock =
false;
3044 bool use_hot_update =
false;
3046 bool all_visible_cleared =
false;
3047 bool all_visible_cleared_new =
false;
3048 bool checked_lockers;
3049 bool locker_remains;
3050 bool id_has_external =
false;
3053 uint16 infomask_old_tuple,
3054 infomask2_old_tuple,
3056 infomask2_new_tuple;
3071 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
3072 errmsg(
"cannot update tuples during a parallel operation")));
3094 interesting_attrs = NULL;
3139 newtup, &id_has_external);
3184 checked_lockers =
false;
3185 locker_remains =
false;
3195 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3196 errmsg(
"attempted to update invisible tuple")));
3202 bool can_continue =
false;
3247 bool current_is_member =
false;
3250 *lockmode, ¤t_is_member))
3258 if (!current_is_member)
3266 checked_lockers =
true;
3267 locker_remains = remain != 0;
3314 can_continue =
true;
3322 checked_lockers =
true;
3323 locker_remains =
true;
3324 can_continue =
true;
3333 checked_lockers =
true;
3334 locker_remains =
true;
3335 can_continue =
true;
3348 checked_lockers =
true;
3364 can_continue =
true;
3385 if (result !=
TM_Ok)
3401 if (have_tuple_lock)
3439 xid, *lockmode,
true,
3440 &xmax_old_tuple, &infomask_old_tuple,
3441 &infomask2_old_tuple);
3452 (checked_lockers && !locker_remains))
3460 infomask2_new_tuple = 0;
3473 &infomask2_new_tuple);
3478 infomask2_new_tuple = 0;
3511 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
3512 relation->
rd_rel->relkind != RELKIND_MATVIEW)
3528 if (need_toast || newtupsize > pagefree)
3531 uint16 infomask_lock_old_tuple,
3532 infomask2_lock_old_tuple;
3533 bool cleared_all_frozen =
false;
3556 xid, *lockmode,
false,
3557 &xmax_lock_old_tuple, &infomask_lock_old_tuple,
3558 &infomask2_lock_old_tuple);
3587 cleared_all_frozen =
true;
3655 if (newtupsize > pagefree)
3660 &vmbuffer_new, &vmbuffer);
3671 if (newtupsize > pagefree ||
3719 if (newbuf == buffer)
3727 use_hot_update =
true;
3800 all_visible_cleared =
true;
3807 all_visible_cleared_new =
true;
3813 if (newbuf != buffer)
3833 newbuf, &oldtup, heaptup,
3835 all_visible_cleared,
3836 all_visible_cleared_new);
3837 if (newbuf != buffer)
3846 if (newbuf != buffer)
3861 if (newbuf != buffer)
3872 if (have_tuple_lock)
3881 if (heaptup != newtup)
3887 if (old_key_tuple != NULL && old_key_copied)
3905 bool isnull1,
bool isnull2)
3913 if (isnull1 != isnull2)
3938 Assert(attrnum <= tupdesc->natts);
3940 return datumIsEqual(value1, value2, att->attbyval, att->attlen);
4012 value1 =
heap_getattr(oldtup, attrnum, tupdesc, &isnull1);
4013 value2 =
heap_getattr(newtup, attrnum, tupdesc, &isnull2);
4016 value2, isnull1, isnull2))
4028 if (attrnum < 0 || isnull1 ||
4039 *has_external =
true;
4068 elog(
ERROR,
"tuple already updated by self");
4076 elog(
ERROR,
"tuple concurrently updated");
4080 elog(
ERROR,
"tuple concurrently deleted");
4084 elog(
ERROR,
"unrecognized heap_update status: %u", result);
4105 is_update ?
"true" :
"false");
4144 bool follow_updates,
4158 bool first_time =
true;
4159 bool skip_tuple_lock =
false;
4160 bool have_tuple_lock =
false;
4161 bool cleared_all_frozen =
false;
4248 for (
i = 0;
i < nmembers;
i++)
4273 skip_tuple_lock =
true;
4322 require_sleep =
true;
4356 if (follow_updates && updated)
4387 require_sleep =
false;
4416 require_sleep =
false;
4442 require_sleep =
false;
4455 require_sleep =
false;
4481 require_sleep =
false;
4500 else if (require_sleep)
4512 if (!skip_tuple_lock &&
4532 elog(
ERROR,
"invalid lock mode in heap_lock_tuple");
4535 switch (wait_policy)
4543 status, infomask, relation,
4554 status, infomask, relation,
4557 (
errcode(ERRCODE_LOCK_NOT_AVAILABLE),
4558 errmsg(
"could not obtain lock on row in relation \"%s\"",
4577 switch (wait_policy)
4595 (
errcode(ERRCODE_LOCK_NOT_AVAILABLE),
4596 errmsg(
"could not obtain lock on row in relation \"%s\"",
4652 if (!require_sleep ||
4664 if (result !=
TM_Ok)
4726 &xid, &new_infomask, &new_infomask2);
4762 cleared_all_frozen =
true;
4821 if (have_tuple_lock)
4843 if (*have_tuple_lock)
4846 switch (wait_policy)
4860 (
errcode(ERRCODE_LOCK_NOT_AVAILABLE),
4861 errmsg(
"could not obtain lock on row in relation \"%s\"",
4865 *have_tuple_lock =
true;
4893 uint16 *result_infomask2)
4916 new_xmax = add_to_xmax;
4926 new_xmax = add_to_xmax;
4930 new_xmax = add_to_xmax;
4934 new_xmax = add_to_xmax;
4938 new_xmax = add_to_xmax;
5062 elog(
WARNING,
"LOCK_ONLY found for Xid in progress %u", xmax);
5084 if (xmax == add_to_xmax)
5098 if (
mode < old_mode)
5109 add_to_xmax, new_status);
5149 *result_infomask = new_infomask;
5150 *result_infomask2 = new_infomask2;
5151 *result_xmax = new_xmax;
5275 bool cleared_all_frozen =
false;
5276 bool pinned_desired_page;
5314 pinned_desired_page =
true;
5317 pinned_desired_page =
false;
5397 for (
i = 0;
i < nmembers;
i++)
5430 if (result !=
TM_Ok)
5467 elog(
ERROR,
"invalid lock status in tuple");
5501 if (result !=
TM_Ok)
5511 &new_xmax, &new_infomask, &new_infomask2);
5516 cleared_all_frozen =
true;
5540 xlrec.
xmax = new_xmax;