PostgreSQL Source Code: contrib/ltree/ltree_gist.c Source File (original) (raw)

1

2

3

4

5

7

14

15#define NEXTVAL(x) ( (lquery*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )

16#define ISEQ(a,b) ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 )

17

20

23{

25 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

26 errmsg("cannot accept a value of type %s", "ltree_gist")));

27

29}

30

33{

35 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

36 errmsg("cannot display a value of type %s", "ltree_gist")));

37

39}

40

44{

46 (left ? VARSIZE(left) + (right ? VARSIZE(right) : 0) : 0);

48

50

51 if (siglen)

52 {

53 result->flag = 0;

54

55 if (isalltrue)

57 else if (sign)

59 else

60 memset(LTG_SIGN(result), 0, siglen);

61

62 if (left)

63 {

65

66 if (!right || left == right || ISEQ(left, right))

68 else

70 }

71 }

72 else

73 {

77 }

78

79 return result;

80}

81

90

91#define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer((vec)->vector[(pos)].key))

92

95{

98

100 {

103

107 entry->offset, false);

108 }

110}

111

114{

117

119 {

121

124 entry->offset, false);

126 }

128}

129

132{

137

138 *result = false;

141

144 else

145 {

149

152

157

158 *result = true;

160 {

162 {

163 if (sa[i] != sb[i])

164 {

165 *result = false;

166 break;

167 }

168 }

169 }

170 }

171

173}

174

175static void

177{

181

182 while (tlen > 0)

183 {

187 tlen--;

188 }

189}

190

193{

199 j;

202 ltree *left = NULL,

203 *right = NULL,

204 *curtree;

205 bool isalltrue = false;

206

207 for (j = 0; j < entryvec->n; j++)

208 {

211 {

213 hashing(base, curtree, siglen);

215 left = curtree;

217 right = curtree;

218 }

219 else

220 {

222 isalltrue = true;

223 else

224 {

226

228 ((unsigned char *) base)[i] |= sc[i];

229 }

230

233 left = curtree;

236 right = curtree;

237 }

238 }

239

240 if (isalltrue == false)

241 {

242 isalltrue = true;

244 {

245 if (((unsigned char *) base)[i] != 0xff)

246 {

247 isalltrue = false;

248 break;

249 }

250 }

251 }

252

253 result = ltree_gist_alloc(isalltrue, base, siglen, left, right);

254

256

258}

259

262{

268 cmpl;

269

272

273 *penalty = Max(cmpl, 0) + Max(cmpr, 0);

274

276}

277

278

280{

284

285static int

287{

289 ((const RIX *) b)->r);

290}

291

292

295{

301 RIX *array;

303 int nbytes;

305 *lu_r,

306 *ru_l,

307 *ru_r;

309 *ru;

312 bool lisat = false,

313 risat = false;

314

315 maxoff = entryvec->n - 1;

316 nbytes = (maxoff + 2) * sizeof(OffsetNumber);

321 array = (RIX *) palloc(sizeof(RIX) * (maxoff + 1));

322

323

325 {

327 lu = GETENTRY(entryvec, j);

329 }

330

333

334 lu_l = lu_r = ru_l = ru_r = NULL;

336 {

337 lu = GETENTRY(entryvec, array[j].index);

339 {

346 else

347 {

349 lisat = true;

350 else

351 {

353

355 ((unsigned char *) ls)[i] |= sc[i];

356 }

357 }

358 }

359 else

360 {

367 else

368 {

370 risat = true;

371 else

372 {

374

376 ((unsigned char *) rs)[i] |= sc[i];

377 }

378 }

379 }

380 }

381

382 if (lisat == false)

383 {

384 lisat = true;

386 {

387 if (((unsigned char *) ls)[i] != 0xff)

388 {

389 lisat = false;

390 break;

391 }

392 }

393 }

394

395 if (risat == false)

396 {

397 risat = true;

399 {

400 if (((unsigned char *) rs)[i] != 0xff)

401 {

402 risat = false;

403 break;

404 }

405 }

406 }

407

410

413

416

419

421}

422

423static bool

425{

427 int i;

428

430 {

434 {

436 return true;

437 }

438 }

439

441 return false;

442}

443

446{

448

449 memcpy(dst, src, VARSIZE(src));

450 return dst;

451}

452

453static bool

455{

458 bool res = true;

459

462

464 res = false;

465

468

470 res = false;

471

474

475 return res;

476}

477

478static bool

480{

484

486 return true;

487

488 while (qlen > 0)

489 {

491 {

492 bool isexist = false;

493 int vlen = curq->numvar;

495

496 while (vlen > 0)

497 {

499 {

500 isexist = true;

501 break;

502 }

504 vlen--;

505 }

506 if (!isexist)

507 return false;

508 }

509

511 qlen--;

512 }

513

514 return true;

515}

516

517static int

519{

525 int res = 0;

526

527 while (an > 0 && bn > 0)

528 {

530 if ((res = memcmp(al->name, bl->name, Min(al->len, bl->len))) == 0)

531 {

532 if (al->len != bl->len)

533 return al->len - bl->len;

534 }

535 else

536 return res;

537 an--;

538 bn--;

541 }

542

544}

545

546static bool

548{

550 return true;

551

553 return false;

554

556 return false;

557

558 return true;

559}

560

562{

566

567static bool

569{

571

573}

574

575static bool

577{

579

581 return true;

582

584 sig.siglen = siglen;

585

587 &sig, false,

589}

590

591static bool

593{

596

599 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),

600 errmsg("array must be one-dimensional")));

603 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),

604 errmsg("array must not contain nulls")));

605

606 while (num > 0)

607 {

609 return true;

610 num--;

612 }

613 return false;

614}

615

618{

621

622

626 void *query = NULL;

627 bool res = false;

628

629

630 *recheck = false;

631

632 switch (strategy)

633 {

638 :

640 break;

644 break;

649 else

651 &&

653 break;

657 break;

662 :

664 break;

665 case 10:

669 :

671 break;

672 case 11:

676 :

678 break;

679 case 12:

680 case 13:

686 ));

687 else

690 break;

691 case 14:

692 case 15:

698 ));

699 else

701 break;

702 case 16:

703 case 17:

709 ));

710 else

712 break;

713 default:

714

715 elog(ERROR, "unrecognized StrategyNumber: %d", strategy);

716 }

717

720}

721

722static void

724 int nvals)

725{

727

730 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

731 errmsg("siglen value must be a multiple of %d", ALIGNOF_INT)));

732}

733

736{

738

741 "signature length in bytes",

747

749}

#define PG_GETARG_ARRAYTYPE_P(n)

bool array_contains_nulls(ArrayType *array)

int ArrayGetNItems(int ndim, const int *dims)

unsigned int ltree_crc32_sz(const char *buf, int size)

int errcode(int sqlerrcode)

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

#define ereport(elevel,...)

#define PG_FREE_IF_COPY(ptr, n)

#define DirectFunctionCall2(func, arg1, arg2)

#define PG_GETARG_POINTER(n)

#define PG_GETARG_UINT16(n)

#define PG_DETOAST_DATUM(datum)

#define PG_RETURN_POINTER(x)

#define PG_RETURN_BOOL(x)

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

Assert(PointerIsAligned(start, uint64))

#define HASHVAL(val, siglen)

#define HASH(sign, val, siglen)

Datum lt_q_regex(PG_FUNCTION_ARGS)

Datum ltq_regex(PG_FUNCTION_ARGS)

bool inner_isparent(const ltree *c, const ltree *p)

#define DatumGetLtreeP(X)

#define FLG_CANLOOKSIGN(x)

#define PG_GETARG_LTXTQUERY_P(n)

PGDLLEXPORT Datum ltxtq_exec(PG_FUNCTION_ARGS)

#define LTG_RNODE(x, siglen)

#define PG_GETARG_LQUERY_P(n)

#define LTG_GETRNODE(x, siglen)

int ltree_compare(const ltree *a, const ltree *b)

#define LTREE_GET_SIGLEN()

bool ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool(*chkcond)(void *checkval, ITEM *val))

#define PG_GETARG_LTREE_P_COPY(n)

#define LQL_CANLOOKSIGN(x)

#define LTREE_SIGLEN_DEFAULT

#define LTG_LNODE(x, siglen)

#define PG_GETARG_LTREE_P(n)

#define LTG_GETLNODE(x, siglen)

Datum ltree_same(PG_FUNCTION_ARGS)

Datum ltree_picksplit(PG_FUNCTION_ARGS)

static bool gist_qe(ltree_gist *key, lquery *query, int siglen)

Datum ltree_union(PG_FUNCTION_ARGS)

Datum ltree_gist_options(PG_FUNCTION_ARGS)

Datum ltree_compress(PG_FUNCTION_ARGS)

static void hashing(BITVECP sign, ltree *t, int siglen)

static bool gist_ischild(ltree_gist *key, ltree *query, int siglen)

static int gist_tqcmp(ltree *t, lquery *q)

static void ltree_gist_relopts_validator(void *parsed_options, relopt_value *vals, int nvals)

#define GETENTRY(vec, pos)

Datum ltree_penalty(PG_FUNCTION_ARGS)

static bool gist_qtxt(ltree_gist *key, ltxtquery *query, int siglen)

Datum ltree_gist_in(PG_FUNCTION_ARGS)

Datum ltree_gist_out(PG_FUNCTION_ARGS)

static bool gist_between(ltree_gist *key, lquery *query, int siglen)

struct LtreeSignature LtreeSignature

static bool arrq_cons(ltree_gist *key, ArrayType *_query, int siglen)

PG_FUNCTION_INFO_V1(ltree_gist_in)

static bool gist_isparent(ltree_gist *key, ltree *query, int siglen)

Datum ltree_decompress(PG_FUNCTION_ARGS)

static int treekey_cmp(const void *a, const void *b)

static bool checkcondition_bit(void *cxt, ITEM *val)

Datum ltree_consistent(PG_FUNCTION_ARGS)

static ltree * copy_ltree(ltree *src)

ltree_gist * ltree_gist_alloc(bool isalltrue, BITVECP sign, int siglen, ltree *left, ltree *right)

void pfree(void *pointer)

void * palloc0(Size size)

#define OffsetNumberNext(offsetNumber)

#define FirstOffsetNumber

#define qsort(a, b, c, d)

static bool DatumGetBool(Datum X)

static Datum PointerGetDatum(const void *X)

static Pointer DatumGetPointer(Datum X)

static unsigned hash(unsigned *uv, int n)

void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)

void register_reloptions_validator(local_relopts *relopts, relopts_validator validator)

void add_local_int_reloption(local_relopts *relopts, const char *name, const char *desc, int default_val, int min_val, int max_val, int offset)

#define BTGreaterStrategyNumber

#define BTLessStrategyNumber

#define BTEqualStrategyNumber

#define BTLessEqualStrategyNumber

#define BTGreaterEqualStrategyNumber

char name[FLEXIBLE_ARRAY_MEMBER]

char name[FLEXIBLE_ARRAY_MEMBER]

#define SET_VARSIZE(PTR, len)