PostgreSQL Source Code: contrib/pgstattuple/pgstatindex.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

29

42

43

44

45

46

47

48

49

50

51

58

64

66

67#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)

68#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)

69#define IS_GIN(r) ((r)->rd_rel->relam == GIN_AM_OID)

70#define IS_HASH(r) ((r)->rd_rel->relam == HASH_AM_OID)

71

72

73

74

75

76

78{

82

87

90

93

94

95

96

97

98

100{

102

106

107

108

109

110

111

113{

116

121

126

130

131

132

133

134

135

136

137

138

139

140

143{

147

150 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

151 errmsg("must be superuser to use pgstattuple functions")));

152

155

157}

158

159

160

161

162

163

164

165

168{

172

175

177}

178

179

180

181

182

183

186{

189

192 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

193 errmsg("must be superuser to use pgstattuple functions")));

194

196

198}

199

200

203{

206

208

210}

211

214{

220

223 (errcode(ERRCODE_WRONG_OBJECT_TYPE),

224 errmsg("relation \"%s\" is not a btree index",

226

227

228

229

230

231

234 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

235 errmsg("cannot access temporary tables of other sessions")));

236

237

238

239

240

241

242

243 if (!rel->rd_index->indisvalid)

245 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

246 errmsg("index \"%s\" is not valid",

248

249

250

251

252 {

256

260

262 }

263

264

269

272

274

275

276

277

279

280 for (blkno = 1; blkno < nblocks; blkno++)

281 {

285

287

288

291

294

295

296

297

298

299

300

304 indexStat.empty_pages++;

306 {

307 int max_avail;

308

310 indexStat.max_avail += max_avail;

312

314

315

316

317

318

321 }

322 else

324

325

328 }

329

331

332

333

334

335

336 {

338 int j;

341

342

344 elog(ERROR, "return type must be a row type");

345

346 j = 0;

350 (1 +

362 100.0 - (double) indexStat.free_space / (double) indexStat.max_avail * 100.0);

363 else

368 else

370

373

375 }

376

377 return result;

378}

379

380

381

382

383

384

385

386

387

388

389

390

393{

397

400 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

401 errmsg("must be superuser to use pgstattuple functions")));

402

405

407}

408

409

412{

416

419

421}

422

423

426{

429

432 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

433 errmsg("must be superuser to use pgstattuple functions")));

434

436

438}

439

440

443{

446

448

450}

451

454{

456

457 if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))

459 (errcode(ERRCODE_WRONG_OBJECT_TYPE),

460 errmsg("cannot get page count of relation \"%s\"",

463

464

465

467

469

470 return relpages;

471}

472

473

474

475

476

477

478

479

480

483{

485

488 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),

489 errmsg("must be superuser to use pgstattuple functions")));

490

492}

493

494

497{

499

501}

502

505{

514 bool nulls[3] = {false, false, false};

516

518

521 (errcode(ERRCODE_WRONG_OBJECT_TYPE),

522 errmsg("relation \"%s\" is not a GIN index",

524

525

526

527

528

529

532 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

533 errmsg("cannot access temporary indexes of other sessions")));

534

535

536 if (!rel->rd_index->indisvalid)

538 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

539 errmsg("index \"%s\" is not valid",

541

542

543

544

549

553

556

557

558

559

561 elog(ERROR, "return type must be a row type");

562

566

567

568

569

572

573 return result;

574}

575

576

577

578

579

580

581

584{

594 bool nulls[8] = {0};

599

601

604 (errcode(ERRCODE_WRONG_OBJECT_TYPE),

605 errmsg("relation \"%s\" is not a hash index",

607

608

609

610

611

612

615 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

616 errmsg("cannot access temporary indexes of other sessions")));

617

618

619 if (!rel->rd_index->indisvalid)

621 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

622 errmsg("index \"%s\" is not valid",

624

625

626 memset(&stats, 0, sizeof(stats));

632

633

635

636

638

639

640 for (blkno = 1; blkno < nblocks; blkno++)

641 {

644

646

648 bstrategy);

651

657 (errcode(ERRCODE_INDEX_CORRUPTED),

658 errmsg("index \"%s\" contains corrupted page at block %u",

661 else

662 {

664 int pagetype;

665

668

670 {

673 }

675 {

678 }

683 else

685 (errcode(ERRCODE_INDEX_CORRUPTED),

686 errmsg("unexpected page type 0x%04X in HASH index \"%s\" block %u",

689 }

691 }

692

693

695

696

698

699

700

701

702

705

706 if (total_space == 0)

707 free_percent = 0.0;

708 else

709 free_percent = 100.0 * stats.free_space / total_space;

710

711

712

713

715 elog(ERROR, "return type must be a row type");

716

718

719

720

721

731

733}

734

735

736

737

738

739

740

741static void

743{

745 int off;

746

747

749 {

751

754 else

756 }

758}

static Datum values[MAXATTR]

BlockNumber BufferGetBlockNumber(Buffer buffer)

void ReleaseBuffer(Buffer buffer)

void UnlockReleaseBuffer(Buffer buffer)

void LockBuffer(Buffer buffer, int mode)

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

Buffer ReadBuffer(Relation reln, BlockNumber blockNum)

#define BUFFER_LOCK_UNLOCK

#define BUFFER_LOCK_SHARE

#define RelationGetNumberOfBlocks(reln)

static Page BufferGetPage(Buffer buffer)

Size PageGetExactFreeSpace(const PageData *page)

PageHeaderData * PageHeader

static uint16 PageGetSpecialSize(const PageData *page)

static bool PageIsNew(const PageData *page)

#define SizeOfPageHeaderData

static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)

static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)

int errcode(int sqlerrcode)

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

#define ereport(elevel,...)

TupleDesc BlessTupleDesc(TupleDesc tupdesc)

HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)

AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)

Datum Int64GetDatum(int64 X)

Datum Float8GetDatum(float8 X)

#define PG_GETARG_TEXT_PP(n)

#define PG_RETURN_INT64(x)

#define PG_RETURN_DATUM(x)

BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)

TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)

static Datum HeapTupleGetDatum(const HeapTupleData *tuple)

#define GIN_METAPAGE_BLKNO

#define GinPageGetMeta(p)

#define HashPageGetOpaque(page)

#define HashPageGetMeta(page)

void _hash_relbuf(Relation rel, Buffer buf)

Buffer _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)

HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)

void index_close(Relation relation, LOCKMODE lockmode)

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

#define ItemIdIsDead(itemId)

char * pstrdup(const char *in)

#define CHECK_FOR_INTERRUPTS()

RangeVar * makeRangeVarFromNameList(const List *names)

#define BTPageGetOpaque(page)

#define P_ISDELETED(opaque)

#define FirstOffsetNumber

int errdetail_relkind_not_supported(char relkind)

Datum pgstatindexbyid(PG_FUNCTION_ARGS)

Datum pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)

Datum pgstatindex_v1_5(PG_FUNCTION_ARGS)

static void GetHashPageStats(Page page, HashIndexStat *stats)

static int64 pg_relpages_impl(Relation rel)

Datum pgstatginindex_v1_5(PG_FUNCTION_ARGS)

Datum pg_relpagesbyid(PG_FUNCTION_ARGS)

Datum pg_relpages(PG_FUNCTION_ARGS)

Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)

Datum pg_relpages_v1_5(PG_FUNCTION_ARGS)

struct HashIndexStat HashIndexStat

static Datum pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)

Datum pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)

PG_FUNCTION_INFO_V1(pgstatindex)

Datum pgstatginindex(PG_FUNCTION_ARGS)

struct GinIndexStat GinIndexStat

Datum pgstathashindex(PG_FUNCTION_ARGS)

struct BTIndexStat BTIndexStat

Datum pgstatindex(PG_FUNCTION_ARGS)

static Datum Int32GetDatum(int32 X)

static Datum UInt32GetDatum(uint32 X)

char * psprintf(const char *fmt,...)

#define RelationGetRelationName(relation)

#define RELATION_IS_OTHER_TEMP(relation)

void relation_close(Relation relation, LOCKMODE lockmode)

Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)

Relation relation_open(Oid relationId, LOCKMODE lockmode)

BlockNumber pending_pages

BlockNumber nPendingPages

BlockNumber overflow_pages

List * textToQualifiedNameList(text *textval)