PostgreSQL Source Code: src/backend/access/nbtree/nbtree.c File Reference (original) (raw)

Go to the source code of this file.

Functions
static void _bt_parallel_serialize_arrays (Relation rel, BTParallelScanDesc btscan, BTScanOpaque so)
static void _bt_parallel_restore_arrays (Relation rel, BTParallelScanDesc btscan, BTScanOpaque so)
static void btvacuumscan (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state, BTCycleId cycleid)
static BlockNumber btvacuumpage (BTVacState *vstate, Buffer buf)
static BTVacuumPosting btreevacuumposting (BTVacState *vstate, IndexTuple posting, OffsetNumber updatedoffset, int *nremaining)
Datum bthandler (PG_FUNCTION_ARGS)
void btbuildempty (Relation index)
bool btinsert (Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
bool btgettuple (IndexScanDesc scan, ScanDirection dir)
int64 btgetbitmap (IndexScanDesc scan, TIDBitmap *tbm)
IndexScanDesc btbeginscan (Relation rel, int nkeys, int norderbys)
void btrescan (IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
void btendscan (IndexScanDesc scan)
void btmarkpos (IndexScanDesc scan)
void btrestrpos (IndexScanDesc scan)
Size btestimateparallelscan (Relation rel, int nkeys, int norderbys)
void btinitparallelscan (void *target)
void btparallelrescan (IndexScanDesc scan)
bool _bt_parallel_seize (IndexScanDesc scan, BlockNumber *next_scan_page, BlockNumber *last_curr_page, bool first)
void _bt_parallel_release (IndexScanDesc scan, BlockNumber next_scan_page, BlockNumber curr_page)
void _bt_parallel_done (IndexScanDesc scan)
void _bt_parallel_primscan_schedule (IndexScanDesc scan, BlockNumber curr_page)
IndexBulkDeleteResult * btbulkdelete (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
IndexBulkDeleteResult * btvacuumcleanup (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
bool btcanreturn (Relation index, int attno)
int btgettreeheight (Relation rel)
CompareType bttranslatestrategy (StrategyNumber strategy, Oid opfamily)
StrategyNumber bttranslatecmptype (CompareType cmptype, Oid opfamily)

BTParallelScanDesc

BTParallelScanDescData

BTPS_State

Enumerator
BTPARALLEL_NOT_INITIALIZED
BTPARALLEL_NEED_PRIMSCAN
BTPARALLEL_ADVANCING
BTPARALLEL_IDLE
BTPARALLEL_DONE

Definition at line 54 of file nbtree.c.

55{

@ BTPARALLEL_NEED_PRIMSCAN

@ BTPARALLEL_NOT_INITIALIZED

_bt_parallel_done()

Definition at line 949 of file nbtree.c.

950{

954 bool status_changed = false;

955

957

958

959 if (parallel_scan == NULL)

960 return;

961

962

963

964

965

967 return;

968

970 parallel_scan->ps_offset_am);

971

972

973

974

975

979 {

981 status_changed = true;

982 }

984

985

986 if (status_changed)

988}

#define OffsetToPointer(base, offset)

void ConditionVariableBroadcast(ConditionVariable *cv)

Assert(PointerIsAligned(start, uint64))

bool LWLockAcquire(LWLock *lock, LWLockMode mode)

void LWLockRelease(LWLock *lock)

struct BTParallelScanDescData * BTParallelScanDesc

#define BTScanPosIsValid(scanpos)

BTScanOpaqueData * BTScanOpaque

struct ParallelIndexScanDescData * parallel_scan

References Assert(), BTPARALLEL_DONE, BTPARALLEL_NEED_PRIMSCAN, BTScanPosIsValid, ConditionVariableBroadcast(), BTScanOpaqueData::currPos, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), BTScanOpaqueData::needPrimScan, OffsetToPointer, IndexScanDescData::opaque, and IndexScanDescData::parallel_scan.

Referenced by _bt_endpoint(), _bt_first(), _bt_parallel_seize(), _bt_readnextpage(), and _bt_start_prim_scan().

_bt_parallel_primscan_schedule()

Definition at line 999 of file nbtree.c.

1000{

1005

1007

1009 parallel_scan->ps_offset_am);

1010

1012 if (btscan->btps_lastCurrPage == curr_page &&

1014 {

1018

1019

1021 }

1023}

#define InvalidBlockNumber

static void _bt_parallel_serialize_arrays(Relation rel, BTParallelScanDesc btscan, BTScanOpaque so)

References _bt_parallel_serialize_arrays(), Assert(), BTPARALLEL_IDLE, BTPARALLEL_NEED_PRIMSCAN, IndexScanDescData::indexRelation, InvalidBlockNumber, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), BTScanOpaqueData::numArrayKeys, OffsetToPointer, IndexScanDescData::opaque, and IndexScanDescData::parallel_scan.

Referenced by _bt_advance_array_keys(), and _bt_readpage().

_bt_parallel_release()

Definition at line 922 of file nbtree.c.

924{

927

929

932

939}

static bool BlockNumberIsValid(BlockNumber blockNumber)

void ConditionVariableSignal(ConditionVariable *cv)

BTPS_State btps_pageStatus

BlockNumber btps_lastCurrPage

ConditionVariable btps_cv

BlockNumber btps_nextScanPage

References Assert(), BlockNumberIsValid(), BTPARALLEL_IDLE, BTParallelScanDescData::btps_cv, BTParallelScanDescData::btps_lastCurrPage, BTParallelScanDescData::btps_lock, BTParallelScanDescData::btps_nextScanPage, BTParallelScanDescData::btps_pageStatus, ConditionVariableSignal(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), OffsetToPointer, IndexScanDescData::parallel_scan, and ParallelIndexScanDescData::ps_offset_am.

Referenced by _bt_readnextpage(), and _bt_readpage().

_bt_parallel_restore_arrays()

Definition at line 674 of file nbtree.c.

676{

677 char *datumshared;

678

679

682 {

685 bool isnull;

686

688 {

689

693 continue;

694 }

695

696

700 memcpy(&skey->sk_flags, datumshared, sizeof(int));

701 datumshared += sizeof(int);

702

704

706 {

707

708 continue;

709 }

710

712 if (isnull)

713 {

717 }

718 }

719}

Datum datumRestore(char **start_address, bool *isnull)

void pfree(void *pointer)

static Pointer DatumGetPointer(Datum X)

int btps_arrElems[FLEXIBLE_ARRAY_MEMBER]

BTArrayKeyInfo * arrayKeys

References BTScanOpaqueData::arrayKeys, Assert(), BTArrayKeyInfo::attbyval, BTParallelScanDescData::btps_arrElems, BTArrayKeyInfo::cur_elem, DatumGetPointer(), datumRestore(), BTArrayKeyInfo::elem_values, i, BTScanOpaqueData::keyData, BTArrayKeyInfo::num_elems, BTScanOpaqueData::numArrayKeys, pfree(), BTArrayKeyInfo::scan_key, ScanKeyData::sk_argument, SK_BT_MAXVAL, SK_BT_MINVAL, SK_BT_SKIP, ScanKeyData::sk_flags, SK_ISNULL, and SK_SEARCHNULL.

Referenced by _bt_parallel_seize().

_bt_parallel_seize()

Definition at line 784 of file nbtree.c.

786{

789 bool exit_loop = false,

790 status = true,

791 endscan = false;

794

797

798

799

800

801

802

803

806

807 if (first)

808 {

809

810

811

812

816 }

817 else

818 {

819

820

821

822

824 return false;

825 }

826

828 parallel_scan->ps_offset_am);

829

830 while (1)

831 {

833

835 {

836

837 status = false;

838 }

840 btscan->btps_nextScanPage == P_NONE)

841 {

842

843 status = false;

844 endscan = true;

845 }

847 {

849

850 if (first)

851 {

852

854

855

857 exit_loop = true;

858 }

859 else

860 {

861

862

863

864

865

866 status = false;

867 }

868

869

870

871

872

876 }

878 {

879

880

881

882

885 *next_scan_page = btscan->btps_nextScanPage;

886 *last_curr_page = btscan->btps_lastCurrPage;

887 exit_loop = true;

888 }

890 if (exit_loop || !status)

891 break;

893 }

895

896

897 if (endscan)

899

900 return status;

901}

bool ConditionVariableCancelSleep(void)

void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)

void _bt_parallel_done(IndexScanDesc scan)

static void _bt_parallel_restore_arrays(Relation rel, BTParallelScanDesc btscan, BTScanOpaque so)

#define BTScanPosInvalidate(scanpos)

References _bt_parallel_done(), _bt_parallel_restore_arrays(), Assert(), BTPARALLEL_ADVANCING, BTPARALLEL_DONE, BTPARALLEL_IDLE, BTPARALLEL_NEED_PRIMSCAN, BTScanPosInvalidate, ConditionVariableCancelSleep(), ConditionVariableSleep(), BTScanOpaqueData::currPos, IndexScanDescData::indexRelation, InvalidBlockNumber, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), BTScanPosData::moreLeft, BTScanPosData::moreRight, BTScanOpaqueData::needPrimScan, BTScanOpaqueData::numArrayKeys, OffsetToPointer, IndexScanDescData::opaque, BTScanOpaqueData::oppositeDirCheck, P_NONE, IndexScanDescData::parallel_scan, and BTScanOpaqueData::scanBehind.

Referenced by _bt_first(), and _bt_readnextpage().

_bt_parallel_serialize_arrays()

Definition at line 631 of file nbtree.c.

633{

634 char *datumshared;

635

636

639 {

642

644 {

645

648 continue;

649 }

650

651

653 memcpy(datumshared, &skey->sk_flags, sizeof(int));

654 datumshared += sizeof(int);

655

657 {

658

660 continue;

661 }

662

665 }

666}

void datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address)

References BTScanOpaqueData::arrayKeys, Assert(), BTArrayKeyInfo::attbyval, BTArrayKeyInfo::attlen, BTParallelScanDescData::btps_arrElems, BTArrayKeyInfo::cur_elem, datumSerialize(), i, BTScanOpaqueData::keyData, BTArrayKeyInfo::num_elems, BTScanOpaqueData::numArrayKeys, BTArrayKeyInfo::scan_key, ScanKeyData::sk_argument, SK_BT_MAXVAL, SK_BT_MINVAL, SK_BT_SKIP, ScanKeyData::sk_flags, and SK_ISNULL.

Referenced by _bt_parallel_primscan_schedule().

btbeginscan()

Definition at line 332 of file nbtree.c.

333{

336

337

338 Assert(norderbys == 0);

339

340

342

343

349 else

351

359

360 so->killedItems = NULL;

362

363

364

365

366

367

369

371

373

374 return scan;

375}

IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)

#define RelationGetDescr(relation)

MemoryContext arrayContext

struct TupleDescData * xs_itupdesc

References BTScanOpaqueData::arrayContext, BTScanOpaqueData::arrayKeys, Assert(), BTScanPosInvalidate, BTScanOpaqueData::currPos, BTScanOpaqueData::currTuples, BTScanOpaqueData::keyData, BTScanOpaqueData::killedItems, BTScanOpaqueData::markPos, BTScanOpaqueData::markTuples, BTScanOpaqueData::needPrimScan, IndexScanDescData::numberOfKeys, BTScanOpaqueData::numKilled, IndexScanDescData::opaque, BTScanOpaqueData::oppositeDirCheck, BTScanOpaqueData::orderProcs, palloc(), RelationGetDescr, RelationGetIndexScan(), BTScanOpaqueData::scanBehind, BTScanOpaqueData::skipScan, and IndexScanDescData::xs_itupdesc.

Referenced by bthandler().

btbuildempty()

Definition at line 179 of file nbtree.c.

180{

184

186

187

191

193}

BulkWriteState * smgr_bulk_start_rel(Relation rel, ForkNumber forknum)

void smgr_bulk_write(BulkWriteState *bulkstate, BlockNumber blocknum, BulkWriteBuffer buf, bool page_std)

BulkWriteBuffer smgr_bulk_get_buf(BulkWriteState *bulkstate)

void smgr_bulk_finish(BulkWriteState *bulkstate)

void _bt_initmetapage(Page page, BlockNumber rootbknum, uint32 level, bool allequalimage)

bool _bt_allequalimage(Relation rel, bool debugmessage)

References _bt_allequalimage(), _bt_initmetapage(), BTREE_METAPAGE, INIT_FORKNUM, P_NONE, smgr_bulk_finish(), smgr_bulk_get_buf(), smgr_bulk_start_rel(), and smgr_bulk_write().

Referenced by bthandler().

btbulkdelete()

Definition at line 1033 of file nbtree.c.

1035{

1038

1039

1040 if (stats == NULL)

1042

1043

1044

1046 {

1048

1050 }

1053

1054 return stats;

1055}

#define PG_ENSURE_ERROR_CLEANUP(cleanup_function, arg)

#define PG_END_ENSURE_ERROR_CLEANUP(cleanup_function, arg)

void * palloc0(Size size)

static void btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state, BTCycleId cycleid)

void _bt_end_vacuum(Relation rel)

void _bt_end_vacuum_callback(int code, Datum arg)

BTCycleId _bt_start_vacuum(Relation rel)

static Datum PointerGetDatum(const void *X)

static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)

References _bt_end_vacuum(), _bt_end_vacuum_callback(), _bt_start_vacuum(), btvacuumscan(), callback(), IndexVacuumInfo::index, palloc0(), PG_END_ENSURE_ERROR_CLEANUP, PG_ENSURE_ERROR_CLEANUP, and PointerGetDatum().

Referenced by bthandler().

btcanreturn()

bool btcanreturn ( Relation index,
int attno
)

btendscan()

Definition at line 438 of file nbtree.c.

439{

441

442

444 {

445

449 }

450

453

454

455

456

459

466

468}

if(TABLE==NULL||TABLE_index==NULL)

void MemoryContextDelete(MemoryContext context)

#define BTScanPosUnpinIfPinned(scanpos)

void _bt_killitems(IndexScanDesc scan)

References _bt_killitems(), BTScanOpaqueData::arrayContext, BTScanPosIsValid, BTScanPosUnpinIfPinned, BTScanOpaqueData::currPos, BTScanOpaqueData::currTuples, if(), BTScanOpaqueData::keyData, BTScanOpaqueData::killedItems, BTScanOpaqueData::markItemIndex, BTScanOpaqueData::markPos, MemoryContextDelete(), BTScanOpaqueData::numKilled, IndexScanDescData::opaque, and pfree().

Referenced by bthandler().

btestimateparallelscan()

Size btestimateparallelscan ( Relation rel,
int nkeys,
int norderbys
)

Definition at line 558 of file nbtree.c.

559{

561 Size estnbtreeshared,

562 genericattrspace;

563

564

565

566

567

569 sizeof(int) * nkeys;

570

571

572 if (nkeyatts == 1)

573 return estnbtreeshared;

574

575

576

577

578

582 {

584

585

586

587

588

589

590

591 estnbtreeshared = add_size(estnbtreeshared, sizeof(int));

592

593

596 {

597

600

601 estnbtreeshared = add_size(estnbtreeshared, estfixed);

602 continue;

603 }

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618 estnbtreeshared = add_size(estnbtreeshared, genericattrspace);

620 }

621

622 return estnbtreeshared;

623}

Size datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)

#define IndexRelationGetNumberOfKeyAttributes(relation)

Size add_size(Size s1, Size s2)

static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)

References add_size(), CompactAttribute::attbyval, CompactAttribute::attlen, attnum, BTMaxItemSize, BTParallelScanDescData::btps_arrElems, datumEstimateSpace(), IndexRelationGetNumberOfKeyAttributes, RelationData::rd_att, and TupleDescCompactAttr().

Referenced by bthandler().

btgetbitmap()

Definition at line 286 of file nbtree.c.

287{

291

292

293 do

294 {

295

297 {

298

301 ntids++;

302

303 for (;;)

304 {

305

306

307

308

310 {

311

313 break;

314 }

315

316

319 ntids++;

320 }

321 }

322

324

325 return ntids;

326}

bool _bt_first(IndexScanDesc scan, ScanDirection dir)

bool _bt_next(IndexScanDesc scan, ScanDirection dir)

bool _bt_start_prim_scan(IndexScanDesc scan, ScanDirection dir)

BTScanPosItem items[MaxTIDsPerBTreePage]

ItemPointerData xs_heaptid

void tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids, bool recheck)

References _bt_first(), _bt_next(), BTScanOpaqueData::currPos, ForwardScanDirection, BTScanPosItem::heapTid, if(), BTScanPosData::itemIndex, BTScanPosData::items, BTScanPosData::lastItem, IndexScanDescData::opaque, tbm_add_tuples(), and IndexScanDescData::xs_heaptid.

Referenced by bthandler().

btgettreeheight()

btgettuple()

Definition at line 226 of file nbtree.c.

227{

229 bool res;

230

231

233

234

235 do

236 {

237

238

239

240

241

244 else

245 {

246

247

248

250 {

251

252

253

254

255

256

257

258

259

265 }

266

267

268

269

271 }

272

273

274 if (res)

275 break;

276

278

279 return res;

280}

#define MaxTIDsPerBTreePage

References _bt_first(), _bt_next(), BTScanPosIsValid, BTScanOpaqueData::currPos, if(), BTScanPosData::itemIndex, IndexScanDescData::kill_prior_tuple, BTScanOpaqueData::killedItems, MaxTIDsPerBTreePage, BTScanOpaqueData::numKilled, IndexScanDescData::opaque, palloc(), and IndexScanDescData::xs_recheck.

Referenced by bthandler().

bthandler()

Definition at line 115 of file nbtree.c.

116{

118

144

171

173}

#define PG_RETURN_POINTER(x)

bool btcanreturn(Relation index, int attno)

StrategyNumber bttranslatecmptype(CompareType cmptype, Oid opfamily)

IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys)

Size btestimateparallelscan(Relation rel, int nkeys, int norderbys)

IndexBulkDeleteResult * btvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)

CompareType bttranslatestrategy(StrategyNumber strategy, Oid opfamily)

bool btgettuple(IndexScanDesc scan, ScanDirection dir)

void btparallelrescan(IndexScanDesc scan)

bool btinsert(Relation rel, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)

void btbuildempty(Relation index)

int btgettreeheight(Relation rel)

void btinitparallelscan(void *target)

IndexBulkDeleteResult * btbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)

int64 btgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)

void btmarkpos(IndexScanDesc scan)

void btendscan(IndexScanDesc scan)

void btrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)

void btrestrpos(IndexScanDesc scan)

IndexBuildResult * btbuild(Relation heap, Relation index, IndexInfo *indexInfo)

char * btbuildphasename(int64 phasenum)

bytea * btoptions(Datum reloptions, bool validate)

bool btproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)

bool btvalidate(Oid opclassoid)

void btadjustmembers(Oid opfamilyoid, Oid opclassoid, List *operators, List *functions)

void btcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)

#define BTMaxStrategyNumber

ambuildphasename_function ambuildphasename

ambuildempty_function ambuildempty

amvacuumcleanup_function amvacuumcleanup

amoptions_function amoptions

amestimateparallelscan_function amestimateparallelscan

amrestrpos_function amrestrpos

aminsert_function aminsert

amendscan_function amendscan

amtranslate_strategy_function amtranslatestrategy

amparallelrescan_function amparallelrescan

bool amconsistentordering

amtranslate_cmptype_function amtranslatecmptype

amcostestimate_function amcostestimate

amadjustmembers_function amadjustmembers

amgettuple_function amgettuple

amcanreturn_function amcanreturn

amgetbitmap_function amgetbitmap

amproperty_function amproperty

ambulkdelete_function ambulkdelete

amvalidate_function amvalidate

ammarkpos_function ammarkpos

bool amusemaintenanceworkmem

ambeginscan_function ambeginscan

amrescan_function amrescan

aminitparallelscan_function aminitparallelscan

uint8 amparallelvacuumoptions

aminsertcleanup_function aminsertcleanup

amgettreeheight_function amgettreeheight

bool amconsistentequality

#define VACUUM_OPTION_PARALLEL_BULKDEL

#define VACUUM_OPTION_PARALLEL_COND_CLEANUP

References IndexAmRoutine::amadjustmembers, IndexAmRoutine::ambeginscan, IndexAmRoutine::ambuild, IndexAmRoutine::ambuildempty, IndexAmRoutine::ambuildphasename, IndexAmRoutine::ambulkdelete, IndexAmRoutine::amcanbackward, IndexAmRoutine::amcanbuildparallel, IndexAmRoutine::amcanhash, IndexAmRoutine::amcaninclude, IndexAmRoutine::amcanmulticol, IndexAmRoutine::amcanorder, IndexAmRoutine::amcanorderbyop, IndexAmRoutine::amcanparallel, IndexAmRoutine::amcanreturn, IndexAmRoutine::amcanunique, IndexAmRoutine::amclusterable, IndexAmRoutine::amconsistentequality, IndexAmRoutine::amconsistentordering, IndexAmRoutine::amcostestimate, IndexAmRoutine::amendscan, IndexAmRoutine::amestimateparallelscan, IndexAmRoutine::amgetbitmap, IndexAmRoutine::amgettreeheight, IndexAmRoutine::amgettuple, IndexAmRoutine::aminitparallelscan, IndexAmRoutine::aminsert, IndexAmRoutine::aminsertcleanup, IndexAmRoutine::amkeytype, IndexAmRoutine::ammarkpos, IndexAmRoutine::amoptionalkey, IndexAmRoutine::amoptions, IndexAmRoutine::amoptsprocnum, IndexAmRoutine::amparallelrescan, IndexAmRoutine::amparallelvacuumoptions, IndexAmRoutine::ampredlocks, IndexAmRoutine::amproperty, IndexAmRoutine::amrescan, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexAmRoutine::amsearchnulls, IndexAmRoutine::amstorage, IndexAmRoutine::amstrategies, IndexAmRoutine::amsummarizing, IndexAmRoutine::amsupport, IndexAmRoutine::amtranslatecmptype, IndexAmRoutine::amtranslatestrategy, IndexAmRoutine::amusemaintenanceworkmem, IndexAmRoutine::amvacuumcleanup, IndexAmRoutine::amvalidate, btadjustmembers(), btbeginscan(), btbuild(), btbuildempty(), btbuildphasename(), btbulkdelete(), btcanreturn(), btcostestimate(), btendscan(), btestimateparallelscan(), btgetbitmap(), btgettreeheight(), btgettuple(), btinitparallelscan(), btinsert(), btmarkpos(), BTMaxStrategyNumber, BTNProcs, btoptions(), BTOPTIONS_PROC, btparallelrescan(), btproperty(), btrescan(), btrestrpos(), bttranslatecmptype(), bttranslatestrategy(), btvacuumcleanup(), btvalidate(), InvalidOid, makeNode, PG_RETURN_POINTER, VACUUM_OPTION_PARALLEL_BULKDEL, and VACUUM_OPTION_PARALLEL_COND_CLEANUP.

btinitparallelscan()

void btinitparallelscan ( void * target )

Definition at line 725 of file nbtree.c.

726{

728

735}

void ConditionVariableInit(ConditionVariable *cv)

void LWLockInitialize(LWLock *lock, int tranche_id)

@ LWTRANCHE_PARALLEL_BTREE_SCAN

References BTPARALLEL_NOT_INITIALIZED, BTParallelScanDescData::btps_cv, BTParallelScanDescData::btps_lastCurrPage, BTParallelScanDescData::btps_lock, BTParallelScanDescData::btps_nextScanPage, BTParallelScanDescData::btps_pageStatus, ConditionVariableInit(), InvalidBlockNumber, LWLockInitialize(), and LWTRANCHE_PARALLEL_BTREE_SCAN.

Referenced by bthandler().

btinsert()

Definition at line 202 of file nbtree.c.

207{

208 bool result;

210

211

213 itup->t_tid = *ht_ctid;

214

215 result = _bt_doinsert(rel, itup, checkUnique, indexUnchanged, heapRel);

216

218

219 return result;

220}

static Datum values[MAXATTR]

IndexTuple index_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)

bool _bt_doinsert(Relation rel, IndexTuple itup, IndexUniqueCheck checkUnique, bool indexUnchanged, Relation heapRel)

References _bt_doinsert(), index_form_tuple(), pfree(), RelationGetDescr, IndexTupleData::t_tid, and values.

Referenced by bthandler().

btmarkpos()

btparallelrescan()

Definition at line 741 of file nbtree.c.

742{

745

746 Assert(parallel_scan);

747

750

751

752

753

754

755

761}

References Assert(), BTPARALLEL_NOT_INITIALIZED, BTParallelScanDescData::btps_lastCurrPage, BTParallelScanDescData::btps_lock, BTParallelScanDescData::btps_nextScanPage, BTParallelScanDescData::btps_pageStatus, InvalidBlockNumber, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), OffsetToPointer, IndexScanDescData::parallel_scan, and ParallelIndexScanDescData::ps_offset_am.

Referenced by bthandler().

btreevacuumposting()

Definition at line 1664 of file nbtree.c.

1666{

1667 int live = 0;

1671

1672 for (int i = 0; i < nitem; i++)

1673 {

1675 {

1676

1677 live++;

1678 }

1679 else if (vacposting == NULL)

1680 {

1681

1682

1683

1684

1685

1686

1687

1689 nitem * sizeof(uint16));

1690

1691 vacposting->itup = posting;

1695 }

1696 else

1697 {

1698

1700 }

1701 }

1702

1703 *nremaining = live;

1704 return vacposting;

1705}

static uint16 BTreeTupleGetNPosting(IndexTuple posting)

static ItemPointer BTreeTupleGetPosting(IndexTuple posting)

IndexBulkDeleteCallback callback

uint16 deletetids[FLEXIBLE_ARRAY_MEMBER]

OffsetNumber updatedoffset

References BTreeTupleGetNPosting(), BTreeTupleGetPosting(), BTVacState::callback, BTVacState::callback_state, BTVacuumPostingData::deletetids, i, items, BTVacuumPostingData::itup, BTVacuumPostingData::ndeletedtids, palloc(), and BTVacuumPostingData::updatedoffset.

Referenced by btvacuumpage().

btrescan()

Definition at line 381 of file nbtree.c.

383{

385

386

388 {

389

394 }

395

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

420 {

423 }

424

425

426

427

430 so->numberOfKeys = 0;

432}

struct ScanKeyData * keyData

References _bt_killitems(), BTScanPosInvalidate, BTScanPosIsValid, BTScanPosUnpinIfPinned, BTScanOpaqueData::currPos, BTScanOpaqueData::currTuples, if(), IndexScanDescData::keyData, BTScanOpaqueData::markItemIndex, BTScanOpaqueData::markPos, BTScanOpaqueData::markTuples, BTScanOpaqueData::needPrimScan, BTScanOpaqueData::numArrayKeys, BTScanOpaqueData::numberOfKeys, IndexScanDescData::numberOfKeys, BTScanOpaqueData::numKilled, IndexScanDescData::opaque, BTScanOpaqueData::oppositeDirCheck, palloc(), BTScanOpaqueData::scanBehind, and IndexScanDescData::xs_want_itup.

Referenced by bthandler().

btrestrpos()

Definition at line 500 of file nbtree.c.

501{

503

505 {

506

507

508

509

510

511

512

514 }

515 else

516 {

517

518

519

520

521

522

524 {

525

529 }

530

532 {

533

542

544 {

547 }

548 }

549 else

551 }

552}

void IncrBufferRefCount(Buffer buffer)

#define BTScanPosIsPinned(scanpos)

void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir)

References _bt_killitems(), _bt_start_array_keys(), BTScanPosInvalidate, BTScanPosIsPinned, BTScanPosIsValid, BTScanPosUnpinIfPinned, BTScanPosData::buf, BTScanOpaqueData::currPos, BTScanOpaqueData::currTuples, BTScanPosData::dir, if(), IncrBufferRefCount(), BTScanPosData::itemIndex, items, BTScanPosData::lastItem, BTScanOpaqueData::markItemIndex, BTScanOpaqueData::markPos, BTScanOpaqueData::markTuples, BTScanOpaqueData::needPrimScan, BTScanPosData::nextTupleOffset, BTScanOpaqueData::numArrayKeys, BTScanOpaqueData::numKilled, and IndexScanDescData::opaque.

Referenced by bthandler().

bttranslatecmptype()

Definition at line 1748 of file nbtree.c.

1749{

1750 switch (cmptype)

1751 {

1762 default:

1764 }

1765}

#define BTGreaterStrategyNumber

#define BTLessStrategyNumber

#define BTEqualStrategyNumber

#define BTLessEqualStrategyNumber

#define BTGreaterEqualStrategyNumber

References BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, COMPARE_EQ, COMPARE_GE, COMPARE_GT, COMPARE_LE, COMPARE_LT, and InvalidStrategy.

Referenced by bthandler().

bttranslatestrategy()

Definition at line 1728 of file nbtree.c.

1729{

1730 switch (strategy)

1731 {

1742 default:

1744 }

1745}

References BTEqualStrategyNumber, BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, COMPARE_EQ, COMPARE_GE, COMPARE_GT, COMPARE_INVALID, COMPARE_LE, and COMPARE_LT.

Referenced by bthandler().

btvacuumcleanup()

Definition at line 1063 of file nbtree.c.

1064{

1066

1067

1069 return stats;

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082 if (stats == NULL)

1083 {

1084

1086 return NULL;

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1105 }

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1122

1123

1124

1125

1126

1127

1128

1130 {

1133 }

1134

1135 return stats;

1136}

void _bt_set_cleanup_info(Relation rel, BlockNumber num_delpages)

bool _bt_vacuum_needs_cleanup(Relation rel)

BlockNumber pages_deleted

References _bt_set_cleanup_info(), _bt_vacuum_needs_cleanup(), IndexVacuumInfo::analyze_only, Assert(), btvacuumscan(), IndexVacuumInfo::estimated_count, IndexBulkDeleteResult::estimated_count, IndexVacuumInfo::index, IndexVacuumInfo::num_heap_tuples, IndexBulkDeleteResult::num_index_tuples, IndexBulkDeleteResult::pages_deleted, IndexBulkDeleteResult::pages_free, and palloc0().

Referenced by bthandler().

btvacuumpage()

Definition at line 1326 of file nbtree.c.

1327{

1334 bool attempt_pagedel;

1336 backtrack_to;

1340

1341 blkno = scanblkno;

1342

1343backtrack:

1344

1345 attempt_pagedel = false;

1346 backtrack_to = P_NONE;

1347

1350 opaque = NULL;

1352 {

1355 }

1356

1357 Assert(blkno <= scanblkno);

1358 if (blkno != scanblkno)

1359 {

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1376 {

1379 (errcode(ERRCODE_INDEX_CORRUPTED),

1380 errmsg_internal("right sibling %u of scanblkno %u unexpectedly in an inconsistent state in index \"%s\"",

1383 return scanblkno;

1384 }

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1400 {

1401

1403 return scanblkno;

1404 }

1405 }

1406

1408 {

1409

1413 }

1415 {

1416

1417

1418

1419

1421 }

1423 {

1424

1425 attempt_pagedel = true;

1426

1427

1428

1429

1430

1431 }

1433 {

1435 int ndeletable;

1437 int nupdatable;

1439 minoff,

1440 maxoff;

1441 int nhtidsdead,

1442 nhtidslive;

1443

1444

1445

1446

1447

1448

1449

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461 if (vstate->cycleid != 0 &&

1466 backtrack_to = opaque->btpo_next;

1467

1468 ndeletable = 0;

1469 nupdatable = 0;

1472 nhtidsdead = 0;

1473 nhtidslive = 0;

1475 {

1476

1477 for (offnum = minoff;

1478 offnum <= maxoff;

1480 {

1482

1485

1488 {

1489

1491 {

1492 deletable[ndeletable++] = offnum;

1493 nhtidsdead++;

1494 }

1495 else

1496 nhtidslive++;

1497 }

1498 else

1499 {

1501 int nremaining;

1502

1503

1505 &nremaining);

1506 if (vacposting == NULL)

1507 {

1508

1509

1510

1511

1513 }

1514 else if (nremaining > 0)

1515 {

1516

1517

1518

1519

1520

1521

1522

1524 updatable[nupdatable++] = vacposting;

1526 }

1527 else

1528 {

1529

1530

1531

1532

1533

1534 Assert(nremaining == 0);

1535 deletable[ndeletable++] = offnum;

1537 pfree(vacposting);

1538 }

1539

1540 nhtidslive += nremaining;

1541 }

1542 }

1543 }

1544

1545

1546

1547

1548

1549 if (ndeletable > 0 || nupdatable > 0)

1550 {

1551 Assert(nhtidsdead >= ndeletable + nupdatable);

1553 nupdatable);

1554

1556

1558

1559

1560 for (int i = 0; i < nupdatable; i++)

1561 pfree(updatable[i]);

1562 }

1563 else

1564 {

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575 Assert(nhtidsdead == 0);

1576 if (vstate->cycleid != 0 &&

1578 {

1581 }

1582 }

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599 if (minoff > maxoff)

1600 attempt_pagedel = (blkno == scanblkno);

1603 else

1605

1606 Assert(!attempt_pagedel || nhtidslive == 0);

1607 }

1608

1609 if (attempt_pagedel)

1610 {

1612

1613

1616

1617

1618

1619

1620

1621

1622 Assert(blkno == scanblkno);

1624

1626

1627 }

1628 else

1630

1631 if (backtrack_to != P_NONE)

1632 {

1633 blkno = backtrack_to;

1634

1635

1637

1638

1639

1640

1641

1642

1643

1646 goto backtrack;

1647 }

1648

1649 return scanblkno;

1650}

BlockNumber BufferGetBlockNumber(Buffer buffer)

void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)

Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)

static Page BufferGetPage(Buffer buffer)

static Item PageGetItem(const PageData *page, const ItemIdData *itemId)

static bool PageIsNew(const PageData *page)

static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)

static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)

int errmsg_internal(const char *fmt,...)

int errcode(int sqlerrcode)

#define ereport(elevel,...)

bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)

void RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)

IndexTupleData * IndexTuple

#define MaxIndexTuplesPerPage

void MemoryContextReset(MemoryContext context)

void _bt_relbuf(Relation rel, Buffer buf)

void _bt_pagedel(Relation rel, Buffer leafbuf, BTVacState *vstate)

void _bt_delitems_vacuum(Relation rel, Buffer buf, OffsetNumber *deletable, int ndeletable, BTVacuumPosting *updatable, int nupdatable)

void _bt_checkpage(Relation rel, Buffer buf)

void _bt_upgradelockbufcleanup(Relation rel, Buffer buf)

void _bt_lockbuf(Relation rel, Buffer buf, int access)

static BTVacuumPosting btreevacuumposting(BTVacState *vstate, IndexTuple posting, OffsetNumber updatedoffset, int *nremaining)

#define P_ISHALFDEAD(opaque)

static bool BTreeTupleIsPivot(IndexTuple itup)

#define BTPageGetOpaque(page)

#define P_ISDELETED(opaque)

#define P_FIRSTDATAKEY(opaque)

#define P_RIGHTMOST(opaque)

static bool BTPageIsRecyclable(Page page, Relation heaprel)

static bool BTreeTupleIsPosting(IndexTuple itup)

#define OffsetNumberNext(offsetNumber)

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

#define RelationGetRelationName(relation)

IndexBulkDeleteResult * stats

MemoryContext pagedelcontext

BufferAccessStrategy strategy

void vacuum_delay_point(bool is_analyze)

References _bt_checkpage(), _bt_delitems_vacuum(), _bt_lockbuf(), _bt_pagedel(), _bt_relbuf(), _bt_upgradelockbufcleanup(), Assert(), BT_READ, BTP_SPLIT_END, BTPageGetOpaque, BTPageIsRecyclable(), BTPageOpaqueData::btpo_cycleid, BTPageOpaqueData::btpo_flags, BTPageOpaqueData::btpo_next, BTreeTupleGetNPosting(), BTreeTupleIsPivot(), BTreeTupleIsPosting(), btreevacuumposting(), buf, BufferGetBlockNumber(), BufferGetPage(), BTVacState::callback, callback(), BTVacState::callback_state, BTVacState::cycleid, ereport, errcode(), errmsg_internal(), IndexVacuumInfo::heaprel, i, IndexVacuumInfo::index, BTVacState::info, LOG, MAIN_FORKNUM, MarkBufferDirtyHint(), MaxIndexTuplesPerPage, MemoryContextReset(), MemoryContextSwitchTo(), IndexBulkDeleteResult::num_index_tuples, OffsetNumberNext, P_FIRSTDATAKEY, P_ISDELETED, P_ISHALFDEAD, P_ISLEAF, P_NONE, P_RIGHTMOST, BTVacState::pagedelcontext, PageGetItem(), PageGetItemId(), PageGetMaxOffsetNumber(), PageIsNew(), IndexBulkDeleteResult::pages_deleted, IndexBulkDeleteResult::pages_free, pfree(), RBM_NORMAL, ReadBufferExtended(), RecordFreeIndexPage(), RelationGetRelationName, BTVacState::stats, IndexVacuumInfo::strategy, IndexTupleData::t_tid, IndexBulkDeleteResult::tuples_removed, and vacuum_delay_point().

Referenced by btvacuumscan().

btvacuumscan()

Definition at line 1151 of file nbtree.c.

1154{

1158 bool needLock;

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1181

1182

1183 vstate.info = info;

1184 vstate.stats = stats;

1187 vstate.cycleid = cycleid;

1188

1189

1191 "_bt_pagedel",

1193

1194

1199

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1228

1230

1231

1232

1233

1234

1239 rel,

1242 &p,

1243 0);

1244 for (;;)

1245 {

1246

1247 if (needLock)

1250 if (needLock)

1252

1255 num_pages);

1256

1257

1259 break;

1260

1262

1263

1264 while (true)

1265 {

1268

1269

1271

1273

1275 break;

1276

1278

1281 current_block);

1282 }

1283

1284

1285

1286

1287

1288

1290 }

1291

1293

1294

1296

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1311}

void pgstat_progress_update_param(int index, int64 val)

#define RelationGetNumberOfBlocks(reln)

static bool BufferIsValid(Buffer bufnum)

void IndexFreeSpaceMapVacuum(Relation rel)

void LockRelationForExtension(Relation relation, LOCKMODE lockmode)

void UnlockRelationForExtension(Relation relation, LOCKMODE lockmode)

MemoryContext CurrentMemoryContext

#define AllocSetContextCreate

#define ALLOCSET_DEFAULT_SIZES

void _bt_pendingfsm_finalize(Relation rel, BTVacState *vstate)

void _bt_pendingfsm_init(Relation rel, BTVacState *vstate, bool cleanuponly)

static BlockNumber btvacuumpage(BTVacState *vstate, Buffer buf)

#define PROGRESS_SCAN_BLOCKS_DONE

#define PROGRESS_SCAN_BLOCKS_TOTAL

void read_stream_reset(ReadStream *stream)

Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)

ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)

void read_stream_end(ReadStream *stream)

BlockNumber block_range_read_stream_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)

#define READ_STREAM_MAINTENANCE

#define READ_STREAM_USE_BATCHING

#define RELATION_IS_LOCAL(relation)

BTPendingFSM * pendingpages

BlockNumber last_exclusive

BlockNumber current_blocknum

References _bt_pendingfsm_finalize(), _bt_pendingfsm_init(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, block_range_read_stream_cb(), BTREE_METAPAGE, btvacuumpage(), buf, BufferIsValid(), BTVacState::bufsize, BTVacState::callback, callback(), BTVacState::callback_state, BlockRangeReadStreamPrivate::current_blocknum, CurrentMemoryContext, BTVacState::cycleid, ExclusiveLock, IndexVacuumInfo::index, IndexFreeSpaceMapVacuum(), BTVacState::info, BlockRangeReadStreamPrivate::last_exclusive, LockRelationForExtension(), MAIN_FORKNUM, BTVacState::maxbufsize, MemoryContextDelete(), BTVacState::npendingpages, IndexBulkDeleteResult::num_index_tuples, IndexBulkDeleteResult::num_pages, BTVacState::pagedelcontext, IndexBulkDeleteResult::pages_deleted, IndexBulkDeleteResult::pages_free, BTVacState::pendingpages, pgstat_progress_update_param(), PROGRESS_SCAN_BLOCKS_DONE, PROGRESS_SCAN_BLOCKS_TOTAL, read_stream_begin_relation(), read_stream_end(), READ_STREAM_FULL, READ_STREAM_MAINTENANCE, read_stream_next_buffer(), read_stream_reset(), READ_STREAM_USE_BATCHING, RELATION_IS_LOCAL, RelationGetNumberOfBlocks, IndexVacuumInfo::report_progress, BTVacState::stats, IndexVacuumInfo::strategy, UnlockRelationForExtension(), and vacuum_delay_point().

Referenced by btbulkdelete(), and btvacuumcleanup().