Commit bf50caf1 authored by Bruce Momjian's avatar Bruce Momjian

pgindent run before PG 9.1 beta 1.

parent 9a8b7314
...@@ -78,18 +78,19 @@ convert_and_check_filename(text *arg, bool logAllowed) ...@@ -78,18 +78,19 @@ convert_and_check_filename(text *arg, bool logAllowed)
/* Disallow '/a/b/data/..' */ /* Disallow '/a/b/data/..' */
if (path_contains_parent_reference(filename)) if (path_contains_parent_reference(filename))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("reference to parent directory (\"..\") not allowed")))); (errmsg("reference to parent directory (\"..\") not allowed"))));
/* /*
* Allow absolute paths if within DataDir or Log_directory, even * Allow absolute paths if within DataDir or Log_directory, even
* though Log_directory might be outside DataDir. * though Log_directory might be outside DataDir.
*/ */
if (!path_is_prefix_of_path(DataDir, filename) && if (!path_is_prefix_of_path(DataDir, filename) &&
(!logAllowed || !is_absolute_path(Log_directory) || (!logAllowed || !is_absolute_path(Log_directory) ||
!path_is_prefix_of_path(Log_directory, filename))) !path_is_prefix_of_path(Log_directory, filename)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("absolute path not allowed")))); (errmsg("absolute path not allowed"))));
} }
else if (!path_is_relative_and_below_cwd(filename)) else if (!path_is_relative_and_below_cwd(filename))
ereport(ERROR, ereport(ERROR,
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
PG_MODULE_MAGIC; PG_MODULE_MAGIC;
void _PG_init(void); void _PG_init(void);
/* GUC Variables */ /* GUC Variables */
static int auth_delay_milliseconds; static int auth_delay_milliseconds;
/* Original Hook */ /* Original Hook */
static ClientAuthentication_hook_type original_client_auth_hook = NULL; static ClientAuthentication_hook_type original_client_auth_hook = NULL;
/* /*
* Check authentication * Check authentication
...@@ -55,7 +55,7 @@ _PG_init(void) ...@@ -55,7 +55,7 @@ _PG_init(void)
{ {
/* Define custom GUC variables */ /* Define custom GUC variables */
DefineCustomIntVariable("auth_delay.milliseconds", DefineCustomIntVariable("auth_delay.milliseconds",
"Milliseconds to delay before reporting authentication failure", "Milliseconds to delay before reporting authentication failure",
NULL, NULL,
&auth_delay_milliseconds, &auth_delay_milliseconds,
0, 0,
......
...@@ -169,7 +169,7 @@ gbt_cash_distance(PG_FUNCTION_ARGS) ...@@ -169,7 +169,7 @@ gbt_cash_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -90,9 +90,9 @@ static float8 ...@@ -90,9 +90,9 @@ static float8
gdb_date_dist(const void *a, const void *b) gdb_date_dist(const void *a, const void *b)
{ {
/* we assume the difference can't overflow */ /* we assume the difference can't overflow */
Datum diff = DirectFunctionCall2(date_mi, Datum diff = DirectFunctionCall2(date_mi,
DateADTGetDatum(*((const DateADT *) a)), DateADTGetDatum(*((const DateADT *) a)),
DateADTGetDatum(*((const DateADT *) b))); DateADTGetDatum(*((const DateADT *) b)));
return (float8) Abs(DatumGetInt32(diff)); return (float8) Abs(DatumGetInt32(diff));
} }
...@@ -113,14 +113,14 @@ static const gbtree_ninfo tinfo = ...@@ -113,14 +113,14 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(date_dist); PG_FUNCTION_INFO_V1(date_dist);
Datum date_dist(PG_FUNCTION_ARGS); Datum date_dist(PG_FUNCTION_ARGS);
Datum Datum
date_dist(PG_FUNCTION_ARGS) date_dist(PG_FUNCTION_ARGS)
{ {
/* we assume the difference can't overflow */ /* we assume the difference can't overflow */
Datum diff = DirectFunctionCall2(date_mi, Datum diff = DirectFunctionCall2(date_mi,
PG_GETARG_DATUM(0), PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1)); PG_GETARG_DATUM(1));
PG_RETURN_INT32(Abs(DatumGetInt32(diff))); PG_RETURN_INT32(Abs(DatumGetInt32(diff)));
} }
...@@ -181,7 +181,7 @@ gbt_date_distance(PG_FUNCTION_ARGS) ...@@ -181,7 +181,7 @@ gbt_date_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -94,18 +94,18 @@ static const gbtree_ninfo tinfo = ...@@ -94,18 +94,18 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(float4_dist); PG_FUNCTION_INFO_V1(float4_dist);
Datum float4_dist(PG_FUNCTION_ARGS); Datum float4_dist(PG_FUNCTION_ARGS);
Datum Datum
float4_dist(PG_FUNCTION_ARGS) float4_dist(PG_FUNCTION_ARGS)
{ {
float4 a = PG_GETARG_FLOAT4(0); float4 a = PG_GETARG_FLOAT4(0);
float4 b = PG_GETARG_FLOAT4(1); float4 b = PG_GETARG_FLOAT4(1);
float4 r; float4 r;
r = a - b; r = a - b;
CHECKFLOATVAL(r, isinf(a) || isinf(b), true); CHECKFLOATVAL(r, isinf(a) || isinf(b), true);
PG_RETURN_FLOAT4( Abs(r) ); PG_RETURN_FLOAT4(Abs(r));
} }
...@@ -162,7 +162,7 @@ gbt_float4_distance(PG_FUNCTION_ARGS) ...@@ -162,7 +162,7 @@ gbt_float4_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -76,8 +76,8 @@ gbt_float8key_cmp(const void *a, const void *b) ...@@ -76,8 +76,8 @@ gbt_float8key_cmp(const void *a, const void *b)
static float8 static float8
gbt_float8_dist(const void *a, const void *b) gbt_float8_dist(const void *a, const void *b)
{ {
float8 arg1 = *(const float8 *)a; float8 arg1 = *(const float8 *) a;
float8 arg2 = *(const float8 *)b; float8 arg2 = *(const float8 *) b;
float8 r; float8 r;
r = arg1 - arg2; r = arg1 - arg2;
...@@ -102,7 +102,7 @@ static const gbtree_ninfo tinfo = ...@@ -102,7 +102,7 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(float8_dist); PG_FUNCTION_INFO_V1(float8_dist);
Datum float8_dist(PG_FUNCTION_ARGS); Datum float8_dist(PG_FUNCTION_ARGS);
Datum Datum
float8_dist(PG_FUNCTION_ARGS) float8_dist(PG_FUNCTION_ARGS)
{ {
...@@ -113,7 +113,7 @@ float8_dist(PG_FUNCTION_ARGS) ...@@ -113,7 +113,7 @@ float8_dist(PG_FUNCTION_ARGS)
r = a - b; r = a - b;
CHECKFLOATVAL(r, isinf(a) || isinf(b), true); CHECKFLOATVAL(r, isinf(a) || isinf(b), true);
PG_RETURN_FLOAT8( Abs(r) ); PG_RETURN_FLOAT8(Abs(r));
} }
/************************************************** /**************************************************
...@@ -169,7 +169,7 @@ gbt_float8_distance(PG_FUNCTION_ARGS) ...@@ -169,7 +169,7 @@ gbt_float8_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -94,12 +94,12 @@ static const gbtree_ninfo tinfo = ...@@ -94,12 +94,12 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(int2_dist); PG_FUNCTION_INFO_V1(int2_dist);
Datum int2_dist(PG_FUNCTION_ARGS); Datum int2_dist(PG_FUNCTION_ARGS);
Datum Datum
int2_dist(PG_FUNCTION_ARGS) int2_dist(PG_FUNCTION_ARGS)
{ {
int2 a = PG_GETARG_INT16(0); int2 a = PG_GETARG_INT16(0);
int2 b = PG_GETARG_INT16(1); int2 b = PG_GETARG_INT16(1);
int2 r; int2 r;
int2 ra; int2 ra;
...@@ -169,7 +169,7 @@ gbt_int2_distance(PG_FUNCTION_ARGS) ...@@ -169,7 +169,7 @@ gbt_int2_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -95,14 +95,14 @@ static const gbtree_ninfo tinfo = ...@@ -95,14 +95,14 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(int4_dist); PG_FUNCTION_INFO_V1(int4_dist);
Datum int4_dist(PG_FUNCTION_ARGS); Datum int4_dist(PG_FUNCTION_ARGS);
Datum Datum
int4_dist(PG_FUNCTION_ARGS) int4_dist(PG_FUNCTION_ARGS)
{ {
int4 a = PG_GETARG_INT32(0); int4 a = PG_GETARG_INT32(0);
int4 b = PG_GETARG_INT32(1); int4 b = PG_GETARG_INT32(1);
int4 r; int4 r;
int4 ra; int4 ra;
r = a - b; r = a - b;
ra = Abs(r); ra = Abs(r);
...@@ -111,7 +111,7 @@ int4_dist(PG_FUNCTION_ARGS) ...@@ -111,7 +111,7 @@ int4_dist(PG_FUNCTION_ARGS)
if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a))) if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("integer out of range")));
PG_RETURN_INT32(ra); PG_RETURN_INT32(ra);
} }
...@@ -170,7 +170,7 @@ gbt_int4_distance(PG_FUNCTION_ARGS) ...@@ -170,7 +170,7 @@ gbt_int4_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -95,14 +95,14 @@ static const gbtree_ninfo tinfo = ...@@ -95,14 +95,14 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(int8_dist); PG_FUNCTION_INFO_V1(int8_dist);
Datum int8_dist(PG_FUNCTION_ARGS); Datum int8_dist(PG_FUNCTION_ARGS);
Datum Datum
int8_dist(PG_FUNCTION_ARGS) int8_dist(PG_FUNCTION_ARGS)
{ {
int64 a = PG_GETARG_INT64(0); int64 a = PG_GETARG_INT64(0);
int64 b = PG_GETARG_INT64(1); int64 b = PG_GETARG_INT64(1);
int64 r; int64 r;
int64 ra; int64 ra;
r = a - b; r = a - b;
ra = Abs(r); ra = Abs(r);
...@@ -111,7 +111,7 @@ int8_dist(PG_FUNCTION_ARGS) ...@@ -111,7 +111,7 @@ int8_dist(PG_FUNCTION_ARGS)
if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a))) if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range"))); errmsg("bigint out of range")));
PG_RETURN_INT64(ra); PG_RETURN_INT64(ra);
} }
...@@ -170,7 +170,7 @@ gbt_int8_distance(PG_FUNCTION_ARGS) ...@@ -170,7 +170,7 @@ gbt_int8_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -88,7 +88,7 @@ intr2num(const Interval *i) ...@@ -88,7 +88,7 @@ intr2num(const Interval *i)
static float8 static float8
gbt_intv_dist(const void *a, const void *b) gbt_intv_dist(const void *a, const void *b)
{ {
return (float8)Abs(intr2num((Interval*)a) - intr2num((Interval*)b)); return (float8) Abs(intr2num((Interval *) a) - intr2num((Interval *) b));
} }
/* /*
...@@ -127,7 +127,7 @@ abs_interval(Interval *a) ...@@ -127,7 +127,7 @@ abs_interval(Interval *a)
} }
PG_FUNCTION_INFO_V1(interval_dist); PG_FUNCTION_INFO_V1(interval_dist);
Datum interval_dist(PG_FUNCTION_ARGS); Datum interval_dist(PG_FUNCTION_ARGS);
Datum Datum
interval_dist(PG_FUNCTION_ARGS) interval_dist(PG_FUNCTION_ARGS)
{ {
...@@ -240,7 +240,7 @@ gbt_intv_distance(PG_FUNCTION_ARGS) ...@@ -240,7 +240,7 @@ gbt_intv_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -101,13 +101,13 @@ static const gbtree_ninfo tinfo = ...@@ -101,13 +101,13 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(oid_dist); PG_FUNCTION_INFO_V1(oid_dist);
Datum oid_dist(PG_FUNCTION_ARGS); Datum oid_dist(PG_FUNCTION_ARGS);
Datum Datum
oid_dist(PG_FUNCTION_ARGS) oid_dist(PG_FUNCTION_ARGS)
{ {
Oid a = PG_GETARG_OID(0); Oid a = PG_GETARG_OID(0);
Oid b = PG_GETARG_OID(1); Oid b = PG_GETARG_OID(1);
Oid res; Oid res;
if (a < b) if (a < b)
res = b - a; res = b - a;
...@@ -170,7 +170,7 @@ gbt_oid_distance(PG_FUNCTION_ARGS) ...@@ -170,7 +170,7 @@ gbt_oid_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -119,7 +119,7 @@ gbt_time_dist(const void *a, const void *b) ...@@ -119,7 +119,7 @@ gbt_time_dist(const void *a, const void *b)
{ {
const TimeADT *aa = (const TimeADT *) a; const TimeADT *aa = (const TimeADT *) a;
const TimeADT *bb = (const TimeADT *) b; const TimeADT *bb = (const TimeADT *) b;
Interval *i; Interval *i;
i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time, i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
TimeADTGetDatumFast(*aa), TimeADTGetDatumFast(*aa),
...@@ -143,7 +143,7 @@ static const gbtree_ninfo tinfo = ...@@ -143,7 +143,7 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(time_dist); PG_FUNCTION_INFO_V1(time_dist);
Datum time_dist(PG_FUNCTION_ARGS); Datum time_dist(PG_FUNCTION_ARGS);
Datum Datum
time_dist(PG_FUNCTION_ARGS) time_dist(PG_FUNCTION_ARGS)
{ {
...@@ -239,7 +239,7 @@ gbt_time_distance(PG_FUNCTION_ARGS) ...@@ -239,7 +239,7 @@ gbt_time_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -120,7 +120,7 @@ gbt_ts_dist(const void *a, const void *b) ...@@ -120,7 +120,7 @@ gbt_ts_dist(const void *a, const void *b)
{ {
const Timestamp *aa = (const Timestamp *) a; const Timestamp *aa = (const Timestamp *) a;
const Timestamp *bb = (const Timestamp *) b; const Timestamp *bb = (const Timestamp *) b;
Interval *i; Interval *i;
if (TIMESTAMP_NOT_FINITE(*aa) || TIMESTAMP_NOT_FINITE(*bb)) if (TIMESTAMP_NOT_FINITE(*aa) || TIMESTAMP_NOT_FINITE(*bb))
return get_float8_infinity(); return get_float8_infinity();
...@@ -147,17 +147,17 @@ static const gbtree_ninfo tinfo = ...@@ -147,17 +147,17 @@ static const gbtree_ninfo tinfo =
PG_FUNCTION_INFO_V1(ts_dist); PG_FUNCTION_INFO_V1(ts_dist);
Datum ts_dist(PG_FUNCTION_ARGS); Datum ts_dist(PG_FUNCTION_ARGS);
Datum Datum
ts_dist(PG_FUNCTION_ARGS) ts_dist(PG_FUNCTION_ARGS)
{ {
Timestamp a = PG_GETARG_TIMESTAMP(0); Timestamp a = PG_GETARG_TIMESTAMP(0);
Timestamp b = PG_GETARG_TIMESTAMP(1); Timestamp b = PG_GETARG_TIMESTAMP(1);
Interval *r; Interval *r;
if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b)) if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
{ {
Interval *p = palloc(sizeof(Interval)); Interval *p = palloc(sizeof(Interval));
p->day = INT_MAX; p->day = INT_MAX;
p->month = INT_MAX; p->month = INT_MAX;
...@@ -169,25 +169,24 @@ ts_dist(PG_FUNCTION_ARGS) ...@@ -169,25 +169,24 @@ ts_dist(PG_FUNCTION_ARGS)
PG_RETURN_INTERVAL_P(p); PG_RETURN_INTERVAL_P(p);
} }
else else
r = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
r = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi, PG_GETARG_DATUM(0),
PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)));
PG_GETARG_DATUM(1))); PG_RETURN_INTERVAL_P(abs_interval(r));
PG_RETURN_INTERVAL_P( abs_interval(r) );
} }
PG_FUNCTION_INFO_V1(tstz_dist); PG_FUNCTION_INFO_V1(tstz_dist);
Datum tstz_dist(PG_FUNCTION_ARGS); Datum tstz_dist(PG_FUNCTION_ARGS);
Datum Datum
tstz_dist(PG_FUNCTION_ARGS) tstz_dist(PG_FUNCTION_ARGS)
{ {
TimestampTz a = PG_GETARG_TIMESTAMPTZ(0); TimestampTz a = PG_GETARG_TIMESTAMPTZ(0);
TimestampTz b = PG_GETARG_TIMESTAMPTZ(1); TimestampTz b = PG_GETARG_TIMESTAMPTZ(1);
Interval *r; Interval *r;
if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b)) if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
{ {
Interval *p = palloc(sizeof(Interval)); Interval *p = palloc(sizeof(Interval));
p->day = INT_MAX; p->day = INT_MAX;
p->month = INT_MAX; p->month = INT_MAX;
...@@ -202,7 +201,7 @@ tstz_dist(PG_FUNCTION_ARGS) ...@@ -202,7 +201,7 @@ tstz_dist(PG_FUNCTION_ARGS)
r = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi, r = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
PG_GETARG_DATUM(0), PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1))); PG_GETARG_DATUM(1)));
PG_RETURN_INTERVAL_P( abs_interval(r) ); PG_RETURN_INTERVAL_P(abs_interval(r));
} }
...@@ -309,7 +308,7 @@ gbt_ts_distance(PG_FUNCTION_ARGS) ...@@ -309,7 +308,7 @@ gbt_ts_distance(PG_FUNCTION_ARGS)
key.upper = (GBT_NUMKEY *) &kkk->upper; key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo)
); );
} }
...@@ -354,7 +353,7 @@ gbt_tstz_distance(PG_FUNCTION_ARGS) ...@@ -354,7 +353,7 @@ gbt_tstz_distance(PG_FUNCTION_ARGS)
qqq = tstz_to_ts_gmt(query); qqq = tstz_to_ts_gmt(query);
PG_RETURN_FLOAT8( PG_RETURN_FLOAT8(
gbt_num_distance(&key, (void *) &qqq, GIST_LEAF(entry), &tinfo) gbt_num_distance(&key, (void *) &qqq, GIST_LEAF(entry), &tinfo)
); );
} }
......
...@@ -223,8 +223,8 @@ gbt_num_consistent(const GBT_NUMKEY_R *key, ...@@ -223,8 +223,8 @@ gbt_num_consistent(const GBT_NUMKEY_R *key,
retval = (*tinfo->f_le) (query, key->upper); retval = (*tinfo->f_le) (query, key->upper);
break; break;
case BtreeGistNotEqualStrategyNumber: case BtreeGistNotEqualStrategyNumber:
retval = (! ((*tinfo->f_eq) (query, key->lower) && retval = (!((*tinfo->f_eq) (query, key->lower) &&
(*tinfo->f_eq) (query, key->upper))) ? true : false; (*tinfo->f_eq) (query, key->upper))) ? true : false;
break; break;
default: default:
retval = false; retval = false;
...@@ -249,9 +249,9 @@ gbt_num_distance(const GBT_NUMKEY_R *key, ...@@ -249,9 +249,9 @@ gbt_num_distance(const GBT_NUMKEY_R *key,
if (tinfo->f_dist == NULL) if (tinfo->f_dist == NULL)
elog(ERROR, "KNN search is not supported for btree_gist type %d", elog(ERROR, "KNN search is not supported for btree_gist type %d",
(int) tinfo->t); (int) tinfo->t);
if ( tinfo->f_le(query, key->lower) ) if (tinfo->f_le(query, key->lower))
retval = tinfo->f_dist(query, key->lower); retval = tinfo->f_dist(query, key->lower);
else if ( tinfo->f_ge(query, key->upper) ) else if (tinfo->f_ge(query, key->upper))
retval = tinfo->f_dist(query, key->upper); retval = tinfo->f_dist(query, key->upper);
else else
retval = 0.0; retval = 0.0;
......
...@@ -46,7 +46,7 @@ typedef struct ...@@ -46,7 +46,7 @@ typedef struct
bool (*f_le) (const void *, const void *); /* less or equal */ bool (*f_le) (const void *, const void *); /* less or equal */
bool (*f_lt) (const void *, const void *); /* less than */ bool (*f_lt) (const void *, const void *); /* less than */
int (*f_cmp) (const void *, const void *); /* key compare function */ int (*f_cmp) (const void *, const void *); /* key compare function */
float8 (*f_dist) (const void *, const void *); /* key distance function */ float8 (*f_dist) (const void *, const void *); /* key distance function */
} gbtree_ninfo; } gbtree_ninfo;
...@@ -94,7 +94,7 @@ typedef struct ...@@ -94,7 +94,7 @@ typedef struct
#define GET_FLOAT_DISTANCE(t, arg1, arg2) Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) ) #define GET_FLOAT_DISTANCE(t, arg1, arg2) Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
#define SAMESIGN(a,b) (((a) < 0) == ((b) < 0)) #define SAMESIGN(a,b) (((a) < 0) == ((b) < 0))
/* /*
* check to see if a float4/8 val has underflowed or overflowed * check to see if a float4/8 val has underflowed or overflowed
...@@ -121,7 +121,7 @@ extern bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, ...@@ -121,7 +121,7 @@ extern bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query,
const gbtree_ninfo *tinfo); const gbtree_ninfo *tinfo);
extern float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, extern float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query,
bool is_leaf, const gbtree_ninfo *tinfo); bool is_leaf, const gbtree_ninfo *tinfo);
extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
const gbtree_ninfo *tinfo); const gbtree_ninfo *tinfo);
......
...@@ -598,7 +598,7 @@ gbt_var_consistent( ...@@ -598,7 +598,7 @@ gbt_var_consistent(
|| gbt_var_node_pf_match(key, query, tinfo); || gbt_var_node_pf_match(key, query, tinfo);
break; break;
case BtreeGistNotEqualStrategyNumber: case BtreeGistNotEqualStrategyNumber:
retval = ! ((*tinfo->f_eq) (query, key->lower) && (*tinfo->f_eq) (query, key->upper)); retval = !((*tinfo->f_eq) (query, key->lower) && (*tinfo->f_eq) (query, key->upper));
break; break;
default: default:
retval = FALSE; retval = FALSE;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
PG_MODULE_MAGIC; PG_MODULE_MAGIC;
/* Entrypoint of the module */ /* Entrypoint of the module */
void _PG_init(void); void _PG_init(void);
static void static void
dummy_object_relabel(const ObjectAddress *object, const char *seclabel) dummy_object_relabel(const ObjectAddress *object, const char *seclabel)
......
...@@ -45,17 +45,17 @@ struct FileFdwOption ...@@ -45,17 +45,17 @@ struct FileFdwOption
*/ */
static struct FileFdwOption valid_options[] = { static struct FileFdwOption valid_options[] = {
/* File options */ /* File options */
{ "filename", ForeignTableRelationId }, {"filename", ForeignTableRelationId},
/* Format options */ /* Format options */
/* oids option is not supported */ /* oids option is not supported */
{ "format", ForeignTableRelationId }, {"format", ForeignTableRelationId},
{ "header", ForeignTableRelationId }, {"header", ForeignTableRelationId},
{ "delimiter", ForeignTableRelationId }, {"delimiter", ForeignTableRelationId},
{ "quote", ForeignTableRelationId }, {"quote", ForeignTableRelationId},
{ "escape", ForeignTableRelationId }, {"escape", ForeignTableRelationId},
{ "null", ForeignTableRelationId }, {"null", ForeignTableRelationId},
{ "encoding", ForeignTableRelationId }, {"encoding", ForeignTableRelationId},
/* /*
* force_quote is not supported by file_fdw because it's for COPY TO. * force_quote is not supported by file_fdw because it's for COPY TO.
...@@ -68,7 +68,7 @@ static struct FileFdwOption valid_options[] = { ...@@ -68,7 +68,7 @@ static struct FileFdwOption valid_options[] = {
*/ */
/* Sentinel */ /* Sentinel */
{ NULL, InvalidOid } {NULL, InvalidOid}
}; };
/* /*
...@@ -76,9 +76,9 @@ static struct FileFdwOption valid_options[] = { ...@@ -76,9 +76,9 @@ static struct FileFdwOption valid_options[] = {
*/ */
typedef struct FileFdwExecutionState typedef struct FileFdwExecutionState
{ {
char *filename; /* file to read */ char *filename; /* file to read */
List *options; /* merged COPY options, excluding filename */ List *options; /* merged COPY options, excluding filename */
CopyState cstate; /* state of reading file */ CopyState cstate; /* state of reading file */
} FileFdwExecutionState; } FileFdwExecutionState;
/* /*
...@@ -94,8 +94,8 @@ PG_FUNCTION_INFO_V1(file_fdw_validator); ...@@ -94,8 +94,8 @@ PG_FUNCTION_INFO_V1(file_fdw_validator);
* FDW callback routines * FDW callback routines
*/ */
static FdwPlan *filePlanForeignScan(Oid foreigntableid, static FdwPlan *filePlanForeignScan(Oid foreigntableid,
PlannerInfo *root, PlannerInfo *root,
RelOptInfo *baserel); RelOptInfo *baserel);
static void fileExplainForeignScan(ForeignScanState *node, ExplainState *es); static void fileExplainForeignScan(ForeignScanState *node, ExplainState *es);
static void fileBeginForeignScan(ForeignScanState *node, int eflags); static void fileBeginForeignScan(ForeignScanState *node, int eflags);
static TupleTableSlot *fileIterateForeignScan(ForeignScanState *node); static TupleTableSlot *fileIterateForeignScan(ForeignScanState *node);
...@@ -109,8 +109,8 @@ static bool is_valid_option(const char *option, Oid context); ...@@ -109,8 +109,8 @@ static bool is_valid_option(const char *option, Oid context);
static void fileGetOptions(Oid foreigntableid, static void fileGetOptions(Oid foreigntableid,
char **filename, List **other_options); char **filename, List **other_options);
static void estimate_costs(PlannerInfo *root, RelOptInfo *baserel, static void estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
const char *filename, const char *filename,
Cost *startup_cost, Cost *total_cost); Cost *startup_cost, Cost *total_cost);
/* /*
...@@ -149,16 +149,16 @@ file_fdw_validator(PG_FUNCTION_ARGS) ...@@ -149,16 +149,16 @@ file_fdw_validator(PG_FUNCTION_ARGS)
/* /*
* Only superusers are allowed to set options of a file_fdw foreign table. * Only superusers are allowed to set options of a file_fdw foreign table.
* This is because the filename is one of those options, and we don't * This is because the filename is one of those options, and we don't want
* want non-superusers to be able to determine which file gets read. * non-superusers to be able to determine which file gets read.
* *
* Putting this sort of permissions check in a validator is a bit of a * Putting this sort of permissions check in a validator is a bit of a
* crock, but there doesn't seem to be any other place that can enforce * crock, but there doesn't seem to be any other place that can enforce
* the check more cleanly. * the check more cleanly.
* *
* Note that the valid_options[] array disallows setting filename at * Note that the valid_options[] array disallows setting filename at any
* any options level other than foreign table --- otherwise there'd * options level other than foreign table --- otherwise there'd still be a
* still be a security hole. * security hole.
*/ */
if (catalog == ForeignTableRelationId && !superuser()) if (catalog == ForeignTableRelationId && !superuser())
ereport(ERROR, ereport(ERROR,
...@@ -171,7 +171,7 @@ file_fdw_validator(PG_FUNCTION_ARGS) ...@@ -171,7 +171,7 @@ file_fdw_validator(PG_FUNCTION_ARGS)
*/ */
foreach(cell, options_list) foreach(cell, options_list)
{ {
DefElem *def = (DefElem *) lfirst(cell); DefElem *def = (DefElem *) lfirst(cell);
if (!is_valid_option(def->defname, catalog)) if (!is_valid_option(def->defname, catalog))
{ {
...@@ -276,7 +276,7 @@ fileGetOptions(Oid foreigntableid, ...@@ -276,7 +276,7 @@ fileGetOptions(Oid foreigntableid,
prev = NULL; prev = NULL;
foreach(lc, options) foreach(lc, options)
{ {
DefElem *def = (DefElem *) lfirst(lc); DefElem *def = (DefElem *) lfirst(lc);
if (strcmp(def->defname, "filename") == 0) if (strcmp(def->defname, "filename") == 0)
{ {
...@@ -302,7 +302,7 @@ filePlanForeignScan(Oid foreigntableid, ...@@ -302,7 +302,7 @@ filePlanForeignScan(Oid foreigntableid,
PlannerInfo *root, PlannerInfo *root,
RelOptInfo *baserel) RelOptInfo *baserel)
{ {
FdwPlan *fdwplan; FdwPlan *fdwplan;
char *filename; char *filename;
List *options; List *options;
...@@ -313,7 +313,7 @@ filePlanForeignScan(Oid foreigntableid, ...@@ -313,7 +313,7 @@ filePlanForeignScan(Oid foreigntableid,
fdwplan = makeNode(FdwPlan); fdwplan = makeNode(FdwPlan);
estimate_costs(root, baserel, filename, estimate_costs(root, baserel, filename,
&fdwplan->startup_cost, &fdwplan->total_cost); &fdwplan->startup_cost, &fdwplan->total_cost);
fdwplan->fdw_private = NIL; /* not used */ fdwplan->fdw_private = NIL; /* not used */
return fdwplan; return fdwplan;
} }
...@@ -337,7 +337,7 @@ fileExplainForeignScan(ForeignScanState *node, ExplainState *es) ...@@ -337,7 +337,7 @@ fileExplainForeignScan(ForeignScanState *node, ExplainState *es)
/* Suppress file size if we're not showing cost details */ /* Suppress file size if we're not showing cost details */
if (es->costs) if (es->costs)
{ {
struct stat stat_buf; struct stat stat_buf;
if (stat(filename, &stat_buf) == 0) if (stat(filename, &stat_buf) == 0)
ExplainPropertyLong("Foreign File Size", (long) stat_buf.st_size, ExplainPropertyLong("Foreign File Size", (long) stat_buf.st_size,
...@@ -368,8 +368,8 @@ fileBeginForeignScan(ForeignScanState *node, int eflags) ...@@ -368,8 +368,8 @@ fileBeginForeignScan(ForeignScanState *node, int eflags)
&filename, &options); &filename, &options);
/* /*
* Create CopyState from FDW options. We always acquire all columns, * Create CopyState from FDW options. We always acquire all columns, so
* so as to match the expected ScanTupleSlot signature. * as to match the expected ScanTupleSlot signature.
*/ */
cstate = BeginCopyFrom(node->ss.ss_currentRelation, cstate = BeginCopyFrom(node->ss.ss_currentRelation,
filename, filename,
...@@ -398,7 +398,7 @@ fileIterateForeignScan(ForeignScanState *node) ...@@ -398,7 +398,7 @@ fileIterateForeignScan(ForeignScanState *node)
{ {
FileFdwExecutionState *festate = (FileFdwExecutionState *) node->fdw_state; FileFdwExecutionState *festate = (FileFdwExecutionState *) node->fdw_state;
TupleTableSlot *slot = node->ss.ss_ScanTupleSlot; TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
bool found; bool found;
ErrorContextCallback errcontext; ErrorContextCallback errcontext;
/* Set up callback to identify error line number. */ /* Set up callback to identify error line number. */
...@@ -410,8 +410,8 @@ fileIterateForeignScan(ForeignScanState *node) ...@@ -410,8 +410,8 @@ fileIterateForeignScan(ForeignScanState *node)
/* /*
* The protocol for loading a virtual tuple into a slot is first * The protocol for loading a virtual tuple into a slot is first
* ExecClearTuple, then fill the values/isnull arrays, then * ExecClearTuple, then fill the values/isnull arrays, then
* ExecStoreVirtualTuple. If we don't find another row in the file, * ExecStoreVirtualTuple. If we don't find another row in the file, we
* we just skip the last step, leaving the slot empty as required. * just skip the last step, leaving the slot empty as required.
* *
* We can pass ExprContext = NULL because we read all columns from the * We can pass ExprContext = NULL because we read all columns from the
* file, so no need to evaluate default expressions. * file, so no need to evaluate default expressions.
...@@ -471,17 +471,17 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel, ...@@ -471,17 +471,17 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
const char *filename, const char *filename,
Cost *startup_cost, Cost *total_cost) Cost *startup_cost, Cost *total_cost)
{ {
struct stat stat_buf; struct stat stat_buf;
BlockNumber pages; BlockNumber pages;
int tuple_width; int tuple_width;
double ntuples; double ntuples;
double nrows; double nrows;
Cost run_cost = 0; Cost run_cost = 0;
Cost cpu_per_tuple; Cost cpu_per_tuple;
/* /*
* Get size of the file. It might not be there at plan time, though, * Get size of the file. It might not be there at plan time, though, in
* in which case we have to use a default estimate. * which case we have to use a default estimate.
*/ */
if (stat(filename, &stat_buf) < 0) if (stat(filename, &stat_buf) < 0)
stat_buf.st_size = 10 * BLCKSZ; stat_buf.st_size = 10 * BLCKSZ;
...@@ -489,7 +489,7 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel, ...@@ -489,7 +489,7 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
/* /*
* Convert size to pages for use in I/O cost estimate below. * Convert size to pages for use in I/O cost estimate below.
*/ */
pages = (stat_buf.st_size + (BLCKSZ-1)) / BLCKSZ; pages = (stat_buf.st_size + (BLCKSZ - 1)) / BLCKSZ;
if (pages < 1) if (pages < 1)
pages = 1; pages = 1;
...@@ -505,10 +505,9 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel, ...@@ -505,10 +505,9 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
ntuples = clamp_row_est((double) stat_buf.st_size / (double) tuple_width); ntuples = clamp_row_est((double) stat_buf.st_size / (double) tuple_width);
/* /*
* Now estimate the number of rows returned by the scan after applying * Now estimate the number of rows returned by the scan after applying the
* the baserestrictinfo quals. This is pretty bogus too, since the * baserestrictinfo quals. This is pretty bogus too, since the planner
* planner will have no stats about the relation, but it's better than * will have no stats about the relation, but it's better than nothing.
* nothing.
*/ */
nrows = ntuples * nrows = ntuples *
clauselist_selectivity(root, clauselist_selectivity(root,
...@@ -523,7 +522,7 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel, ...@@ -523,7 +522,7 @@ estimate_costs(PlannerInfo *root, RelOptInfo *baserel,
baserel->rows = nrows; baserel->rows = nrows;
/* /*
* Now estimate costs. We estimate costs almost the same way as * Now estimate costs. We estimate costs almost the same way as
* cost_seqscan(), thus assuming that I/O costs are equivalent to a * cost_seqscan(), thus assuming that I/O costs are equivalent to a
* regular table file of the same size. However, we take per-tuple CPU * regular table file of the same size. However, we take per-tuple CPU
* costs as 10x of a seqscan, to account for the cost of parsing records. * costs as 10x of a seqscan, to account for the cost of parsing records.
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
*/ */
#ifdef LEVENSHTEIN_LESS_EQUAL #ifdef LEVENSHTEIN_LESS_EQUAL
static int levenshtein_less_equal_internal(text *s, text *t, static int levenshtein_less_equal_internal(text *s, text *t,
int ins_c, int del_c, int sub_c, int max_d); int ins_c, int del_c, int sub_c, int max_d);
#else #else
static int levenshtein_internal(text *s, text *t, static int levenshtein_internal(text *s, text *t,
int ins_c, int del_c, int sub_c); int ins_c, int del_c, int sub_c);
...@@ -50,7 +50,7 @@ static int levenshtein_internal(text *s, text *t, ...@@ -50,7 +50,7 @@ static int levenshtein_internal(text *s, text *t,
* array. * array.
* *
* If max_d >= 0, we only need to provide an accurate answer when that answer * If max_d >= 0, we only need to provide an accurate answer when that answer
* is less than or equal to the bound. From any cell in the matrix, there is * is less than or equal to the bound. From any cell in the matrix, there is
* theoretical "minimum residual distance" from that cell to the last column * theoretical "minimum residual distance" from that cell to the last column
* of the final row. This minimum residual distance is zero when the * of the final row. This minimum residual distance is zero when the
* untransformed portions of the strings are of equal length (because we might * untransformed portions of the strings are of equal length (because we might
...@@ -87,11 +87,13 @@ levenshtein_internal(text *s, text *t, ...@@ -87,11 +87,13 @@ levenshtein_internal(text *s, text *t,
/* /*
* For levenshtein_less_equal_internal, we have real variables called * For levenshtein_less_equal_internal, we have real variables called
* start_column and stop_column; otherwise it's just short-hand for 0 * start_column and stop_column; otherwise it's just short-hand for 0 and
* and m. * m.
*/ */
#ifdef LEVENSHTEIN_LESS_EQUAL #ifdef LEVENSHTEIN_LESS_EQUAL
int start_column, stop_column; int start_column,
stop_column;
#undef START_COLUMN #undef START_COLUMN
#undef STOP_COLUMN #undef STOP_COLUMN
#define START_COLUMN start_column #define START_COLUMN start_column
...@@ -139,16 +141,16 @@ levenshtein_internal(text *s, text *t, ...@@ -139,16 +141,16 @@ levenshtein_internal(text *s, text *t,
stop_column = m + 1; stop_column = m + 1;
/* /*
* If max_d >= 0, determine whether the bound is impossibly tight. If so, * If max_d >= 0, determine whether the bound is impossibly tight. If so,
* return max_d + 1 immediately. Otherwise, determine whether it's tight * return max_d + 1 immediately. Otherwise, determine whether it's tight
* enough to limit the computation we must perform. If so, figure out * enough to limit the computation we must perform. If so, figure out
* initial stop column. * initial stop column.
*/ */
if (max_d >= 0) if (max_d >= 0)
{ {
int min_theo_d; /* Theoretical minimum distance. */ int min_theo_d; /* Theoretical minimum distance. */
int max_theo_d; /* Theoretical maximum distance. */ int max_theo_d; /* Theoretical maximum distance. */
int net_inserts = n - m; int net_inserts = n - m;
min_theo_d = net_inserts < 0 ? min_theo_d = net_inserts < 0 ?
-net_inserts * del_c : net_inserts * ins_c; -net_inserts * del_c : net_inserts * ins_c;
...@@ -162,20 +164,20 @@ levenshtein_internal(text *s, text *t, ...@@ -162,20 +164,20 @@ levenshtein_internal(text *s, text *t,
else if (ins_c + del_c > 0) else if (ins_c + del_c > 0)
{ {
/* /*
* Figure out how much of the first row of the notional matrix * Figure out how much of the first row of the notional matrix we
* we need to fill in. If the string is growing, the theoretical * need to fill in. If the string is growing, the theoretical
* minimum distance already incorporates the cost of deleting the * minimum distance already incorporates the cost of deleting the
* number of characters necessary to make the two strings equal * number of characters necessary to make the two strings equal in
* in length. Each additional deletion forces another insertion, * length. Each additional deletion forces another insertion, so
* so the best-case total cost increases by ins_c + del_c. * the best-case total cost increases by ins_c + del_c. If the
* If the string is shrinking, the minimum theoretical cost * string is shrinking, the minimum theoretical cost assumes no
* assumes no excess deletions; that is, we're starting no futher * excess deletions; that is, we're starting no futher right than
* right than column n - m. If we do start further right, the * column n - m. If we do start further right, the best-case
* best-case total cost increases by ins_c + del_c for each move * total cost increases by ins_c + del_c for each move right.
* right.
*/ */
int slack_d = max_d - min_theo_d; int slack_d = max_d - min_theo_d;
int best_column = net_inserts < 0 ? -net_inserts : 0; int best_column = net_inserts < 0 ? -net_inserts : 0;
stop_column = best_column + (slack_d / (ins_c + del_c)) + 1; stop_column = best_column + (slack_d / (ins_c + del_c)) + 1;
if (stop_column > m) if (stop_column > m)
stop_column = m + 1; stop_column = m + 1;
...@@ -185,15 +187,15 @@ levenshtein_internal(text *s, text *t, ...@@ -185,15 +187,15 @@ levenshtein_internal(text *s, text *t,
/* /*
* In order to avoid calling pg_mblen() repeatedly on each character in s, * In order to avoid calling pg_mblen() repeatedly on each character in s,
* we cache all the lengths before starting the main loop -- but if all the * we cache all the lengths before starting the main loop -- but if all
* characters in both strings are single byte, then we skip this and use * the characters in both strings are single byte, then we skip this and
* a fast-path in the main loop. If only one string contains multi-byte * use a fast-path in the main loop. If only one string contains
* characters, we still build the array, so that the fast-path needn't * multi-byte characters, we still build the array, so that the fast-path
* deal with the case where the array hasn't been initialized. * needn't deal with the case where the array hasn't been initialized.
*/ */
if (m != s_bytes || n != t_bytes) if (m != s_bytes || n != t_bytes)
{ {
int i; int i;
const char *cp = s_data; const char *cp = s_data;
s_char_len = (int *) palloc((m + 1) * sizeof(int)); s_char_len = (int *) palloc((m + 1) * sizeof(int));
...@@ -214,8 +216,8 @@ levenshtein_internal(text *s, text *t, ...@@ -214,8 +216,8 @@ levenshtein_internal(text *s, text *t,
curr = prev + m; curr = prev + m;
/* /*
* To transform the first i characters of s into the first 0 characters * To transform the first i characters of s into the first 0 characters of
* of t, we must perform i deletions. * t, we must perform i deletions.
*/ */
for (i = START_COLUMN; i < STOP_COLUMN; i++) for (i = START_COLUMN; i < STOP_COLUMN; i++)
prev[i] = i * del_c; prev[i] = i * del_c;
...@@ -228,6 +230,7 @@ levenshtein_internal(text *s, text *t, ...@@ -228,6 +230,7 @@ levenshtein_internal(text *s, text *t,
int y_char_len = n != t_bytes + 1 ? pg_mblen(y) : 1; int y_char_len = n != t_bytes + 1 ? pg_mblen(y) : 1;
#ifdef LEVENSHTEIN_LESS_EQUAL #ifdef LEVENSHTEIN_LESS_EQUAL
/* /*
* In the best case, values percolate down the diagonal unchanged, so * In the best case, values percolate down the diagonal unchanged, so
* we must increment stop_column unless it's already on the right end * we must increment stop_column unless it's already on the right end
...@@ -241,10 +244,10 @@ levenshtein_internal(text *s, text *t, ...@@ -241,10 +244,10 @@ levenshtein_internal(text *s, text *t,
} }
/* /*
* The main loop fills in curr, but curr[0] needs a special case: * The main loop fills in curr, but curr[0] needs a special case: to
* to transform the first 0 characters of s into the first j * transform the first 0 characters of s into the first j characters
* characters of t, we must perform j insertions. However, if * of t, we must perform j insertions. However, if start_column > 0,
* start_column > 0, this special case does not apply. * this special case does not apply.
*/ */
if (start_column == 0) if (start_column == 0)
{ {
...@@ -285,7 +288,7 @@ levenshtein_internal(text *s, text *t, ...@@ -285,7 +288,7 @@ levenshtein_internal(text *s, text *t,
*/ */
ins = prev[i] + ins_c; ins = prev[i] + ins_c;
del = curr[i - 1] + del_c; del = curr[i - 1] + del_c;
if (x[x_char_len-1] == y[y_char_len-1] if (x[x_char_len - 1] == y[y_char_len - 1]
&& x_char_len == y_char_len && && x_char_len == y_char_len &&
(x_char_len == 1 || rest_of_char_same(x, y, x_char_len))) (x_char_len == 1 || rest_of_char_same(x, y, x_char_len)))
sub = prev[i - 1]; sub = prev[i - 1];
...@@ -331,6 +334,7 @@ levenshtein_internal(text *s, text *t, ...@@ -331,6 +334,7 @@ levenshtein_internal(text *s, text *t,
y += y_char_len; y += y_char_len;
#ifdef LEVENSHTEIN_LESS_EQUAL #ifdef LEVENSHTEIN_LESS_EQUAL
/* /*
* This chunk of code represents a significant performance hit if used * This chunk of code represents a significant performance hit if used
* in the case where there is no max_d bound. This is probably not * in the case where there is no max_d bound. This is probably not
...@@ -348,15 +352,16 @@ levenshtein_internal(text *s, text *t, ...@@ -348,15 +352,16 @@ levenshtein_internal(text *s, text *t,
* string, so we want to find the value for zp where where (n - 1) * string, so we want to find the value for zp where where (n - 1)
* - j = (m - 1) - zp. * - j = (m - 1) - zp.
*/ */
int zp = j - (n - m); int zp = j - (n - m);
/* Check whether the stop column can slide left. */ /* Check whether the stop column can slide left. */
while (stop_column > 0) while (stop_column > 0)
{ {
int ii = stop_column - 1; int ii = stop_column - 1;
int net_inserts = ii - zp; int net_inserts = ii - zp;
if (prev[ii] + (net_inserts > 0 ? net_inserts * ins_c : if (prev[ii] + (net_inserts > 0 ? net_inserts * ins_c :
-net_inserts * del_c) <= max_d) -net_inserts * del_c) <= max_d)
break; break;
stop_column--; stop_column--;
} }
...@@ -364,14 +369,16 @@ levenshtein_internal(text *s, text *t, ...@@ -364,14 +369,16 @@ levenshtein_internal(text *s, text *t,
/* Check whether the start column can slide right. */ /* Check whether the start column can slide right. */
while (start_column < stop_column) while (start_column < stop_column)
{ {
int net_inserts = start_column - zp; int net_inserts = start_column - zp;
if (prev[start_column] + if (prev[start_column] +
(net_inserts > 0 ? net_inserts * ins_c : (net_inserts > 0 ? net_inserts * ins_c :
-net_inserts * del_c) <= max_d) -net_inserts * del_c) <= max_d)
break; break;
/* /*
* We'll never again update these values, so we must make * We'll never again update these values, so we must make sure
* sure there's nothing here that could confuse any future * there's nothing here that could confuse any future
* iteration of the outer loop. * iteration of the outer loop.
*/ */
prev[start_column] = max_d + 1; prev[start_column] = max_d + 1;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/* /*
* When using a GIN index for hstore, we choose to index both keys and values. * When using a GIN index for hstore, we choose to index both keys and values.
* The storage format is "text" values, with K, V, or N prepended to the string * The storage format is "text" values, with K, V, or N prepended to the string
* to indicate key, value, or null values. (As of 9.1 it might be better to * to indicate key, value, or null values. (As of 9.1 it might be better to
* store null values as nulls, but we'll keep it this way for on-disk * store null values as nulls, but we'll keep it this way for on-disk
* compatibility.) * compatibility.)
*/ */
...@@ -168,7 +168,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS) ...@@ -168,7 +168,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
{ {
/* /*
* Index doesn't have information about correspondence of keys and * Index doesn't have information about correspondence of keys and
* values, so we need recheck. However, if not all the keys are * values, so we need recheck. However, if not all the keys are
* present, we can fail at once. * present, we can fail at once.
*/ */
*recheck = true; *recheck = true;
......
...@@ -437,7 +437,7 @@ hstore_delete_hstore(PG_FUNCTION_ARGS) ...@@ -437,7 +437,7 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
if (snullval != HS_VALISNULL(es2, j) if (snullval != HS_VALISNULL(es2, j)
|| (!snullval || (!snullval
&& (svallen != HS_VALLEN(es2, j) && (svallen != HS_VALLEN(es2, j)
|| memcmp(HS_VAL(es, ps, i), HS_VAL(es2, ps2, j), svallen) != 0))) || memcmp(HS_VAL(es, ps, i), HS_VAL(es2, ps2, j), svallen) != 0)))
{ {
HS_COPYITEM(ed, bufd, pd, HS_COPYITEM(ed, bufd, pd,
HS_KEY(es, ps, i), HS_KEYLEN(es, i), HS_KEY(es, ps, i), HS_KEYLEN(es, i),
...@@ -1000,7 +1000,7 @@ hstore_contains(PG_FUNCTION_ARGS) ...@@ -1000,7 +1000,7 @@ hstore_contains(PG_FUNCTION_ARGS)
if (nullval != HS_VALISNULL(ve, idx) if (nullval != HS_VALISNULL(ve, idx)
|| (!nullval || (!nullval
&& (vallen != HS_VALLEN(ve, idx) && (vallen != HS_VALLEN(ve, idx)
|| memcmp(HS_VAL(te, tstr, i), HS_VAL(ve, vstr, idx), vallen)))) || memcmp(HS_VAL(te, tstr, i), HS_VAL(ve, vstr, idx), vallen))))
res = false; res = false;
} }
else else
......
...@@ -98,7 +98,7 @@ gettoken(WORKSTATE *state, int4 *val) ...@@ -98,7 +98,7 @@ gettoken(WORKSTATE *state, int4 *val)
} }
else else
{ {
long lval; long lval;
nnn[innn] = '\0'; nnn[innn] = '\0';
errno = 0; errno = 0;
...@@ -355,8 +355,8 @@ gin_bool_consistent(QUERYTYPE *query, bool *check) ...@@ -355,8 +355,8 @@ gin_bool_consistent(QUERYTYPE *query, bool *check)
return FALSE; return FALSE;
/* /*
* Set up data for checkcondition_gin. This must agree with the * Set up data for checkcondition_gin. This must agree with the query
* query extraction code in ginint4_queryextract. * extraction code in ginint4_queryextract.
*/ */
gcv.first = items; gcv.first = items;
gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size); gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
......
...@@ -34,8 +34,8 @@ ginint4_queryextract(PG_FUNCTION_ARGS) ...@@ -34,8 +34,8 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
/* /*
* If the query doesn't have any required primitive values (for * If the query doesn't have any required primitive values (for
* instance, it's something like '! 42'), we have to do a full * instance, it's something like '! 42'), we have to do a full index
* index scan. * scan.
*/ */
if (query_has_required_values(query)) if (query_has_required_values(query))
*searchMode = GIN_SEARCH_MODE_DEFAULT; *searchMode = GIN_SEARCH_MODE_DEFAULT;
...@@ -95,7 +95,7 @@ ginint4_queryextract(PG_FUNCTION_ARGS) ...@@ -95,7 +95,7 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
case RTOldContainsStrategyNumber: case RTOldContainsStrategyNumber:
if (*nentries > 0) if (*nentries > 0)
*searchMode = GIN_SEARCH_MODE_DEFAULT; *searchMode = GIN_SEARCH_MODE_DEFAULT;
else /* everything contains the empty set */ else /* everything contains the empty set */
*searchMode = GIN_SEARCH_MODE_ALL; *searchMode = GIN_SEARCH_MODE_ALL;
break; break;
default: default:
...@@ -116,6 +116,7 @@ ginint4_consistent(PG_FUNCTION_ARGS) ...@@ -116,6 +116,7 @@ ginint4_consistent(PG_FUNCTION_ARGS)
bool *check = (bool *) PG_GETARG_POINTER(0); bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1); StrategyNumber strategy = PG_GETARG_UINT16(1);
int32 nkeys = PG_GETARG_INT32(3); int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5); bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = FALSE; bool res = FALSE;
......
...@@ -183,7 +183,7 @@ rt__int_size(ArrayType *a, float *size) ...@@ -183,7 +183,7 @@ rt__int_size(ArrayType *a, float *size)
*size = (float) ARRNELEMS(a); *size = (float) ARRNELEMS(a);
} }
/* Sort the given data (len >= 2). Return true if any duplicates found */ /* Sort the given data (len >= 2). Return true if any duplicates found */
bool bool
isort(int4 *a, int len) isort(int4 *a, int len)
{ {
...@@ -195,7 +195,7 @@ isort(int4 *a, int len) ...@@ -195,7 +195,7 @@ isort(int4 *a, int len)
bool r = FALSE; bool r = FALSE;
/* /*
* We use a simple insertion sort. While this is O(N^2) in the worst * We use a simple insertion sort. While this is O(N^2) in the worst
* case, it's quite fast if the input is already sorted or nearly so. * case, it's quite fast if the input is already sorted or nearly so.
* Also, for not-too-large inputs it's faster than more complex methods * Also, for not-too-large inputs it's faster than more complex methods
* anyhow. * anyhow.
......
...@@ -988,4 +988,3 @@ const char *ISBN_range_new[][2] = { ...@@ -988,4 +988,3 @@ const char *ISBN_range_new[][2] = {
{"10-976000", "10-999999"}, {"10-976000", "10-999999"},
{NULL, NULL}, {NULL, NULL},
}; };
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
#else /* WIN32 */ #else /* WIN32 */
extern int getopt(int argc, char *const argv[], const char *optstring); extern int getopt(int argc, char *const argv[], const char *optstring);
#endif /* ! WIN32 */ #endif /* ! WIN32 */
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
......
...@@ -137,7 +137,7 @@ typedef enum ...@@ -137,7 +137,7 @@ typedef enum
PGSS_TRACK_NONE, /* track no statements */ PGSS_TRACK_NONE, /* track no statements */
PGSS_TRACK_TOP, /* only top level statements */ PGSS_TRACK_TOP, /* only top level statements */
PGSS_TRACK_ALL /* all statements, including nested ones */ PGSS_TRACK_ALL /* all statements, including nested ones */
} PGSSTrackLevel; } PGSSTrackLevel;
static const struct config_enum_entry track_options[] = static const struct config_enum_entry track_options[] =
{ {
......
...@@ -28,24 +28,28 @@ ...@@ -28,24 +28,28 @@
static const char *progname; static const char *progname;
static int ops_per_test = 2000; static int ops_per_test = 2000;
static char full_buf[XLOG_SEG_SIZE], *buf, *filename = FSYNC_FILENAME; static char full_buf[XLOG_SEG_SIZE],
static struct timeval start_t, stop_t; *buf,
*filename = FSYNC_FILENAME;
static struct timeval start_t,
static void handle_args(int argc, char *argv[]); stop_t;
static void prepare_buf(void);
static void test_open(void);
static void test_non_sync(void); static void handle_args(int argc, char *argv[]);
static void test_sync(int writes_per_op); static void prepare_buf(void);
static void test_open_syncs(void); static void test_open(void);
static void test_open_sync(const char *msg, int writes_size); static void test_non_sync(void);
static void test_file_descriptor_sync(void); static void test_sync(int writes_per_op);
static void test_open_syncs(void);
static void test_open_sync(const char *msg, int writes_size);
static void test_file_descriptor_sync(void);
#ifdef HAVE_FSYNC_WRITETHROUGH #ifdef HAVE_FSYNC_WRITETHROUGH
static int pg_fsync_writethrough(int fd); static int pg_fsync_writethrough(int fd);
#endif #endif
static void print_elapse(struct timeval start_t, struct timeval stop_t); static void print_elapse(struct timeval start_t, struct timeval stop_t);
static void die(const char *str); static void die(const char *str);
int int
...@@ -103,7 +107,7 @@ handle_args(int argc, char *argv[]) ...@@ -103,7 +107,7 @@ handle_args(int argc, char *argv[])
} }
while ((option = getopt_long(argc, argv, "f:o:", while ((option = getopt_long(argc, argv, "f:o:",
long_options, &optindex)) != -1) long_options, &optindex)) != -1)
{ {
switch (option) switch (option)
{ {
...@@ -176,7 +180,9 @@ test_open(void) ...@@ -176,7 +180,9 @@ test_open(void)
static void static void
test_sync(int writes_per_op) test_sync(int writes_per_op)
{ {
int tmpfile, ops, writes; int tmpfile,
ops,
writes;
bool fs_warning = false; bool fs_warning = false;
if (writes_per_op == 1) if (writes_per_op == 1)
...@@ -353,7 +359,9 @@ test_open_syncs(void) ...@@ -353,7 +359,9 @@ test_open_syncs(void)
static void static void
test_open_sync(const char *msg, int writes_size) test_open_sync(const char *msg, int writes_size)
{ {
int tmpfile, ops, writes; int tmpfile,
ops,
writes;
printf(LABEL_FORMAT, msg); printf(LABEL_FORMAT, msg);
fflush(stdout); fflush(stdout);
...@@ -377,7 +385,6 @@ test_open_sync(const char *msg, int writes_size) ...@@ -377,7 +385,6 @@ test_open_sync(const char *msg, int writes_size)
close(tmpfile); close(tmpfile);
print_elapse(start_t, stop_t); print_elapse(start_t, stop_t);
} }
#else #else
printf(NA_FORMAT, "n/a\n"); printf(NA_FORMAT, "n/a\n");
#endif #endif
...@@ -386,22 +393,22 @@ test_open_sync(const char *msg, int writes_size) ...@@ -386,22 +393,22 @@ test_open_sync(const char *msg, int writes_size)
static void static void
test_file_descriptor_sync(void) test_file_descriptor_sync(void)
{ {
int tmpfile, ops; int tmpfile,
ops;
/* /*
* Test whether fsync can sync data written on a different * Test whether fsync can sync data written on a different descriptor for
* descriptor for the same file. This checks the efficiency * the same file. This checks the efficiency of multi-process fsyncs
* of multi-process fsyncs against the same file. * against the same file. Possibly this should be done with writethrough
* Possibly this should be done with writethrough on platforms * on platforms which support it.
* which support it.
*/ */
printf("\nTest if fsync on non-write file descriptor is honored:\n"); printf("\nTest if fsync on non-write file descriptor is honored:\n");
printf("(If the times are similar, fsync() can sync data written\n"); printf("(If the times are similar, fsync() can sync data written\n");
printf("on a different descriptor.)\n"); printf("on a different descriptor.)\n");
/* /*
* first write, fsync and close, which is the * first write, fsync and close, which is the normal behavior without
* normal behavior without multiple descriptors * multiple descriptors
*/ */
printf(LABEL_FORMAT, "write, fsync, close"); printf(LABEL_FORMAT, "write, fsync, close");
fflush(stdout); fflush(stdout);
...@@ -416,9 +423,10 @@ test_file_descriptor_sync(void) ...@@ -416,9 +423,10 @@ test_file_descriptor_sync(void)
if (fsync(tmpfile) != 0) if (fsync(tmpfile) != 0)
die("fsync failed"); die("fsync failed");
close(tmpfile); close(tmpfile);
/* /*
* open and close the file again to be consistent * open and close the file again to be consistent with the following
* with the following test * test
*/ */
if ((tmpfile = open(filename, O_RDWR, 0)) == -1) if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
die("could not open output file"); die("could not open output file");
...@@ -428,9 +436,8 @@ test_file_descriptor_sync(void) ...@@ -428,9 +436,8 @@ test_file_descriptor_sync(void)
print_elapse(start_t, stop_t); print_elapse(start_t, stop_t);
/* /*
* Now open, write, close, open again and fsync * Now open, write, close, open again and fsync This simulates processes
* This simulates processes fsyncing each other's * fsyncing each other's writes.
* writes.
*/ */
printf(LABEL_FORMAT, "write, close, fsync"); printf(LABEL_FORMAT, "write, close, fsync");
fflush(stdout); fflush(stdout);
...@@ -458,7 +465,8 @@ test_file_descriptor_sync(void) ...@@ -458,7 +465,8 @@ test_file_descriptor_sync(void)
static void static void
test_non_sync(void) test_non_sync(void)
{ {
int tmpfile, ops; int tmpfile,
ops;
/* /*
* Test a simple write without fsync * Test a simple write without fsync
...@@ -494,7 +502,6 @@ pg_fsync_writethrough(int fd) ...@@ -494,7 +502,6 @@ pg_fsync_writethrough(int fd)
return -1; return -1;
#endif #endif
} }
#endif #endif
/* /*
......
...@@ -51,8 +51,9 @@ uint32 trgm2int(trgm *ptr); ...@@ -51,8 +51,9 @@ uint32 trgm2int(trgm *ptr);
#endif #endif
#define ISPRINTABLETRGM(t) ( ISPRINTABLECHAR( ((char*)(t)) ) && ISPRINTABLECHAR( ((char*)(t))+1 ) && ISPRINTABLECHAR( ((char*)(t))+2 ) ) #define ISPRINTABLETRGM(t) ( ISPRINTABLECHAR( ((char*)(t)) ) && ISPRINTABLECHAR( ((char*)(t))+1 ) && ISPRINTABLECHAR( ((char*)(t))+2 ) )
#define ISESCAPECHAR(x) (*(x) == '\\') /* Wildcard escape character */ #define ISESCAPECHAR(x) (*(x) == '\\') /* Wildcard escape character */
#define ISWILDCARDCHAR(x) (*(x) == '_' || *(x) == '%') /* Wildcard meta-character */ #define ISWILDCARDCHAR(x) (*(x) == '_' || *(x) == '%') /* Wildcard
* meta-character */
typedef struct typedef struct
{ {
...@@ -105,4 +106,4 @@ TRGM *generate_wildcard_trgm(const char *str, int slen); ...@@ -105,4 +106,4 @@ TRGM *generate_wildcard_trgm(const char *str, int slen);
float4 cnt_sml(TRGM *trg1, TRGM *trg2); float4 cnt_sml(TRGM *trg1, TRGM *trg2);
bool trgm_contained_by(TRGM *trg1, TRGM *trg2); bool trgm_contained_by(TRGM *trg1, TRGM *trg2);
#endif /* __TRGM_H__ */ #endif /* __TRGM_H__ */
...@@ -67,7 +67,7 @@ gin_extract_value_trgm(PG_FUNCTION_ARGS) ...@@ -67,7 +67,7 @@ gin_extract_value_trgm(PG_FUNCTION_ARGS)
ptr = GETARR(trg); ptr = GETARR(trg);
for (i = 0; i < trglen; i++) for (i = 0; i < trglen; i++)
{ {
int32 item = trgm2int(ptr); int32 item = trgm2int(ptr);
entries[i] = Int32GetDatum(item); entries[i] = Int32GetDatum(item);
ptr++; ptr++;
...@@ -83,10 +83,11 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS) ...@@ -83,10 +83,11 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS)
text *val = (text *) PG_GETARG_TEXT_P(0); text *val = (text *) PG_GETARG_TEXT_P(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1); int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
StrategyNumber strategy = PG_GETARG_UINT16(2); StrategyNumber strategy = PG_GETARG_UINT16(2);
/* bool **pmatch = (bool **) PG_GETARG_POINTER(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* bool **pmatch = (bool **) PG_GETARG_POINTER(3); */
/* bool **nullFlags = (bool **) PG_GETARG_POINTER(5); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
int32 *searchMode = (int32 *) PG_GETARG_POINTER(6); /* bool **nullFlags = (bool **) PG_GETARG_POINTER(5); */
int32 *searchMode = (int32 *) PG_GETARG_POINTER(6);
Datum *entries = NULL; Datum *entries = NULL;
TRGM *trg; TRGM *trg;
int32 trglen; int32 trglen;
...@@ -104,6 +105,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS) ...@@ -104,6 +105,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS)
#endif #endif
/* FALL THRU */ /* FALL THRU */
case LikeStrategyNumber: case LikeStrategyNumber:
/* /*
* For wildcard search we extract all the trigrams that every * For wildcard search we extract all the trigrams that every
* potentially-matching string must include. * potentially-matching string must include.
...@@ -112,7 +114,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS) ...@@ -112,7 +114,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "unrecognized strategy number: %d", strategy); elog(ERROR, "unrecognized strategy number: %d", strategy);
trg = NULL; /* keep compiler quiet */ trg = NULL; /* keep compiler quiet */
break; break;
} }
...@@ -125,7 +127,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS) ...@@ -125,7 +127,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS)
ptr = GETARR(trg); ptr = GETARR(trg);
for (i = 0; i < trglen; i++) for (i = 0; i < trglen; i++)
{ {
int32 item = trgm2int(ptr); int32 item = trgm2int(ptr);
entries[i] = Int32GetDatum(item); entries[i] = Int32GetDatum(item);
ptr++; ptr++;
...@@ -146,9 +148,11 @@ gin_trgm_consistent(PG_FUNCTION_ARGS) ...@@ -146,9 +148,11 @@ gin_trgm_consistent(PG_FUNCTION_ARGS)
{ {
bool *check = (bool *) PG_GETARG_POINTER(0); bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1); StrategyNumber strategy = PG_GETARG_UINT16(1);
/* text *query = PG_GETARG_TEXT_P(2); */ /* text *query = PG_GETARG_TEXT_P(2); */
int32 nkeys = PG_GETARG_INT32(3); int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5); bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res; bool res;
int32 i, int32 i,
......
...@@ -190,17 +190,18 @@ gtrgm_consistent(PG_FUNCTION_ARGS) ...@@ -190,17 +190,18 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
text *query = PG_GETARG_TEXT_P(1); text *query = PG_GETARG_TEXT_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */ /* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4); bool *recheck = (bool *) PG_GETARG_POINTER(4);
TRGM *key = (TRGM *) DatumGetPointer(entry->key); TRGM *key = (TRGM *) DatumGetPointer(entry->key);
TRGM *qtrg; TRGM *qtrg;
bool res; bool res;
char *cache = (char *) fcinfo->flinfo->fn_extra, char *cache = (char *) fcinfo->flinfo->fn_extra,
*cacheContents = cache + MAXALIGN(sizeof(StrategyNumber)); *cacheContents = cache + MAXALIGN(sizeof(StrategyNumber));
/* /*
* Store both the strategy number and extracted trigrams in cache, because * Store both the strategy number and extracted trigrams in cache, because
* trigram extraction is relatively CPU-expensive. We must include * trigram extraction is relatively CPU-expensive. We must include
* strategy number because trigram extraction depends on strategy. * strategy number because trigram extraction depends on strategy.
*/ */
if (cache == NULL || strategy != *((StrategyNumber *) cache) || if (cache == NULL || strategy != *((StrategyNumber *) cache) ||
...@@ -222,7 +223,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS) ...@@ -222,7 +223,7 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
break; break;
default: default:
elog(ERROR, "unrecognized strategy number: %d", strategy); elog(ERROR, "unrecognized strategy number: %d", strategy);
qtrg = NULL; /* keep compiler quiet */ qtrg = NULL; /* keep compiler quiet */
break; break;
} }
...@@ -251,20 +252,20 @@ gtrgm_consistent(PG_FUNCTION_ARGS) ...@@ -251,20 +252,20 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
*recheck = false; *recheck = false;
if (GIST_LEAF(entry)) if (GIST_LEAF(entry))
{ /* all leafs contains orig trgm */ { /* all leafs contains orig trgm */
float4 tmpsml = cnt_sml(key, qtrg); float4 tmpsml = cnt_sml(key, qtrg);
/* strange bug at freebsd 5.2.1 and gcc 3.3.3 */ /* strange bug at freebsd 5.2.1 and gcc 3.3.3 */
res = (*(int *) &tmpsml == *(int *) &trgm_limit || tmpsml > trgm_limit) ? true : false; res = (*(int *) &tmpsml == *(int *) &trgm_limit || tmpsml > trgm_limit) ? true : false;
} }
else if (ISALLTRUE(key)) else if (ISALLTRUE(key))
{ /* non-leaf contains signature */ { /* non-leaf contains signature */
res = true; res = true;
} }
else else
{ /* non-leaf contains signature */ { /* non-leaf contains signature */
int4 count = cnt_sml_sign_common(qtrg, GETSIGN(key)); int4 count = cnt_sml_sign_common(qtrg, GETSIGN(key));
int4 len = ARRNELEM(qtrg); int4 len = ARRNELEM(qtrg);
if (len == 0) if (len == 0)
res = false; res = false;
...@@ -286,20 +287,20 @@ gtrgm_consistent(PG_FUNCTION_ARGS) ...@@ -286,20 +287,20 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
* nodes. * nodes.
*/ */
if (GIST_LEAF(entry)) if (GIST_LEAF(entry))
{ /* all leafs contains orig trgm */ { /* all leafs contains orig trgm */
res = trgm_contained_by(qtrg, key); res = trgm_contained_by(qtrg, key);
} }
else if (ISALLTRUE(key)) else if (ISALLTRUE(key))
{ /* non-leaf contains signature */ { /* non-leaf contains signature */
res = true; res = true;
} }
else else
{ /* non-leaf contains signature */ { /* non-leaf contains signature */
int32 k, int32 k,
tmp = 0, tmp = 0,
len = ARRNELEM(qtrg); len = ARRNELEM(qtrg);
trgm *ptr = GETARR(qtrg); trgm *ptr = GETARR(qtrg);
BITVECP sign = GETSIGN(key); BITVECP sign = GETSIGN(key);
res = true; res = true;
for (k = 0; k < len; k++) for (k = 0; k < len; k++)
...@@ -328,6 +329,7 @@ gtrgm_distance(PG_FUNCTION_ARGS) ...@@ -328,6 +329,7 @@ gtrgm_distance(PG_FUNCTION_ARGS)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
text *query = PG_GETARG_TEXT_P(1); text *query = PG_GETARG_TEXT_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */ /* Oid subtype = PG_GETARG_OID(3); */
TRGM *key = (TRGM *) DatumGetPointer(entry->key); TRGM *key = (TRGM *) DatumGetPointer(entry->key);
TRGM *qtrg; TRGM *qtrg;
...@@ -355,17 +357,17 @@ gtrgm_distance(PG_FUNCTION_ARGS) ...@@ -355,17 +357,17 @@ gtrgm_distance(PG_FUNCTION_ARGS)
{ {
case DistanceStrategyNumber: case DistanceStrategyNumber:
if (GIST_LEAF(entry)) if (GIST_LEAF(entry))
{ /* all leafs contains orig trgm */ { /* all leafs contains orig trgm */
res = 1.0 - cnt_sml(key, qtrg); res = 1.0 - cnt_sml(key, qtrg);
} }
else if (ISALLTRUE(key)) else if (ISALLTRUE(key))
{ /* all leafs contains orig trgm */ { /* all leafs contains orig trgm */
res = 0.0; res = 0.0;
} }
else else
{ /* non-leaf contains signature */ { /* non-leaf contains signature */
int4 count = cnt_sml_sign_common(qtrg, GETSIGN(key)); int4 count = cnt_sml_sign_common(qtrg, GETSIGN(key));
int4 len = ARRNELEM(qtrg); int4 len = ARRNELEM(qtrg);
res = (len == 0) ? -1.0 : 1.0 - ((float8) count) / ((float8) len); res = (len == 0) ? -1.0 : 1.0 - ((float8) count) / ((float8) len);
} }
......
...@@ -273,9 +273,9 @@ get_wildcard_part(const char *str, int lenstr, ...@@ -273,9 +273,9 @@ get_wildcard_part(const char *str, int lenstr,
const char *beginword = str; const char *beginword = str;
const char *endword; const char *endword;
char *s = buf; char *s = buf;
bool in_wildcard_meta = false; bool in_wildcard_meta = false;
bool in_escape = false; bool in_escape = false;
int clen; int clen;
/* /*
* Find the first word character remembering whether last character was * Find the first word character remembering whether last character was
...@@ -410,14 +410,14 @@ generate_wildcard_trgm(const char *str, int slen) ...@@ -410,14 +410,14 @@ generate_wildcard_trgm(const char *str, int slen)
{ {
TRGM *trg; TRGM *trg;
char *buf, char *buf,
*buf2; *buf2;
trgm *tptr; trgm *tptr;
int len, int len,
charlen, charlen,
bytelen; bytelen;
const char *eword; const char *eword;
trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) * 3); trg = (TRGM *) palloc(TRGMHDRSIZE + sizeof(trgm) * (slen / 2 + 1) *3);
trg->flag = ARRKEY; trg->flag = ARRKEY;
SET_VARSIZE(trg, TRGMHDRSIZE); SET_VARSIZE(trg, TRGMHDRSIZE);
...@@ -638,6 +638,7 @@ similarity_dist(PG_FUNCTION_ARGS) ...@@ -638,6 +638,7 @@ similarity_dist(PG_FUNCTION_ARGS)
float4 res = DatumGetFloat4(DirectFunctionCall2(similarity, float4 res = DatumGetFloat4(DirectFunctionCall2(similarity,
PG_GETARG_DATUM(0), PG_GETARG_DATUM(0),
PG_GETARG_DATUM(1))); PG_GETARG_DATUM(1)));
PG_RETURN_FLOAT4(1.0 - res); PG_RETURN_FLOAT4(1.0 - res);
} }
......
...@@ -212,7 +212,10 @@ check_cluster_versions(void) ...@@ -212,7 +212,10 @@ check_cluster_versions(void)
old_cluster.major_version = get_major_server_version(&old_cluster); old_cluster.major_version = get_major_server_version(&old_cluster);
new_cluster.major_version = get_major_server_version(&new_cluster); new_cluster.major_version = get_major_server_version(&new_cluster);
/* We allow upgrades from/to the same major version for alpha/beta upgrades */ /*
* We allow upgrades from/to the same major version for alpha/beta
* upgrades
*/
if (GET_MAJOR_VERSION(old_cluster.major_version) < 803) if (GET_MAJOR_VERSION(old_cluster.major_version) < 803)
pg_log(PG_FATAL, "This utility can only upgrade from PostgreSQL version 8.3 and later.\n"); pg_log(PG_FATAL, "This utility can only upgrade from PostgreSQL version 8.3 and later.\n");
...@@ -516,7 +519,7 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster) ...@@ -516,7 +519,7 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
} }
if (script) if (script)
fclose(script); fclose(script);
if (found) if (found)
{ {
......
...@@ -505,8 +505,7 @@ check_control_data(ControlData *oldctrl, ...@@ -505,8 +505,7 @@ check_control_data(ControlData *oldctrl,
"\nOld and new pg_controldata date/time storage types do not match.\n"); "\nOld and new pg_controldata date/time storage types do not match.\n");
/* /*
* This is a common 8.3 -> 8.4 upgrade problem, so we are more * This is a common 8.3 -> 8.4 upgrade problem, so we are more verbose
* verbose
*/ */
pg_log(PG_FATAL, pg_log(PG_FATAL,
"You will need to rebuild the new server with configure\n" "You will need to rebuild the new server with configure\n"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
static void check_data_dir(const char *pg_data); static void check_data_dir(const char *pg_data);
static void check_bin_dir(ClusterInfo *cluster); static void check_bin_dir(ClusterInfo *cluster);
static void validate_exec(const char *dir, const char *cmdName); static void validate_exec(const char *dir, const char *cmdName);
/* /*
......
...@@ -377,4 +377,5 @@ win32_pghardlink(const char *src, const char *dst) ...@@ -377,4 +377,5 @@ win32_pghardlink(const char *src, const char *dst)
else else
return 0; return 0;
} }
#endif #endif
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
void void
install_support_functions_in_new_db(const char *db_name) install_support_functions_in_new_db(const char *db_name)
{ {
PGconn *conn = connectToServer(&new_cluster, db_name); PGconn *conn = connectToServer(&new_cluster, db_name);
/* suppress NOTICE of dropped objects */ /* suppress NOTICE of dropped objects */
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"SET client_min_messages = warning;")); "SET client_min_messages = warning;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"DROP SCHEMA IF EXISTS binary_upgrade CASCADE;")); "DROP SCHEMA IF EXISTS binary_upgrade CASCADE;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"RESET client_min_messages;")); "RESET client_min_messages;"));
...@@ -42,31 +42,31 @@ install_support_functions_in_new_db(const char *db_name) ...@@ -42,31 +42,31 @@ install_support_functions_in_new_db(const char *db_name)
"LANGUAGE C STRICT;")); "LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION " "CREATE OR REPLACE FUNCTION "
"binary_upgrade.set_next_array_pg_type_oid(OID) " "binary_upgrade.set_next_array_pg_type_oid(OID) "
"RETURNS VOID " "RETURNS VOID "
"AS '$libdir/pg_upgrade_support' " "AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;")); "LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION " "CREATE OR REPLACE FUNCTION "
"binary_upgrade.set_next_toast_pg_type_oid(OID) " "binary_upgrade.set_next_toast_pg_type_oid(OID) "
"RETURNS VOID " "RETURNS VOID "
"AS '$libdir/pg_upgrade_support' " "AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;")); "LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION " "CREATE OR REPLACE FUNCTION "
"binary_upgrade.set_next_heap_pg_class_oid(OID) " "binary_upgrade.set_next_heap_pg_class_oid(OID) "
"RETURNS VOID " "RETURNS VOID "
"AS '$libdir/pg_upgrade_support' " "AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;")); "LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION " "CREATE OR REPLACE FUNCTION "
"binary_upgrade.set_next_index_pg_class_oid(OID) " "binary_upgrade.set_next_index_pg_class_oid(OID) "
"RETURNS VOID " "RETURNS VOID "
"AS '$libdir/pg_upgrade_support' " "AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;")); "LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn, PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION " "CREATE OR REPLACE FUNCTION "
"binary_upgrade.set_next_toast_pg_class_oid(OID) " "binary_upgrade.set_next_toast_pg_class_oid(OID) "
"RETURNS VOID " "RETURNS VOID "
"AS '$libdir/pg_upgrade_support' " "AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;")); "LANGUAGE C STRICT;"));
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
static void create_rel_filename_map(const char *old_data, const char *new_data, static void create_rel_filename_map(const char *old_data, const char *new_data,
const DbInfo *old_db, const DbInfo *new_db, const DbInfo *old_db, const DbInfo *new_db,
const RelInfo *old_rel, const RelInfo *new_rel, const RelInfo *old_rel, const RelInfo *new_rel,
FileNameMap *map); FileNameMap *map);
static void get_db_infos(ClusterInfo *cluster); static void get_db_infos(ClusterInfo *cluster);
static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo); static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
static void free_rel_infos(RelInfoArr *rel_arr); static void free_rel_infos(RelInfoArr *rel_arr);
...@@ -40,7 +40,7 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, ...@@ -40,7 +40,7 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
if (old_db->rel_arr.nrels != new_db->rel_arr.nrels) if (old_db->rel_arr.nrels != new_db->rel_arr.nrels)
pg_log(PG_FATAL, "old and new databases \"%s\" have a different number of relations\n", pg_log(PG_FATAL, "old and new databases \"%s\" have a different number of relations\n",
old_db->db_name); old_db->db_name);
maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) * maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) *
old_db->rel_arr.nrels); old_db->rel_arr.nrels);
...@@ -52,24 +52,24 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, ...@@ -52,24 +52,24 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
if (old_rel->reloid != new_rel->reloid) if (old_rel->reloid != new_rel->reloid)
pg_log(PG_FATAL, "Mismatch of relation id: database \"%s\", old relid %d, new relid %d\n", pg_log(PG_FATAL, "Mismatch of relation id: database \"%s\", old relid %d, new relid %d\n",
old_db->db_name, old_rel->reloid, new_rel->reloid); old_db->db_name, old_rel->reloid, new_rel->reloid);
/* /*
* In pre-8.4, TOAST table names change during CLUSTER; in >= 8.4 * In pre-8.4, TOAST table names change during CLUSTER; in >= 8.4
* TOAST relation names always use heap table oids, hence we * TOAST relation names always use heap table oids, hence we cannot
* cannot check relation names when upgrading from pre-8.4. * check relation names when upgrading from pre-8.4.
*/ */
if (strcmp(old_rel->nspname, new_rel->nspname) != 0 || if (strcmp(old_rel->nspname, new_rel->nspname) != 0 ||
((GET_MAJOR_VERSION(old_cluster.major_version) >= 804 || ((GET_MAJOR_VERSION(old_cluster.major_version) >= 804 ||
strcmp(old_rel->nspname, "pg_toast") != 0) && strcmp(old_rel->nspname, "pg_toast") != 0) &&
strcmp(old_rel->relname, new_rel->relname) != 0)) strcmp(old_rel->relname, new_rel->relname) != 0))
pg_log(PG_FATAL, "Mismatch of relation names: database \"%s\", " pg_log(PG_FATAL, "Mismatch of relation names: database \"%s\", "
"old rel %s.%s, new rel %s.%s\n", "old rel %s.%s, new rel %s.%s\n",
old_db->db_name, old_rel->nspname, old_rel->relname, old_db->db_name, old_rel->nspname, old_rel->relname,
new_rel->nspname, new_rel->relname); new_rel->nspname, new_rel->relname);
create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db, create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
old_rel, new_rel, maps + num_maps); old_rel, new_rel, maps + num_maps);
num_maps++; num_maps++;
} }
...@@ -85,9 +85,9 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db, ...@@ -85,9 +85,9 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
*/ */
static void static void
create_rel_filename_map(const char *old_data, const char *new_data, create_rel_filename_map(const char *old_data, const char *new_data,
const DbInfo *old_db, const DbInfo *new_db, const DbInfo *old_db, const DbInfo *new_db,
const RelInfo *old_rel, const RelInfo *new_rel, const RelInfo *old_rel, const RelInfo *new_rel,
FileNameMap *map) FileNameMap *map)
{ {
if (strlen(old_rel->tablespace) == 0) if (strlen(old_rel->tablespace) == 0)
{ {
...@@ -110,8 +110,8 @@ create_rel_filename_map(const char *old_data, const char *new_data, ...@@ -110,8 +110,8 @@ create_rel_filename_map(const char *old_data, const char *new_data,
} }
/* /*
* old_relfilenode might differ from pg_class.oid (and hence * old_relfilenode might differ from pg_class.oid (and hence
* new_relfilenode) because of CLUSTER, REINDEX, or VACUUM FULL. * new_relfilenode) because of CLUSTER, REINDEX, or VACUUM FULL.
*/ */
map->old_relfilenode = old_rel->relfilenode; map->old_relfilenode = old_rel->relfilenode;
...@@ -185,7 +185,9 @@ get_db_infos(ClusterInfo *cluster) ...@@ -185,7 +185,9 @@ get_db_infos(ClusterInfo *cluster)
int ntups; int ntups;
int tupnum; int tupnum;
DbInfo *dbinfos; DbInfo *dbinfos;
int i_datname, i_oid, i_spclocation; int i_datname,
i_oid,
i_spclocation;
res = executeQueryOrDie(conn, res = executeQueryOrDie(conn,
"SELECT d.oid, d.datname, t.spclocation " "SELECT d.oid, d.datname, t.spclocation "
...@@ -241,15 +243,19 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo) ...@@ -241,15 +243,19 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
int num_rels = 0; int num_rels = 0;
char *nspname = NULL; char *nspname = NULL;
char *relname = NULL; char *relname = NULL;
int i_spclocation, i_nspname, i_relname, i_oid, i_relfilenode; int i_spclocation,
i_nspname,
i_relname,
i_oid,
i_relfilenode;
char query[QUERY_ALLOC]; char query[QUERY_ALLOC];
/* /*
* pg_largeobject contains user data that does not appear in pg_dumpall * pg_largeobject contains user data that does not appear in pg_dumpall
* --schema-only output, so we have to copy that system table heap and * --schema-only output, so we have to copy that system table heap and
* index. We could grab the pg_largeobject oids from template1, but * index. We could grab the pg_largeobject oids from template1, but it is
* it is easy to treat it as a normal table. * easy to treat it as a normal table. Order by oid so we can join old/new
* Order by oid so we can join old/new structures efficiently. * structures efficiently.
*/ */
snprintf(query, sizeof(query), snprintf(query, sizeof(query),
...@@ -263,7 +269,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo) ...@@ -263,7 +269,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
" ((n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') AND " " ((n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade') AND "
" c.oid >= %u) " " c.oid >= %u) "
" OR (n.nspname = 'pg_catalog' AND " " OR (n.nspname = 'pg_catalog' AND "
" relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) " " relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
/* we preserve pg_class.oid so we sort by it to match old/new */ /* we preserve pg_class.oid so we sort by it to match old/new */
"ORDER BY 1;", "ORDER BY 1;",
/* see the comment at the top of old_8_3_create_sequence_script() */ /* see the comment at the top of old_8_3_create_sequence_script() */
...@@ -273,7 +279,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo) ...@@ -273,7 +279,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
FirstNormalObjectId, FirstNormalObjectId,
/* does pg_largeobject_metadata need to be migrated? */ /* does pg_largeobject_metadata need to be migrated? */
(GET_MAJOR_VERSION(old_cluster.major_version) <= 804) ? (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) ?
"" : ", 'pg_largeobject_metadata', 'pg_largeobject_metadata_oid_index'"); "" : ", 'pg_largeobject_metadata', 'pg_largeobject_metadata_oid_index'");
res = executeQueryOrDie(conn, query); res = executeQueryOrDie(conn, query);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* FYI, while pg_class.oid and pg_class.relfilenode are intially the same * FYI, while pg_class.oid and pg_class.relfilenode are intially the same
* in a cluster, but they can diverge due to CLUSTER, REINDEX, or VACUUM * in a cluster, but they can diverge due to CLUSTER, REINDEX, or VACUUM
* FULL. The new cluster will have matching pg_class.oid and * FULL. The new cluster will have matching pg_class.oid and
* pg_class.relfilenode values and be based on the old oid value. This can * pg_class.relfilenode values and be based on the old oid value. This can
* cause the old and new pg_class.relfilenode values to differ. In summary, * cause the old and new pg_class.relfilenode values to differ. In summary,
* old and new pg_class.oid and new pg_class.relfilenode will have the * old and new pg_class.oid and new pg_class.relfilenode will have the
* same value, and old pg_class.relfilenode might differ. * same value, and old pg_class.relfilenode might differ.
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
*/ */
#include "pg_upgrade.h" #include "pg_upgrade.h"
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
...@@ -53,7 +53,8 @@ static void cleanup(void); ...@@ -53,7 +53,8 @@ static void cleanup(void);
/* This is the database used by pg_dumpall to restore global tables */ /* This is the database used by pg_dumpall to restore global tables */
#define GLOBAL_DUMP_DB "postgres" #define GLOBAL_DUMP_DB "postgres"
ClusterInfo old_cluster, new_cluster; ClusterInfo old_cluster,
new_cluster;
OSInfo os_info; OSInfo os_info;
int int
...@@ -192,7 +193,7 @@ prepare_new_cluster(void) ...@@ -192,7 +193,7 @@ prepare_new_cluster(void)
exec_prog(true, exec_prog(true,
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" " SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
"--all --analyze >> %s 2>&1" SYSTEMQUOTE, "--all --analyze >> %s 2>&1" SYSTEMQUOTE,
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename); new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
check_ok(); check_ok();
/* /*
...@@ -205,7 +206,7 @@ prepare_new_cluster(void) ...@@ -205,7 +206,7 @@ prepare_new_cluster(void)
exec_prog(true, exec_prog(true,
SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" " SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
"--all --freeze >> %s 2>&1" SYSTEMQUOTE, "--all --freeze >> %s 2>&1" SYSTEMQUOTE,
new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename); new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
check_ok(); check_ok();
get_pg_database_relfilenode(&new_cluster); get_pg_database_relfilenode(&new_cluster);
...@@ -229,16 +230,16 @@ prepare_new_databases(void) ...@@ -229,16 +230,16 @@ prepare_new_databases(void)
prep_status("Creating databases in the new cluster"); prep_status("Creating databases in the new cluster");
/* /*
* Install support functions in the global-restore database * Install support functions in the global-restore database to preserve
* to preserve pg_authid.oid. * pg_authid.oid.
*/ */
install_support_functions_in_new_db(GLOBAL_DUMP_DB); install_support_functions_in_new_db(GLOBAL_DUMP_DB);
/* /*
* We have to create the databases first so we can install support * We have to create the databases first so we can install support
* functions in all the other databases. Ideally we could create * functions in all the other databases. Ideally we could create the
* the support functions in template1 but pg_dumpall creates database * support functions in template1 but pg_dumpall creates database using
* using the template0 template. * the template0 template.
*/ */
exec_prog(true, exec_prog(true,
SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on " SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on "
......
...@@ -85,6 +85,7 @@ typedef struct ...@@ -85,6 +85,7 @@ typedef struct
{ {
char old_dir[MAXPGPATH]; char old_dir[MAXPGPATH];
char new_dir[MAXPGPATH]; char new_dir[MAXPGPATH];
/* /*
* old/new relfilenodes might differ for pg_largeobject(_metadata) indexes * old/new relfilenodes might differ for pg_largeobject(_metadata) indexes
* due to VACUUM FULL or REINDEX. Other relfilenodes are preserved. * due to VACUUM FULL or REINDEX. Other relfilenodes are preserved.
...@@ -92,7 +93,7 @@ typedef struct ...@@ -92,7 +93,7 @@ typedef struct
Oid old_relfilenode; Oid old_relfilenode;
Oid new_relfilenode; Oid new_relfilenode;
/* the rest are used only for logging and error reporting */ /* the rest are used only for logging and error reporting */
char nspname[NAMEDATALEN]; /* namespaces */ char nspname[NAMEDATALEN]; /* namespaces */
char relname[NAMEDATALEN]; char relname[NAMEDATALEN];
} FileNameMap; } FileNameMap;
...@@ -180,7 +181,7 @@ typedef struct ...@@ -180,7 +181,7 @@ typedef struct
char *bindir; /* pathname for cluster's executable directory */ char *bindir; /* pathname for cluster's executable directory */
unsigned short port; /* port number where postmaster is waiting */ unsigned short port; /* port number where postmaster is waiting */
uint32 major_version; /* PG_VERSION of cluster */ uint32 major_version; /* PG_VERSION of cluster */
char major_version_str[64]; /* string PG_VERSION of cluster */ char major_version_str[64]; /* string PG_VERSION of cluster */
Oid pg_database_oid; /* OID of pg_database relation */ Oid pg_database_oid; /* OID of pg_database relation */
char *libpath; /* pathname for cluster's pkglibdir */ char *libpath; /* pathname for cluster's pkglibdir */
char *tablespace_suffix; /* directory specification */ char *tablespace_suffix; /* directory specification */
...@@ -232,9 +233,10 @@ typedef struct ...@@ -232,9 +233,10 @@ typedef struct
/* /*
* Global variables * Global variables
*/ */
extern LogOpts log_opts; extern LogOpts log_opts;
extern UserOpts user_opts; extern UserOpts user_opts;
extern ClusterInfo old_cluster, new_cluster; extern ClusterInfo old_cluster,
new_cluster;
extern OSInfo os_info; extern OSInfo os_info;
extern char scandir_file_pattern[]; extern char scandir_file_pattern[];
...@@ -246,8 +248,8 @@ void check_old_cluster(bool live_check, ...@@ -246,8 +248,8 @@ void check_old_cluster(bool live_check,
char **sequence_script_file_name); char **sequence_script_file_name);
void check_new_cluster(void); void check_new_cluster(void);
void report_clusters_compatible(void); void report_clusters_compatible(void);
void issue_warnings(char *sequence_script_file_name); void issue_warnings(char *sequence_script_file_name);
void output_completion_banner(char *deletion_script_file_name); void output_completion_banner(char *deletion_script_file_name);
void check_cluster_versions(void); void check_cluster_versions(void);
void check_cluster_compatibility(bool live_check); void check_cluster_compatibility(bool live_check);
void create_script_for_old_cluster_deletion(char **deletion_script_file_name); void create_script_for_old_cluster_deletion(char **deletion_script_file_name);
...@@ -309,11 +311,11 @@ typedef void *pageCnvCtx; ...@@ -309,11 +311,11 @@ typedef void *pageCnvCtx;
int dir_matching_filenames(const struct dirent * scan_ent); int dir_matching_filenames(const struct dirent * scan_ent);
int pg_scandir(const char *dirname, struct dirent *** namelist, int pg_scandir(const char *dirname, struct dirent *** namelist,
int (*selector) (const struct dirent *)); int (*selector) (const struct dirent *));
const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src, const char *copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
const char *dst, bool force); const char *dst, bool force);
const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src, const char *linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src,
const char *dst); const char *dst);
void check_hard_link(void); void check_hard_link(void);
...@@ -329,10 +331,10 @@ void check_loadable_libraries(void); ...@@ -329,10 +331,10 @@ void check_loadable_libraries(void);
FileNameMap *gen_db_file_maps(DbInfo *old_db, FileNameMap *gen_db_file_maps(DbInfo *old_db,
DbInfo *new_db, int *nmaps, const char *old_pgdata, DbInfo *new_db, int *nmaps, const char *old_pgdata,
const char *new_pgdata); const char *new_pgdata);
void get_db_and_rel_infos(ClusterInfo *cluster); void get_db_and_rel_infos(ClusterInfo *cluster);
void free_db_and_rel_infos(DbInfoArr *db_arr); void free_db_and_rel_infos(DbInfoArr *db_arr);
void print_maps(FileNameMap *maps, int n, void print_maps(FileNameMap *maps, int n,
const char *db_name); const char *db_name);
/* option.c */ /* option.c */
...@@ -352,12 +354,12 @@ void init_tablespaces(void); ...@@ -352,12 +354,12 @@ void init_tablespaces(void);
/* server.c */ /* server.c */
PGconn *connectToServer(ClusterInfo *cluster, const char *db_name); PGconn *connectToServer(ClusterInfo *cluster, const char *db_name);
PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...); PGresult *executeQueryOrDie(PGconn *conn, const char *fmt,...);
void start_postmaster(ClusterInfo *cluster, bool quiet); void start_postmaster(ClusterInfo *cluster, bool quiet);
void stop_postmaster(bool fast, bool quiet); void stop_postmaster(bool fast, bool quiet);
uint32 get_major_server_version(ClusterInfo *cluster); uint32 get_major_server_version(ClusterInfo *cluster);
void check_for_libpq_envvars(void); void check_for_libpq_envvars(void);
...@@ -380,14 +382,14 @@ unsigned int str2uint(const char *str); ...@@ -380,14 +382,14 @@ unsigned int str2uint(const char *str);
/* version.c */ /* version.c */
void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
bool check_mode); bool check_mode);
/* version_old_8_3.c */ /* version_old_8_3.c */
void old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster); void old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster);
void old_8_3_check_for_tsquery_usage(ClusterInfo *cluster); void old_8_3_check_for_tsquery_usage(ClusterInfo *cluster);
void old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode); void old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode);
void old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode); void old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode);
void old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster, void old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster,
bool check_mode); bool check_mode);
char *old_8_3_create_sequence_script(ClusterInfo *cluster); char *old_8_3_create_sequence_script(ClusterInfo *cluster);
...@@ -30,7 +30,7 @@ char scandir_file_pattern[MAXPGPATH]; ...@@ -30,7 +30,7 @@ char scandir_file_pattern[MAXPGPATH];
*/ */
const char * const char *
transfer_all_new_dbs(DbInfoArr *old_db_arr, transfer_all_new_dbs(DbInfoArr *old_db_arr,
DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata) DbInfoArr *new_db_arr, char *old_pgdata, char *new_pgdata)
{ {
int dbnum; int dbnum;
const char *msg = NULL; const char *msg = NULL;
...@@ -39,7 +39,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, ...@@ -39,7 +39,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
if (old_db_arr->ndbs != new_db_arr->ndbs) if (old_db_arr->ndbs != new_db_arr->ndbs)
pg_log(PG_FATAL, "old and new clusters have a different number of databases\n"); pg_log(PG_FATAL, "old and new clusters have a different number of databases\n");
for (dbnum = 0; dbnum < old_db_arr->ndbs; dbnum++) for (dbnum = 0; dbnum < old_db_arr->ndbs; dbnum++)
{ {
DbInfo *old_db = &old_db_arr->dbs[dbnum]; DbInfo *old_db = &old_db_arr->dbs[dbnum];
...@@ -50,8 +50,8 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, ...@@ -50,8 +50,8 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr,
if (strcmp(old_db->db_name, new_db->db_name) != 0) if (strcmp(old_db->db_name, new_db->db_name) != 0)
pg_log(PG_FATAL, "old and new databases have different names: old \"%s\", new \"%s\"\n", pg_log(PG_FATAL, "old and new databases have different names: old \"%s\", new \"%s\"\n",
old_db->db_name, new_db->db_name); old_db->db_name, new_db->db_name);
n_maps = 0; n_maps = 0;
mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata, mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata,
new_pgdata); new_pgdata);
...@@ -169,7 +169,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter, ...@@ -169,7 +169,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
for (fileno = 0; fileno < numFiles; fileno++) for (fileno = 0; fileno < numFiles; fileno++)
{ {
if (strncmp(namelist[fileno]->d_name, scandir_file_pattern, if (strncmp(namelist[fileno]->d_name, scandir_file_pattern,
strlen(scandir_file_pattern)) == 0) strlen(scandir_file_pattern)) == 0)
{ {
snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir, snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir,
namelist[fileno]->d_name); namelist[fileno]->d_name);
...@@ -178,7 +178,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter, ...@@ -178,7 +178,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
unlink(new_file); unlink(new_file);
transfer_relfile(pageConverter, old_file, new_file, transfer_relfile(pageConverter, old_file, new_file,
maps[mapnum].nspname, maps[mapnum].relname); maps[mapnum].nspname, maps[mapnum].relname);
} }
} }
} }
...@@ -196,7 +196,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter, ...@@ -196,7 +196,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
for (fileno = 0; fileno < numFiles; fileno++) for (fileno = 0; fileno < numFiles; fileno++)
{ {
if (strncmp(namelist[fileno]->d_name, scandir_file_pattern, if (strncmp(namelist[fileno]->d_name, scandir_file_pattern,
strlen(scandir_file_pattern)) == 0) strlen(scandir_file_pattern)) == 0)
{ {
snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir, snprintf(old_file, sizeof(old_file), "%s/%s", maps[mapnum].old_dir,
namelist[fileno]->d_name); namelist[fileno]->d_name);
...@@ -205,7 +205,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter, ...@@ -205,7 +205,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
unlink(new_file); unlink(new_file);
transfer_relfile(pageConverter, old_file, new_file, transfer_relfile(pageConverter, old_file, new_file,
maps[mapnum].nspname, maps[mapnum].relname); maps[mapnum].nspname, maps[mapnum].relname);
} }
} }
} }
...@@ -227,7 +227,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter, ...@@ -227,7 +227,7 @@ transfer_single_new_db(pageCnvCtx *pageConverter,
*/ */
static void static void
transfer_relfile(pageCnvCtx *pageConverter, const char *old_file, transfer_relfile(pageCnvCtx *pageConverter, const char *old_file,
const char *new_file, const char *nspname, const char *relname) const char *new_file, const char *nspname, const char *relname)
{ {
const char *msg; const char *msg;
...@@ -249,7 +249,7 @@ transfer_relfile(pageCnvCtx *pageConverter, const char *old_file, ...@@ -249,7 +249,7 @@ transfer_relfile(pageCnvCtx *pageConverter, const char *old_file,
if ((msg = linkAndUpdateFile(pageConverter, old_file, new_file)) != NULL) if ((msg = linkAndUpdateFile(pageConverter, old_file, new_file)) != NULL)
pg_log(PG_FATAL, pg_log(PG_FATAL,
"error while creating link from %s.%s (%s to %s): %s\n", "error while creating link from %s.%s (%s to %s): %s\n",
nspname, relname, old_file, new_file, msg); nspname, relname, old_file, new_file, msg);
} }
return; return;
......
...@@ -194,12 +194,12 @@ start_postmaster(ClusterInfo *cluster, bool quiet) ...@@ -194,12 +194,12 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
* because it is being used by another process." so we have to send all * because it is being used by another process." so we have to send all
* other output to 'nul'. * other output to 'nul'.
* *
* Using autovacuum=off disables cleanup vacuum and analyze, but * Using autovacuum=off disables cleanup vacuum and analyze, but freeze
* freeze vacuums can still happen, so we set * vacuums can still happen, so we set autovacuum_freeze_max_age to its
* autovacuum_freeze_max_age to its maximum. We assume all datfrozenxid * maximum. We assume all datfrozenxid and relfrozen values are less than
* and relfrozen values are less than a gap of 2000000000 from the current * a gap of 2000000000 from the current xid counter, so autovacuum will
* xid counter, so autovacuum will not touch them. * not touch them.
*/ */
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" " SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
"-o \"-p %d -c autovacuum=off " "-o \"-p %d -c autovacuum=off "
...@@ -251,7 +251,7 @@ stop_postmaster(bool fast, bool quiet) ...@@ -251,7 +251,7 @@ stop_postmaster(bool fast, bool quiet)
"\"%s\" 2>&1" SYSTEMQUOTE, "\"%s\" 2>&1" SYSTEMQUOTE,
bindir, bindir,
#ifndef WIN32 #ifndef WIN32
log_opts.filename, datadir, fast ? "-m fast" : "", log_opts.filename); log_opts.filename, datadir, fast ? "-m fast" : "", log_opts.filename);
#else #else
DEVNULL, datadir, fast ? "-m fast" : "", DEVNULL); DEVNULL, datadir, fast ? "-m fast" : "", DEVNULL);
#endif #endif
......
...@@ -78,8 +78,8 @@ set_tablespace_directory_suffix(ClusterInfo *cluster) ...@@ -78,8 +78,8 @@ set_tablespace_directory_suffix(ClusterInfo *cluster)
{ {
/* This cluster has a version-specific subdirectory */ /* This cluster has a version-specific subdirectory */
cluster->tablespace_suffix = pg_malloc(4 + cluster->tablespace_suffix = pg_malloc(4 +
strlen(cluster->major_version_str) + strlen(cluster->major_version_str) +
10 /* OIDCHARS */ + 1); 10 /* OIDCHARS */ + 1);
/* The leading slash is needed to start a new directory. */ /* The leading slash is needed to start a new directory. */
sprintf(cluster->tablespace_suffix, "/PG_%s_%d", cluster->major_version_str, sprintf(cluster->tablespace_suffix, "/PG_%s_%d", cluster->major_version_str,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <signal.h> #include <signal.h>
LogOpts log_opts; LogOpts log_opts;
/* /*
* report_status() * report_status()
......
...@@ -288,7 +288,7 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode) ...@@ -288,7 +288,7 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
/* Rebuild all tsvector collumns with one ALTER TABLE command */ /* Rebuild all tsvector collumns with one ALTER TABLE command */
if (strcmp(PQgetvalue(res, rowno, i_nspname), nspname) != 0 || if (strcmp(PQgetvalue(res, rowno, i_nspname), nspname) != 0 ||
strcmp(PQgetvalue(res, rowno, i_relname), relname) != 0) strcmp(PQgetvalue(res, rowno, i_relname), relname) != 0)
{ {
if (strlen(nspname) != 0 || strlen(relname) != 0) if (strlen(nspname) != 0 || strlen(relname) != 0)
fprintf(script, ";\n\n"); fprintf(script, ";\n\n");
......
...@@ -178,9 +178,9 @@ create_empty_extension(PG_FUNCTION_ARGS) ...@@ -178,9 +178,9 @@ create_empty_extension(PG_FUNCTION_ARGS)
&textDatums, NULL, &ndatums); &textDatums, NULL, &ndatums);
for (i = 0; i < ndatums; i++) for (i = 0; i < ndatums; i++)
{ {
text *txtname = DatumGetTextPP(textDatums[i]); text *txtname = DatumGetTextPP(textDatums[i]);
char *extName = text_to_cstring(txtname); char *extName = text_to_cstring(txtname);
Oid extOid = get_extension_oid(extName, false); Oid extOid = get_extension_oid(extName, false);
requiredExtensions = lappend_oid(requiredExtensions, extOid); requiredExtensions = lappend_oid(requiredExtensions, extOid);
} }
...@@ -188,7 +188,7 @@ create_empty_extension(PG_FUNCTION_ARGS) ...@@ -188,7 +188,7 @@ create_empty_extension(PG_FUNCTION_ARGS)
InsertExtensionTuple(text_to_cstring(extName), InsertExtensionTuple(text_to_cstring(extName),
GetUserId(), GetUserId(),
get_namespace_oid(text_to_cstring(schemaName), false), get_namespace_oid(text_to_cstring(schemaName), false),
relocatable, relocatable,
text_to_cstring(extVersion), text_to_cstring(extVersion),
extConfig, extConfig,
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
typedef struct win32_pthread *pthread_t; typedef struct win32_pthread *pthread_t;
typedef int pthread_attr_t; typedef int pthread_attr_t;
static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); static int pthread_create(pthread_t *thread, pthread_attr_t * attr, void *(*start_routine) (void *), void *arg);
static int pthread_join(pthread_t th, void **thread_return); static int pthread_join(pthread_t th, void **thread_return);
#elif defined(ENABLE_THREAD_SAFETY) #elif defined(ENABLE_THREAD_SAFETY)
/* Use platform-dependent pthread capability */ /* Use platform-dependent pthread capability */
...@@ -87,7 +87,7 @@ static int pthread_join(pthread_t th, void **thread_return); ...@@ -87,7 +87,7 @@ static int pthread_join(pthread_t th, void **thread_return);
typedef struct fork_pthread *pthread_t; typedef struct fork_pthread *pthread_t;
typedef int pthread_attr_t; typedef int pthread_attr_t;
static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); static int pthread_create(pthread_t *thread, pthread_attr_t * attr, void *(*start_routine) (void *), void *arg);
static int pthread_join(pthread_t th, void **thread_return); static int pthread_join(pthread_t th, void **thread_return);
#endif #endif
...@@ -817,7 +817,7 @@ top: ...@@ -817,7 +817,7 @@ top:
INSTR_TIME_SET_CURRENT(now); INSTR_TIME_SET_CURRENT(now);
INSTR_TIME_ACCUM_DIFF(thread->exec_elapsed[cnum], INSTR_TIME_ACCUM_DIFF(thread->exec_elapsed[cnum],
now, st->stmt_begin); now, st->stmt_begin);
thread->exec_count[cnum]++; thread->exec_count[cnum]++;
} }
...@@ -850,8 +850,8 @@ top: ...@@ -850,8 +850,8 @@ top:
if (commands[st->state]->type == SQL_COMMAND) if (commands[st->state]->type == SQL_COMMAND)
{ {
/* /*
* Read and discard the query result; note this is not included * Read and discard the query result; note this is not included in
* in the statement latency numbers. * the statement latency numbers.
*/ */
res = PQgetResult(st->con); res = PQgetResult(st->con);
switch (PQresultStatus(res)) switch (PQresultStatus(res))
...@@ -1716,16 +1716,16 @@ printResults(int ttype, int normal_xacts, int nclients, ...@@ -1716,16 +1716,16 @@ printResults(int ttype, int normal_xacts, int nclients,
for (i = 0; i < num_files; i++) for (i = 0; i < num_files; i++)
{ {
Command **commands; Command **commands;
if (num_files > 1) if (num_files > 1)
printf("statement latencies in milliseconds, file %d:\n", i+1); printf("statement latencies in milliseconds, file %d:\n", i + 1);
else else
printf("statement latencies in milliseconds:\n"); printf("statement latencies in milliseconds:\n");
for (commands = sql_files[i]; *commands != NULL; commands++) for (commands = sql_files[i]; *commands != NULL; commands++)
{ {
Command *command = *commands; Command *command = *commands;
int cnum = command->command_num; int cnum = command->command_num;
double total_time; double total_time;
instr_time total_exec_elapsed; instr_time total_exec_elapsed;
...@@ -1737,7 +1737,7 @@ printResults(int ttype, int normal_xacts, int nclients, ...@@ -1737,7 +1737,7 @@ printResults(int ttype, int normal_xacts, int nclients,
total_exec_count = 0; total_exec_count = 0;
for (t = 0; t < nthreads; t++) for (t = 0; t < nthreads; t++)
{ {
TState *thread = &threads[t]; TState *thread = &threads[t];
INSTR_TIME_ADD(total_exec_elapsed, INSTR_TIME_ADD(total_exec_elapsed,
thread->exec_elapsed[cnum]); thread->exec_elapsed[cnum]);
...@@ -2014,9 +2014,9 @@ main(int argc, char **argv) ...@@ -2014,9 +2014,9 @@ main(int argc, char **argv)
* is_latencies only works with multiple threads in thread-based * is_latencies only works with multiple threads in thread-based
* implementations, not fork-based ones, because it supposes that the * implementations, not fork-based ones, because it supposes that the
* parent can see changes made to the per-thread execution stats by child * parent can see changes made to the per-thread execution stats by child
* threads. It seems useful enough to accept despite this limitation, * threads. It seems useful enough to accept despite this limitation, but
* but perhaps we should FIXME someday (by passing the stats data back * perhaps we should FIXME someday (by passing the stats data back up
* up through the parent-to-child pipes). * through the parent-to-child pipes).
*/ */
#ifndef ENABLE_THREAD_SAFETY #ifndef ENABLE_THREAD_SAFETY
if (is_latencies && nthreads > 1) if (is_latencies && nthreads > 1)
...@@ -2161,7 +2161,7 @@ main(int argc, char **argv) ...@@ -2161,7 +2161,7 @@ main(int argc, char **argv)
threads = (TState *) xmalloc(sizeof(TState) * nthreads); threads = (TState *) xmalloc(sizeof(TState) * nthreads);
for (i = 0; i < nthreads; i++) for (i = 0; i < nthreads; i++)
{ {
TState *thread = &threads[i]; TState *thread = &threads[i];
thread->tid = i; thread->tid = i;
thread->state = &state[nclients / nthreads * i]; thread->state = &state[nclients / nthreads * i];
...@@ -2170,7 +2170,7 @@ main(int argc, char **argv) ...@@ -2170,7 +2170,7 @@ main(int argc, char **argv)
if (is_latencies) if (is_latencies)
{ {
/* Reserve memory for the thread to store per-command latencies */ /* Reserve memory for the thread to store per-command latencies */
int t; int t;
thread->exec_elapsed = (instr_time *) thread->exec_elapsed = (instr_time *)
xmalloc(sizeof(instr_time) * num_commands); xmalloc(sizeof(instr_time) * num_commands);
...@@ -2200,7 +2200,7 @@ main(int argc, char **argv) ...@@ -2200,7 +2200,7 @@ main(int argc, char **argv)
/* start threads */ /* start threads */
for (i = 0; i < nthreads; i++) for (i = 0; i < nthreads; i++)
{ {
TState *thread = &threads[i]; TState *thread = &threads[i];
INSTR_TIME_SET_CURRENT(thread->start_time); INSTR_TIME_SET_CURRENT(thread->start_time);
...@@ -2472,7 +2472,7 @@ typedef struct fork_pthread ...@@ -2472,7 +2472,7 @@ typedef struct fork_pthread
static int static int
pthread_create(pthread_t *thread, pthread_create(pthread_t *thread,
pthread_attr_t *attr, pthread_attr_t * attr,
void *(*start_routine) (void *), void *(*start_routine) (void *),
void *arg) void *arg)
{ {
...@@ -2586,7 +2586,7 @@ typedef struct win32_pthread ...@@ -2586,7 +2586,7 @@ typedef struct win32_pthread
void *(*routine) (void *); void *(*routine) (void *);
void *arg; void *arg;
void *result; void *result;
} win32_pthread; } win32_pthread;
static unsigned __stdcall static unsigned __stdcall
win32_pthread_run(void *arg) win32_pthread_run(void *arg)
...@@ -2600,7 +2600,7 @@ win32_pthread_run(void *arg) ...@@ -2600,7 +2600,7 @@ win32_pthread_run(void *arg)
static int static int
pthread_create(pthread_t *thread, pthread_create(pthread_t *thread,
pthread_attr_t *attr, pthread_attr_t * attr,
void *(*start_routine) (void *), void *(*start_routine) (void *),
void *arg) void *arg)
{ {
......
...@@ -356,7 +356,7 @@ gseg_picksplit(GistEntryVector *entryvec, ...@@ -356,7 +356,7 @@ gseg_picksplit(GistEntryVector *entryvec,
{ {
seg = (SEG *) DatumGetPointer(entryvec->vector[i].key); seg = (SEG *) DatumGetPointer(entryvec->vector[i].key);
/* center calculation is done this way to avoid possible overflow */ /* center calculation is done this way to avoid possible overflow */
sort_items[i - 1].center = seg->lower*0.5f + seg->upper*0.5f; sort_items[i - 1].center = seg->lower * 0.5f + seg->upper * 0.5f;
sort_items[i - 1].index = i; sort_items[i - 1].index = i;
sort_items[i - 1].data = seg; sort_items[i - 1].data = seg;
} }
......
...@@ -59,7 +59,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns) ...@@ -59,7 +59,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
result = bms_copy(columns); result = bms_copy(columns);
result = bms_del_member(result, index); result = bms_del_member(result, index);
for (attno=1; attno <= natts; attno++) for (attno = 1; attno <= natts; attno++)
{ {
tuple = SearchSysCache2(ATTNUM, tuple = SearchSysCache2(ATTNUM,
ObjectIdGetDatum(relOid), ObjectIdGetDatum(relOid),
...@@ -108,6 +108,7 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns) ...@@ -108,6 +108,7 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns)
while ((index = bms_first_member(tmpset)) > 0) while ((index = bms_first_member(tmpset)) > 0)
{ {
attno = index + FirstLowInvalidHeapAttributeNumber; attno = index + FirstLowInvalidHeapAttributeNumber;
/* /*
* whole-row-reference shall be fixed-up later * whole-row-reference shall be fixed-up later
*/ */
...@@ -158,14 +159,13 @@ check_relation_privileges(Oid relOid, ...@@ -158,14 +159,13 @@ check_relation_privileges(Oid relOid,
bool result = true; bool result = true;
/* /*
* Hardwired Policies: * Hardwired Policies: SE-PostgreSQL enforces - clients cannot modify
* SE-PostgreSQL enforces * system catalogs using DMLs - clients cannot reference/modify toast
* - clients cannot modify system catalogs using DMLs * relations using DMLs
* - clients cannot reference/modify toast relations using DMLs
*/ */
if (sepgsql_getenforce() > 0) if (sepgsql_getenforce() > 0)
{ {
Oid relnamespace = get_rel_namespace(relOid); Oid relnamespace = get_rel_namespace(relOid);
if (IsSystemNamespace(relnamespace) && if (IsSystemNamespace(relnamespace) &&
(required & (SEPG_DB_TABLE__UPDATE | (required & (SEPG_DB_TABLE__UPDATE |
...@@ -242,7 +242,7 @@ check_relation_privileges(Oid relOid, ...@@ -242,7 +242,7 @@ check_relation_privileges(Oid relOid,
{ {
AttrNumber attnum; AttrNumber attnum;
uint32 column_perms = 0; uint32 column_perms = 0;
ObjectAddress object; ObjectAddress object;
if (bms_is_member(index, selected)) if (bms_is_member(index, selected))
column_perms |= SEPG_DB_COLUMN__SELECT; column_perms |= SEPG_DB_COLUMN__SELECT;
...@@ -290,12 +290,12 @@ sepgsql_dml_privileges(List *rangeTabls, bool abort) ...@@ -290,12 +290,12 @@ sepgsql_dml_privileges(List *rangeTabls, bool abort)
{ {
ListCell *lr; ListCell *lr;
foreach (lr, rangeTabls) foreach(lr, rangeTabls)
{ {
RangeTblEntry *rte = lfirst(lr); RangeTblEntry *rte = lfirst(lr);
uint32 required = 0; uint32 required = 0;
List *tableIds; List *tableIds;
ListCell *li; ListCell *li;
/* /*
* Only regular relations shall be checked * Only regular relations shall be checked
...@@ -328,25 +328,24 @@ sepgsql_dml_privileges(List *rangeTabls, bool abort) ...@@ -328,25 +328,24 @@ sepgsql_dml_privileges(List *rangeTabls, bool abort)
/* /*
* If this RangeTblEntry is also supposed to reference inherited * If this RangeTblEntry is also supposed to reference inherited
* tables, we need to check security label of the child tables. * tables, we need to check security label of the child tables. So, we
* So, we expand rte->relid into list of OIDs of inheritance * expand rte->relid into list of OIDs of inheritance hierarchy, then
* hierarchy, then checker routine will be invoked for each * checker routine will be invoked for each relations.
* relations.
*/ */
if (!rte->inh) if (!rte->inh)
tableIds = list_make1_oid(rte->relid); tableIds = list_make1_oid(rte->relid);
else else
tableIds = find_all_inheritors(rte->relid, NoLock, NULL); tableIds = find_all_inheritors(rte->relid, NoLock, NULL);
foreach (li, tableIds) foreach(li, tableIds)
{ {
Oid tableOid = lfirst_oid(li); Oid tableOid = lfirst_oid(li);
Bitmapset *selectedCols; Bitmapset *selectedCols;
Bitmapset *modifiedCols; Bitmapset *modifiedCols;
/* /*
* child table has different attribute numbers, so we need * child table has different attribute numbers, so we need to fix
* to fix up them. * up them.
*/ */
selectedCols = fixup_inherited_columns(rte->relid, tableOid, selectedCols = fixup_inherited_columns(rte->relid, tableOid,
rte->selectedCols); rte->selectedCols);
......
This diff is collapsed.
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
* *
* security label of the client process * security label of the client process
*/ */
static char *client_label = NULL; static char *client_label = NULL;
char * char *
sepgsql_get_client_label(void) sepgsql_get_client_label(void)
...@@ -49,7 +49,7 @@ sepgsql_get_client_label(void) ...@@ -49,7 +49,7 @@ sepgsql_get_client_label(void)
char * char *
sepgsql_set_client_label(char *new_label) sepgsql_set_client_label(char *new_label)
{ {
char *old_label = client_label; char *old_label = client_label;
client_label = new_label; client_label = new_label;
...@@ -66,22 +66,22 @@ sepgsql_set_client_label(char *new_label) ...@@ -66,22 +66,22 @@ sepgsql_set_client_label(char *new_label)
char * char *
sepgsql_get_label(Oid classId, Oid objectId, int32 subId) sepgsql_get_label(Oid classId, Oid objectId, int32 subId)
{ {
ObjectAddress object; ObjectAddress object;
char *label; char *label;
object.classId = classId; object.classId = classId;
object.objectId = objectId; object.objectId = objectId;
object.objectSubId = subId; object.objectSubId = subId;
label = GetSecurityLabel(&object, SEPGSQL_LABEL_TAG); label = GetSecurityLabel(&object, SEPGSQL_LABEL_TAG);
if (!label || security_check_context_raw((security_context_t)label)) if (!label || security_check_context_raw((security_context_t) label))
{ {
security_context_t unlabeled; security_context_t unlabeled;
if (security_get_initial_context_raw("unlabeled", &unlabeled) < 0) if (security_get_initial_context_raw("unlabeled", &unlabeled) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("SELinux: failed to get initial security label: %m"))); errmsg("SELinux: failed to get initial security label: %m")));
PG_TRY(); PG_TRY();
{ {
label = pstrdup(unlabeled); label = pstrdup(unlabeled);
...@@ -107,21 +107,22 @@ void ...@@ -107,21 +107,22 @@ void
sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel) sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
{ {
/* /*
* validate format of the supplied security label, * validate format of the supplied security label, if it is security
* if it is security context of selinux. * context of selinux.
*/ */
if (seclabel && if (seclabel &&
security_check_context_raw((security_context_t) seclabel) < 0) security_check_context_raw((security_context_t) seclabel) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME), (errcode(ERRCODE_INVALID_NAME),
errmsg("SELinux: invalid security label: \"%s\"", seclabel))); errmsg("SELinux: invalid security label: \"%s\"", seclabel)));
/* /*
* Do actual permission checks for each object classes * Do actual permission checks for each object classes
*/ */
switch (object->classId) switch (object->classId)
{ {
case NamespaceRelationId: case NamespaceRelationId:
sepgsql_schema_relabel(object->objectId, seclabel); sepgsql_schema_relabel(object->objectId, seclabel);
break; break;
case RelationRelationId: case RelationRelationId:
if (object->objectSubId == 0) if (object->objectSubId == 0)
...@@ -151,7 +152,7 @@ PG_FUNCTION_INFO_V1(sepgsql_getcon); ...@@ -151,7 +152,7 @@ PG_FUNCTION_INFO_V1(sepgsql_getcon);
Datum Datum
sepgsql_getcon(PG_FUNCTION_ARGS) sepgsql_getcon(PG_FUNCTION_ARGS)
{ {
char *client_label; char *client_label;
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
PG_RETURN_NULL(); PG_RETURN_NULL();
...@@ -171,9 +172,9 @@ PG_FUNCTION_INFO_V1(sepgsql_mcstrans_in); ...@@ -171,9 +172,9 @@ PG_FUNCTION_INFO_V1(sepgsql_mcstrans_in);
Datum Datum
sepgsql_mcstrans_in(PG_FUNCTION_ARGS) sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
{ {
text *label = PG_GETARG_TEXT_P(0); text *label = PG_GETARG_TEXT_P(0);
char *raw_label; char *raw_label;
char *result; char *result;
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
ereport(ERROR, ereport(ERROR,
...@@ -211,9 +212,9 @@ PG_FUNCTION_INFO_V1(sepgsql_mcstrans_out); ...@@ -211,9 +212,9 @@ PG_FUNCTION_INFO_V1(sepgsql_mcstrans_out);
Datum Datum
sepgsql_mcstrans_out(PG_FUNCTION_ARGS) sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
{ {
text *label = PG_GETARG_TEXT_P(0); text *label = PG_GETARG_TEXT_P(0);
char *qual_label; char *qual_label;
char *result; char *result;
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
ereport(ERROR, ereport(ERROR,
...@@ -250,8 +251,8 @@ static char * ...@@ -250,8 +251,8 @@ static char *
quote_object_name(const char *src1, const char *src2, quote_object_name(const char *src1, const char *src2,
const char *src3, const char *src4) const char *src3, const char *src4)
{ {
StringInfoData result; StringInfoData result;
const char *temp; const char *temp;
initStringInfo(&result); initStringInfo(&result);
...@@ -260,28 +261,28 @@ quote_object_name(const char *src1, const char *src2, ...@@ -260,28 +261,28 @@ quote_object_name(const char *src1, const char *src2,
temp = quote_identifier(src1); temp = quote_identifier(src1);
appendStringInfo(&result, "%s", temp); appendStringInfo(&result, "%s", temp);
if (src1 != temp) if (src1 != temp)
pfree((void *)temp); pfree((void *) temp);
} }
if (src2) if (src2)
{ {
temp = quote_identifier(src2); temp = quote_identifier(src2);
appendStringInfo(&result, ".%s", temp); appendStringInfo(&result, ".%s", temp);
if (src2 != temp) if (src2 != temp)
pfree((void *)temp); pfree((void *) temp);
} }
if (src3) if (src3)
{ {
temp = quote_identifier(src3); temp = quote_identifier(src3);
appendStringInfo(&result, ".%s", temp); appendStringInfo(&result, ".%s", temp);
if (src3 != temp) if (src3 != temp)
pfree((void *)temp); pfree((void *) temp);
} }
if (src4) if (src4)
{ {
temp = quote_identifier(src4); temp = quote_identifier(src4);
appendStringInfo(&result, ".%s", temp); appendStringInfo(&result, ".%s", temp);
if (src4 != temp) if (src4 != temp)
pfree((void *)temp); pfree((void *) temp);
} }
return result.data; return result.data;
} }
...@@ -294,19 +295,19 @@ quote_object_name(const char *src1, const char *src2, ...@@ -294,19 +295,19 @@ quote_object_name(const char *src1, const char *src2,
* catalog OID. * catalog OID.
*/ */
static void static void
exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId) exec_object_restorecon(struct selabel_handle * sehnd, Oid catalogId)
{ {
Relation rel; Relation rel;
SysScanDesc sscan; SysScanDesc sscan;
HeapTuple tuple; HeapTuple tuple;
char *database_name = get_database_name(MyDatabaseId); char *database_name = get_database_name(MyDatabaseId);
char *namespace_name; char *namespace_name;
Oid namespace_id; Oid namespace_id;
char *relation_name; char *relation_name;
/* /*
* Open the target catalog. We don't want to allow writable * Open the target catalog. We don't want to allow writable accesses by
* accesses by other session during initial labeling. * other session during initial labeling.
*/ */
rel = heap_open(catalogId, AccessShareLock); rel = heap_open(catalogId, AccessShareLock);
...@@ -314,18 +315,18 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId) ...@@ -314,18 +315,18 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
SnapshotNow, 0, NULL); SnapshotNow, 0, NULL);
while (HeapTupleIsValid(tuple = systable_getnext(sscan))) while (HeapTupleIsValid(tuple = systable_getnext(sscan)))
{ {
Form_pg_namespace nspForm; Form_pg_namespace nspForm;
Form_pg_class relForm; Form_pg_class relForm;
Form_pg_attribute attForm; Form_pg_attribute attForm;
Form_pg_proc proForm; Form_pg_proc proForm;
char *objname; char *objname;
int objtype = 1234; int objtype = 1234;
ObjectAddress object; ObjectAddress object;
security_context_t context; security_context_t context;
/* /*
* The way to determine object name depends on object classes. * The way to determine object name depends on object classes. So, any
* So, any branches set up `objtype', `objname' and `object' here. * branches set up `objtype', `objname' and `object' here.
*/ */
switch (catalogId) switch (catalogId)
{ {
...@@ -409,7 +410,7 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId) ...@@ -409,7 +410,7 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
default: default:
elog(ERROR, "unexpected catalog id: %u", catalogId); elog(ERROR, "unexpected catalog id: %u", catalogId);
objname = NULL; /* for compiler quiet */ objname = NULL; /* for compiler quiet */
break; break;
} }
...@@ -464,8 +465,8 @@ PG_FUNCTION_INFO_V1(sepgsql_restorecon); ...@@ -464,8 +465,8 @@ PG_FUNCTION_INFO_V1(sepgsql_restorecon);
Datum Datum
sepgsql_restorecon(PG_FUNCTION_ARGS) sepgsql_restorecon(PG_FUNCTION_ARGS)
{ {
struct selabel_handle *sehnd; struct selabel_handle *sehnd;
struct selinux_opt seopts; struct selinux_opt seopts;
/* /*
* SELinux has to be enabled on the running platform. * SELinux has to be enabled on the running platform.
...@@ -474,19 +475,19 @@ sepgsql_restorecon(PG_FUNCTION_ARGS) ...@@ -474,19 +475,19 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("sepgsql is not currently enabled"))); errmsg("sepgsql is not currently enabled")));
/* /*
* Check DAC permission. Only superuser can set up initial * Check DAC permission. Only superuser can set up initial security
* security labels, like root-user in filesystems * labels, like root-user in filesystems
*/ */
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("SELinux: must be superuser to restore initial contexts"))); errmsg("SELinux: must be superuser to restore initial contexts")));
/* /*
* Open selabel_lookup(3) stuff. It provides a set of mapping * Open selabel_lookup(3) stuff. It provides a set of mapping between an
* between an initial security label and object class/name due * initial security label and object class/name due to the system setting.
* to the system setting.
*/ */
if (PG_ARGISNULL(0)) if (PG_ARGISNULL(0))
{ {
...@@ -502,12 +503,12 @@ sepgsql_restorecon(PG_FUNCTION_ARGS) ...@@ -502,12 +503,12 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
if (!sehnd) if (!sehnd)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("SELinux: failed to initialize labeling handle: %m"))); errmsg("SELinux: failed to initialize labeling handle: %m")));
PG_TRY(); PG_TRY();
{ {
/* /*
* Right now, we have no support labeling on the shared * Right now, we have no support labeling on the shared database
* database objects, such as database, role, or tablespace. * objects, such as database, role, or tablespace.
*/ */
exec_object_restorecon(sehnd, NamespaceRelationId); exec_object_restorecon(sehnd, NamespaceRelationId);
exec_object_restorecon(sehnd, RelationRelationId); exec_object_restorecon(sehnd, RelationRelationId);
...@@ -519,7 +520,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS) ...@@ -519,7 +520,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
selabel_close(sehnd); selabel_close(sehnd);
PG_RE_THROW(); PG_RE_THROW();
} }
PG_END_TRY(); PG_END_TRY();
selabel_close(sehnd); selabel_close(sehnd);
......
...@@ -33,15 +33,15 @@ ...@@ -33,15 +33,15 @@
void void
sepgsql_proc_post_create(Oid functionId) sepgsql_proc_post_create(Oid functionId)
{ {
Relation rel; Relation rel;
ScanKeyData skey; ScanKeyData skey;
SysScanDesc sscan; SysScanDesc sscan;
HeapTuple tuple; HeapTuple tuple;
Oid namespaceId; Oid namespaceId;
ObjectAddress object; ObjectAddress object;
char *scontext; char *scontext;
char *tcontext; char *tcontext;
char *ncontext; char *ncontext;
/* /*
* Fetch namespace of the new procedure. Because pg_proc entry is not * Fetch namespace of the new procedure. Because pg_proc entry is not
...@@ -67,8 +67,8 @@ sepgsql_proc_post_create(Oid functionId) ...@@ -67,8 +67,8 @@ sepgsql_proc_post_create(Oid functionId)
heap_close(rel, AccessShareLock); heap_close(rel, AccessShareLock);
/* /*
* Compute a default security label when we create a new procedure * Compute a default security label when we create a new procedure object
* object under the specified namespace. * under the specified namespace.
*/ */
scontext = sepgsql_get_client_label(); scontext = sepgsql_get_client_label();
tcontext = sepgsql_get_label(NamespaceRelationId, namespaceId, 0); tcontext = sepgsql_get_label(NamespaceRelationId, namespaceId, 0);
...@@ -144,9 +144,9 @@ sepgsql_proc_relabel(Oid functionId, const char *seclabel) ...@@ -144,9 +144,9 @@ sepgsql_proc_relabel(Oid functionId, const char *seclabel)
char * char *
sepgsql_proc_get_domtrans(Oid functionId) sepgsql_proc_get_domtrans(Oid functionId)
{ {
char *scontext = sepgsql_get_client_label(); char *scontext = sepgsql_get_client_label();
char *tcontext; char *tcontext;
char *ncontext; char *ncontext;
tcontext = sepgsql_get_label(ProcedureRelationId, functionId, 0); tcontext = sepgsql_get_label(ProcedureRelationId, functionId, 0);
......
...@@ -36,26 +36,27 @@ ...@@ -36,26 +36,27 @@
void void
sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum) sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
{ {
char *scontext = sepgsql_get_client_label(); char *scontext = sepgsql_get_client_label();
char *tcontext; char *tcontext;
char *ncontext; char *ncontext;
ObjectAddress object; ObjectAddress object;
/* /*
* Only attributes within regular relation have individual * Only attributes within regular relation have individual security
* security labels. * labels.
*/ */
if (get_rel_relkind(relOid) != RELKIND_RELATION) if (get_rel_relkind(relOid) != RELKIND_RELATION)
return; return;
/* /*
* Compute a default security label when we create a new procedure * Compute a default security label when we create a new procedure object
* object under the specified namespace. * under the specified namespace.
*/ */
scontext = sepgsql_get_client_label(); scontext = sepgsql_get_client_label();
tcontext = sepgsql_get_label(RelationRelationId, relOid, 0); tcontext = sepgsql_get_label(RelationRelationId, relOid, 0);
ncontext = sepgsql_compute_create(scontext, tcontext, ncontext = sepgsql_compute_create(scontext, tcontext,
SEPG_CLASS_DB_COLUMN); SEPG_CLASS_DB_COLUMN);
/* /*
* Assign the default security label on a new procedure * Assign the default security label on a new procedure
*/ */
...@@ -81,7 +82,7 @@ sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum, ...@@ -81,7 +82,7 @@ sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum,
char *scontext = sepgsql_get_client_label(); char *scontext = sepgsql_get_client_label();
char *tcontext; char *tcontext;
char *audit_name; char *audit_name;
ObjectAddress object; ObjectAddress object;
if (get_rel_relkind(relOid) != RELKIND_RELATION) if (get_rel_relkind(relOid) != RELKIND_RELATION)
ereport(ERROR, ereport(ERROR,
...@@ -127,21 +128,21 @@ sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum, ...@@ -127,21 +128,21 @@ sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum,
void void
sepgsql_relation_post_create(Oid relOid) sepgsql_relation_post_create(Oid relOid)
{ {
Relation rel; Relation rel;
ScanKeyData skey; ScanKeyData skey;
SysScanDesc sscan; SysScanDesc sscan;
HeapTuple tuple; HeapTuple tuple;
Form_pg_class classForm; Form_pg_class classForm;
ObjectAddress object; ObjectAddress object;
uint16 tclass; uint16 tclass;
char *scontext; /* subject */ char *scontext; /* subject */
char *tcontext; /* schema */ char *tcontext; /* schema */
char *rcontext; /* relation */ char *rcontext; /* relation */
char *ccontext; /* column */ char *ccontext; /* column */
/* /*
* Fetch catalog record of the new relation. Because pg_class entry is * Fetch catalog record of the new relation. Because pg_class entry is not
* not visible right now, we need to scan the catalog using SnapshotSelf. * visible right now, we need to scan the catalog using SnapshotSelf.
*/ */
rel = heap_open(RelationRelationId, AccessShareLock); rel = heap_open(RelationRelationId, AccessShareLock);
...@@ -166,11 +167,11 @@ sepgsql_relation_post_create(Oid relOid) ...@@ -166,11 +167,11 @@ sepgsql_relation_post_create(Oid relOid)
else if (classForm->relkind == RELKIND_VIEW) else if (classForm->relkind == RELKIND_VIEW)
tclass = SEPG_CLASS_DB_VIEW; tclass = SEPG_CLASS_DB_VIEW;
else else
goto out; /* No need to assign individual labels */ goto out; /* No need to assign individual labels */
/* /*
* Compute a default security label when we create a new relation * Compute a default security label when we create a new relation object
* object under the specified namespace. * under the specified namespace.
*/ */
scontext = sepgsql_get_client_label(); scontext = sepgsql_get_client_label();
tcontext = sepgsql_get_label(NamespaceRelationId, tcontext = sepgsql_get_label(NamespaceRelationId,
...@@ -186,8 +187,8 @@ sepgsql_relation_post_create(Oid relOid) ...@@ -186,8 +187,8 @@ sepgsql_relation_post_create(Oid relOid)
SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext); SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext);
/* /*
* We also assigns a default security label on columns of the new * We also assigns a default security label on columns of the new regular
* regular tables. * tables.
*/ */
if (classForm->relkind == RELKIND_RELATION) if (classForm->relkind == RELKIND_RELATION)
{ {
......
...@@ -26,21 +26,21 @@ ...@@ -26,21 +26,21 @@
void void
sepgsql_schema_post_create(Oid namespaceId) sepgsql_schema_post_create(Oid namespaceId)
{ {
char *scontext = sepgsql_get_client_label(); char *scontext = sepgsql_get_client_label();
char *tcontext; char *tcontext;
char *ncontext; char *ncontext;
ObjectAddress object; ObjectAddress object;
/* /*
* FIXME: Right now, we assume pg_database object has a fixed * FIXME: Right now, we assume pg_database object has a fixed security
* security label, because pg_seclabel does not support to store * label, because pg_seclabel does not support to store label of shared
* label of shared database objects. * database objects.
*/ */
tcontext = "system_u:object_r:sepgsql_db_t:s0"; tcontext = "system_u:object_r:sepgsql_db_t:s0";
/* /*
* Compute a default security label when we create a new schema * Compute a default security label when we create a new schema object
* object under the working database. * under the working database.
*/ */
ncontext = sepgsql_compute_create(scontext, tcontext, ncontext = sepgsql_compute_create(scontext, tcontext,
SEPG_CLASS_DB_SCHEMA); SEPG_CLASS_DB_SCHEMA);
......
This diff is collapsed.
...@@ -218,33 +218,34 @@ extern bool sepgsql_get_debug_audit(void); ...@@ -218,33 +218,34 @@ extern bool sepgsql_get_debug_audit(void);
/* /*
* selinux.c * selinux.c
*/ */
extern bool sepgsql_is_enabled(void); extern bool sepgsql_is_enabled(void);
extern int sepgsql_get_mode(void); extern int sepgsql_get_mode(void);
extern int sepgsql_set_mode(int new_mode); extern int sepgsql_set_mode(int new_mode);
extern bool sepgsql_getenforce(void); extern bool sepgsql_getenforce(void);
extern void sepgsql_audit_log(bool denied, extern void sepgsql_audit_log(bool denied,
const char *scontext, const char *scontext,
const char *tcontext, const char *tcontext,
uint16 tclass, uint16 tclass,
uint32 audited, uint32 audited,
const char *audit_name); const char *audit_name);
extern void sepgsql_compute_avd(const char *scontext, extern void sepgsql_compute_avd(const char *scontext,
const char *tcontext, const char *tcontext,
uint16 tclass, uint16 tclass,
struct av_decision *avd); struct av_decision * avd);
extern char *sepgsql_compute_create(const char *scontext, extern char *sepgsql_compute_create(const char *scontext,
const char *tcontext, const char *tcontext,
uint16 tclass); uint16 tclass);
extern bool sepgsql_check_perms(const char *scontext, extern bool sepgsql_check_perms(const char *scontext,
const char *tcontext, const char *tcontext,
uint16 tclass, uint16 tclass,
uint32 required, uint32 required,
const char *audit_name, const char *audit_name,
bool abort); bool abort);
/* /*
* label.c * label.c
*/ */
...@@ -252,8 +253,8 @@ extern char *sepgsql_get_client_label(void); ...@@ -252,8 +253,8 @@ extern char *sepgsql_get_client_label(void);
extern char *sepgsql_set_client_label(char *new_label); extern char *sepgsql_set_client_label(char *new_label);
extern char *sepgsql_get_label(Oid relOid, Oid objOid, int32 subId); extern char *sepgsql_get_label(Oid relOid, Oid objOid, int32 subId);
extern void sepgsql_object_relabel(const ObjectAddress *object, extern void sepgsql_object_relabel(const ObjectAddress *object,
const char *seclabel); const char *seclabel);
extern Datum sepgsql_getcon(PG_FUNCTION_ARGS); extern Datum sepgsql_getcon(PG_FUNCTION_ARGS);
extern Datum sepgsql_mcstrans_in(PG_FUNCTION_ARGS); extern Datum sepgsql_mcstrans_in(PG_FUNCTION_ARGS);
...@@ -276,7 +277,7 @@ extern void sepgsql_schema_relabel(Oid namespaceId, const char *seclabel); ...@@ -276,7 +277,7 @@ extern void sepgsql_schema_relabel(Oid namespaceId, const char *seclabel);
*/ */
extern void sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum); extern void sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum);
extern void sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum, extern void sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum,
const char *seclabel); const char *seclabel);
extern void sepgsql_relation_post_create(Oid relOid); extern void sepgsql_relation_post_create(Oid relOid);
extern void sepgsql_relation_relabel(Oid relOid, const char *seclabel); extern void sepgsql_relation_relabel(Oid relOid, const char *seclabel);
...@@ -287,4 +288,4 @@ extern void sepgsql_proc_post_create(Oid functionId); ...@@ -287,4 +288,4 @@ extern void sepgsql_proc_post_create(Oid functionId);
extern void sepgsql_proc_relabel(Oid functionId, const char *seclabel); extern void sepgsql_proc_relabel(Oid functionId, const char *seclabel);
extern char *sepgsql_proc_get_domtrans(Oid functionId); extern char *sepgsql_proc_get_domtrans(Oid functionId);
#endif /* SEPGSQL_H */ #endif /* SEPGSQL_H */
...@@ -84,7 +84,7 @@ moddatetime(PG_FUNCTION_ARGS) ...@@ -84,7 +84,7 @@ moddatetime(PG_FUNCTION_ARGS)
/* /*
* This is where we check to see if the field we are supposed to update * This is where we check to see if the field we are supposed to update
* even exists. The above function must return -1 if name not found? * even exists. The above function must return -1 if name not found?
*/ */
if (attnum < 0) if (attnum < 0)
ereport(ERROR, ereport(ERROR,
......
...@@ -61,7 +61,7 @@ static text *pgxml_result_to_text(xmlXPathObjectPtr res, xmlChar *toptag, ...@@ -61,7 +61,7 @@ static text *pgxml_result_to_text(xmlXPathObjectPtr res, xmlChar *toptag,
static xmlChar *pgxml_texttoxmlchar(text *textstring); static xmlChar *pgxml_texttoxmlchar(text *textstring);
static xmlXPathObjectPtr pgxml_xpath(text *document, xmlChar *xpath, static xmlXPathObjectPtr pgxml_xpath(text *document, xmlChar *xpath,
xpath_workspace *workspace); xpath_workspace *workspace);
static void cleanup_workspace(xpath_workspace *workspace); static void cleanup_workspace(xpath_workspace *workspace);
...@@ -234,7 +234,7 @@ Datum ...@@ -234,7 +234,7 @@ Datum
xpath_nodeset(PG_FUNCTION_ARGS) xpath_nodeset(PG_FUNCTION_ARGS)
{ {
text *document = PG_GETARG_TEXT_P(0); text *document = PG_GETARG_TEXT_P(0);
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */ text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
xmlChar *toptag = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(2)); xmlChar *toptag = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(2));
xmlChar *septag = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(3)); xmlChar *septag = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(3));
xmlChar *xpath; xmlChar *xpath;
...@@ -267,7 +267,7 @@ Datum ...@@ -267,7 +267,7 @@ Datum
xpath_list(PG_FUNCTION_ARGS) xpath_list(PG_FUNCTION_ARGS)
{ {
text *document = PG_GETARG_TEXT_P(0); text *document = PG_GETARG_TEXT_P(0);
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */ text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
xmlChar *plainsep = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(2)); xmlChar *plainsep = pgxml_texttoxmlchar(PG_GETARG_TEXT_P(2));
xmlChar *xpath; xmlChar *xpath;
text *xpres; text *xpres;
...@@ -296,7 +296,7 @@ Datum ...@@ -296,7 +296,7 @@ Datum
xpath_string(PG_FUNCTION_ARGS) xpath_string(PG_FUNCTION_ARGS)
{ {
text *document = PG_GETARG_TEXT_P(0); text *document = PG_GETARG_TEXT_P(0);
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */ text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
xmlChar *xpath; xmlChar *xpath;
int32 pathsize; int32 pathsize;
text *xpres; text *xpres;
...@@ -337,7 +337,7 @@ Datum ...@@ -337,7 +337,7 @@ Datum
xpath_number(PG_FUNCTION_ARGS) xpath_number(PG_FUNCTION_ARGS)
{ {
text *document = PG_GETARG_TEXT_P(0); text *document = PG_GETARG_TEXT_P(0);
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */ text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
xmlChar *xpath; xmlChar *xpath;
float4 fRes; float4 fRes;
xmlXPathObjectPtr res; xmlXPathObjectPtr res;
...@@ -369,7 +369,7 @@ Datum ...@@ -369,7 +369,7 @@ Datum
xpath_bool(PG_FUNCTION_ARGS) xpath_bool(PG_FUNCTION_ARGS)
{ {
text *document = PG_GETARG_TEXT_P(0); text *document = PG_GETARG_TEXT_P(0);
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */ text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
xmlChar *xpath; xmlChar *xpath;
int bRes; int bRes;
xmlXPathObjectPtr res; xmlXPathObjectPtr res;
......
...@@ -42,7 +42,6 @@ extern void pgxml_parser_init(void); ...@@ -42,7 +42,6 @@ extern void pgxml_parser_init(void);
/* local defs */ /* local defs */
static const char **parse_params(text *paramstr); static const char **parse_params(text *paramstr);
#endif /* USE_LIBXSLT */ #endif /* USE_LIBXSLT */
...@@ -166,7 +165,7 @@ parse_params(text *paramstr) ...@@ -166,7 +165,7 @@ parse_params(text *paramstr)
{ {
max_params *= 2; max_params *= 2;
params = (const char **) repalloc(params, params = (const char **) repalloc(params,
(max_params + 1) * sizeof(char *)); (max_params + 1) * sizeof(char *));
} }
params[nparams++] = pos; params[nparams++] = pos;
pos = strstr(pos, nvsep); pos = strstr(pos, nvsep);
......
...@@ -350,7 +350,7 @@ nocachegetattr(HeapTuple tuple, ...@@ -350,7 +350,7 @@ nocachegetattr(HeapTuple tuple,
* *
* check to see if any preceding bits are null... * check to see if any preceding bits are null...
*/ */
int byte = attnum >> 3; int byte = attnum >> 3;
int finalbit = attnum & 0x07; int finalbit = attnum & 0x07;
/* check for nulls "before" final bit of last byte */ /* check for nulls "before" final bit of last byte */
......
...@@ -237,7 +237,7 @@ nocache_index_getattr(IndexTuple tup, ...@@ -237,7 +237,7 @@ nocache_index_getattr(IndexTuple tup,
* Now check to see if any preceding bits are null... * Now check to see if any preceding bits are null...
*/ */
{ {
int byte = attnum >> 3; int byte = attnum >> 3;
int finalbit = attnum & 0x07; int finalbit = attnum & 0x07;
/* check for nulls "before" final bit of last byte */ /* check for nulls "before" final bit of last byte */
......
...@@ -82,7 +82,8 @@ ginqueryarrayextract(PG_FUNCTION_ARGS) ...@@ -82,7 +82,8 @@ ginqueryarrayextract(PG_FUNCTION_ARGS)
ArrayType *array = PG_GETARG_ARRAYTYPE_P_COPY(0); ArrayType *array = PG_GETARG_ARRAYTYPE_P_COPY(0);
int32 *nkeys = (int32 *) PG_GETARG_POINTER(1); int32 *nkeys = (int32 *) PG_GETARG_POINTER(1);
StrategyNumber strategy = PG_GETARG_UINT16(2); StrategyNumber strategy = PG_GETARG_UINT16(2);
/* bool **pmatch = (bool **) PG_GETARG_POINTER(3); */
/* bool **pmatch = (bool **) PG_GETARG_POINTER(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool **nullFlags = (bool **) PG_GETARG_POINTER(5); bool **nullFlags = (bool **) PG_GETARG_POINTER(5);
int32 *searchMode = (int32 *) PG_GETARG_POINTER(6); int32 *searchMode = (int32 *) PG_GETARG_POINTER(6);
...@@ -112,7 +113,7 @@ ginqueryarrayextract(PG_FUNCTION_ARGS) ...@@ -112,7 +113,7 @@ ginqueryarrayextract(PG_FUNCTION_ARGS)
case GinContainsStrategy: case GinContainsStrategy:
if (nelems > 0) if (nelems > 0)
*searchMode = GIN_SEARCH_MODE_DEFAULT; *searchMode = GIN_SEARCH_MODE_DEFAULT;
else /* everything contains the empty set */ else /* everything contains the empty set */
*searchMode = GIN_SEARCH_MODE_ALL; *searchMode = GIN_SEARCH_MODE_ALL;
break; break;
case GinContainedStrategy: case GinContainedStrategy:
...@@ -142,10 +143,13 @@ ginarrayconsistent(PG_FUNCTION_ARGS) ...@@ -142,10 +143,13 @@ ginarrayconsistent(PG_FUNCTION_ARGS)
{ {
bool *check = (bool *) PG_GETARG_POINTER(0); bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1); StrategyNumber strategy = PG_GETARG_UINT16(1);
/* ArrayType *query = PG_GETARG_ARRAYTYPE_P(2); */ /* ArrayType *query = PG_GETARG_ARRAYTYPE_P(2); */
int32 nkeys = PG_GETARG_INT32(3); int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */ /* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5); bool *recheck = (bool *) PG_GETARG_POINTER(5);
/* Datum *queryKeys = (Datum *) PG_GETARG_POINTER(6); */ /* Datum *queryKeys = (Datum *) PG_GETARG_POINTER(6); */
bool *nullFlags = (bool *) PG_GETARG_POINTER(7); bool *nullFlags = (bool *) PG_GETARG_POINTER(7);
bool res; bool res;
...@@ -190,10 +194,11 @@ ginarrayconsistent(PG_FUNCTION_ARGS) ...@@ -190,10 +194,11 @@ ginarrayconsistent(PG_FUNCTION_ARGS)
case GinEqualStrategy: case GinEqualStrategy:
/* we will need recheck */ /* we will need recheck */
*recheck = true; *recheck = true;
/* /*
* Must have all elements in check[] true; no discrimination * Must have all elements in check[] true; no discrimination
* against nulls here. This is because array_contain_compare * against nulls here. This is because array_contain_compare and
* and array_eq handle nulls differently ... * array_eq handle nulls differently ...
*/ */
res = true; res = true;
for (i = 0; i < nkeys; i++) for (i = 0; i < nkeys; i++)
......
...@@ -80,8 +80,8 @@ ginAllocEntryAccumulator(void *arg) ...@@ -80,8 +80,8 @@ ginAllocEntryAccumulator(void *arg)
GinEntryAccumulator *ea; GinEntryAccumulator *ea;
/* /*
* Allocate memory by rather big chunks to decrease overhead. We have * Allocate memory by rather big chunks to decrease overhead. We have no
* no need to reclaim RBNodes individually, so this costs nothing. * need to reclaim RBNodes individually, so this costs nothing.
*/ */
if (accum->entryallocator == NULL || accum->eas_used >= DEF_NENTRY) if (accum->entryallocator == NULL || accum->eas_used >= DEF_NENTRY)
{ {
...@@ -108,7 +108,7 @@ ginInitBA(BuildAccumulator *accum) ...@@ -108,7 +108,7 @@ ginInitBA(BuildAccumulator *accum)
cmpEntryAccumulator, cmpEntryAccumulator,
ginCombineData, ginCombineData,
ginAllocEntryAccumulator, ginAllocEntryAccumulator,
NULL, /* no freefunc needed */ NULL, /* no freefunc needed */
(void *) accum); (void *) accum);
} }
...@@ -145,8 +145,8 @@ ginInsertBAEntry(BuildAccumulator *accum, ...@@ -145,8 +145,8 @@ ginInsertBAEntry(BuildAccumulator *accum,
bool isNew; bool isNew;
/* /*
* For the moment, fill only the fields of eatmp that will be looked at * For the moment, fill only the fields of eatmp that will be looked at by
* by cmpEntryAccumulator or ginCombineData. * cmpEntryAccumulator or ginCombineData.
*/ */
eatmp.attnum = attnum; eatmp.attnum = attnum;
eatmp.key = key; eatmp.key = key;
......
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
int int
ginCompareItemPointers(ItemPointer a, ItemPointer b) ginCompareItemPointers(ItemPointer a, ItemPointer b)
{ {
BlockNumber ba = GinItemPointerGetBlockNumber(a); BlockNumber ba = GinItemPointerGetBlockNumber(a);
BlockNumber bb = GinItemPointerGetBlockNumber(b); BlockNumber bb = GinItemPointerGetBlockNumber(b);
if (ba == bb) if (ba == bb)
{ {
OffsetNumber oa = GinItemPointerGetOffsetNumber(a); OffsetNumber oa = GinItemPointerGetOffsetNumber(a);
OffsetNumber ob = GinItemPointerGetOffsetNumber(b); OffsetNumber ob = GinItemPointerGetOffsetNumber(b);
if (oa == ob) if (oa == ob)
return 0; return 0;
...@@ -383,6 +383,7 @@ dataPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prda ...@@ -383,6 +383,7 @@ dataPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prda
Page page = BufferGetPage(buf); Page page = BufferGetPage(buf);
int sizeofitem = GinSizeOfDataPageItem(page); int sizeofitem = GinSizeOfDataPageItem(page);
int cnt = 0; int cnt = 0;
/* these must be static so they can be returned to caller */ /* these must be static so they can be returned to caller */
static XLogRecData rdata[3]; static XLogRecData rdata[3];
static ginxlogInsert data; static ginxlogInsert data;
...@@ -474,6 +475,7 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe ...@@ -474,6 +475,7 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe
Size pageSize = PageGetPageSize(lpage); Size pageSize = PageGetPageSize(lpage);
Size freeSpace; Size freeSpace;
uint32 nCopied = 1; uint32 nCopied = 1;
/* these must be static so they can be returned to caller */ /* these must be static so they can be returned to caller */
static ginxlogSplit data; static ginxlogSplit data;
static XLogRecData rdata[4]; static XLogRecData rdata[4];
......
...@@ -98,11 +98,11 @@ GinFormTuple(GinState *ginstate, ...@@ -98,11 +98,11 @@ GinFormTuple(GinState *ginstate,
if (errorTooBig) if (errorTooBig)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("index row size %lu exceeds maximum %lu for index \"%s\"", errmsg("index row size %lu exceeds maximum %lu for index \"%s\"",
(unsigned long) newsize, (unsigned long) newsize,
(unsigned long) Min(INDEX_SIZE_MASK, (unsigned long) Min(INDEX_SIZE_MASK,
GinMaxItemSize), GinMaxItemSize),
RelationGetRelationName(ginstate->index)))); RelationGetRelationName(ginstate->index))));
pfree(itup); pfree(itup);
return NULL; return NULL;
} }
...@@ -164,7 +164,7 @@ GinShortenTuple(IndexTuple itup, uint32 nipd) ...@@ -164,7 +164,7 @@ GinShortenTuple(IndexTuple itup, uint32 nipd)
* Form a non-leaf entry tuple by copying the key data from the given tuple, * Form a non-leaf entry tuple by copying the key data from the given tuple,
* which can be either a leaf or non-leaf entry tuple. * which can be either a leaf or non-leaf entry tuple.
* *
* Any posting list in the source tuple is not copied. The specified child * Any posting list in the source tuple is not copied. The specified child
* block number is inserted into t_tid. * block number is inserted into t_tid.
*/ */
static IndexTuple static IndexTuple
...@@ -225,7 +225,7 @@ entryIsMoveRight(GinBtree btree, Page page) ...@@ -225,7 +225,7 @@ entryIsMoveRight(GinBtree btree, Page page)
key = gintuple_get_key(btree->ginstate, itup, &category); key = gintuple_get_key(btree->ginstate, itup, &category);
if (ginCompareAttEntries(btree->ginstate, if (ginCompareAttEntries(btree->ginstate,
btree->entryAttnum, btree->entryKey, btree->entryCategory, btree->entryAttnum, btree->entryKey, btree->entryCategory,
attnum, key, category) > 0) attnum, key, category) > 0)
return TRUE; return TRUE;
...@@ -488,6 +488,7 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd ...@@ -488,6 +488,7 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd
Page page = BufferGetPage(buf); Page page = BufferGetPage(buf);
OffsetNumber placed; OffsetNumber placed;
int cnt = 0; int cnt = 0;
/* these must be static so they can be returned to caller */ /* these must be static so they can be returned to caller */
static XLogRecData rdata[3]; static XLogRecData rdata[3];
static ginxlogInsert data; static ginxlogInsert data;
...@@ -561,6 +562,7 @@ entrySplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogR ...@@ -561,6 +562,7 @@ entrySplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogR
Page lpage = PageGetTempPageCopy(BufferGetPage(lbuf)); Page lpage = PageGetTempPageCopy(BufferGetPage(lbuf));
Page rpage = BufferGetPage(rbuf); Page rpage = BufferGetPage(rbuf);
Size pageSize = PageGetPageSize(lpage); Size pageSize = PageGetPageSize(lpage);
/* these must be static so they can be returned to caller */ /* these must be static so they can be returned to caller */
static XLogRecData rdata[2]; static XLogRecData rdata[2];
static ginxlogSplit data; static ginxlogSplit data;
......
...@@ -88,9 +88,9 @@ writeListPage(Relation index, Buffer buffer, ...@@ -88,9 +88,9 @@ writeListPage(Relation index, Buffer buffer,
GinPageGetOpaque(page)->rightlink = rightlink; GinPageGetOpaque(page)->rightlink = rightlink;
/* /*
* tail page may contain only whole row(s) or final part of row placed * tail page may contain only whole row(s) or final part of row placed on
* on previous pages (a "row" here meaning all the index tuples generated * previous pages (a "row" here meaning all the index tuples generated for
* for one heap tuple) * one heap tuple)
*/ */
if (rightlink == InvalidBlockNumber) if (rightlink == InvalidBlockNumber)
{ {
...@@ -437,7 +437,7 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector) ...@@ -437,7 +437,7 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
* Create temporary index tuples for a single indexable item (one index column * Create temporary index tuples for a single indexable item (one index column
* for the heap tuple specified by ht_ctid), and append them to the array * for the heap tuple specified by ht_ctid), and append them to the array
* in *collector. They will subsequently be written out using * in *collector. They will subsequently be written out using
* ginHeapTupleFastInsert. Note that to guarantee consistent state, all * ginHeapTupleFastInsert. Note that to guarantee consistent state, all
* temp tuples for a given heap tuple must be written in one call to * temp tuples for a given heap tuple must be written in one call to
* ginHeapTupleFastInsert. * ginHeapTupleFastInsert.
*/ */
...@@ -475,8 +475,8 @@ ginHeapTupleFastCollect(GinState *ginstate, ...@@ -475,8 +475,8 @@ ginHeapTupleFastCollect(GinState *ginstate,
} }
/* /*
* Build an index tuple for each key value, and add to array. In * Build an index tuple for each key value, and add to array. In pending
* pending tuples we just stick the heap TID into t_tid. * tuples we just stick the heap TID into t_tid.
*/ */
for (i = 0; i < nentries; i++) for (i = 0; i < nentries; i++)
{ {
...@@ -665,7 +665,7 @@ processPendingPage(BuildAccumulator *accum, KeyArray *ka, ...@@ -665,7 +665,7 @@ processPendingPage(BuildAccumulator *accum, KeyArray *ka,
{ {
IndexTuple itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, i)); IndexTuple itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, i));
OffsetNumber curattnum; OffsetNumber curattnum;
Datum curkey; Datum curkey;
GinNullCategory curcategory; GinNullCategory curcategory;
/* Check for change of heap TID or attnum */ /* Check for change of heap TID or attnum */
...@@ -830,7 +830,7 @@ ginInsertCleanup(GinState *ginstate, ...@@ -830,7 +830,7 @@ ginInsertCleanup(GinState *ginstate,
*/ */
ginBeginBAScan(&accum); ginBeginBAScan(&accum);
while ((list = ginGetBAEntry(&accum, while ((list = ginGetBAEntry(&accum,
&attnum, &key, &category, &nlist)) != NULL) &attnum, &key, &category, &nlist)) != NULL)
{ {
ginEntryInsert(ginstate, attnum, key, category, ginEntryInsert(ginstate, attnum, key, category,
list, nlist, NULL); list, nlist, NULL);
...@@ -867,7 +867,7 @@ ginInsertCleanup(GinState *ginstate, ...@@ -867,7 +867,7 @@ ginInsertCleanup(GinState *ginstate,
ginBeginBAScan(&accum); ginBeginBAScan(&accum);
while ((list = ginGetBAEntry(&accum, while ((list = ginGetBAEntry(&accum,
&attnum, &key, &category, &nlist)) != NULL) &attnum, &key, &category, &nlist)) != NULL)
ginEntryInsert(ginstate, attnum, key, category, ginEntryInsert(ginstate, attnum, key, category,
list, nlist, NULL); list, nlist, NULL);
} }
......
This diff is collapsed.
...@@ -97,7 +97,7 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems) ...@@ -97,7 +97,7 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems)
* Adds array of item pointers to tuple's posting list, or * Adds array of item pointers to tuple's posting list, or
* creates posting tree and tuple pointing to tree in case * creates posting tree and tuple pointing to tree in case
* of not enough space. Max size of tuple is defined in * of not enough space. Max size of tuple is defined in
* GinFormTuple(). Returns a new, modified index tuple. * GinFormTuple(). Returns a new, modified index tuple.
* items[] must be in sorted order with no duplicates. * items[] must be in sorted order with no duplicates.
*/ */
static IndexTuple static IndexTuple
...@@ -195,14 +195,14 @@ buildFreshLeafTuple(GinState *ginstate, ...@@ -195,14 +195,14 @@ buildFreshLeafTuple(GinState *ginstate,
BlockNumber postingRoot; BlockNumber postingRoot;
/* /*
* Build posting-tree-only result tuple. We do this first so as * Build posting-tree-only result tuple. We do this first so as to
* to fail quickly if the key is too big. * fail quickly if the key is too big.
*/ */
res = GinFormTuple(ginstate, attnum, key, category, NULL, 0, true); res = GinFormTuple(ginstate, attnum, key, category, NULL, 0, true);
/* /*
* Initialize posting tree with as many TIDs as will fit on the * Initialize posting tree with as many TIDs as will fit on the first
* first page. * page.
*/ */
postingRoot = createPostingTree(ginstate->index, postingRoot = createPostingTree(ginstate->index,
items, items,
...@@ -361,7 +361,7 @@ ginBuildCallback(Relation index, HeapTuple htup, Datum *values, ...@@ -361,7 +361,7 @@ ginBuildCallback(Relation index, HeapTuple htup, Datum *values,
ginBeginBAScan(&buildstate->accum); ginBeginBAScan(&buildstate->accum);
while ((list = ginGetBAEntry(&buildstate->accum, while ((list = ginGetBAEntry(&buildstate->accum,
&attnum, &key, &category, &nlist)) != NULL) &attnum, &key, &category, &nlist)) != NULL)
{ {
/* there could be many entries, so be willing to abort here */ /* there could be many entries, so be willing to abort here */
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
......
...@@ -199,7 +199,7 @@ ginFillScanKey(GinScanOpaque so, OffsetNumber attnum, ...@@ -199,7 +199,7 @@ ginFillScanKey(GinScanOpaque so, OffsetNumber attnum,
break; break;
default: default:
elog(ERROR, "unexpected searchMode: %d", searchMode); elog(ERROR, "unexpected searchMode: %d", searchMode);
queryCategory = 0; /* keep compiler quiet */ queryCategory = 0; /* keep compiler quiet */
break; break;
} }
isPartialMatch = false; isPartialMatch = false;
...@@ -294,8 +294,8 @@ ginNewScanKey(IndexScanDesc scan) ...@@ -294,8 +294,8 @@ ginNewScanKey(IndexScanDesc scan)
int32 searchMode = GIN_SEARCH_MODE_DEFAULT; int32 searchMode = GIN_SEARCH_MODE_DEFAULT;
/* /*
* We assume that GIN-indexable operators are strict, so a null * We assume that GIN-indexable operators are strict, so a null query
* query argument means an unsatisfiable query. * argument means an unsatisfiable query.
*/ */
if (skey->sk_flags & SK_ISNULL) if (skey->sk_flags & SK_ISNULL)
{ {
...@@ -315,8 +315,8 @@ ginNewScanKey(IndexScanDesc scan) ...@@ -315,8 +315,8 @@ ginNewScanKey(IndexScanDesc scan)
PointerGetDatum(&searchMode))); PointerGetDatum(&searchMode)));
/* /*
* If bogus searchMode is returned, treat as GIN_SEARCH_MODE_ALL; * If bogus searchMode is returned, treat as GIN_SEARCH_MODE_ALL; note
* note in particular we don't allow extractQueryFn to select * in particular we don't allow extractQueryFn to select
* GIN_SEARCH_MODE_EVERYTHING. * GIN_SEARCH_MODE_EVERYTHING.
*/ */
if (searchMode < GIN_SEARCH_MODE_DEFAULT || if (searchMode < GIN_SEARCH_MODE_DEFAULT ||
...@@ -344,20 +344,20 @@ ginNewScanKey(IndexScanDesc scan) ...@@ -344,20 +344,20 @@ ginNewScanKey(IndexScanDesc scan)
* If the extractQueryFn didn't create a nullFlags array, create one, * If the extractQueryFn didn't create a nullFlags array, create one,
* assuming that everything's non-null. Otherwise, run through the * assuming that everything's non-null. Otherwise, run through the
* array and make sure each value is exactly 0 or 1; this ensures * array and make sure each value is exactly 0 or 1; this ensures
* binary compatibility with the GinNullCategory representation. * binary compatibility with the GinNullCategory representation. While
* While at it, detect whether any null keys are present. * at it, detect whether any null keys are present.
*/ */
if (nullFlags == NULL) if (nullFlags == NULL)
nullFlags = (bool *) palloc0(nQueryValues * sizeof(bool)); nullFlags = (bool *) palloc0(nQueryValues * sizeof(bool));
else else
{ {
int32 j; int32 j;
for (j = 0; j < nQueryValues; j++) for (j = 0; j < nQueryValues; j++)
{ {
if (nullFlags[j]) if (nullFlags[j])
{ {
nullFlags[j] = true; /* not any other nonzero value */ nullFlags[j] = true; /* not any other nonzero value */
hasNullQuery = true; hasNullQuery = true;
} }
} }
...@@ -387,11 +387,11 @@ ginNewScanKey(IndexScanDesc scan) ...@@ -387,11 +387,11 @@ ginNewScanKey(IndexScanDesc scan)
/* /*
* If the index is version 0, it may be missing null and placeholder * If the index is version 0, it may be missing null and placeholder
* entries, which would render searches for nulls and full-index scans * entries, which would render searches for nulls and full-index scans
* unreliable. Throw an error if so. * unreliable. Throw an error if so.
*/ */
if (hasNullQuery && !so->isVoidRes) if (hasNullQuery && !so->isVoidRes)
{ {
GinStatsData ginStats; GinStatsData ginStats;
ginGetStats(scan->indexRelation, &ginStats); ginGetStats(scan->indexRelation, &ginStats);
if (ginStats.ginVersion < 1) if (ginStats.ginVersion < 1)
...@@ -410,6 +410,7 @@ ginrescan(PG_FUNCTION_ARGS) ...@@ -410,6 +410,7 @@ ginrescan(PG_FUNCTION_ARGS)
{ {
IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
ScanKey scankey = (ScanKey) PG_GETARG_POINTER(1); ScanKey scankey = (ScanKey) PG_GETARG_POINTER(1);
/* remaining arguments are ignored */ /* remaining arguments are ignored */
GinScanOpaque so = (GinScanOpaque) scan->opaque; GinScanOpaque so = (GinScanOpaque) scan->opaque;
......
...@@ -70,7 +70,7 @@ initGinState(GinState *state, Relation index) ...@@ -70,7 +70,7 @@ initGinState(GinState *state, Relation index)
* However, we may have a collatable storage type for a noncollatable * However, we may have a collatable storage type for a noncollatable
* indexed data type (for instance, hstore uses text index entries). * indexed data type (for instance, hstore uses text index entries).
* If there's no index collation then specify default collation in * If there's no index collation then specify default collation in
* case the comparison function needs one. This is harmless if the * case the comparison function needs one. This is harmless if the
* comparison function doesn't care about collation, so we just do it * comparison function doesn't care about collation, so we just do it
* unconditionally. (We could alternatively call get_typcollation, * unconditionally. (We could alternatively call get_typcollation,
* but that seems like expensive overkill --- there aren't going to be * but that seems like expensive overkill --- there aren't going to be
...@@ -359,9 +359,9 @@ cmpEntries(const void *a, const void *b, void *arg) ...@@ -359,9 +359,9 @@ cmpEntries(const void *a, const void *b, void *arg)
aa->datum, bb->datum)); aa->datum, bb->datum));
/* /*
* Detect if we have any duplicates. If there are equal keys, qsort * Detect if we have any duplicates. If there are equal keys, qsort must
* must compare them at some point, else it wouldn't know whether one * compare them at some point, else it wouldn't know whether one should go
* should go before or after the other. * before or after the other.
*/ */
if (res == 0) if (res == 0)
data->haveDups = true; data->haveDups = true;
...@@ -422,9 +422,9 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, ...@@ -422,9 +422,9 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
/* /*
* If the extractValueFn didn't create a nullFlags array, create one, * If the extractValueFn didn't create a nullFlags array, create one,
* assuming that everything's non-null. Otherwise, run through the * assuming that everything's non-null. Otherwise, run through the array
* array and make sure each value is exactly 0 or 1; this ensures * and make sure each value is exactly 0 or 1; this ensures binary
* binary compatibility with the GinNullCategory representation. * compatibility with the GinNullCategory representation.
*/ */
if (nullFlags == NULL) if (nullFlags == NULL)
nullFlags = (bool *) palloc0(*nentries * sizeof(bool)); nullFlags = (bool *) palloc0(*nentries * sizeof(bool));
...@@ -440,8 +440,8 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, ...@@ -440,8 +440,8 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
* If there's more than one key, sort and unique-ify. * If there's more than one key, sort and unique-ify.
* *
* XXX Using qsort here is notationally painful, and the overhead is * XXX Using qsort here is notationally painful, and the overhead is
* pretty bad too. For small numbers of keys it'd likely be better to * pretty bad too. For small numbers of keys it'd likely be better to use
* use a simple insertion sort. * a simple insertion sort.
*/ */
if (*nentries > 1) if (*nentries > 1)
{ {
...@@ -470,7 +470,7 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, ...@@ -470,7 +470,7 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum,
j = 1; j = 1;
for (i = 1; i < *nentries; i++) for (i = 1; i < *nentries; i++)
{ {
if (cmpEntries(&keydata[i-1], &keydata[i], &arg) != 0) if (cmpEntries(&keydata[i - 1], &keydata[i], &arg) != 0)
{ {
entries[j] = keydata[i].datum; entries[j] = keydata[i].datum;
nullFlags[j] = keydata[i].isnull; nullFlags[j] = keydata[i].isnull;
...@@ -533,9 +533,9 @@ ginoptions(PG_FUNCTION_ARGS) ...@@ -533,9 +533,9 @@ ginoptions(PG_FUNCTION_ARGS)
void void
ginGetStats(Relation index, GinStatsData *stats) ginGetStats(Relation index, GinStatsData *stats)
{ {
Buffer metabuffer; Buffer metabuffer;
Page metapage; Page metapage;
GinMetaPageData *metadata; GinMetaPageData *metadata;
metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO); metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
LockBuffer(metabuffer, GIN_SHARE); LockBuffer(metabuffer, GIN_SHARE);
...@@ -560,9 +560,9 @@ ginGetStats(Relation index, GinStatsData *stats) ...@@ -560,9 +560,9 @@ ginGetStats(Relation index, GinStatsData *stats)
void void
ginUpdateStats(Relation index, const GinStatsData *stats) ginUpdateStats(Relation index, const GinStatsData *stats)
{ {
Buffer metabuffer; Buffer metabuffer;
Page metapage; Page metapage;
GinMetaPageData *metadata; GinMetaPageData *metadata;
metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO); metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
LockBuffer(metabuffer, GIN_EXCLUSIVE); LockBuffer(metabuffer, GIN_EXCLUSIVE);
...@@ -580,9 +580,9 @@ ginUpdateStats(Relation index, const GinStatsData *stats) ...@@ -580,9 +580,9 @@ ginUpdateStats(Relation index, const GinStatsData *stats)
if (RelationNeedsWAL(index)) if (RelationNeedsWAL(index))
{ {
XLogRecPtr recptr; XLogRecPtr recptr;
ginxlogUpdateMeta data; ginxlogUpdateMeta data;
XLogRecData rdata; XLogRecData rdata;
data.node = index->rd_node; data.node = index->rd_node;
data.ntuples = 0; data.ntuples = 0;
......
...@@ -783,7 +783,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -783,7 +783,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS)
{ {
idxStat.nEntryPages++; idxStat.nEntryPages++;
if ( GinPageIsLeaf(page) ) if (GinPageIsLeaf(page))
idxStat.nEntries += PageGetMaxOffsetNumber(page); idxStat.nEntries += PageGetMaxOffsetNumber(page);
} }
......
...@@ -388,7 +388,7 @@ ginRedoVacuumPage(XLogRecPtr lsn, XLogRecord *record) ...@@ -388,7 +388,7 @@ ginRedoVacuumPage(XLogRecPtr lsn, XLogRecord *record)
else else
{ {
OffsetNumber i, OffsetNumber i,
*tod; *tod;
IndexTuple itup = (IndexTuple) (XLogRecGetData(record) + sizeof(ginxlogVacuumPage)); IndexTuple itup = (IndexTuple) (XLogRecGetData(record) + sizeof(ginxlogVacuumPage));
tod = (OffsetNumber *) palloc(sizeof(OffsetNumber) * PageGetMaxOffsetNumber(page)); tod = (OffsetNumber *) palloc(sizeof(OffsetNumber) * PageGetMaxOffsetNumber(page));
...@@ -513,10 +513,10 @@ ginRedoUpdateMetapage(XLogRecPtr lsn, XLogRecord *record) ...@@ -513,10 +513,10 @@ ginRedoUpdateMetapage(XLogRecPtr lsn, XLogRecord *record)
if (!XLByteLE(lsn, PageGetLSN(page))) if (!XLByteLE(lsn, PageGetLSN(page)))
{ {
OffsetNumber l, OffsetNumber l,
off = (PageIsEmpty(page)) ? FirstOffsetNumber : off = (PageIsEmpty(page)) ? FirstOffsetNumber :
OffsetNumberNext(PageGetMaxOffsetNumber(page)); OffsetNumberNext(PageGetMaxOffsetNumber(page));
int i, int i,
tupsize; tupsize;
IndexTuple tuples = (IndexTuple) (XLogRecGetData(record) + sizeof(ginxlogUpdateMeta)); IndexTuple tuples = (IndexTuple) (XLogRecGetData(record) + sizeof(ginxlogUpdateMeta));
for (i = 0; i < data->ntuples; i++) for (i = 0; i < data->ntuples; i++)
......
This diff is collapsed.
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
* *
* On success return for a heap tuple, *recheck_p is set to indicate * On success return for a heap tuple, *recheck_p is set to indicate
* whether recheck is needed. We recheck if any of the consistent() functions * whether recheck is needed. We recheck if any of the consistent() functions
* request it. recheck is not interesting when examining a non-leaf entry, * request it. recheck is not interesting when examining a non-leaf entry,
* since we must visit the lower index page if there's any doubt. * since we must visit the lower index page if there's any doubt.
* *
* If we are doing an ordered scan, so->distances[] is filled with distance * If we are doing an ordered scan, so->distances[] is filled with distance
...@@ -62,15 +62,15 @@ gistindex_keytest(IndexScanDesc scan, ...@@ -62,15 +62,15 @@ gistindex_keytest(IndexScanDesc scan,
*recheck_p = false; *recheck_p = false;
/* /*
* If it's a leftover invalid tuple from pre-9.1, treat it as a match * If it's a leftover invalid tuple from pre-9.1, treat it as a match with
* with minimum possible distances. This means we'll always follow it * minimum possible distances. This means we'll always follow it to the
* to the referenced page. * referenced page.
*/ */
if (GistTupleIsInvalid(tuple)) if (GistTupleIsInvalid(tuple))
{ {
int i; int i;
if (GistPageIsLeaf(page)) /* shouldn't happen */ if (GistPageIsLeaf(page)) /* shouldn't happen */
elog(ERROR, "invalid GIST tuple found on leaf page"); elog(ERROR, "invalid GIST tuple found on leaf page");
for (i = 0; i < scan->numberOfOrderBys; i++) for (i = 0; i < scan->numberOfOrderBys; i++)
so->distances[i] = -get_float8_infinity(); so->distances[i] = -get_float8_infinity();
...@@ -191,8 +191,8 @@ gistindex_keytest(IndexScanDesc scan, ...@@ -191,8 +191,8 @@ gistindex_keytest(IndexScanDesc scan,
* always be zero, but might as well pass it for possible future * always be zero, but might as well pass it for possible future
* use.) * use.)
* *
* Note that Distance functions don't get a recheck argument. * Note that Distance functions don't get a recheck argument. We
* We can't tolerate lossy distance calculations on leaf tuples; * can't tolerate lossy distance calculations on leaf tuples;
* there is no opportunity to re-sort the tuples afterwards. * there is no opportunity to re-sort the tuples afterwards.
*/ */
dist = FunctionCall4(&key->sk_func, dist = FunctionCall4(&key->sk_func,
...@@ -223,7 +223,7 @@ gistindex_keytest(IndexScanDesc scan, ...@@ -223,7 +223,7 @@ gistindex_keytest(IndexScanDesc scan,
* ntids: if not NULL, gistgetbitmap's output tuple counter * ntids: if not NULL, gistgetbitmap's output tuple counter
* *
* If tbm/ntids aren't NULL, we are doing an amgetbitmap scan, and heap * If tbm/ntids aren't NULL, we are doing an amgetbitmap scan, and heap
* tuples should be reported directly into the bitmap. If they are NULL, * tuples should be reported directly into the bitmap. If they are NULL,
* we're doing a plain or ordered indexscan. For a plain indexscan, heap * we're doing a plain or ordered indexscan. For a plain indexscan, heap
* tuple TIDs are returned into so->pageData[]. For an ordered indexscan, * tuple TIDs are returned into so->pageData[]. For an ordered indexscan,
* heap tuple TIDs are pushed into individual search queue items. * heap tuple TIDs are pushed into individual search queue items.
...@@ -525,8 +525,8 @@ gistgettuple(PG_FUNCTION_ARGS) ...@@ -525,8 +525,8 @@ gistgettuple(PG_FUNCTION_ARGS)
/* /*
* While scanning a leaf page, ItemPointers of matching heap * While scanning a leaf page, ItemPointers of matching heap
* tuples are stored in so->pageData. If there are any on * tuples are stored in so->pageData. If there are any on
* this page, we fall out of the inner "do" and loop around * this page, we fall out of the inner "do" and loop around to
* to return them. * return them.
*/ */
gistScanPage(scan, item, so->curTreeItem->distances, NULL, NULL); gistScanPage(scan, item, so->curTreeItem->distances, NULL, NULL);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment