PostgreSQL Source Code: contrib/pg_trgm/trgm_gist.c Source File (original) (raw)
1
2
3
5
12
13
19
20#define GET_SIGLEN() (PG_HAS_OPCLASS_OPTIONS() ? \
21 ((TrgmGistOptions *) PG_GET_OPCLASS_OPTIONS())->siglen : \
22 SIGLEN_DEFAULT)
23
24typedef struct
25{
26
29
31
33
34
35
36
37
39
40#define GETENTRY(vec,pos) ((TRGM *) DatumGetPointer((vec)->vector[(pos)].key))
41
42
54
55
58{
61 errmsg("cannot accept a value of type %s", "gtrgm")));
62
64}
65
68{
71 errmsg("cannot display a value of type %s", "gtrgm")));
72
74}
75
78{
82
85
87 {
90 else
92 }
93
94 return res;
95}
96
97static void
99{
104
107 for (k = 0; k < len; k++)
108 {
109 CPTRGM(&tmp, ptr + k);
111 }
112}
113
116{
120
122 {
125
130 entry->offset, false);
131 }
134 {
138
140 {
141 if ((sign[i] & 0xff) != 0xff)
143 }
144
149 entry->offset, false);
150 }
152}
153
156{
160
162
164 {
165
170 }
171 else
172 {
173
175 }
176}
177
180{
186
187 for (k = 0; k < len; k++)
188 {
189 CPTRGM(&tmp, ptr + k);
191 }
192
193 return count;
194}
195
198{
202#ifdef NOT_USED
204#endif
209 bool res;
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
229 if (cache == NULL ||
230 cache->strategy != strategy ||
233 {
237
238 switch (strategy)
239 {
246 break;
248#ifndef IGNORECASE
249 elog(ERROR, "cannot handle ~~* with case-sensitive trigrams");
250#endif
255 break;
257#ifndef IGNORECASE
258 elog(ERROR, "cannot handle ~* with case-sensitive trigrams");
259#endif
263 &graph, fcinfo->flinfo->fn_mcxt);
264
266 {
269 }
270 break;
271 default:
272 elog(ERROR, "unrecognized strategy number: %d", strategy);
274 break;
275 }
276
278
284
285 newcache->strategy = strategy;
290 {
294
296 }
297 else
300
301 if (cache)
303 fcinfo->flinfo->fn_extra = newcache;
305 }
306
308
309 switch (strategy)
310 {
314
315
316
317
318
320
322
324 {
326
328 }
330 {
331 res = true;
332 }
333 else
334 {
337
338 if (len == 0)
339 res = false;
340 else
342 }
343 break;
345#ifndef IGNORECASE
346 elog(ERROR, "cannot handle ~~* with case-sensitive trigrams");
347#endif
351
352 *recheck = true;
353
354
355
356
357
359 {
361 }
363 {
364 res = true;
365 }
366 else
367 {
369 tmp = 0,
373
374 res = true;
375 for (k = 0; k < len; k++)
376 {
377 CPTRGM(&tmp, ptr + k);
379 {
380 res = false;
381 break;
382 }
383 }
384 }
385 break;
387#ifndef IGNORECASE
388 elog(ERROR, "cannot handle ~* with case-sensitive trigrams");
389#endif
392
393 *recheck = true;
394
395
397 {
399 {
400 bool *check;
401
405 }
407 {
408 res = true;
409 }
410 else
411 {
413 tmp = 0,
417 bool *check;
418
419
420
421
422
423
424
425
426
427 check = (bool *) palloc(len * sizeof(bool));
428 for (k = 0; k < len; k++)
429 {
430 CPTRGM(&tmp, ptr + k);
432 }
435 }
436 }
437 else
438 {
439
440 res = true;
441 }
442 break;
443 default:
444 elog(ERROR, "unrecognized strategy number: %d", strategy);
445 res = false;
446 break;
447 }
448
450}
451
454{
458#ifdef NOT_USED
460#endif
467 char *cache = (char *) fcinfo->flinfo->fn_extra;
468
469
470
471
472 if (cache == NULL ||
475 {
477
479
483
486
487 if (cache)
489 fcinfo->flinfo->fn_extra = newcache;
491 }
492
494
495 switch (strategy)
496 {
500
503 {
504
505
506
507
508
509
511
512 res = 1.0 - sml;
513 }
515 {
516 res = 0.0;
517 }
518 else
519 {
522
524 }
525 break;
526 default:
527 elog(ERROR, "unrecognized strategy number: %d", strategy);
528 res = 0;
529 break;
530 }
531
533}
534
537{
539
541 {
543
545 return 1;
546
549 }
550 else
551 {
554
556 {
559 }
560 }
561 return 0;
562}
563
564
567{
575
577 {
579 {
582 break;
583 }
584 }
585
587
589}
590
593{
598
600 {
602 *result = true;
604 *result = false;
606 *result = false;
607 else
608 {
612
613 *result = true;
615 {
617 {
618 *result = false;
619 break;
620 }
621 }
622 }
623 }
624 else
625 {
628
630 *result = false;
631 else
632 {
636
637 *result = true;
638 for (i = 0; i < lena; i++)
640 {
641 *result = false;
642 break;
643 }
644 }
645 }
646
648}
649
655
656static int
658{
659 int i,
662
664 {
666
668 }
670}
671
672static int
674{
676 {
678 return 0;
679 else
681 }
684
686}
687
690{
698
699 *penalty = 0.0;
700
702 {
703 char *cache = (char *) fcinfo->flinfo->fn_extra;
707
708 if (cache != NULL)
710
711
712
713
714 if (cache == NULL ||
717 {
719
723
725
728
729 if (cache)
731 fcinfo->flinfo->fn_extra = newcache;
733 }
734
736
739 else
741 }
742 else
745}
746
752
753static void
765
766#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
767typedef struct
768{
772
773static int
775{
777 return 0;
778 else
779 return (((const SPLITCOST *) a)->cost > ((const SPLITCOST *) b)->cost) ? 1 : -1;
780}
781
782
783static int
785{
786 if (a->allistrue)
787 {
788 if (b->allistrue)
789 return 0;
790 else
792 }
793 else if (b->allistrue)
795
797}
798
801{
807 j;
815 waste = -1;
820 *right;
822 int i;
826
827
830
833 siglen);
834
835
837 {
839 {
842 {
846 }
847 }
848 }
849
850
852 {
855 }
856
857
863
864
867
870
871
874 {
879 }
881
882 for (k = 0; k < maxoff; k++)
883 {
886 {
887 *left++ = j;
889 continue;
890 }
892 {
893 *right++ = j;
895 continue;
896 }
897
899 {
902 else
906 siglen);
907 }
908 else
910
912 {
915 else
919 siglen);
920 }
921 else
923
925 {
927 {
930 }
931 else
932 {
936 }
937 *left++ = j;
939 }
940 else
941 {
943 {
946 }
947 else
948 {
952 }
953 *right++ = j;
955 }
956 }
957
960
962}
963
966{
968
971 "signature length in bytes",
974
976}
#define MemSet(start, val, len)
int errcode(int sqlerrcode)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define PG_RETURN_FLOAT8(x)
#define DatumGetTextPP(X)
#define PG_GETARG_POINTER(n)
#define PG_FUNCTION_INFO_V1(funcname)
#define PG_GETARG_UINT16(n)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
#define PG_GETARG_TEXT_P(n)
#define gistentryinit(e, k, r, pg, o, l)
#define HASHVAL(val, siglen)
#define CALCGTSIZE(flag, siglen)
#define SIGLENBIT(siglen)
#define HASH(sign, val, siglen)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
PGDLLIMPORT const uint8 pg_number_of_ones[256]
static uint64 pg_popcount(const char *buf, int bytes)
#define qsort(a, b, c, d)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)
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 RegExpICaseStrategyNumber
#define WordSimilarityStrategyNumber
TRGM * generate_trgm(char *str, int slen)
#define DistanceStrategyNumber
#define StrictWordSimilarityStrategyNumber
#define StrictWordDistanceStrategyNumber
int(* CMPTRGM)(const void *a, const void *b)
bool * trgm_presence_map(TRGM *query, TRGM *key)
double index_strategy_get_limit(StrategyNumber strategy)
TRGM * createTrgmNFA(text *text_re, Oid collation, TrgmPackedGraph **graph, MemoryContext rcontext)
#define SimilarityStrategyNumber
bool trigramsMatchGraph(TrgmPackedGraph *graph, bool *check)
bool trgm_contained_by(TRGM *trg1, TRGM *trg2)
#define ILikeStrategyNumber
TRGM * generate_wildcard_trgm(const char *str, int slen)
float4 cnt_sml(TRGM *trg1, TRGM *trg2, bool inexact)
#define LikeStrategyNumber
#define EqualStrategyNumber
#define RegExpStrategyNumber
#define WordDistanceStrategyNumber
Datum gtrgm_out(PG_FUNCTION_ARGS)
static int hemdistcache(CACHESIGN *a, CACHESIGN *b, int siglen)
static void fillcache(CACHESIGN *item, TRGM *key, BITVECP sign, int siglen)
Datum gtrgm_same(PG_FUNCTION_ARGS)
static int32 unionkey(BITVECP sbase, TRGM *add, int siglen)
Datum gtrgm_distance(PG_FUNCTION_ARGS)
static int32 sizebitvec(BITVECP sign, int siglen)
Datum gtrgm_in(PG_FUNCTION_ARGS)
Datum gtrgm_options(PG_FUNCTION_ARGS)
static int hemdistsign(BITVECP a, BITVECP b, int siglen)
#define GETENTRY(vec, pos)
Datum gtrgm_compress(PG_FUNCTION_ARGS)
Datum gtrgm_picksplit(PG_FUNCTION_ARGS)
Datum gtrgm_decompress(PG_FUNCTION_ARGS)
static TRGM * gtrgm_alloc(bool isalltrue, int siglen, BITVECP sign)
Datum gtrgm_union(PG_FUNCTION_ARGS)
Datum gtrgm_penalty(PG_FUNCTION_ARGS)
static void makesign(BITVECP sign, TRGM *a, int siglen)
Datum gtrgm_consistent(PG_FUNCTION_ARGS)
static int32 cnt_sml_sign_common(TRGM *qtrg, BITVECP sign, int siglen)
static int hemdist(TRGM *a, TRGM *b, int siglen)
static int comparecost(const void *a, const void *b)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static Size VARSIZE(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)