PostgreSQL Source Code: src/backend/access/gist/gistbuildbuffers.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

16

21

35

38

39

40

41

42

45{

48

52

53

54

55

56

59

60

64

65

66

67

68

70

71

72

73

74

79 1024,

80 &hashCtl,

82

84

85

86

87

88

93

94

95

96

97

102

104

105 return gfbb;

106}

107

108

109

110

111

115{

117 bool found;

118

119

121 &nodeBlocknum,

123 &found);

124 if (!found)

125 {

126

127

128

130

131

136 nodeBuffer->isTemp = false;

137 nodeBuffer->level = level;

138

139

140

141

142

144 {

145 int i;

146

149 (level + 1) * sizeof(List *));

150

151

155 }

156

157

158

159

160

161

162

163

164

165

166

167

170

172 }

173

174 return nodeBuffer;

175}

176

177

178

179

182{

184

186 BLCKSZ);

188

189

191 return pageBuffer;

192}

193

194

195

196

197static void

199{

200

201 if (nodeBuffer->isTemp)

202 return;

203

204

206 {

211 }

212

215}

216

217

218

219

220static void

222{

223

225 {

226

228

229

232

233

235

236

239 }

240}

241

242

243

244

245static void

247{

248

250 {

252

253

255

256

258

259

262

263

265 }

266}

267

268

269

270

271void

273{

274 int i;

275

276

279

280

282}

283

284

285

286

287static void

289{

291 char *ptr;

292

293

295

296

298

299

302

303

304 memcpy(ptr, itup, itupsz);

305}

306

307

308

309

310static void

312{

315

317

318

319 ptr = (IndexTuple) ((char *) pageBuffer

323

324

326 memcpy(*itup, ptr, itupsz);

327

328

330}

331

332

333

334

335void

338{

339

340

341

342

344

345

346

347

349 {

353 }

354

355

358

359

360

361

363 {

364

365

366

368

369

372

373

374

375

376

380

381

383 }

384

386

387

388

389

391 {

395 }

396

397

399}

400

401

402

403

404

405bool

408{

409

410

411

413 return false;

414

415

418

419

420

421

423

424

425

426

427

429 {

431

432

433

434

436

437

438

439

442 {

443

446

447

448

449

450

452 }

453 else

454 {

455

459 }

460 }

461 return true;

462}

463

464

465

466

467static long

469{

470

471

472

473

474

477 else

479}

480

481

482

483

484static void

486{

487 int ndx;

488

489

491 {

495 sizeof(long));

496 }

497

498

501}

502

503

504

505

506void

508{

509

511

512

513}

514

515

516

517

518

519typedef struct

520{

526

527

528

529

530

531

532void

536{

538 bool found;

542 int splitPagesCount = 0;

547

548

550 return;

551

552

553

554

558 if (!found)

559 {

560

561 return;

562 }

563

564

565

566

567

568

569

570

571

574 oldBuf.isTemp = true;

575

576

580

581

582

583

584 splitPagesCount = list_length(splitinfo);

585 relocationBuffersInfos =

587 splitPagesCount);

588

589

590

591

592

593 foreach(lc, splitinfo)

594 {

598

599

602 relocationBuffersInfos[i].entry,

603 relocationBuffersInfos[i].isnull);

604

605

606

607

608

609

610

611

613

614 relocationBuffersInfos[i].nodeBuffer = newNodeBuffer;

615 relocationBuffersInfos[i].splitinfo = si;

616 }

617

618

619

620

621

622

623

624

625

626

628 {

630 int i,

631 which;

634

636 itup, NULL, (OffsetNumber) 0, entry, isnull);

637

638

639 which = 0;

640

641

642

643

644

645

646 best_penalty[0] = -1;

647

648

649

650

651

652 for (i = 0; i < splitPagesCount; i++)

653 {

655 bool zero_penalty;

656 int j;

657

658 zero_penalty = true;

659

660

662 {

663 float usize;

664

665

667 &splitPageInfo->entry[j],

668 splitPageInfo->isnull[j],

669 &entry[j], isnull[j]);

670 if (usize > 0)

671 zero_penalty = false;

672

673 if (best_penalty[j] < 0 || usize < best_penalty[j])

674 {

675

676

677

678

679

680

681

682

683

684 which = i;

685 best_penalty[j] = usize;

686

688 best_penalty[j + 1] = -1;

689 }

690 else if (best_penalty[j] == usize)

691 {

692

693

694

695

696

697 }

698 else

699 {

700

701

702

703

704

705 zero_penalty = false;

706 break;

707 }

708 }

709

710

711

712

713

714

715 if (zero_penalty)

716 break;

717 }

718

719

720 targetBufferInfo = &relocationBuffersInfos[which];

721

722

724

725

727 itup, giststate);

728 if (newtup)

729 {

732 targetBufferInfo->entry,

733 targetBufferInfo->isnull);

734

736 }

737 }

738

739 pfree(relocationBuffersInfos);

740}

741

742

743

744

745

746

747

748

749static void

751{

753 elog(ERROR, "could not seek to block %ld in temporary file", blknum);

755}

756

757static void

759{

761 elog(ERROR, "could not seek to block %ld in temporary file", blknum);

763}

#define InvalidBlockNumber

int BufFileSeekBlock(BufFile *file, int64 blknum)

void BufFileReadExact(BufFile *file, void *ptr, size_t size)

BufFile * BufFileCreateTemp(bool interXact)

void BufFileWrite(BufFile *file, const void *ptr, size_t size)

void BufFileClose(BufFile *file)

BlockNumber BufferGetBlockNumber(Buffer buffer)

void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)

HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)

#define PAGE_IS_EMPTY(nbp)

#define BUFFER_HALF_FILLED(nodeBuffer, gfbb)

#define PAGE_FREE_SPACE(nbp)

#define LEVEL_HAS_BUFFERS(nlevel, gfbb)

#define BUFFER_PAGE_DATA_OFFSET

#define PAGE_NO_SPACE(nbp, itup)

void gistPushItupToNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple itup)

void gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, GISTSTATE *giststate, Relation r, int level, Buffer buffer, List *splitinfo)

GISTBuildBuffers * gistInitBuildBuffers(int pagesPerBuffer, int levelStep, int maxLevel)

static void gistBuffersReleaseBlock(GISTBuildBuffers *gfbb, long blocknum)

static void gistLoadNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer)

static void WriteTempFileBlock(BufFile *file, long blknum, const void *ptr)

static void gistAddLoadedBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer)

void gistFreeBuildBuffers(GISTBuildBuffers *gfbb)

static void gistPlaceItupToPage(GISTNodeBufferPage *pageBuffer, IndexTuple itup)

static GISTNodeBufferPage * gistAllocateNewPageBuffer(GISTBuildBuffers *gfbb)

static long gistBuffersGetFreeBlock(GISTBuildBuffers *gfbb)

static void gistUnloadNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer)

bool gistPopItupFromNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple *itup)

static void ReadTempFileBlock(BufFile *file, long blknum, void *ptr)

GISTNodeBuffer * gistGetNodeBuffer(GISTBuildBuffers *gfbb, GISTSTATE *giststate, BlockNumber nodeBlocknum, int level)

static void gistGetItupFromPage(GISTNodeBufferPage *pageBuffer, IndexTuple *itup)

void gistUnloadNodeBuffers(GISTBuildBuffers *gfbb)

void gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, OffsetNumber o, GISTENTRY *attdata, bool *isnull)

IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)

float gistpenalty(GISTSTATE *giststate, int attno, GISTENTRY *orig, bool isNullOrig, GISTENTRY *add, bool isNullAdd)

Assert(PointerIsAligned(start, uint64))

IndexTupleData * IndexTuple

static Size IndexTupleSize(const IndexTupleData *itup)

List * lcons(void *datum, List *list)

void * MemoryContextAllocZero(MemoryContext context, Size size)

void * repalloc(void *pointer, Size size)

void pfree(void *pointer)

MemoryContext CurrentMemoryContext

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

static int list_length(const List *l)

#define foreach_current_index(var_or_cell)

#define IndexRelationGetNumberOfKeyAttributes(relation)

GISTNodeBuffer ** loadedBuffers

List * bufferEmptyingQueue

GISTNodeBufferPage * pageBuffer

bool isnull[INDEX_MAX_KEYS]

GISTPageSplitInfo * splitinfo

GISTNodeBuffer * nodeBuffer

GISTENTRY entry[INDEX_MAX_KEYS]