PostgreSQL Source Code: src/backend/access/gin/ginutil.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

31

32

33

34

35

36

39{

41

67

92

94}

95

96

97

98

99

100

101void

103{

105 int i;

106

108

110 state->oneCol = (origTupdesc->natts == 1);

111 state->origTupdesc = origTupdesc;

112

113 for (i = 0; i < origTupdesc->natts; i++)

114 {

116

117 if (state->oneCol)

119 else

120 {

122

124 INT2OID, -1, 0);

126 attr->atttypid,

127 attr->atttypmod,

128 attr->attndims);

130 attr->attcollation);

131 }

132

133

134

135

136

138 {

142 }

143 else

144 {

146

151 (errcode(ERRCODE_UNDEFINED_FUNCTION),

152 errmsg("could not identify a comparison function for type %s",

157 }

158

159

166

167

168

169

170

172 {

176 }

177

179 {

183 }

184

187 {

188 elog(ERROR, "missing GIN support function (%d or %d) for attribute %d of index \"%s\"",

191 }

192

193

194

195

197 {

201 state->canPartialMatch[i] = true;

202 }

203 else

204 {

205 state->canPartialMatch[i] = false;

206 }

207

208

209

210

211

212

213

214

215

216

217

218

219

221 state->supportCollation[i] = index->rd_indcollation[i];

222 else

223 state->supportCollation[i] = DEFAULT_COLLATION_OID;

224 }

225}

226

227

228

229

232{

234

235 if (ginstate->oneCol)

236 {

237

239 }

240 else

241 {

243 bool isnull;

244

245

246

247

248

250 &isnull);

252

255 }

256

257 return colN;

258}

259

260

261

262

266{

268 bool isnull;

269

270 if (ginstate->oneCol)

271 {

272

273

274

276 &isnull);

277 }

278 else

279 {

280

281

282

283

285

287 ginstate->tupdesc[colN - 1],

288 &isnull);

289 }

290

291 if (isnull)

293 else

295

296 return res;

297}

298

299

300

301

302

303

306{

308

309

310 for (;;)

311 {

313

315 break;

316

318

319

320

321

322

324 {

326 return buffer;

327

329 }

330

331

333 }

334

335

338

339 return buffer;

340}

341

342void

344{

346

348

350 opaque->flags = f;

352}

353

354void

356{

358}

359

360void

362{

365

367

369

379

380

381

382

383

384

386 ((char *) metadata + sizeof(GinMetaPageData)) - (char *) page;

387}

388

389

390

391

392int

396{

397

398 if (categorya != categoryb)

399 return (categorya < categoryb) ? -1 : 1;

400

401

403 return 0;

404

405

408 a, b));

409}

410

411

412

413

414int

418{

419

420 if (attnuma != attnumb)

421 return (attnuma < attnumb) ? -1 : 1;

422

424}

425

426

427

428

429

430

431

432

433

434typedef struct

435{

439

440typedef struct

441{

446

447static int

449{

453 int res;

454

456 {

458 res = 0;

459 else

460 res = 1;

461 }

463 res = -1;

464 else

466 data->collation,

468

469

470

471

472

473

474 if (res == 0)

475 data->haveDups = true;

476

477 return res;

478}

479

480

481

482

483

484

485

486

491{

493 bool *nullFlags;

495

496

497

498

499

500 if (isNull)

501 {

502 *nentries = 1;

504 entries[0] = (Datum) 0;

507 return entries;

508 }

509

510

511 nullFlags = NULL;

512 entries = (Datum *)

518

519

520

521

522 if (entries == NULL || *nentries <= 0)

523 {

524 *nentries = 1;

526 entries[0] = (Datum) 0;

529 return entries;

530 }

531

532

533

534

535

536 if (nullFlags == NULL)

537 nullFlags = (bool *) palloc0(*nentries * sizeof(bool));

538

539

540

541

542

543

544

545

546 if (*nentries > 1)

547 {

550

552 for (i = 0; i < *nentries; i++)

553 {

554 keydata[i].datum = entries[i];

555 keydata[i].isnull = nullFlags[i];

556 }

557

560 arg.haveDups = false;

563

564 if (arg.haveDups)

565 {

566

568

569 entries[0] = keydata[0].datum;

570 nullFlags[0] = keydata[0].isnull;

571 j = 1;

572 for (i = 1; i < *nentries; i++)

573 {

575 {

576 entries[j] = keydata[i].datum;

577 nullFlags[j] = keydata[i].isnull;

578 j++;

579 }

580 }

581 *nentries = j;

582 }

583 else

584 {

585

586 for (i = 0; i < *nentries; i++)

587 {

588 entries[i] = keydata[i].datum;

589 nullFlags[i] = keydata[i].isnull;

590 }

591 }

592

594 }

595

596

597

598

600 for (i = 0; i < *nentries; i++)

602

603 return entries;

604}

605

608{

612 pendingListCleanupSize)}

613 };

614

619}

620

621

622

623

624

625

626

627void

629{

631 Page metapage;

633

638

645

647}

648

649

650

651

652

653

654void

656{

658 Page metapage;

660

665

667

672

673

674

675

676

677

678

679

681 ((char *) metadata + sizeof(GinMetaPageData)) - (char *) metapage;

682

684

686 {

689

690 data.locator = index->rd_locator;

691 data.ntuples = 0;

694

698

701 }

702

704

706}

707

708

709

710

711char *

713{

714 switch (phasenum)

715 {

717 return "initializing";

719 return "scanning table";

721 return "sorting tuples (workers)";

723 return "merging tuples (workers)";

725 return "sorting tuples";

727 return "merging tuples";

728 default:

729 return NULL;

730 }

731}

static bool validate(Port *port, const char *auth)

#define InvalidBlockNumber

Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)

bool ConditionalLockBuffer(Buffer buffer)

void ReleaseBuffer(Buffer buffer)

void UnlockReleaseBuffer(Buffer buffer)

void MarkBufferDirty(Buffer buffer)

void LockBuffer(Buffer buffer, int mode)

Buffer ReadBuffer(Relation reln, BlockNumber blockNum)

static Page BufferGetPage(Buffer buffer)

static Size BufferGetPageSize(Buffer buffer)

void PageInit(Page page, Size pageSize, Size specialSize)

PageHeaderData * PageHeader

static void PageSetLSN(Page page, XLogRecPtr lsn)

#define MemSet(start, val, len)

#define OidIsValid(objectId)

int errcode(int sqlerrcode)

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

#define ereport(elevel,...)

Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)

Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)

void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)

#define PG_RETURN_POINTER(x)

char * format_type_be(Oid type_oid)

#define GIN_CONSISTENT_PROC

#define PROGRESS_GIN_PHASE_PERFORMSORT_2

#define PROGRESS_GIN_PHASE_MERGE_1

#define PROGRESS_GIN_PHASE_PERFORMSORT_1

#define GIN_EXTRACTQUERY_PROC

#define GIN_EXTRACTVALUE_PROC

#define PROGRESS_GIN_PHASE_MERGE_2

#define GIN_TRICONSISTENT_PROC

#define GIN_COMPARE_PARTIAL_PROC

#define PROGRESS_GIN_PHASE_INDEXBUILD_TABLESCAN

#define GIN_CURRENT_VERSION

#define GIN_METAPAGE_BLKNO

#define GinGetNullCategory(itup, ginstate)

#define GinPageGetOpaque(page)

#define GIN_CAT_EMPTY_ITEM

signed char GinNullCategory

#define GIN_CAT_NULL_ITEM

#define GinPageGetMeta(p)

int64 gingetbitmap(IndexScanDesc scan, TIDBitmap *tbm)

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

void ginbuildempty(Relation index)

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

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

void ginendscan(IndexScanDesc scan)

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

void GinInitPage(Page page, uint32 f, Size pageSize)

bytea * ginoptions(Datum reloptions, bool validate)

Datum ginhandler(PG_FUNCTION_ARGS)

void ginGetStats(Relation index, GinStatsData *stats)

OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple)

Buffer GinNewBuffer(Relation index)

void GinInitBuffer(Buffer b, uint32 f)

Datum * ginExtractEntries(GinState *ginstate, OffsetNumber attnum, Datum value, bool isNull, int32 *nentries, GinNullCategory **categories)

int ginCompareAttEntries(GinState *ginstate, OffsetNumber attnuma, Datum a, GinNullCategory categorya, OffsetNumber attnumb, Datum b, GinNullCategory categoryb)

Datum gintuple_get_key(GinState *ginstate, IndexTuple tuple, GinNullCategory *category)

void GinInitMetabuffer(Buffer b)

static int cmpEntries(const void *a, const void *b, void *arg)

char * ginbuildphasename(int64 phasenum)

void initGinState(GinState *state, Relation index)

int ginCompareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, GinNullCategory categorya, Datum b, GinNullCategory categoryb)

void ginUpdateStats(Relation index, const GinStatsData *stats, bool is_build)

bool GinPageIsRecyclable(Page page)

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

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

bool ginvalidate(Oid opclassoid)

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

#define XLOG_GIN_UPDATE_META_PAGE

Assert(PointerIsAligned(start, uint64))

FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)

RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)

BlockNumber GetFreeIndexPage(Relation rel)

static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)

void pfree(void *pointer)

void * palloc0(Size size)

MemoryContext CurrentMemoryContext

#define START_CRIT_SECTION()

#define END_CRIT_SECTION()

#define OffsetNumberNext(offsetNumber)

#define FirstOffsetNumber

FormData_pg_attribute * Form_pg_attribute

void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)

static Datum PointerGetDatum(const void *X)

static uint16 DatumGetUInt16(Datum X)

static Pointer DatumGetPointer(Datum X)

static int32 DatumGetInt32(Datum X)

#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE

#define RelationGetDescr(relation)

#define RelationGetRelationName(relation)

#define RelationNeedsWAL(relation)

void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)

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

BlockNumber nPendingPages

TupleDesc tupdesc[INDEX_MAX_KEYS]

FmgrInfo extractValueFn[INDEX_MAX_KEYS]

Oid supportCollation[INDEX_MAX_KEYS]

FmgrInfo compareFn[INDEX_MAX_KEYS]

BlockNumber nPendingPages

ambuildphasename_function ambuildphasename

ambuildempty_function ambuildempty

amvacuumcleanup_function amvacuumcleanup

amoptions_function amoptions

amestimateparallelscan_function amestimateparallelscan

amrestrpos_function amrestrpos

aminsert_function aminsert

amendscan_function amendscan

amparallelrescan_function amparallelrescan

bool amconsistentordering

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

TupleDesc CreateTemplateTupleDesc(int natts)

void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)

void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)

static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)

TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)

#define TYPECACHE_CMP_PROC_FINFO

#define VACUUM_OPTION_PARALLEL_CLEANUP

#define VACUUM_OPTION_PARALLEL_BULKDEL

XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)

void XLogRegisterData(const void *data, uint32 len)

void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)

void XLogBeginInsert(void)