56#define STATENTRYHDRSZ (offsetof(StatEntry, lexeme))
92 else if (
a->size <
b->size)
94 else if (
a->size >
b->size)
104 for (
i = 0;
i <
a->size;
i++)
108 return (
aptr->haspos >
bptr->haspos) ? -1 : 1;
114 else if (
aptr->haspos)
145#define TSVECTORCMPFUNC( type, action, ret ) \
147tsvector_##type(PG_FUNCTION_ARGS) \
149 TSVector a = PG_GETARG_TSVECTOR(0); \
150 TSVector b = PG_GETARG_TSVECTOR(1); \
151 int res = silly_cmp_tsvector(a, b); \
152 PG_FREE_IF_COPY(a,0); \
153 PG_FREE_IF_COPY(b,1); \
154 PG_RETURN_##ret( res action 0 ); \
157extern int no_such_variable
354#define compareEntry(pa, a, pb, b) \
355 tsCompareString((pa) + (a)->pos, (a)->len, \
356 (pb) + (b)->pos, (b)->len, \
435 int a = *((
const int *)
va);
436 int b = *((
const int *)
vb);
504 for (
i =
j = k = 0;
i <
tsv->size;
i++)
653 elog(
ERROR,
"return type must be a row type");
671 bool nulls[] = {
false,
false,
false};
691 for (
j = 0;
j <
posv->npos;
j++)
704 nulls[1] = nulls[2] =
true;
730 for (
i = 0;
i <
tsin->size;
i++)
771 errmsg(
"lexeme array may not contain nulls")));
776 errmsg(
"lexeme array may not contain empty strings")));
845 errmsg(
"weight array may not contain nulls")));
878 for (
i =
j = 0;
i <
tsin->size;
i++)
892 for (k = 0; k <
posvin->npos; k++)
1216 data->allocated =
true;
1239 data->allocated =
false;
1242 else if (
val->weight)
1262 data->allocated =
false;
1347 if (
data->allocated)
1350 data->allocated =
false;
1407 if (
data->allocated)
1410 data->allocated =
false;
1425 if (
data && npos > 0)
1432 data->allocated =
true;
1463#define TSPO_L_ONLY 0x01
1464#define TSPO_R_ONLY 0x02
1465#define TSPO_BOTH 0x04
1543 data->allocated =
true;
1642 data->negate =
true;
1650 data->negate =
true;
1659 else if (
data->negate)
1662 data->negate =
false;
1729 data->negate =
true;
1732 else if (
Ldata.negate)
1740 else if (
Rdata.negate)
1804 data->negate =
true;
1807 else if (
Ldata.negate)
1814 data->negate =
true;
1817 else if (
Rdata.negate)
1824 data->negate =
true;
2310#define compareStatWord(a,e,t) \
2311 tsCompareString((a)->lexeme, (a)->lenlexeme, \
2312 STRPTR(t) + (e)->pos, (e)->len, \
2325 if (
stat->weight == 0)
2344 node = (res < 0) ? node->
left : node->
right;
2349 if (depth >
stat->maxdepth)
2350 stat->maxdepth = depth;
2387 pos = (low +
middle) >> 1;
2390 pos = (high +
middle + 1) >> 1;
2435 for (;
i > 0;
i >>= 1)
2439 offset = (
nbit -
txt->size) / 2;
2469 stat->stack[
stat->stackpos] = node;
2481 elog(
ERROR,
"return type must be a row type");
2482 funcctx->tuple_desc = tupdesc;
2496 if (node->
ndoc != 0)
2510 stat->stack[
stat->stackpos] = node;
2524 if (
stat->stackpos == 0)
2585 elog(
ERROR,
"SPI_prepare(\"%s\") failed", query);
2589 elog(
ERROR,
"SPI_cursor_open(\"%s\") failed", query);
2599 errmsg(
"ts_stat query must return one tsvector column")));
2617 stat->weight |= 1 << 3;
2621 stat->weight |= 1 << 2;
2625 stat->weight |= 1 << 1;
2756 elog(
ERROR,
"tsvector_update_trigger: not fired by trigger manager");
2760 elog(
ERROR,
"tsvector_update_trigger: must be fired for row");
2762 elog(
ERROR,
"tsvector_update_trigger: must be fired BEFORE event");
2775 elog(
ERROR,
"tsvector_update_trigger: must be fired for INSERT or UPDATE");
2781 elog(
ERROR,
"tsvector_update_trigger: arguments must be tsvector_field, ts_config, text_field1, ...)");
2788 errmsg(
"tsvector column \"%s\" does not exist",
2795 errmsg(
"column \"%s\" is not of tsvector type",
2807 errmsg(
"configuration column \"%s\" does not exist",
2813 errmsg(
"column \"%s\" is not of regconfig type",
2820 errmsg(
"configuration column \"%s\" must not be null",
2833 errmsg(
"text search configuration name \"%s\" must be schema-qualified",
2853 errmsg(
"column \"%s\" does not exist",
2858 errmsg(
"column \"%s\" is not of a character type",
#define PG_GETARG_ARRAYTYPE_P(n)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
bool bms_is_member(int x, const Bitmapset *a)
static Datum values[MAXATTR]
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
#define repalloc_array(pointer, type, count)
#define palloc_array(type, count)
#define palloc0_array(type, count)
#define palloc0_object(type)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_TEXT_PP(n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_CHAR(n)
#define DatumGetTextPP(X)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_INT32(x)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define SRF_RETURN_DONE(_funcctx)
Datum difference(PG_FUNCTION_ARGS)
HeapTuple heap_modify_tuple_by_cols(HeapTuple tuple, TupleDesc tupleDesc, int nCols, const int *replCols, const Datum *replValues, const bool *replIsnull)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
#define CALCDATASIZE(x, lenstr)
static int pg_cmp_s32(int32 a, int32 b)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
int pg_mblen(const char *mbstr)
void * MemoryContextAlloc(MemoryContext context, Size size)
void * MemoryContextAllocZero(MemoryContext context, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
#define CHECK_FOR_INTERRUPTS()
Oid get_ts_config_oid(List *names, bool missing_ok)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
static int list_length(const List *l)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define qsort(a, b, c, d)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Oid DatumGetObjectId(Datum X)
static Datum Int16GetDatum(int16 X)
static Pointer DatumGetPointer(Datum X)
static char DatumGetChar(Datum X)
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
static int cmp(const chr *x, const chr *y, size_t len)
List * stringToQualifiedNameList(const char *string, Node *escontext)
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
int SPI_freeplan(SPIPlanPtr plan)
SPITupleTable * SPI_tuptable
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, const Datum *Values, const char *Nulls, bool read_only)
void SPI_cursor_fetch(Portal portal, bool forward, long count)
void SPI_freetuptable(SPITupleTable *tuptable)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
void SPI_cursor_close(Portal portal)
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
#define SPI_ERROR_NOATTRIBUTE
void check_stack_depth(void)
char lexeme[FLEXIBLE_ARRAY_MEMBER]
const Bitmapset * tg_updatedcols
WordEntryPos pos[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
Datum to_tsvector(PG_FUNCTION_ARGS)
TSVector make_tsvector(ParsedText *prs)
Datum plainto_tsquery(PG_FUNCTION_ARGS)
#define TRIGGER_FIRED_BEFORE(event)
#define CALLED_AS_TRIGGER(fcinfo)
#define TRIGGER_FIRED_FOR_ROW(event)
#define TRIGGER_FIRED_BY_INSERT(event)
#define TRIGGER_FIRED_BY_UPDATE(event)
void parsetext(Oid cfgId, ParsedText *prs, char *buf, int buflen)
#define PG_GETARG_TSVECTOR(n)
static TSQuery DatumGetTSQuery(Datum X)
static TSVector DatumGetTSVector(Datum X)
static Datum TSVectorGetDatum(const TSVectorData *X)
#define PG_GETARG_TSQUERY(n)
#define PG_GETARG_TSVECTOR_COPY(n)
#define WEP_SETWEIGHT(x, v)
static Datum TSQueryGetDatum(const TSQueryData *X)
#define TS_EXEC_PHRASE_NO_POS
TSTernaryValue(* TSExecuteCallback)(void *arg, QueryOperand *val, ExecPhraseData *data)
int compareWordEntryPos(const void *a, const void *b)
Datum tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
static Datum ts_process_call(FuncCallContext *funcctx)
static TSTernaryValue checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
bool TS_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
Datum ts_match_vq(PG_FUNCTION_ARGS)
Datum tsvector_update_trigger_byid(PG_FUNCTION_ARGS)
static int32 add_pos(TSVector src, WordEntry *srcptr, TSVector dest, WordEntry *destptr, int32 maxpos)
static TSVectorStat * ts_stat_sql(MemoryContext persistentContext, text *txt, text *ws)
List * TS_execute_locations(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
Datum tsvector_delete_arr(PG_FUNCTION_ARGS)
Datum array_to_tsvector(PG_FUNCTION_ARGS)
Datum tsvector_filter(PG_FUNCTION_ARGS)
static TSTernaryValue TS_phrase_output(ExecPhraseData *data, ExecPhraseData *Ldata, ExecPhraseData *Rdata, int emit, int Loffset, int Roffset, int max_npos)
#define compareEntry(pa, a, pb, b)
Datum tsvector_setweight(PG_FUNCTION_ARGS)
#define TSVECTORCMPFUNC(type, action, ret)
static int check_weight(TSVector txt, WordEntry *wptr, int8 weight)
Datum tsvector_strip(PG_FUNCTION_ARGS)
Datum tsvector_length(PG_FUNCTION_ARGS)
Datum tsvector_to_array(PG_FUNCTION_ARGS)
Datum ts_match_tq(PG_FUNCTION_ARGS)
static int silly_cmp_tsvector(const TSVectorData *a, const TSVectorData *b)
Datum ts_stat1(PG_FUNCTION_ARGS)
int32 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
Datum tsvector_delete_str(PG_FUNCTION_ARGS)
static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
Datum ts_match_qv(PG_FUNCTION_ARGS)
bool tsquery_requires_match(QueryItem *curitem)
Datum tsvector_concat(PG_FUNCTION_ARGS)
Datum tsvector_update_trigger_bycolumn(PG_FUNCTION_ARGS)
static bool TS_execute_locations_recurse(QueryItem *curitem, void *arg, TSExecuteCallback chkcond, List **locations)
static TSTernaryValue TS_execute_recurse(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
static TSVectorStat * ts_accum(MemoryContext persistentContext, TSVectorStat *stat, Datum data)
TSTernaryValue TS_execute_ternary(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond)
static int compare_int(const void *va, const void *vb)
static void ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx, TSVectorStat *stat)
static void chooseNextStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector txt, uint32 low, uint32 high, uint32 offset)
Datum ts_match_tt(PG_FUNCTION_ARGS)
static TSTernaryValue TS_phrase_execute(QueryItem *curitem, void *arg, uint32 flags, TSExecuteCallback chkcond, ExecPhraseData *data)
static int tsvector_bsearch(const TSVectorData *tsv, char *lexeme, int lexeme_len)
static int compare_text_lexemes(const void *va, const void *vb)
static TSTernaryValue checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val, ExecPhraseData *data)
#define compareStatWord(a, e, t)
Datum tsvector_unnest(PG_FUNCTION_ARGS)
static StatEntry * walkStatEntryTree(TSVectorStat *stat)
Datum ts_stat2(PG_FUNCTION_ARGS)
static void insertStatEntry(MemoryContext persistentContext, TSVectorStat *stat, TSVector txt, uint32 off)
static TSVector tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete, int indices_count)
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
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)
text * cstring_to_text_with_len(const char *s, int len)
char * text_to_cstring(const text *t)