Exemple #1
0
/*
 * Extract attribute (column) number of stored entry from GIN tuple
 */
OffsetNumber
gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple)
{
	OffsetNumber colN;

	if (ginstate->oneCol)
	{
		/* column number is not stored explicitly */
		colN = FirstOffsetNumber;
	}
	else
	{
		Datum		res;
		bool		isnull;

		/*
		 * First attribute is always int16, so we can safely use any tuple
		 * descriptor to obtain first attribute of tuple
		 */
		res = index_getattr(tuple, FirstOffsetNumber, ginstate->tupdesc[0],
							&isnull);
		Assert(!isnull);

		colN = DatumGetUInt16(res);
		Assert(colN >= FirstOffsetNumber && colN <= ginstate->origTupdesc->natts);
	}

	return colN;
}
Exemple #2
0
static uint16
GetNewLabelId(char *graphname, Oid graphid)
{
	char		sname[128];
	Datum		stext;
	uint16		labid;
	int			cnt;

	snprintf(sname, 128, "%s.%s", graphname, AG_LABEL_SEQ);
	stext = CStringGetTextDatum(sname);

	cnt = 0;
	for (;;)
	{
		Datum val;

		val = DirectFunctionCall1(nextval, stext);
		labid = DatumGetUInt16(val);
		if (!labid_exists(graphid, labid))
			break;

		if (++cnt >= GRAPHID_LABID_MAX)
			ereport(ERROR,
					(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
					 errmsg("no more new labels are available")));
	}

	return labid;
}
Exemple #3
0
Datum
gin_extract_tsquery(PG_FUNCTION_ARGS)
{
	QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
	uint32	   *nentries = (uint32 *) PG_GETARG_POINTER(1);
	StrategyNumber strategy = DatumGetUInt16(PG_GETARG_DATUM(2));
	Datum	   *entries = NULL;

	*nentries = 0;
	if (query->size > 0)
	{
		int4		i,
					j = 0,
					len;
		ITEM	   *item;

		item = clean_NOT_v2(GETQUERY(query), &len);
		if (!item)
			elog(ERROR, "Query requires full scan, GIN doesn't support it");

		item = GETQUERY(query);

		for (i = 0; i < query->size; i++)
			if (item[i].type == VAL)
				(*nentries)++;

		entries = (Datum *) palloc(sizeof(Datum) * (*nentries));

		for (i = 0; i < query->size; i++)
			if (item[i].type == VAL)
			{
				text	   *txt;

				txt = (text *) palloc(VARHDRSZ + item[i].length);

				VARATT_SIZEP(txt) = VARHDRSZ + item[i].length;
				memcpy(VARDATA(txt), GETOPERAND(query) + item[i].distance, item[i].length);

				entries[j++] = PointerGetDatum(txt);

				if (strategy == 1 && item[i].weight != 0)
					elog(ERROR, "With class of lexeme restrictions use @@@ operation");
			}

	}

	PG_FREE_IF_COPY(query, 0);
	PG_RETURN_POINTER(entries);
}