mirror of
https://github.com/postgres/postgres.git
synced 2025-08-18 12:22:09 +03:00
pgindent run for 9.6
This commit is contained in:
@@ -5277,12 +5277,12 @@ check_rolespec_name(const Node *node, const char *detail_msg)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_RESERVED_NAME),
|
||||
errmsg("role \"%s\" is reserved",
|
||||
role->rolename),
|
||||
role->rolename),
|
||||
errdetail("%s", detail_msg)));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_RESERVED_NAME),
|
||||
errmsg("role \"%s\" is reserved",
|
||||
role->rolename)));
|
||||
role->rolename)));
|
||||
}
|
||||
}
|
||||
|
@@ -257,7 +257,7 @@ datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
|
||||
Size
|
||||
datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
|
||||
{
|
||||
Size sz = sizeof(int);
|
||||
Size sz = sizeof(int);
|
||||
|
||||
if (!isnull)
|
||||
{
|
||||
@@ -267,6 +267,7 @@ datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
|
||||
else if (VARATT_IS_EXTERNAL_EXPANDED(value))
|
||||
{
|
||||
ExpandedObjectHeader *eoh = DatumGetEOHP(value);
|
||||
|
||||
sz += EOH_get_flat_size(eoh);
|
||||
}
|
||||
else
|
||||
@@ -298,7 +299,7 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
|
||||
char **start_address)
|
||||
{
|
||||
ExpandedObjectHeader *eoh = NULL;
|
||||
int header;
|
||||
int header;
|
||||
|
||||
/* Write header word. */
|
||||
if (isnull)
|
||||
@@ -346,8 +347,8 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
|
||||
Datum
|
||||
datumRestore(char **start_address, bool *isnull)
|
||||
{
|
||||
int header;
|
||||
void *d;
|
||||
int header;
|
||||
void *d;
|
||||
|
||||
/* Read header word. */
|
||||
memcpy(&header, *start_address, sizeof(int));
|
||||
|
@@ -5074,9 +5074,9 @@ numeric_to_number(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Numeric x;
|
||||
Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(10)));
|
||||
Int32GetDatum(10)));
|
||||
Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric,
|
||||
Int32GetDatum(-Num.multi)));
|
||||
Int32GetDatum(-Num.multi)));
|
||||
|
||||
x = DatumGetNumeric(DirectFunctionCall2(numeric_power,
|
||||
NumericGetDatum(a),
|
||||
|
@@ -101,19 +101,19 @@ typedef struct
|
||||
{
|
||||
double low;
|
||||
double high;
|
||||
} Range;
|
||||
} Range;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Range left;
|
||||
Range right;
|
||||
} RangeBox;
|
||||
} RangeBox;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
RangeBox range_box_x;
|
||||
RangeBox range_box_y;
|
||||
} RectBox;
|
||||
} RectBox;
|
||||
|
||||
/*
|
||||
* Calculate the quadrant
|
||||
@@ -173,7 +173,7 @@ getRangeBox(BOX *box)
|
||||
static RectBox *
|
||||
initRectBox(void)
|
||||
{
|
||||
RectBox *rect_box = (RectBox *) palloc(sizeof(RectBox));
|
||||
RectBox *rect_box = (RectBox *) palloc(sizeof(RectBox));
|
||||
double infinity = get_float8_infinity();
|
||||
|
||||
rect_box->range_box_x.left.low = -infinity;
|
||||
@@ -201,7 +201,7 @@ initRectBox(void)
|
||||
static RectBox *
|
||||
nextRectBox(RectBox *rect_box, RangeBox *centroid, uint8 quadrant)
|
||||
{
|
||||
RectBox *next_rect_box = (RectBox *) palloc(sizeof(RectBox));
|
||||
RectBox *next_rect_box = (RectBox *) palloc(sizeof(RectBox));
|
||||
|
||||
memcpy(next_rect_box, rect_box, sizeof(RectBox));
|
||||
|
||||
@@ -233,7 +233,7 @@ static bool
|
||||
overlap2D(RangeBox *range_box, Range *query)
|
||||
{
|
||||
return FPge(range_box->right.high, query->low) &&
|
||||
FPle(range_box->left.low, query->high);
|
||||
FPle(range_box->left.low, query->high);
|
||||
}
|
||||
|
||||
/* Can any rectangle from rect_box overlap with this argument? */
|
||||
@@ -241,7 +241,7 @@ static bool
|
||||
overlap4D(RectBox *rect_box, RangeBox *query)
|
||||
{
|
||||
return overlap2D(&rect_box->range_box_x, &query->left) &&
|
||||
overlap2D(&rect_box->range_box_y, &query->right);
|
||||
overlap2D(&rect_box->range_box_y, &query->right);
|
||||
}
|
||||
|
||||
/* Can any range from range_box contain this argument? */
|
||||
@@ -249,15 +249,15 @@ static bool
|
||||
contain2D(RangeBox *range_box, Range *query)
|
||||
{
|
||||
return FPge(range_box->right.high, query->high) &&
|
||||
FPle(range_box->left.low, query->low);
|
||||
FPle(range_box->left.low, query->low);
|
||||
}
|
||||
|
||||
/* Can any rectangle from rect_box contain this argument? */
|
||||
static bool
|
||||
contain4D(RectBox *rect_box, RangeBox * query)
|
||||
contain4D(RectBox *rect_box, RangeBox *query)
|
||||
{
|
||||
return contain2D(&rect_box->range_box_x, &query->left) &&
|
||||
contain2D(&rect_box->range_box_y, &query->right);
|
||||
contain2D(&rect_box->range_box_y, &query->right);
|
||||
}
|
||||
|
||||
/* Can any range from range_box be contained by this argument? */
|
||||
@@ -265,9 +265,9 @@ static bool
|
||||
contained2D(RangeBox *range_box, Range *query)
|
||||
{
|
||||
return FPle(range_box->left.low, query->high) &&
|
||||
FPge(range_box->left.high, query->low) &&
|
||||
FPle(range_box->right.low, query->high) &&
|
||||
FPge(range_box->right.high, query->low);
|
||||
FPge(range_box->left.high, query->low) &&
|
||||
FPle(range_box->right.low, query->high) &&
|
||||
FPge(range_box->right.high, query->low);
|
||||
}
|
||||
|
||||
/* Can any rectangle from rect_box be contained by this argument? */
|
||||
@@ -275,7 +275,7 @@ static bool
|
||||
contained4D(RectBox *rect_box, RangeBox *query)
|
||||
{
|
||||
return contained2D(&rect_box->range_box_x, &query->left) &&
|
||||
contained2D(&rect_box->range_box_y, &query->right);
|
||||
contained2D(&rect_box->range_box_y, &query->right);
|
||||
}
|
||||
|
||||
/* Can any range from range_box to be lower than this argument? */
|
||||
@@ -283,7 +283,7 @@ static bool
|
||||
lower2D(RangeBox *range_box, Range *query)
|
||||
{
|
||||
return FPlt(range_box->left.low, query->low) &&
|
||||
FPlt(range_box->right.low, query->low);
|
||||
FPlt(range_box->right.low, query->low);
|
||||
}
|
||||
|
||||
/* Can any range from range_box to be higher than this argument? */
|
||||
@@ -291,7 +291,7 @@ static bool
|
||||
higher2D(RangeBox *range_box, Range *query)
|
||||
{
|
||||
return FPgt(range_box->left.high, query->high) &&
|
||||
FPgt(range_box->right.high, query->high);
|
||||
FPgt(range_box->right.high, query->high);
|
||||
}
|
||||
|
||||
/* Can any rectangle from rect_box be left of this argument? */
|
||||
@@ -396,8 +396,8 @@ spg_box_quad_choose(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
spg_box_quad_picksplit(PG_FUNCTION_ARGS)
|
||||
{
|
||||
spgPickSplitIn *in = (spgPickSplitIn *) PG_GETARG_POINTER(0);
|
||||
spgPickSplitOut *out = (spgPickSplitOut *) PG_GETARG_POINTER(1);
|
||||
spgPickSplitIn *in = (spgPickSplitIn *) PG_GETARG_POINTER(0);
|
||||
spgPickSplitOut *out = (spgPickSplitOut *) PG_GETARG_POINTER(1);
|
||||
BOX *centroid;
|
||||
int median,
|
||||
i;
|
||||
@@ -409,7 +409,7 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS)
|
||||
/* Calculate median of all 4D coordinates */
|
||||
for (i = 0; i < in->nTuples; i++)
|
||||
{
|
||||
BOX *box = DatumGetBoxP(in->datums[i]);
|
||||
BOX *box = DatumGetBoxP(in->datums[i]);
|
||||
|
||||
lowXs[i] = box->low.x;
|
||||
highXs[i] = box->high.x;
|
||||
@@ -442,13 +442,13 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS)
|
||||
out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples);
|
||||
|
||||
/*
|
||||
* Assign ranges to corresponding nodes according to quadrants
|
||||
* relative to the "centroid" range
|
||||
* Assign ranges to corresponding nodes according to quadrants relative to
|
||||
* the "centroid" range
|
||||
*/
|
||||
for (i = 0; i < in->nTuples; i++)
|
||||
{
|
||||
BOX *box = DatumGetBoxP(in->datums[i]);
|
||||
uint8 quadrant = getQuadrant(centroid, box);
|
||||
BOX *box = DatumGetBoxP(in->datums[i]);
|
||||
uint8 quadrant = getQuadrant(centroid, box);
|
||||
|
||||
out->leafTupleDatums[i] = BoxPGetDatum(box);
|
||||
out->mapTuplesToNodes[i] = quadrant;
|
||||
@@ -465,12 +465,12 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
{
|
||||
spgInnerConsistentIn *in = (spgInnerConsistentIn *) PG_GETARG_POINTER(0);
|
||||
spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1);
|
||||
int i;
|
||||
MemoryContext old_ctx;
|
||||
RectBox *rect_box;
|
||||
uint8 quadrant;
|
||||
RangeBox *centroid,
|
||||
**queries;
|
||||
int i;
|
||||
MemoryContext old_ctx;
|
||||
RectBox *rect_box;
|
||||
uint8 quadrant;
|
||||
RangeBox *centroid,
|
||||
**queries;
|
||||
|
||||
if (in->allTheSame)
|
||||
{
|
||||
@@ -484,8 +484,8 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
/*
|
||||
* We are saving the traversal value or initialize it an unbounded
|
||||
* one, if we have just begun to walk the tree.
|
||||
* We are saving the traversal value or initialize it an unbounded one, if
|
||||
* we have just begun to walk the tree.
|
||||
*/
|
||||
if (in->traversalValue)
|
||||
rect_box = in->traversalValue;
|
||||
@@ -493,8 +493,8 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
rect_box = initRectBox();
|
||||
|
||||
/*
|
||||
* We are casting the prefix and queries to RangeBoxes for ease of
|
||||
* the following operations.
|
||||
* We are casting the prefix and queries to RangeBoxes for ease of the
|
||||
* following operations.
|
||||
*/
|
||||
centroid = getRangeBox(DatumGetBoxP(in->prefixDatum));
|
||||
queries = (RangeBox **) palloc(in->nkeys * sizeof(RangeBox *));
|
||||
@@ -507,15 +507,15 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
out->traversalValues = (void **) palloc(sizeof(void *) * in->nNodes);
|
||||
|
||||
/*
|
||||
* We switch memory context, because we want to allocate memory for
|
||||
* new traversal values (next_rect_box) and pass these pieces of
|
||||
* memory to further call of this function.
|
||||
* We switch memory context, because we want to allocate memory for new
|
||||
* traversal values (next_rect_box) and pass these pieces of memory to
|
||||
* further call of this function.
|
||||
*/
|
||||
old_ctx = MemoryContextSwitchTo(in->traversalMemoryContext);
|
||||
|
||||
for (quadrant = 0; quadrant < in->nNodes; quadrant++)
|
||||
{
|
||||
RectBox *next_rect_box = nextRectBox(rect_box, centroid, quadrant);
|
||||
RectBox *next_rect_box = nextRectBox(rect_box, centroid, quadrant);
|
||||
bool flag = true;
|
||||
|
||||
for (i = 0; i < in->nkeys; i++)
|
||||
@@ -587,8 +587,8 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If this node is not selected, we don't need to keep
|
||||
* the next traversal value in the memory context.
|
||||
* If this node is not selected, we don't need to keep the next
|
||||
* traversal value in the memory context.
|
||||
*/
|
||||
pfree(next_rect_box);
|
||||
}
|
||||
|
@@ -1305,7 +1305,7 @@ compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
|
||||
case jbvBool:
|
||||
if (aScalar->val.boolean == bScalar->val.boolean)
|
||||
return 0;
|
||||
else if (aScalar->val.boolean >bScalar->val.boolean)
|
||||
else if (aScalar->val.boolean > bScalar->val.boolean)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
|
@@ -609,7 +609,7 @@ jsonb_array_element(PG_FUNCTION_ARGS)
|
||||
/* Handle negative subscript */
|
||||
if (element < 0)
|
||||
{
|
||||
uint32 nelements = JB_ROOT_COUNT(jb);
|
||||
uint32 nelements = JB_ROOT_COUNT(jb);
|
||||
|
||||
if (-element > nelements)
|
||||
PG_RETURN_NULL();
|
||||
@@ -652,7 +652,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS)
|
||||
/* Handle negative subscript */
|
||||
if (element < 0)
|
||||
{
|
||||
uint32 nelements = JB_ROOT_COUNT(jb);
|
||||
uint32 nelements = JB_ROOT_COUNT(jb);
|
||||
|
||||
if (-element > nelements)
|
||||
PG_RETURN_NULL();
|
||||
@@ -992,7 +992,7 @@ get_array_start(void *state)
|
||||
_state->path_indexes[lex_level] != INT_MIN)
|
||||
{
|
||||
/* Negative subscript -- convert to positive-wise subscript */
|
||||
int nelements = json_count_array_elements(_state->lex);
|
||||
int nelements = json_count_array_elements(_state->lex);
|
||||
|
||||
if (-_state->path_indexes[lex_level] <= nelements)
|
||||
_state->path_indexes[lex_level] += nelements;
|
||||
@@ -1002,8 +1002,8 @@ get_array_start(void *state)
|
||||
{
|
||||
/*
|
||||
* Special case: we should match the entire array. We only need this
|
||||
* at the outermost level because at nested levels the match will
|
||||
* have been started by the outer field or array element callback.
|
||||
* at the outermost level because at nested levels the match will have
|
||||
* been started by the outer field or array element callback.
|
||||
*/
|
||||
_state->result_start = _state->lex->token_start;
|
||||
}
|
||||
@@ -3368,9 +3368,9 @@ jsonb_concat(PG_FUNCTION_ARGS)
|
||||
*it2;
|
||||
|
||||
/*
|
||||
* If one of the jsonb is empty, just return the other if it's not
|
||||
* scalar and both are of the same kind. If it's a scalar or they are
|
||||
* of different kinds we need to perform the concatenation even if one is
|
||||
* If one of the jsonb is empty, just return the other if it's not scalar
|
||||
* and both are of the same kind. If it's a scalar or they are of
|
||||
* different kinds we need to perform the concatenation even if one is
|
||||
* empty.
|
||||
*/
|
||||
if (JB_ROOT_IS_OBJECT(jb1) == JB_ROOT_IS_OBJECT(jb2))
|
||||
@@ -3481,7 +3481,7 @@ jsonb_delete_idx(PG_FUNCTION_ARGS)
|
||||
it = JsonbIteratorInit(&in->root);
|
||||
|
||||
r = JsonbIteratorNext(&it, &v, false);
|
||||
Assert (r == WJB_BEGIN_ARRAY);
|
||||
Assert(r == WJB_BEGIN_ARRAY);
|
||||
n = v.val.array.nElems;
|
||||
|
||||
if (idx < 0)
|
||||
@@ -3868,8 +3868,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
|
||||
if (level == path_len - 1)
|
||||
{
|
||||
/*
|
||||
* called from jsonb_insert(), it forbids redefining
|
||||
* an existsing value
|
||||
* called from jsonb_insert(), it forbids redefining an
|
||||
* existsing value
|
||||
*/
|
||||
if (op_type & (JB_PATH_INSERT_BEFORE | JB_PATH_INSERT_AFTER))
|
||||
ereport(ERROR,
|
||||
@@ -3878,7 +3878,7 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
|
||||
errhint("Try using the function jsonb_set "
|
||||
"to replace key value.")));
|
||||
|
||||
r = JsonbIteratorNext(it, &v, true); /* skip value */
|
||||
r = JsonbIteratorNext(it, &v, true); /* skip value */
|
||||
if (!(op_type & JB_PATH_DELETE))
|
||||
{
|
||||
(void) pushJsonbValue(st, WJB_KEY, &k);
|
||||
@@ -4005,8 +4005,8 @@ setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
|
||||
|
||||
/*
|
||||
* We should keep current value only in case of
|
||||
* JB_PATH_INSERT_BEFORE or JB_PATH_INSERT_AFTER
|
||||
* because otherwise it should be deleted or replaced
|
||||
* JB_PATH_INSERT_BEFORE or JB_PATH_INSERT_AFTER because
|
||||
* otherwise it should be deleted or replaced
|
||||
*/
|
||||
if (op_type & (JB_PATH_INSERT_AFTER | JB_PATH_INSERT_BEFORE))
|
||||
(void) pushJsonbValue(st, r, &v);
|
||||
|
@@ -849,13 +849,13 @@ parse_ident(PG_FUNCTION_ARGS)
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("string is not a valid identifier: \"%s\"",
|
||||
text_to_cstring(qualname)),
|
||||
errdetail("No valid identifier before \".\".")));
|
||||
errdetail("No valid identifier before \".\".")));
|
||||
else if (after_dot)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("string is not a valid identifier: \"%s\"",
|
||||
text_to_cstring(qualname)),
|
||||
errdetail("No valid identifier after \".\".")));
|
||||
errdetail("No valid identifier after \".\".")));
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
|
@@ -3355,10 +3355,10 @@ numeric_accum(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_combine(PG_FUNCTION_ARGS)
|
||||
{
|
||||
NumericAggState *state1;
|
||||
NumericAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
NumericAggState *state1;
|
||||
NumericAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, &agg_context))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -3397,8 +3397,8 @@ numeric_combine(PG_FUNCTION_ARGS)
|
||||
state1->NaNcount += state2->NaNcount;
|
||||
|
||||
/*
|
||||
* These are currently only needed for moving aggregates, but let's
|
||||
* do the right thing anyway...
|
||||
* These are currently only needed for moving aggregates, but let's do
|
||||
* the right thing anyway...
|
||||
*/
|
||||
if (state2->maxScale > state1->maxScale)
|
||||
{
|
||||
@@ -3446,10 +3446,10 @@ numeric_avg_accum(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_avg_combine(PG_FUNCTION_ARGS)
|
||||
{
|
||||
NumericAggState *state1;
|
||||
NumericAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
NumericAggState *state1;
|
||||
NumericAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, &agg_context))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -3485,8 +3485,8 @@ numeric_avg_combine(PG_FUNCTION_ARGS)
|
||||
state1->NaNcount += state2->NaNcount;
|
||||
|
||||
/*
|
||||
* These are currently only needed for moving aggregates, but let's
|
||||
* do the right thing anyway...
|
||||
* These are currently only needed for moving aggregates, but let's do
|
||||
* the right thing anyway...
|
||||
*/
|
||||
if (state2->maxScale > state1->maxScale)
|
||||
{
|
||||
@@ -3518,11 +3518,11 @@ numeric_avg_combine(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_avg_serialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
NumericAggState *state;
|
||||
StringInfoData buf;
|
||||
Datum temp;
|
||||
bytea *sumX;
|
||||
bytea *result;
|
||||
NumericAggState *state;
|
||||
StringInfoData buf;
|
||||
Datum temp;
|
||||
bytea *sumX;
|
||||
bytea *result;
|
||||
|
||||
/* Ensure we disallow calling when not in aggregate context */
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
@@ -3549,7 +3549,7 @@ numeric_avg_serialize(PG_FUNCTION_ARGS)
|
||||
pq_sendbytes(&buf, VARDATA(sumX), VARSIZE(sumX) - VARHDRSZ);
|
||||
|
||||
/* maxScale */
|
||||
pq_sendint(&buf, state->maxScale, 4);
|
||||
pq_sendint(&buf, state->maxScale, 4);
|
||||
|
||||
/* maxScaleCount */
|
||||
pq_sendint64(&buf, state->maxScaleCount);
|
||||
@@ -3564,7 +3564,7 @@ numeric_avg_serialize(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* numeric_avg_deserialize
|
||||
* Deserialize bytea into NumericAggState for numeric aggregates that
|
||||
* Deserialize bytea into NumericAggState for numeric aggregates that
|
||||
* don't require sumX2. Deserializes bytea into NumericAggState using the
|
||||
* standard pq API.
|
||||
*
|
||||
@@ -3574,10 +3574,10 @@ numeric_avg_serialize(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_avg_deserialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
NumericAggState *result;
|
||||
Datum temp;
|
||||
StringInfoData buf;
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
NumericAggState *result;
|
||||
Datum temp;
|
||||
StringInfoData buf;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -3628,12 +3628,12 @@ numeric_avg_deserialize(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_serialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
NumericAggState *state;
|
||||
StringInfoData buf;
|
||||
Datum temp;
|
||||
bytea *sumX;
|
||||
bytea *sumX2;
|
||||
bytea *result;
|
||||
NumericAggState *state;
|
||||
StringInfoData buf;
|
||||
Datum temp;
|
||||
bytea *sumX;
|
||||
bytea *sumX2;
|
||||
bytea *result;
|
||||
|
||||
/* Ensure we disallow calling when not in aggregate context */
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
@@ -3667,7 +3667,7 @@ numeric_serialize(PG_FUNCTION_ARGS)
|
||||
pq_sendbytes(&buf, VARDATA(sumX2), VARSIZE(sumX2) - VARHDRSZ);
|
||||
|
||||
/* maxScale */
|
||||
pq_sendint(&buf, state->maxScale, 4);
|
||||
pq_sendint(&buf, state->maxScale, 4);
|
||||
|
||||
/* maxScaleCount */
|
||||
pq_sendint64(&buf, state->maxScaleCount);
|
||||
@@ -3692,10 +3692,10 @@ numeric_serialize(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_deserialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
NumericAggState *result;
|
||||
Datum temp;
|
||||
StringInfoData buf;
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
NumericAggState *result;
|
||||
Datum temp;
|
||||
StringInfoData buf;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -3932,8 +3932,8 @@ numeric_poly_combine(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PolyNumAggState *state1;
|
||||
PolyNumAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, &agg_context))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -4001,11 +4001,11 @@ numeric_poly_combine(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_poly_serialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PolyNumAggState *state;
|
||||
StringInfoData buf;
|
||||
bytea *sumX;
|
||||
bytea *sumX2;
|
||||
bytea *result;
|
||||
PolyNumAggState *state;
|
||||
StringInfoData buf;
|
||||
bytea *sumX;
|
||||
bytea *sumX2;
|
||||
bytea *result;
|
||||
|
||||
/* Ensure we disallow calling when not in aggregate context */
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
@@ -4040,11 +4040,11 @@ numeric_poly_serialize(PG_FUNCTION_ARGS)
|
||||
free_var(&num);
|
||||
#else
|
||||
temp = DirectFunctionCall1(numeric_send,
|
||||
NumericGetDatum(make_result(&state->sumX)));
|
||||
NumericGetDatum(make_result(&state->sumX)));
|
||||
sumX = DatumGetByteaP(temp);
|
||||
|
||||
temp = DirectFunctionCall1(numeric_send,
|
||||
NumericGetDatum(make_result(&state->sumX2)));
|
||||
NumericGetDatum(make_result(&state->sumX2)));
|
||||
sumX2 = DatumGetByteaP(temp);
|
||||
#endif
|
||||
}
|
||||
@@ -4076,11 +4076,11 @@ numeric_poly_serialize(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
numeric_poly_deserialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
PolyNumAggState *result;
|
||||
Datum sumX;
|
||||
Datum sumX2;
|
||||
StringInfoData buf;
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
PolyNumAggState *result;
|
||||
Datum sumX;
|
||||
Datum sumX2;
|
||||
StringInfoData buf;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -4105,13 +4105,13 @@ numeric_poly_deserialize(PG_FUNCTION_ARGS)
|
||||
|
||||
/* sumX2 */
|
||||
sumX2 = DirectFunctionCall3(numeric_recv,
|
||||
PointerGetDatum(&buf),
|
||||
InvalidOid,
|
||||
-1);
|
||||
PointerGetDatum(&buf),
|
||||
InvalidOid,
|
||||
-1);
|
||||
|
||||
#ifdef HAVE_INT128
|
||||
{
|
||||
NumericVar num;
|
||||
NumericVar num;
|
||||
|
||||
init_var(&num);
|
||||
set_var_from_num(DatumGetNumeric(sumX), &num);
|
||||
@@ -4170,10 +4170,10 @@ int8_avg_accum(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
int8_avg_combine(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PolyNumAggState *state1;
|
||||
PolyNumAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
PolyNumAggState *state1;
|
||||
PolyNumAggState *state2;
|
||||
MemoryContext agg_context;
|
||||
MemoryContext old_context;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, &agg_context))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -4233,10 +4233,10 @@ int8_avg_combine(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
int8_avg_serialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PolyNumAggState *state;
|
||||
StringInfoData buf;
|
||||
bytea *sumX;
|
||||
bytea *result;
|
||||
PolyNumAggState *state;
|
||||
StringInfoData buf;
|
||||
bytea *sumX;
|
||||
bytea *result;
|
||||
|
||||
/* Ensure we disallow calling when not in aggregate context */
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
@@ -4265,7 +4265,7 @@ int8_avg_serialize(PG_FUNCTION_ARGS)
|
||||
sumX = DatumGetByteaP(temp);
|
||||
#else
|
||||
temp = DirectFunctionCall1(numeric_send,
|
||||
NumericGetDatum(make_result(&state->sumX)));
|
||||
NumericGetDatum(make_result(&state->sumX)));
|
||||
sumX = DatumGetByteaP(temp);
|
||||
#endif
|
||||
}
|
||||
@@ -4293,10 +4293,10 @@ int8_avg_serialize(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
int8_avg_deserialize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
PolyNumAggState *result;
|
||||
StringInfoData buf;
|
||||
Datum temp;
|
||||
bytea *sstate = PG_GETARG_BYTEA_P(0);
|
||||
PolyNumAggState *result;
|
||||
StringInfoData buf;
|
||||
Datum temp;
|
||||
|
||||
if (!AggCheckCallContext(fcinfo, NULL))
|
||||
elog(ERROR, "aggregate function called in non-aggregate context");
|
||||
@@ -4321,7 +4321,7 @@ int8_avg_deserialize(PG_FUNCTION_ARGS)
|
||||
|
||||
#ifdef HAVE_INT128
|
||||
{
|
||||
NumericVar num;
|
||||
NumericVar num;
|
||||
|
||||
init_var(&num);
|
||||
set_var_from_num(DatumGetNumeric(temp), &num);
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "utils/inet.h"
|
||||
#include "utils/timestamp.h"
|
||||
|
||||
#define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var))))
|
||||
#define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var))))
|
||||
|
||||
/* bogus ... these externs should be in a header file */
|
||||
extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS);
|
||||
@@ -540,7 +540,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
|
||||
int num_backends = pgstat_fetch_stat_numbackends();
|
||||
int curr_backend;
|
||||
char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0));
|
||||
ProgressCommandType cmdtype;
|
||||
ProgressCommandType cmdtype;
|
||||
TupleDesc tupdesc;
|
||||
Tuplestorestate *tupstore;
|
||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||
@@ -582,8 +582,8 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
|
||||
/* 1-based index */
|
||||
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
|
||||
{
|
||||
LocalPgBackendStatus *local_beentry;
|
||||
PgBackendStatus *beentry;
|
||||
LocalPgBackendStatus *local_beentry;
|
||||
PgBackendStatus *beentry;
|
||||
Datum values[PG_STAT_GET_PROGRESS_COLS];
|
||||
bool nulls[PG_STAT_GET_PROGRESS_COLS];
|
||||
int i;
|
||||
@@ -613,14 +613,14 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
|
||||
if (has_privs_of_role(GetUserId(), beentry->st_userid))
|
||||
{
|
||||
values[2] = ObjectIdGetDatum(beentry->st_progress_command_target);
|
||||
for(i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
|
||||
values[i+3] = Int64GetDatum(beentry->st_progress_param[i]);
|
||||
for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
|
||||
values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
nulls[2] = true;
|
||||
for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++)
|
||||
nulls[i+3] = true;
|
||||
nulls[i + 3] = true;
|
||||
}
|
||||
|
||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
||||
@@ -787,7 +787,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
proc = BackendPidGetProc(beentry->st_procpid);
|
||||
if (proc != NULL)
|
||||
{
|
||||
uint32 raw_wait_event;
|
||||
uint32 raw_wait_event;
|
||||
|
||||
raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info);
|
||||
wait_event_type = pgstat_get_wait_event_type(raw_wait_event);
|
||||
|
@@ -760,13 +760,14 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
|
||||
/* Save previous prefix if needed */
|
||||
if (needPrevious)
|
||||
{
|
||||
Datum previousCentroid;
|
||||
Datum previousCentroid;
|
||||
|
||||
/* We know, that in->prefixDatum in this place is varlena,
|
||||
/*
|
||||
* We know, that in->prefixDatum in this place is varlena,
|
||||
* because it's range
|
||||
*/
|
||||
previousCentroid = datumCopy(in->prefixDatum, false, -1);
|
||||
out->traversalValues[out->nNodes] = (void *)previousCentroid;
|
||||
out->traversalValues[out->nNodes] = (void *) previousCentroid;
|
||||
}
|
||||
out->nodeNumbers[out->nNodes] = i - 1;
|
||||
out->nNodes++;
|
||||
|
@@ -184,8 +184,8 @@ checkcondition_gin_internal(GinChkVal *gcv, QueryOperand *val, ExecPhraseData *d
|
||||
int j;
|
||||
|
||||
/*
|
||||
* if any val requiring a weight is used or caller
|
||||
* needs position information then set recheck flag
|
||||
* if any val requiring a weight is used or caller needs position
|
||||
* information then set recheck flag
|
||||
*/
|
||||
if (val->weight != 0 || data != NULL)
|
||||
*gcv->need_recheck = true;
|
||||
@@ -236,9 +236,10 @@ TS_execute_ternary(GinChkVal *gcv, QueryItem *curitem)
|
||||
return !result;
|
||||
|
||||
case OP_PHRASE:
|
||||
|
||||
/*
|
||||
* GIN doesn't contain any information about positions,
|
||||
* treat OP_PHRASE as OP_AND with recheck requirement
|
||||
* GIN doesn't contain any information about positions, treat
|
||||
* OP_PHRASE as OP_AND with recheck requirement
|
||||
*/
|
||||
*gcv->need_recheck = true;
|
||||
/* FALL THRU */
|
||||
|
@@ -24,12 +24,12 @@
|
||||
#include "utils/pg_crc.h"
|
||||
|
||||
/* FTS operator priorities, see ts_type.h */
|
||||
const int tsearch_op_priority[OP_COUNT] =
|
||||
const int tsearch_op_priority[OP_COUNT] =
|
||||
{
|
||||
3, /* OP_NOT */
|
||||
2, /* OP_AND */
|
||||
1, /* OP_OR */
|
||||
4 /* OP_PHRASE */
|
||||
3, /* OP_NOT */
|
||||
2, /* OP_AND */
|
||||
1, /* OP_OR */
|
||||
4 /* OP_PHRASE */
|
||||
};
|
||||
|
||||
struct TSQueryParserStateData
|
||||
@@ -128,15 +128,15 @@ parse_phrase_operator(char *buf, int16 *distance)
|
||||
PHRASE_CLOSE,
|
||||
PHRASE_ERR,
|
||||
PHRASE_FINISH
|
||||
} state = PHRASE_OPEN;
|
||||
} state = PHRASE_OPEN;
|
||||
|
||||
char *ptr = buf;
|
||||
char *endptr;
|
||||
long l = 1;
|
||||
char *ptr = buf;
|
||||
char *endptr;
|
||||
long l = 1;
|
||||
|
||||
while (*ptr)
|
||||
{
|
||||
switch(state)
|
||||
switch (state)
|
||||
{
|
||||
case PHRASE_OPEN:
|
||||
Assert(t_iseq(ptr, '<'));
|
||||
@@ -192,7 +192,7 @@ parse_phrase_operator(char *buf, int16 *distance)
|
||||
}
|
||||
}
|
||||
|
||||
err:
|
||||
err:
|
||||
*distance = -1;
|
||||
return buf;
|
||||
}
|
||||
@@ -440,18 +440,18 @@ makepol(TSQueryParserState state,
|
||||
PushFunction pushval,
|
||||
Datum opaque)
|
||||
{
|
||||
int8 operator = 0;
|
||||
ts_tokentype type;
|
||||
int lenval = 0;
|
||||
char *strval = NULL;
|
||||
int8 operator = 0;
|
||||
ts_tokentype type;
|
||||
int lenval = 0;
|
||||
char *strval = NULL;
|
||||
struct
|
||||
{
|
||||
int8 op;
|
||||
int16 distance;
|
||||
} opstack[STACKDEPTH];
|
||||
int lenstack = 0;
|
||||
int16 weight = 0;
|
||||
bool prefix;
|
||||
int8 op;
|
||||
int16 distance;
|
||||
} opstack[STACKDEPTH];
|
||||
int lenstack = 0;
|
||||
int16 weight = 0;
|
||||
bool prefix;
|
||||
|
||||
/* since this function recurses, it could be driven to stack overflow */
|
||||
check_stack_depth();
|
||||
@@ -538,7 +538,7 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup)
|
||||
}
|
||||
else if (ptr[*pos].type == QI_VALSTOP)
|
||||
{
|
||||
*needcleanup = true; /* we'll have to remove stop words */
|
||||
*needcleanup = true; /* we'll have to remove stop words */
|
||||
(*pos)++;
|
||||
}
|
||||
else
|
||||
@@ -547,7 +547,7 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup)
|
||||
|
||||
if (ptr[*pos].qoperator.oper == OP_NOT)
|
||||
{
|
||||
ptr[*pos].qoperator.left = 1; /* fixed offset */
|
||||
ptr[*pos].qoperator.left = 1; /* fixed offset */
|
||||
(*pos)++;
|
||||
|
||||
/* process the only argument */
|
||||
@@ -555,15 +555,15 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup)
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryOperator *curitem = &ptr[*pos].qoperator;
|
||||
int tmp = *pos; /* save current position */
|
||||
QueryOperator *curitem = &ptr[*pos].qoperator;
|
||||
int tmp = *pos; /* save current position */
|
||||
|
||||
Assert(curitem->oper == OP_AND ||
|
||||
curitem->oper == OP_OR ||
|
||||
curitem->oper == OP_PHRASE);
|
||||
|
||||
if (curitem->oper == OP_PHRASE)
|
||||
*needcleanup = true; /* push OP_PHRASE down later */
|
||||
*needcleanup = true; /* push OP_PHRASE down later */
|
||||
|
||||
(*pos)++;
|
||||
|
||||
@@ -669,7 +669,7 @@ parse_tsquery(char *buf,
|
||||
i = 0;
|
||||
foreach(cell, state.polstr)
|
||||
{
|
||||
QueryItem *item = (QueryItem *) lfirst(cell);
|
||||
QueryItem *item = (QueryItem *) lfirst(cell);
|
||||
|
||||
switch (item->type)
|
||||
{
|
||||
@@ -696,8 +696,8 @@ parse_tsquery(char *buf,
|
||||
findoprnd(ptr, query->size, &needcleanup);
|
||||
|
||||
/*
|
||||
* QI_VALSTOP nodes should be cleaned and
|
||||
* and OP_PHRASE should be pushed down
|
||||
* QI_VALSTOP nodes should be cleaned and and OP_PHRASE should be pushed
|
||||
* down
|
||||
*/
|
||||
if (needcleanup)
|
||||
return cleanup_fakeval_and_phrase(query);
|
||||
@@ -819,7 +819,7 @@ infix(INFIX *in, int parentPriority)
|
||||
}
|
||||
else if (in->curpol->qoperator.oper == OP_NOT)
|
||||
{
|
||||
int priority = PRINT_PRIORITY(in->curpol);
|
||||
int priority = PRINT_PRIORITY(in->curpol);
|
||||
|
||||
if (priority < parentPriority)
|
||||
{
|
||||
@@ -852,8 +852,9 @@ infix(INFIX *in, int parentPriority)
|
||||
in->curpol++;
|
||||
if (priority < parentPriority ||
|
||||
(op == OP_PHRASE &&
|
||||
(priority == parentPriority || /* phrases are not commutative! */
|
||||
parentPriority == OP_PRIORITY(OP_AND))))
|
||||
(priority == parentPriority || /* phrases are not
|
||||
* commutative! */
|
||||
parentPriority == OP_PRIORITY(OP_AND))))
|
||||
{
|
||||
needParenthesis = true;
|
||||
RESIZEBUF(in, 2);
|
||||
@@ -874,7 +875,7 @@ infix(INFIX *in, int parentPriority)
|
||||
infix(in, priority);
|
||||
|
||||
/* print operator & right operand */
|
||||
RESIZEBUF(in, 3 + (2 + 10 /* distance */) + (nrm.cur - nrm.buf));
|
||||
RESIZEBUF(in, 3 + (2 + 10 /* distance */ ) + (nrm.cur - nrm.buf));
|
||||
switch (op)
|
||||
{
|
||||
case OP_OR:
|
||||
@@ -923,7 +924,7 @@ tsqueryout(PG_FUNCTION_ARGS)
|
||||
nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
|
||||
*(nrm.cur) = '\0';
|
||||
nrm.op = GETOPERAND(query);
|
||||
infix(&nrm, -1 /* lowest priority */);
|
||||
infix(&nrm, -1 /* lowest priority */ );
|
||||
|
||||
PG_FREE_IF_COPY(query, 0);
|
||||
PG_RETURN_CSTRING(nrm.buf);
|
||||
@@ -989,16 +990,16 @@ tsquerysend(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
tsqueryrecv(PG_FUNCTION_ARGS)
|
||||
{
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
TSQuery query;
|
||||
int i,
|
||||
len;
|
||||
QueryItem *item;
|
||||
int datalen;
|
||||
char *ptr;
|
||||
uint32 size;
|
||||
const char **operands;
|
||||
bool needcleanup;
|
||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||
TSQuery query;
|
||||
int i,
|
||||
len;
|
||||
QueryItem *item;
|
||||
int datalen;
|
||||
char *ptr;
|
||||
uint32 size;
|
||||
const char **operands;
|
||||
bool needcleanup;
|
||||
|
||||
size = pq_getmsgint(buf, sizeof(uint32));
|
||||
if (size > (MaxAllocSize / sizeof(QueryItem)))
|
||||
|
@@ -224,8 +224,8 @@ clean_NOT(QueryItem *ptr, int *len)
|
||||
static NODE *
|
||||
clean_fakeval_intree(NODE *node, char *result, int *adddistance)
|
||||
{
|
||||
char lresult = V_UNKNOWN,
|
||||
rresult = V_UNKNOWN;
|
||||
char lresult = V_UNKNOWN,
|
||||
rresult = V_UNKNOWN;
|
||||
|
||||
/* since this function recurses, it could be driven to stack overflow. */
|
||||
check_stack_depth();
|
||||
@@ -256,24 +256,26 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance)
|
||||
}
|
||||
else
|
||||
{
|
||||
NODE *res = node;
|
||||
int ndistance, ldistance = 0, rdistance = 0;
|
||||
NODE *res = node;
|
||||
int ndistance,
|
||||
ldistance = 0,
|
||||
rdistance = 0;
|
||||
|
||||
ndistance = (node->valnode->qoperator.oper == OP_PHRASE) ?
|
||||
node->valnode->qoperator.distance :
|
||||
0;
|
||||
node->valnode->qoperator.distance :
|
||||
0;
|
||||
|
||||
node->left = clean_fakeval_intree(node->left,
|
||||
&lresult,
|
||||
ndistance ? &ldistance : NULL);
|
||||
node->left = clean_fakeval_intree(node->left,
|
||||
&lresult,
|
||||
ndistance ? &ldistance : NULL);
|
||||
|
||||
node->right = clean_fakeval_intree(node->right,
|
||||
&rresult,
|
||||
ndistance ? &rdistance : NULL);
|
||||
|
||||
/*
|
||||
* ndistance, ldistance and rdistance are greater than zero
|
||||
* if their corresponding nodes are OP_PHRASE
|
||||
* ndistance, ldistance and rdistance are greater than zero if their
|
||||
* corresponding nodes are OP_PHRASE
|
||||
*/
|
||||
|
||||
if (lresult == V_STOP && rresult == V_STOP)
|
||||
@@ -287,9 +289,10 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance)
|
||||
else if (lresult == V_STOP)
|
||||
{
|
||||
res = node->right;
|
||||
|
||||
/*
|
||||
* propagate distance from current node to the
|
||||
* right upper subtree.
|
||||
* propagate distance from current node to the right upper
|
||||
* subtree.
|
||||
*/
|
||||
if (adddistance && ndistance)
|
||||
*adddistance = rdistance;
|
||||
@@ -298,6 +301,7 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance)
|
||||
else if (rresult == V_STOP)
|
||||
{
|
||||
res = node->left;
|
||||
|
||||
/*
|
||||
* propagate distance from current node to the upper tree.
|
||||
*/
|
||||
@@ -324,7 +328,7 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance)
|
||||
static NODE *
|
||||
copyNODE(NODE *node)
|
||||
{
|
||||
NODE *cnode = palloc(sizeof(NODE));
|
||||
NODE *cnode = palloc(sizeof(NODE));
|
||||
|
||||
/* since this function recurses, it could be driven to stack overflow. */
|
||||
check_stack_depth();
|
||||
@@ -345,7 +349,7 @@ copyNODE(NODE *node)
|
||||
static NODE *
|
||||
makeNODE(int8 op, NODE *left, NODE *right)
|
||||
{
|
||||
NODE *node = palloc(sizeof(NODE));
|
||||
NODE *node = palloc(sizeof(NODE));
|
||||
|
||||
/* zeroing allocation to prevent difference in unused bytes */
|
||||
node->valnode = palloc0(sizeof(QueryItem));
|
||||
@@ -368,15 +372,15 @@ makeNODE(int8 op, NODE *left, NODE *right)
|
||||
* <-> (<n>) operation since it's needed solely for the phrase operator.
|
||||
*
|
||||
* Rules:
|
||||
* a <-> (b | c) => (a <-> b) | (a <-> c)
|
||||
* (a | b) <-> c => (a <-> c) | (b <-> c)
|
||||
* a <-> !b => a & !(a <-> b)
|
||||
* !a <-> b => b & !(a <-> b)
|
||||
* a <-> (b | c) => (a <-> b) | (a <-> c)
|
||||
* (a | b) <-> c => (a <-> c) | (b <-> c)
|
||||
* a <-> !b => a & !(a <-> b)
|
||||
* !a <-> b => b & !(a <-> b)
|
||||
*
|
||||
* Warnings for readers:
|
||||
* a <-> b != b <-> a
|
||||
*
|
||||
* a <n> (b <n> c) != (a <n> b) <n> c since the phrase lengths are:
|
||||
* a <n> (b <n> c) != (a <n> b) <n> c since the phrase lengths are:
|
||||
* n 2n-1
|
||||
*/
|
||||
static NODE *
|
||||
@@ -397,7 +401,7 @@ normalize_phrase_tree(NODE *node)
|
||||
{
|
||||
/* eliminate NOT sequence */
|
||||
while (node->valnode->type == QI_OPR &&
|
||||
node->valnode->qoperator.oper == node->right->valnode->qoperator.oper)
|
||||
node->valnode->qoperator.oper == node->right->valnode->qoperator.oper)
|
||||
{
|
||||
node = node->right->right;
|
||||
}
|
||||
@@ -406,19 +410,19 @@ normalize_phrase_tree(NODE *node)
|
||||
}
|
||||
else if (node->valnode->qoperator.oper == OP_PHRASE)
|
||||
{
|
||||
int16 distance;
|
||||
NODE *X;
|
||||
int16 distance;
|
||||
NODE *X;
|
||||
|
||||
node->left = normalize_phrase_tree(node->left);
|
||||
node->right = normalize_phrase_tree(node->right);
|
||||
|
||||
if (NODE_PRIORITY(node) <= NODE_PRIORITY(node->right) &&
|
||||
NODE_PRIORITY(node) <= NODE_PRIORITY(node->left))
|
||||
return node;
|
||||
return node;
|
||||
|
||||
/*
|
||||
* We can't swap left-right and works only with left child
|
||||
* because of a <-> b != b <-> a
|
||||
* We can't swap left-right and works only with left child because of
|
||||
* a <-> b != b <-> a
|
||||
*/
|
||||
|
||||
distance = node->valnode->qoperator.distance;
|
||||
@@ -464,8 +468,8 @@ normalize_phrase_tree(NODE *node)
|
||||
/* no-op */
|
||||
break;
|
||||
default:
|
||||
elog(ERROR,"Wrong type of tsquery node: %d",
|
||||
node->right->valnode->qoperator.oper);
|
||||
elog(ERROR, "Wrong type of tsquery node: %d",
|
||||
node->right->valnode->qoperator.oper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,10 +480,10 @@ normalize_phrase_tree(NODE *node)
|
||||
* if the node is still OP_PHRASE, check the left subtree,
|
||||
* otherwise the whole node will be transformed later.
|
||||
*/
|
||||
switch(node->left->valnode->qoperator.oper)
|
||||
switch (node->left->valnode->qoperator.oper)
|
||||
{
|
||||
case OP_AND:
|
||||
/* (a & b) <-> c => (a <-> c) & (b <-> c) */
|
||||
/* (a & b) <-> c => (a <-> c) & (b <-> c) */
|
||||
node = makeNODE(OP_AND,
|
||||
makeNODE(OP_PHRASE,
|
||||
node->left->left,
|
||||
@@ -515,15 +519,15 @@ normalize_phrase_tree(NODE *node)
|
||||
/* no-op */
|
||||
break;
|
||||
default:
|
||||
elog(ERROR,"Wrong type of tsquery node: %d",
|
||||
node->left->valnode->qoperator.oper);
|
||||
elog(ERROR, "Wrong type of tsquery node: %d",
|
||||
node->left->valnode->qoperator.oper);
|
||||
}
|
||||
}
|
||||
|
||||
/* continue transformation */
|
||||
node = normalize_phrase_tree(node);
|
||||
}
|
||||
else /* AND or OR */
|
||||
else /* AND or OR */
|
||||
{
|
||||
node->left = normalize_phrase_tree(node->left);
|
||||
node->right = normalize_phrase_tree(node->right);
|
||||
@@ -538,7 +542,7 @@ normalize_phrase_tree(NODE *node)
|
||||
static int32
|
||||
calcstrlen(NODE *node)
|
||||
{
|
||||
int32 size = 0;
|
||||
int32 size = 0;
|
||||
|
||||
if (node->valnode->type == QI_VAL)
|
||||
{
|
||||
|
@@ -147,10 +147,10 @@ Datum
|
||||
tsquery_phrase(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_RETURN_POINTER(DirectFunctionCall3(
|
||||
tsquery_phrase_distance,
|
||||
PG_GETARG_DATUM(0),
|
||||
PG_GETARG_DATUM(1),
|
||||
Int32GetDatum(1)));
|
||||
tsquery_phrase_distance,
|
||||
PG_GETARG_DATUM(0),
|
||||
PG_GETARG_DATUM(1),
|
||||
Int32GetDatum(1)));
|
||||
}
|
||||
|
||||
Datum
|
||||
|
@@ -366,8 +366,8 @@ calc_rank(const float *w, TSVector t, TSQuery q, int32 method)
|
||||
/* XXX: What about NOT? */
|
||||
res = (item->type == QI_OPR && (item->qoperator.oper == OP_AND ||
|
||||
item->qoperator.oper == OP_PHRASE)) ?
|
||||
calc_rank_and(w, t, q) :
|
||||
calc_rank_or(w, t, q);
|
||||
calc_rank_and(w, t, q) :
|
||||
calc_rank_or(w, t, q);
|
||||
|
||||
if (res < 0)
|
||||
res = 1e-20f;
|
||||
@@ -498,17 +498,21 @@ ts_rank_tt(PG_FUNCTION_ARGS)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union {
|
||||
struct { /* compiled doc representation */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{ /* compiled doc representation */
|
||||
QueryItem **items;
|
||||
int16 nitem;
|
||||
} query;
|
||||
struct { /* struct is used for preparing doc representation */
|
||||
} query;
|
||||
struct
|
||||
{ /* struct is used for preparing doc
|
||||
* representation */
|
||||
QueryItem *item;
|
||||
WordEntry *entry;
|
||||
} map;
|
||||
} data;
|
||||
WordEntryPos pos;
|
||||
} map;
|
||||
} data;
|
||||
WordEntryPos pos;
|
||||
} DocRepresentation;
|
||||
|
||||
static int
|
||||
@@ -536,16 +540,16 @@ compareDocR(const void *va, const void *vb)
|
||||
#define MAXQROPOS MAXENTRYPOS
|
||||
typedef struct
|
||||
{
|
||||
bool operandexists;
|
||||
bool reverseinsert; /* indicates insert order,
|
||||
true means descending order */
|
||||
uint32 npos;
|
||||
WordEntryPos pos[MAXQROPOS];
|
||||
bool operandexists;
|
||||
bool reverseinsert; /* indicates insert order, true means
|
||||
* descending order */
|
||||
uint32 npos;
|
||||
WordEntryPos pos[MAXQROPOS];
|
||||
} QueryRepresentationOperand;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TSQuery query;
|
||||
TSQuery query;
|
||||
QueryRepresentationOperand *operandData;
|
||||
} QueryRepresentation;
|
||||
|
||||
@@ -555,8 +559,8 @@ typedef struct
|
||||
static bool
|
||||
checkcondition_QueryOperand(void *checkval, QueryOperand *val, ExecPhraseData *data)
|
||||
{
|
||||
QueryRepresentation *qr = (QueryRepresentation *) checkval;
|
||||
QueryRepresentationOperand *opData = QR_GET_OPERAND_DATA(qr, val);
|
||||
QueryRepresentation *qr = (QueryRepresentation *) checkval;
|
||||
QueryRepresentationOperand *opData = QR_GET_OPERAND_DATA(qr, val);
|
||||
|
||||
if (!opData->operandexists)
|
||||
return false;
|
||||
@@ -584,9 +588,9 @@ typedef struct
|
||||
static void
|
||||
resetQueryRepresentation(QueryRepresentation *qr, bool reverseinsert)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < qr->query->size; i++)
|
||||
for (i = 0; i < qr->query->size; i++)
|
||||
{
|
||||
qr->operandData[i].operandexists = false;
|
||||
qr->operandData[i].reverseinsert = reverseinsert;
|
||||
@@ -597,8 +601,8 @@ resetQueryRepresentation(QueryRepresentation *qr, bool reverseinsert)
|
||||
static void
|
||||
fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry)
|
||||
{
|
||||
int i;
|
||||
int lastPos;
|
||||
int i;
|
||||
int lastPos;
|
||||
QueryRepresentationOperand *opData;
|
||||
|
||||
for (i = 0; i < entry->data.query.nitem; i++)
|
||||
@@ -619,14 +623,14 @@ fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry)
|
||||
}
|
||||
|
||||
lastPos = opData->reverseinsert ?
|
||||
(MAXQROPOS - opData->npos) :
|
||||
(opData->npos - 1);
|
||||
(MAXQROPOS - opData->npos) :
|
||||
(opData->npos - 1);
|
||||
|
||||
if (WEP_GETPOS(opData->pos[lastPos]) != WEP_GETPOS(entry->pos))
|
||||
{
|
||||
lastPos = opData->reverseinsert ?
|
||||
(MAXQROPOS - 1 - opData->npos) :
|
||||
(opData->npos);
|
||||
(MAXQROPOS - 1 - opData->npos) :
|
||||
(opData->npos);
|
||||
|
||||
opData->pos[lastPos] = entry->pos;
|
||||
opData->npos++;
|
||||
@@ -637,9 +641,9 @@ fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry)
|
||||
static bool
|
||||
Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext)
|
||||
{
|
||||
DocRepresentation *ptr;
|
||||
int lastpos = ext->pos;
|
||||
bool found = false;
|
||||
DocRepresentation *ptr;
|
||||
int lastpos = ext->pos;
|
||||
bool found = false;
|
||||
|
||||
/*
|
||||
* since this function recurses, it could be driven to stack overflow.
|
||||
@@ -720,7 +724,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
|
||||
WordEntry *entry,
|
||||
*firstentry;
|
||||
WordEntryPos *post;
|
||||
int32 dimt, /* number of 'post' items */
|
||||
int32 dimt, /* number of 'post' items */
|
||||
j,
|
||||
i,
|
||||
nitem;
|
||||
@@ -731,8 +735,8 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
|
||||
doc = (DocRepresentation *) palloc(sizeof(DocRepresentation) * len);
|
||||
|
||||
/*
|
||||
* Iterate through query to make DocRepresentaion for words and it's entries
|
||||
* satisfied by query
|
||||
* Iterate through query to make DocRepresentaion for words and it's
|
||||
* entries satisfied by query
|
||||
*/
|
||||
for (i = 0; i < qr->query->size; i++)
|
||||
{
|
||||
@@ -787,9 +791,9 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
|
||||
|
||||
if (cur > 0)
|
||||
{
|
||||
DocRepresentation *rptr = doc + 1,
|
||||
*wptr = doc,
|
||||
storage;
|
||||
DocRepresentation *rptr = doc + 1,
|
||||
*wptr = doc,
|
||||
storage;
|
||||
|
||||
/*
|
||||
* Sort representation in ascending order by pos and entry
|
||||
@@ -806,8 +810,8 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
|
||||
|
||||
while (rptr - doc < cur)
|
||||
{
|
||||
if (rptr->pos == (rptr-1)->pos &&
|
||||
rptr->data.map.entry == (rptr-1)->data.map.entry)
|
||||
if (rptr->pos == (rptr - 1)->pos &&
|
||||
rptr->data.map.entry == (rptr - 1)->data.map.entry)
|
||||
{
|
||||
storage.data.query.items[storage.data.query.nitem] = rptr->data.map.item;
|
||||
storage.data.query.nitem++;
|
||||
@@ -865,7 +869,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method)
|
||||
|
||||
qr.query = query;
|
||||
qr.operandData = (QueryRepresentationOperand *)
|
||||
palloc0(sizeof(QueryRepresentationOperand) * query->size);
|
||||
palloc0(sizeof(QueryRepresentationOperand) * query->size);
|
||||
|
||||
doc = get_docrep(txt, &qr, &doclen);
|
||||
if (!doc)
|
||||
|
@@ -66,7 +66,7 @@ typedef struct
|
||||
#define STATHDRSIZE (offsetof(TSVectorStat, data))
|
||||
|
||||
static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column);
|
||||
static int tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len);
|
||||
static int tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len);
|
||||
|
||||
/*
|
||||
* Order: haspos, len, word, for all positions (pos, weight)
|
||||
@@ -276,16 +276,20 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
|
||||
|
||||
switch (char_weight)
|
||||
{
|
||||
case 'A': case 'a':
|
||||
case 'A':
|
||||
case 'a':
|
||||
weight = 3;
|
||||
break;
|
||||
case 'B': case 'b':
|
||||
case 'B':
|
||||
case 'b':
|
||||
weight = 2;
|
||||
break;
|
||||
case 'C': case 'c':
|
||||
case 'C':
|
||||
case 'c':
|
||||
weight = 1;
|
||||
break;
|
||||
case 'D': case 'd':
|
||||
case 'D':
|
||||
case 'd':
|
||||
weight = 0;
|
||||
break;
|
||||
default:
|
||||
@@ -301,15 +305,15 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
|
||||
&dlexemes, &nulls, &nlexemes);
|
||||
|
||||
/*
|
||||
* Assuming that lexemes array is significantly shorter than tsvector
|
||||
* we can iterate through lexemes performing binary search
|
||||
* of each lexeme from lexemes in tsvector.
|
||||
* Assuming that lexemes array is significantly shorter than tsvector we
|
||||
* can iterate through lexemes performing binary search of each lexeme
|
||||
* from lexemes in tsvector.
|
||||
*/
|
||||
for (i = 0; i < nlexemes; i++)
|
||||
{
|
||||
char *lex;
|
||||
int lex_len,
|
||||
lex_pos;
|
||||
char *lex;
|
||||
int lex_len,
|
||||
lex_pos;
|
||||
|
||||
if (nulls[i])
|
||||
ereport(ERROR,
|
||||
@@ -323,6 +327,7 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS)
|
||||
if (lex_pos >= 0 && (j = POSDATALEN(tsout, entry + lex_pos)) != 0)
|
||||
{
|
||||
WordEntryPos *p = POSDATAPTR(tsout, entry + lex_pos);
|
||||
|
||||
while (j--)
|
||||
{
|
||||
WEP_SETWEIGHT(*p, weight);
|
||||
@@ -393,18 +398,18 @@ tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len)
|
||||
|
||||
while (StopLow < StopHigh)
|
||||
{
|
||||
StopMiddle = (StopLow + StopHigh)/2;
|
||||
StopMiddle = (StopLow + StopHigh) / 2;
|
||||
|
||||
cmp = tsCompareString(lexeme, lexeme_len,
|
||||
STRPTR(tsv) + arrin[StopMiddle].pos,
|
||||
arrin[StopMiddle].len,
|
||||
false);
|
||||
STRPTR(tsv) + arrin[StopMiddle].pos,
|
||||
arrin[StopMiddle].len,
|
||||
false);
|
||||
|
||||
if (cmp < 0)
|
||||
StopHigh = StopMiddle;
|
||||
else if (cmp > 0)
|
||||
StopLow = StopMiddle + 1;
|
||||
else /* found it */
|
||||
else /* found it */
|
||||
return StopMiddle;
|
||||
}
|
||||
|
||||
@@ -440,13 +445,15 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete,
|
||||
*arrout;
|
||||
char *data = STRPTR(tsv),
|
||||
*dataout;
|
||||
int i, j, k,
|
||||
int i,
|
||||
j,
|
||||
k,
|
||||
curoff;
|
||||
|
||||
/*
|
||||
* Here we overestimates tsout size, since we don't know exact size
|
||||
* occupied by positions and weights. We will set exact size later
|
||||
* after a pass through TSVector.
|
||||
* occupied by positions and weights. We will set exact size later after a
|
||||
* pass through TSVector.
|
||||
*/
|
||||
tsout = (TSVector) palloc0(VARSIZE(tsv));
|
||||
arrout = ARRPTR(tsout);
|
||||
@@ -465,10 +472,11 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete,
|
||||
{
|
||||
/*
|
||||
* Here we should check whether current i is present in
|
||||
* indices_to_delete or not. Since indices_to_delete is already
|
||||
* sorted we can advance it index only when we have match.
|
||||
* indices_to_delete or not. Since indices_to_delete is already sorted
|
||||
* we can advance it index only when we have match.
|
||||
*/
|
||||
if (k < indices_count && i == indices_to_delete[k]){
|
||||
if (k < indices_count && i == indices_to_delete[k])
|
||||
{
|
||||
k++;
|
||||
continue;
|
||||
}
|
||||
@@ -481,8 +489,9 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete,
|
||||
curoff += arrin[i].len;
|
||||
if (arrin[i].haspos)
|
||||
{
|
||||
int len = POSDATALEN(tsv, arrin+i) * sizeof(WordEntryPos) +
|
||||
sizeof(uint16);
|
||||
int len = POSDATALEN(tsv, arrin + i) * sizeof(WordEntryPos) +
|
||||
sizeof(uint16);
|
||||
|
||||
curoff = SHORTALIGN(curoff);
|
||||
memcpy(dataout + curoff,
|
||||
STRPTR(tsv) + SHORTALIGN(arrin[i].pos + arrin[i].len),
|
||||
@@ -494,9 +503,10 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete,
|
||||
}
|
||||
|
||||
/*
|
||||
* After the pass through TSVector k should equals exactly to indices_count.
|
||||
* If it isn't then the caller provided us with indices outside of
|
||||
* [0, tsv->size) range and estimation of tsout's size is wrong.
|
||||
* After the pass through TSVector k should equals exactly to
|
||||
* indices_count. If it isn't then the caller provided us with indices
|
||||
* outside of [0, tsv->size) range and estimation of tsout's size is
|
||||
* wrong.
|
||||
*/
|
||||
Assert(k == indices_count);
|
||||
|
||||
@@ -538,7 +548,8 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
|
||||
TSVector tsin = PG_GETARG_TSVECTOR(0),
|
||||
tsout;
|
||||
ArrayType *lexemes = PG_GETARG_ARRAYTYPE_P(1);
|
||||
int i, nlex,
|
||||
int i,
|
||||
nlex,
|
||||
skip_count,
|
||||
*skip_indices;
|
||||
Datum *dlexemes;
|
||||
@@ -548,16 +559,16 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
|
||||
&dlexemes, &nulls, &nlex);
|
||||
|
||||
/*
|
||||
* In typical use case array of lexemes to delete is relatively small.
|
||||
* So here we optimizing things for that scenario: iterate through lexarr
|
||||
* In typical use case array of lexemes to delete is relatively small. So
|
||||
* here we optimizing things for that scenario: iterate through lexarr
|
||||
* performing binary search of each lexeme from lexarr in tsvector.
|
||||
*/
|
||||
skip_indices = palloc0(nlex * sizeof(int));
|
||||
for (i = skip_count = 0; i < nlex; i++)
|
||||
{
|
||||
char *lex;
|
||||
int lex_len,
|
||||
lex_pos;
|
||||
char *lex;
|
||||
int lex_len,
|
||||
lex_pos;
|
||||
|
||||
if (nulls[i])
|
||||
ereport(ERROR,
|
||||
@@ -583,15 +594,15 @@ tsvector_delete_arr(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* Expand tsvector as table with following columns:
|
||||
* lexeme: lexeme text
|
||||
* positions: integer array of lexeme positions
|
||||
* weights: char array of weights corresponding to positions
|
||||
* lexeme: lexeme text
|
||||
* positions: integer array of lexeme positions
|
||||
* weights: char array of weights corresponding to positions
|
||||
*/
|
||||
Datum
|
||||
tsvector_unnest(PG_FUNCTION_ARGS)
|
||||
{
|
||||
FuncCallContext *funcctx;
|
||||
TSVector tsin;
|
||||
FuncCallContext *funcctx;
|
||||
TSVector tsin;
|
||||
|
||||
if (SRF_IS_FIRSTCALL())
|
||||
{
|
||||
@@ -629,8 +640,8 @@ tsvector_unnest(PG_FUNCTION_ARGS)
|
||||
Datum values[3];
|
||||
|
||||
values[0] = PointerGetDatum(
|
||||
cstring_to_text_with_len(data + arrin[i].pos, arrin[i].len)
|
||||
);
|
||||
cstring_to_text_with_len(data + arrin[i].pos, arrin[i].len)
|
||||
);
|
||||
|
||||
if (arrin[i].haspos)
|
||||
{
|
||||
@@ -641,25 +652,25 @@ tsvector_unnest(PG_FUNCTION_ARGS)
|
||||
|
||||
/*
|
||||
* Internally tsvector stores position and weight in the same
|
||||
* uint16 (2 bits for weight, 14 for position). Here we extract that
|
||||
* in two separate arrays.
|
||||
* uint16 (2 bits for weight, 14 for position). Here we extract
|
||||
* that in two separate arrays.
|
||||
*/
|
||||
posv = _POSVECPTR(tsin, arrin + i);
|
||||
positions = palloc(posv->npos * sizeof(Datum));
|
||||
weights = palloc(posv->npos * sizeof(Datum));
|
||||
weights = palloc(posv->npos * sizeof(Datum));
|
||||
for (j = 0; j < posv->npos; j++)
|
||||
{
|
||||
positions[j] = Int16GetDatum(WEP_GETPOS(posv->pos[j]));
|
||||
weight = 'D' - WEP_GETWEIGHT(posv->pos[j]);
|
||||
weights[j] = PointerGetDatum(
|
||||
cstring_to_text_with_len(&weight, 1)
|
||||
);
|
||||
cstring_to_text_with_len(&weight, 1)
|
||||
);
|
||||
}
|
||||
|
||||
values[1] = PointerGetDatum(
|
||||
construct_array(positions, posv->npos, INT2OID, 2, true, 's'));
|
||||
construct_array(positions, posv->npos, INT2OID, 2, true, 's'));
|
||||
values[2] = PointerGetDatum(
|
||||
construct_array(weights, posv->npos, TEXTOID, -1, false, 'i'));
|
||||
construct_array(weights, posv->npos, TEXTOID, -1, false, 'i'));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -682,19 +693,19 @@ tsvector_unnest(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
tsvector_to_array(PG_FUNCTION_ARGS)
|
||||
{
|
||||
TSVector tsin = PG_GETARG_TSVECTOR(0);
|
||||
WordEntry *arrin = ARRPTR(tsin);
|
||||
Datum *elements;
|
||||
int i;
|
||||
ArrayType *array;
|
||||
TSVector tsin = PG_GETARG_TSVECTOR(0);
|
||||
WordEntry *arrin = ARRPTR(tsin);
|
||||
Datum *elements;
|
||||
int i;
|
||||
ArrayType *array;
|
||||
|
||||
elements = palloc(tsin->size * sizeof(Datum));
|
||||
|
||||
for (i = 0; i < tsin->size; i++)
|
||||
{
|
||||
elements[i] = PointerGetDatum(
|
||||
cstring_to_text_with_len(STRPTR(tsin) + arrin[i].pos, arrin[i].len)
|
||||
);
|
||||
cstring_to_text_with_len(STRPTR(tsin) + arrin[i].pos, arrin[i].len)
|
||||
);
|
||||
}
|
||||
|
||||
array = construct_array(elements, tsin->size, TEXTOID, -1, false, 'i');
|
||||
@@ -742,8 +753,8 @@ array_to_tsvector(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; i < nitems; i++)
|
||||
{
|
||||
char *lex = VARDATA(dlexemes[i]);
|
||||
int lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]);
|
||||
char *lex = VARDATA(dlexemes[i]);
|
||||
int lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]);
|
||||
|
||||
memcpy(cur, lex, lex_len);
|
||||
arrout[i].haspos = 0;
|
||||
@@ -772,7 +783,8 @@ tsvector_filter(PG_FUNCTION_ARGS)
|
||||
Datum *dweights;
|
||||
bool *nulls;
|
||||
int nweights;
|
||||
int i, j;
|
||||
int i,
|
||||
j;
|
||||
int cur_pos = 0;
|
||||
char mask = 0;
|
||||
|
||||
@@ -781,7 +793,7 @@ tsvector_filter(PG_FUNCTION_ARGS)
|
||||
|
||||
for (i = 0; i < nweights; i++)
|
||||
{
|
||||
char char_weight;
|
||||
char char_weight;
|
||||
|
||||
if (nulls[i])
|
||||
ereport(ERROR,
|
||||
@@ -791,22 +803,26 @@ tsvector_filter(PG_FUNCTION_ARGS)
|
||||
char_weight = DatumGetChar(dweights[i]);
|
||||
switch (char_weight)
|
||||
{
|
||||
case 'A': case 'a':
|
||||
case 'A':
|
||||
case 'a':
|
||||
mask = mask | 8;
|
||||
break;
|
||||
case 'B': case 'b':
|
||||
case 'B':
|
||||
case 'b':
|
||||
mask = mask | 4;
|
||||
break;
|
||||
case 'C': case 'c':
|
||||
case 'C':
|
||||
case 'c':
|
||||
mask = mask | 2;
|
||||
break;
|
||||
case 'D': case 'd':
|
||||
case 'D':
|
||||
case 'd':
|
||||
mask = mask | 1;
|
||||
break;
|
||||
default:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized weight: \"%c\"", char_weight)));
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized weight: \"%c\"", char_weight)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,16 +834,16 @@ tsvector_filter(PG_FUNCTION_ARGS)
|
||||
for (i = j = 0; i < tsin->size; i++)
|
||||
{
|
||||
WordEntryPosVector *posvin,
|
||||
*posvout;
|
||||
int npos = 0;
|
||||
int k;
|
||||
*posvout;
|
||||
int npos = 0;
|
||||
int k;
|
||||
|
||||
if (!arrin[i].haspos)
|
||||
continue;
|
||||
|
||||
posvin = _POSVECPTR(tsin, arrin + i);
|
||||
posvin = _POSVECPTR(tsin, arrin + i);
|
||||
posvout = (WordEntryPosVector *)
|
||||
(dataout + SHORTALIGN(cur_pos + arrin[i].len));
|
||||
(dataout + SHORTALIGN(cur_pos + arrin[i].len));
|
||||
|
||||
for (k = 0; k < posvin->npos; k++)
|
||||
{
|
||||
@@ -846,8 +862,8 @@ tsvector_filter(PG_FUNCTION_ARGS)
|
||||
memcpy(dataout + cur_pos, datain + arrin[i].pos, arrin[i].len);
|
||||
posvout->npos = npos;
|
||||
cur_pos += SHORTALIGN(arrin[i].len);
|
||||
cur_pos += POSDATALEN(tsout, arrout+j) * sizeof(WordEntryPos) +
|
||||
sizeof(uint16);
|
||||
cur_pos += POSDATALEN(tsout, arrout + j) * sizeof(WordEntryPos) +
|
||||
sizeof(uint16);
|
||||
j++;
|
||||
}
|
||||
|
||||
@@ -1129,11 +1145,11 @@ static bool
|
||||
checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val,
|
||||
ExecPhraseData *data)
|
||||
{
|
||||
bool result = false;
|
||||
bool result = false;
|
||||
|
||||
if (entry->haspos && (val->weight || data))
|
||||
{
|
||||
WordEntryPosVector *posvec;
|
||||
WordEntryPosVector *posvec;
|
||||
|
||||
/*
|
||||
* We can't use the _POSVECPTR macro here because the pointer to the
|
||||
@@ -1144,8 +1160,8 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val,
|
||||
|
||||
if (val->weight && data)
|
||||
{
|
||||
WordEntryPos *posvec_iter = posvec->pos;
|
||||
WordEntryPos *dptr;
|
||||
WordEntryPos *posvec_iter = posvec->pos;
|
||||
WordEntryPos *dptr;
|
||||
|
||||
/*
|
||||
* Filter position information by weights
|
||||
@@ -1173,7 +1189,7 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val,
|
||||
}
|
||||
else if (val->weight)
|
||||
{
|
||||
WordEntryPos *posvec_iter = posvec->pos;
|
||||
WordEntryPos *posvec_iter = posvec->pos;
|
||||
|
||||
/* Is there a position with a matching weight? */
|
||||
while (posvec_iter < posvec->pos + posvec->npos)
|
||||
@@ -1181,16 +1197,16 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val,
|
||||
if (val->weight & (1 << WEP_GETWEIGHT(*posvec_iter)))
|
||||
{
|
||||
result = true;
|
||||
break; /* no need to go further */
|
||||
break; /* no need to go further */
|
||||
}
|
||||
|
||||
posvec_iter++;
|
||||
}
|
||||
}
|
||||
else /* data != NULL */
|
||||
else /* data != NULL */
|
||||
{
|
||||
data->npos = posvec->npos;
|
||||
data->pos = posvec->pos;
|
||||
data->pos = posvec->pos;
|
||||
data->allocated = false;
|
||||
result = true;
|
||||
}
|
||||
@@ -1213,7 +1229,7 @@ static int
|
||||
uniqueLongPos(WordEntryPos *pos, int npos)
|
||||
{
|
||||
WordEntryPos *pos_iter,
|
||||
*result;
|
||||
*result;
|
||||
|
||||
if (npos <= 1)
|
||||
return npos;
|
||||
@@ -1273,9 +1289,10 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data)
|
||||
|
||||
if ((!res || data) && val->prefix)
|
||||
{
|
||||
WordEntryPos *allpos = NULL;
|
||||
int npos = 0,
|
||||
totalpos = 0;
|
||||
WordEntryPos *allpos = NULL;
|
||||
int npos = 0,
|
||||
totalpos = 0;
|
||||
|
||||
/*
|
||||
* there was a failed exact search, so we should scan further to find
|
||||
* a prefix match. We also need to do so if caller needs position info
|
||||
@@ -1355,11 +1372,11 @@ TS_phrase_execute(QueryItem *curitem,
|
||||
}
|
||||
else
|
||||
{
|
||||
ExecPhraseData Ldata = {0, false, NULL},
|
||||
Rdata = {0, false, NULL};
|
||||
WordEntryPos *Lpos,
|
||||
*Rpos,
|
||||
*pos_iter = NULL;
|
||||
ExecPhraseData Ldata = {0, false, NULL},
|
||||
Rdata = {0, false, NULL};
|
||||
WordEntryPos *Lpos,
|
||||
*Rpos,
|
||||
*pos_iter = NULL;
|
||||
|
||||
Assert(curitem->qoperator.oper == OP_PHRASE);
|
||||
|
||||
@@ -1371,22 +1388,24 @@ TS_phrase_execute(QueryItem *curitem,
|
||||
return false;
|
||||
|
||||
/*
|
||||
* if at least one of the operands has no position
|
||||
* information, fallback to AND operation.
|
||||
* if at least one of the operands has no position information,
|
||||
* fallback to AND operation.
|
||||
*/
|
||||
if (Ldata.npos == 0 || Rdata.npos == 0)
|
||||
return true;
|
||||
|
||||
/*
|
||||
* Result of the operation is a list of the
|
||||
* corresponding positions of RIGHT operand.
|
||||
* Result of the operation is a list of the corresponding positions of
|
||||
* RIGHT operand.
|
||||
*/
|
||||
if (data)
|
||||
{
|
||||
if (!Rdata.allocated)
|
||||
|
||||
/*
|
||||
* OP_PHRASE is based on the OP_AND, so the number of resulting
|
||||
* positions could not be greater than the total amount of operands.
|
||||
* OP_PHRASE is based on the OP_AND, so the number of
|
||||
* resulting positions could not be greater than the total
|
||||
* amount of operands.
|
||||
*/
|
||||
data->pos = palloc(sizeof(WordEntryPos) * Min(Ldata.npos, Rdata.npos));
|
||||
else
|
||||
@@ -1423,8 +1442,8 @@ TS_phrase_execute(QueryItem *curitem,
|
||||
*pos_iter = WEP_GETPOS(*Rpos);
|
||||
pos_iter++;
|
||||
|
||||
break; /* We need to build a unique result
|
||||
* array, so go to the next Rpos */
|
||||
break; /* We need to build a unique result
|
||||
* array, so go to the next Rpos */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1439,8 +1458,8 @@ TS_phrase_execute(QueryItem *curitem,
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Go to the next Rpos, because Lpos
|
||||
* is ahead of the current Rpos
|
||||
* Go to the next Rpos, because Lpos is ahead of the
|
||||
* current Rpos
|
||||
*/
|
||||
break;
|
||||
}
|
||||
@@ -1477,14 +1496,14 @@ TS_phrase_execute(QueryItem *curitem,
|
||||
*/
|
||||
bool
|
||||
TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
|
||||
bool (*chkcond) (void *checkval, QueryOperand *val, ExecPhraseData *data))
|
||||
bool (*chkcond) (void *checkval, QueryOperand *val, ExecPhraseData *data))
|
||||
{
|
||||
/* since this function recurses, it could be driven to stack overflow */
|
||||
check_stack_depth();
|
||||
|
||||
if (curitem->type == QI_VAL)
|
||||
return chkcond(checkval, (QueryOperand *) curitem,
|
||||
NULL /* we don't need position info */);
|
||||
NULL /* we don't need position info */ );
|
||||
|
||||
switch (curitem->qoperator.oper)
|
||||
{
|
||||
@@ -1546,6 +1565,7 @@ tsquery_requires_match(QueryItem *curitem)
|
||||
return false;
|
||||
|
||||
case OP_PHRASE:
|
||||
|
||||
/*
|
||||
* Treat OP_PHRASE as OP_AND here
|
||||
*/
|
||||
@@ -1972,7 +1992,7 @@ ts_stat_sql(MemoryContext persistentContext, text *txt, text *ws)
|
||||
if (SPI_tuptable == NULL ||
|
||||
SPI_tuptable->tupdesc->natts != 1 ||
|
||||
!IsBinaryCoercible(SPI_gettypeid(SPI_tuptable->tupdesc, 1),
|
||||
TSVECTOROID))
|
||||
TSVECTOROID))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("ts_stat query must return one tsvector column")));
|
||||
@@ -2160,7 +2180,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
|
||||
errmsg("tsvector column \"%s\" does not exist",
|
||||
trigger->tgargs[0])));
|
||||
if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, tsvector_attr_num),
|
||||
TSVECTOROID))
|
||||
TSVECTOROID))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("column \"%s\" is not of tsvector type",
|
||||
@@ -2178,7 +2198,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
|
||||
errmsg("configuration column \"%s\" does not exist",
|
||||
trigger->tgargs[1])));
|
||||
if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, config_attr_num),
|
||||
REGCONFIGOID))
|
||||
REGCONFIGOID))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATATYPE_MISMATCH),
|
||||
errmsg("column \"%s\" is not of regconfig type",
|
||||
|
@@ -44,8 +44,8 @@ static void string_to_uuid(const char *source, pg_uuid_t *uuid);
|
||||
static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2);
|
||||
static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup);
|
||||
static int uuid_cmp_abbrev(Datum x, Datum y, SortSupport ssup);
|
||||
static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup);
|
||||
static Datum uuid_abbrev_convert(Datum original, SortSupport ssup);
|
||||
static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup);
|
||||
static Datum uuid_abbrev_convert(Datum original, SortSupport ssup);
|
||||
|
||||
Datum
|
||||
uuid_in(PG_FUNCTION_ARGS)
|
||||
@@ -245,15 +245,15 @@ uuid_cmp(PG_FUNCTION_ARGS)
|
||||
Datum
|
||||
uuid_sortsupport(PG_FUNCTION_ARGS)
|
||||
{
|
||||
SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
|
||||
SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0);
|
||||
|
||||
ssup->comparator = uuid_fast_cmp;
|
||||
ssup->ssup_extra = NULL;
|
||||
|
||||
if (ssup->abbreviate)
|
||||
{
|
||||
uuid_sortsupport_state *uss;
|
||||
MemoryContext oldcontext;
|
||||
uuid_sortsupport_state *uss;
|
||||
MemoryContext oldcontext;
|
||||
|
||||
oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt);
|
||||
|
||||
@@ -310,8 +310,8 @@ uuid_cmp_abbrev(Datum x, Datum y, SortSupport ssup)
|
||||
static bool
|
||||
uuid_abbrev_abort(int memtupcount, SortSupport ssup)
|
||||
{
|
||||
uuid_sortsupport_state *uss = ssup->ssup_extra;
|
||||
double abbr_card;
|
||||
uuid_sortsupport_state *uss = ssup->ssup_extra;
|
||||
double abbr_card;
|
||||
|
||||
if (memtupcount < 10000 || uss->input_count < 10000 || !uss->estimating)
|
||||
return false;
|
||||
@@ -340,8 +340,8 @@ uuid_abbrev_abort(int memtupcount, SortSupport ssup)
|
||||
/*
|
||||
* Target minimum cardinality is 1 per ~2k of non-null inputs. 0.5 row
|
||||
* fudge factor allows us to abort earlier on genuinely pathological data
|
||||
* where we've had exactly one abbreviated value in the first 2k (non-null)
|
||||
* rows.
|
||||
* where we've had exactly one abbreviated value in the first 2k
|
||||
* (non-null) rows.
|
||||
*/
|
||||
if (abbr_card < uss->input_count / 2000.0 + 0.5)
|
||||
{
|
||||
@@ -349,7 +349,7 @@ uuid_abbrev_abort(int memtupcount, SortSupport ssup)
|
||||
if (trace_sort)
|
||||
elog(LOG,
|
||||
"uuid_abbrev: aborting abbreviation at cardinality %f"
|
||||
" below threshold %f after " INT64_FORMAT " values (%d rows)",
|
||||
" below threshold %f after " INT64_FORMAT " values (%d rows)",
|
||||
abbr_card, uss->input_count / 2000.0 + 0.5, uss->input_count,
|
||||
memtupcount);
|
||||
#endif
|
||||
@@ -376,9 +376,9 @@ uuid_abbrev_abort(int memtupcount, SortSupport ssup)
|
||||
static Datum
|
||||
uuid_abbrev_convert(Datum original, SortSupport ssup)
|
||||
{
|
||||
uuid_sortsupport_state *uss = ssup->ssup_extra;
|
||||
pg_uuid_t *authoritative = DatumGetUUIDP(original);
|
||||
Datum res;
|
||||
uuid_sortsupport_state *uss = ssup->ssup_extra;
|
||||
pg_uuid_t *authoritative = DatumGetUUIDP(original);
|
||||
Datum res;
|
||||
|
||||
memcpy(&res, authoritative->data, sizeof(Datum));
|
||||
uss->input_count += 1;
|
||||
@@ -400,9 +400,9 @@ uuid_abbrev_convert(Datum original, SortSupport ssup)
|
||||
* Byteswap on little-endian machines.
|
||||
*
|
||||
* This is needed so that uuid_cmp_abbrev() (an unsigned integer 3-way
|
||||
* comparator) works correctly on all platforms. If we didn't do this, the
|
||||
* comparator would have to call memcmp() with a pair of pointers to the
|
||||
* first byte of each abbreviated key, which is slower.
|
||||
* comparator) works correctly on all platforms. If we didn't do this,
|
||||
* the comparator would have to call memcmp() with a pair of pointers to
|
||||
* the first byte of each abbreviated key, which is slower.
|
||||
*/
|
||||
res = DatumBigEndianToNative(res);
|
||||
|
||||
|
@@ -5055,9 +5055,9 @@ text_format(PG_FUNCTION_ARGS)
|
||||
/* should not get here, because of previous check */
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("unrecognized format() type specifier \"%c\"",
|
||||
*cp),
|
||||
errhint("For a single \"%%\" use \"%%%%\".")));
|
||||
errmsg("unrecognized format() type specifier \"%c\"",
|
||||
*cp),
|
||||
errhint("For a single \"%%\" use \"%%%%\".")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user