PostgreSQL Source Code: src/backend/utils/adt/network_gist.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

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

47

49

52#include "utils/fmgrprotos.h"

55

56

57

58

59#define INETSTRAT_OVERLAPS RTOverlapStrategyNumber

60#define INETSTRAT_EQ RTEqualStrategyNumber

61#define INETSTRAT_NE RTNotEqualStrategyNumber

62#define INETSTRAT_LT RTLessStrategyNumber

63#define INETSTRAT_LE RTLessEqualStrategyNumber

64#define INETSTRAT_GT RTGreaterStrategyNumber

65#define INETSTRAT_GE RTGreaterEqualStrategyNumber

66#define INETSTRAT_SUB RTSubStrategyNumber

67#define INETSTRAT_SUBEQ RTSubEqualStrategyNumber

68#define INETSTRAT_SUP RTSuperStrategyNumber

69#define INETSTRAT_SUPEQ RTSuperEqualStrategyNumber

70

71

72

73

74

75

76

77

78

80{

81 uint8 va_header;

82 unsigned char family;

83 unsigned char minbits;

84 unsigned char commonbits;

85 unsigned char ipaddr[16];

87

88#define DatumGetInetKeyP(X) ((GistInetKey *) DatumGetPointer(X))

89#define InetKeyPGetDatum(X) PointerGetDatum(X)

90

91

92

93

94

95

96#define gk_ip_family(gkptr) ((gkptr)->family)

97#define gk_ip_minbits(gkptr) ((gkptr)->minbits)

98#define gk_ip_commonbits(gkptr) ((gkptr)->commonbits)

99#define gk_ip_addr(gkptr) ((gkptr)->ipaddr)

100#define ip_family_maxbits(fam) ((fam) == PGSQL_AF_INET6 ? 128 : 32)

101

102

103#define gk_ip_addrsize(gkptr) \

104 (gk_ip_family(gkptr) == PGSQL_AF_INET6 ? 16 : 4)

105#define gk_ip_maxbits(gkptr) \

106 ip_family_maxbits(gk_ip_family(gkptr))

107#define SET_GK_VARSIZE(dst) \

108 SET_VARSIZE_SHORT(dst, offsetof(GistInetKey, ipaddr) + gk_ip_addrsize(dst))

109

110

111

112

113

116{

120

121

124 int minbits,

125 order;

126

127

128 *recheck = false;

129

130

131

132

133

134

135

137 {

140 }

141

142

143

144

145

146

148 {

149 switch (strategy)

150 {

155 break;

156

161 break;

162

165 }

166

168 }

169

170

171

172

173

174

175

176

177

178 switch (strategy)

179 {

183 break;

184

188 break;

189

194 break;

195

199 break;

200 }

201

202

203

204

205

206

207

208

209

210

211

212

213

215 minbits = Min(minbits, ip_bits(query));

216

218

219 switch (strategy)

220 {

227

230 if (order > 0)

232 if (order < 0 || GIST\_LEAF(ent))

234 break;

235

237 if (order != 0)

241 break;

242

245 if (order < 0)

247 if (order > 0 || GIST\_LEAF(ent))

249 break;

250

252 if (order != 0 || GIST\_LEAF(ent))

254 break;

255 }

256

257

258

259

260

261

262

264

265

266

267

268

269

270 switch (strategy)

271 {

278 break;

279

283 break;

284

291 break;

292

296 break;

297 }

298

299

300

301

302

303

305

306 switch (strategy)

307 {

310

313

316

319

322

325 }

326

327 elog(ERROR, "unknown strategy for inet GiST");

329}

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344static void

346 int m, int n,

347 int *minfamily_p,

348 int *maxfamily_p,

349 int *minbits_p,

350 int *commonbits_p)

351{

352 int minfamily,

353 maxfamily,

354 minbits,

355 commonbits;

356 unsigned char *addr;

358 int i;

359

360

362

363

369

370

371 for (i = m + 1; i <= n; i++)

372 {

374

375

380

381

384

385

388 if (commonbits > 0)

390 }

391

392

393 if (minfamily != maxfamily)

394 minbits = commonbits = 0;

395

396 *minfamily_p = minfamily;

397 *maxfamily_p = maxfamily;

398 *minbits_p = minbits;

399 *commonbits_p = commonbits;

400}

401

402

403

404

405

406static void

409 int *minfamily_p,

410 int *maxfamily_p,

411 int *minbits_p,

412 int *commonbits_p)

413{

414 int minfamily,

415 maxfamily,

416 minbits,

417 commonbits;

418 unsigned char *addr;

420 int i;

421

422

423 Assert(noffsets > 0);

424

425

431

432

433 for (i = 1; i < noffsets; i++)

434 {

436

437

442

443

446

447

450 if (commonbits > 0)

452 }

453

454

455 if (minfamily != maxfamily)

456 minbits = commonbits = 0;

457

458 *minfamily_p = minfamily;

459 *maxfamily_p = maxfamily;

460 *minbits_p = minbits;

461 *commonbits_p = commonbits;

462}

463

464

465

466

467

468

469

470

473 unsigned char *addr)

474{

476

477

479

483

484

485 if (commonbits > 0)

486 memcpy(gk_ip_addr(result), addr, (commonbits + 7) / 8);

487

488

489 if (commonbits % 8 != 0)

490 gk_ip_addr(result)[commonbits / 8] &= ~(0xFF >> (commonbits % 8));

491

492

494

495 return result;

496}

497

498

499

500

501

502

503

506{

509 int minfamily,

510 maxfamily,

511 minbits,

512 commonbits;

513 unsigned char *addr;

515 *result;

516

517

519 &minfamily, &maxfamily,

520 &minbits, &commonbits);

521

522

523 if (minfamily != maxfamily)

524 minfamily = 0;

525

526

529

530

532

534}

535

536

537

538

539

540

543{

546

548 {

551 {

554

556

562

565 entry->offset, false);

566 }

567 else

568 {

571 entry->offset, false);

572 }

573 }

574 else

575 retval = entry;

577}

578

579

580

581

582

583

584

585

586

587

588

591{

596

598

603

606 entry->offset, false);

607

609}

610

611

612

613

614

615

616

617

618

621{

627 int commonbits;

628

630 {

632 {

636 if (commonbits > 0)

637 *penalty = 1.0f / commonbits;

638 else

639 *penalty = 2;

640 }

641 else

642 *penalty = 3;

643 }

644 else

645 *penalty = 4;

646

648}

649

650

651

652

653

654

655

656

657

658

659

660

661

664{

668 int minfamily,

669 maxfamily,

670 minbits,

671 commonbits;

672 unsigned char *addr;

674 *left_union,

675 *right_union;

676 int maxoff,

677 nbytes;

679 *left,

680 *right;

681

682 maxoff = entryvec->n - 1;

683 nbytes = (maxoff + 1) * sizeof(OffsetNumber);

684

687

690

693

694

696 &minfamily, &maxfamily,

697 &minbits, &commonbits);

698

699 if (minfamily != maxfamily)

700 {

701

703 {

704

705

706

707

708

712 else

714 }

715 }

716 else

717 {

718

719

720

721

722

724

725 while (commonbits < maxbits)

726 {

727

728 int bitbyte = commonbits / 8;

729 int bitmask = 0x80 >> (commonbits % 8);

730

732

734 {

737 if ((addr[bitbyte] & bitmask) == 0)

739 else

741 }

742

744 break;

745 commonbits++;

746 }

747

748 if (commonbits >= maxbits)

749 {

750

752

754 {

756 }

758 {

760 }

761 }

762 }

763

764

765

766

767

768

769

771 &minfamily, &maxfamily,

772 &minbits, &commonbits);

773 if (minfamily != maxfamily)

774 minfamily = 0;

779

781 &minfamily, &maxfamily,

782 &minbits, &commonbits);

783 if (minfamily != maxfamily)

784 minfamily = 0;

789

791}

792

793

794

795

798{

802

808

810}

#define PG_GETARG_POINTER(n)

#define PG_GETARG_DATUM(n)

#define PG_GETARG_UINT16(n)

#define PG_RETURN_POINTER(x)

#define PG_RETURN_BOOL(x)

#define gistentryinit(e, k, r, pg, o, l)

Assert(PointerIsAligned(start, uint64))

void * palloc0(Size size)

int bitncommon(const unsigned char *l, const unsigned char *r, int n)

int bitncmp(const unsigned char *l, const unsigned char *r, int n)

#define gk_ip_commonbits(gkptr)

static void calc_inet_union_params(GISTENTRY *ent, int m, int n, int *minfamily_p, int *maxfamily_p, int *minbits_p, int *commonbits_p)

Datum inet_gist_fetch(PG_FUNCTION_ARGS)

#define DatumGetInetKeyP(X)

static void calc_inet_union_params_indexed(GISTENTRY *ent, OffsetNumber *offsets, int noffsets, int *minfamily_p, int *maxfamily_p, int *minbits_p, int *commonbits_p)

#define gk_ip_maxbits(gkptr)

Datum inet_gist_compress(PG_FUNCTION_ARGS)

#define gk_ip_family(gkptr)

#define gk_ip_addr(gkptr)

#define gk_ip_addrsize(gkptr)

struct GistInetKey GistInetKey

static GistInetKey * build_inet_union_key(int family, int minbits, int commonbits, unsigned char *addr)

#define SET_GK_VARSIZE(dst)

Datum inet_gist_consistent(PG_FUNCTION_ARGS)

#define ip_family_maxbits(fam)

Datum inet_gist_union(PG_FUNCTION_ARGS)

Datum inet_gist_picksplit(PG_FUNCTION_ARGS)

Datum inet_gist_penalty(PG_FUNCTION_ARGS)

Datum inet_gist_same(PG_FUNCTION_ARGS)

#define INETSTRAT_OVERLAPS

#define gk_ip_minbits(gkptr)

#define OffsetNumberNext(offsetNumber)

#define FirstOffsetNumber

static Datum PointerGetDatum(const void *X)

static Pointer DatumGetPointer(Datum X)

GISTENTRY vector[FLEXIBLE_ARRAY_MEMBER]

static Datum InetPGetDatum(const inet *X)

static inet * DatumGetInetPP(Datum X)

#define SET_INET_VARSIZE(dst)

#define PG_GETARG_INET_PP(n)

#define ip_family(inetptr)

#define ip_addrsize(inetptr)