provided by Andrew.
PG_MODULE_MAGIC;
/* GUC variables */
-static int auto_explain_log_min_duration = -1; /* msec or -1 */
+static int auto_explain_log_min_duration = -1; /* msec or -1 */
static bool auto_explain_log_analyze = false;
static bool auto_explain_log_verbose = false;
static bool auto_explain_log_nested_statements = false;
static int nesting_level = 0;
/* Saved hook values in case of unload */
-static ExecutorStart_hook_type prev_ExecutorStart = NULL;
-static ExecutorRun_hook_type prev_ExecutorRun = NULL;
-static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
+static ExecutorStart_hook_type prev_ExecutorStart = NULL;
+static ExecutorRun_hook_type prev_ExecutorRun = NULL;
+static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
#define auto_explain_enabled() \
(auto_explain_log_min_duration >= 0 && \
(nesting_level == 0 || auto_explain_log_nested_statements))
-void _PG_init(void);
-void _PG_fini(void);
+void _PG_init(void);
+void _PG_fini(void);
static void explain_ExecutorStart(QueryDesc *queryDesc, int eflags);
static void explain_ExecutorRun(QueryDesc *queryDesc,
- ScanDirection direction,
- long count);
+ ScanDirection direction,
+ long count);
static void explain_ExecutorEnd(QueryDesc *queryDesc);
{
/* Define custom GUC variables. */
DefineCustomIntVariable("auto_explain.log_min_duration",
- "Sets the minimum execution time above which plans will be logged.",
- "Zero prints all plans. -1 turns this feature off.",
+ "Sets the minimum execution time above which plans will be logged.",
+ "Zero prints all plans. -1 turns this feature off.",
&auto_explain_log_min_duration,
-1,
-1, INT_MAX / 1000,
if (auto_explain_enabled())
{
/*
- * Set up to track total elapsed time in ExecutorRun. Make sure
- * the space is allocated in the per-query context so it will go
- * away at ExecutorEnd.
+ * Set up to track total elapsed time in ExecutorRun. Make sure the
+ * space is allocated in the per-query context so it will go away at
+ * ExecutorEnd.
*/
if (queryDesc->totaltime == NULL)
{
{
if (queryDesc->totaltime && auto_explain_enabled())
{
- double msec;
+ double msec;
/*
- * Make sure stats accumulation is done. (Note: it's okay if
- * several levels of hook all do this.)
+ * Make sure stats accumulation is done. (Note: it's okay if several
+ * levels of hook all do this.)
*/
InstrEndLoop(queryDesc->totaltime);
msec = queryDesc->totaltime->total * 1000.0;
if (msec >= auto_explain_log_min_duration)
{
- StringInfoData buf;
+ StringInfoData buf;
initStringInfo(&buf);
ExplainPrintPlan(&buf, queryDesc,
- queryDesc->doInstrument && auto_explain_log_analyze,
+ queryDesc->doInstrument && auto_explain_log_analyze,
auto_explain_log_verbose);
/* Remove last line break */
typedef struct TypeInfo
{
- bool is_varlena;
- Datum (*leftmostvalue)(void);
- Datum (*typecmp)(FunctionCallInfo);
+ bool is_varlena;
+ Datum (*leftmostvalue) (void);
+ Datum (*typecmp) (FunctionCallInfo);
} TypeInfo;
typedef struct QueryInfo
{
- StrategyNumber strategy;
- Datum datum;
+ StrategyNumber strategy;
+ Datum datum;
} QueryInfo;
#define GIN_EXTRACT_VALUE(type) \
PG_FUNCTION_INFO_V1(gin_extract_value_##type); \
-Datum gin_extract_value_##type(PG_FUNCTION_ARGS); \
+Datum gin_extract_value_##type(PG_FUNCTION_ARGS); \
Datum \
gin_extract_value_##type(PG_FUNCTION_ARGS) \
{ \
#define GIN_EXTRACT_QUERY(type) \
PG_FUNCTION_INFO_V1(gin_extract_query_##type); \
-Datum gin_extract_query_##type(PG_FUNCTION_ARGS); \
+Datum gin_extract_query_##type(PG_FUNCTION_ARGS); \
Datum \
gin_extract_query_##type(PG_FUNCTION_ARGS) \
{ \
int32 *nentries = (int32 *) PG_GETARG_POINTER(1); \
StrategyNumber strategy = PG_GETARG_UINT16(2); \
bool **partialmatch = (bool **) PG_GETARG_POINTER(3); \
- Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4); \
+ Pointer **extra_data = (Pointer **) PG_GETARG_POINTER(4); \
Datum *entries = (Datum *) palloc(sizeof(Datum)); \
QueryInfo *data = (QueryInfo *) palloc(sizeof(QueryInfo)); \
bool *ptr_partialmatch; \
*/
#define GIN_COMPARE_PREFIX(type) \
PG_FUNCTION_INFO_V1(gin_compare_prefix_##type); \
-Datum gin_compare_prefix_##type(PG_FUNCTION_ARGS); \
+Datum gin_compare_prefix_##type(PG_FUNCTION_ARGS); \
Datum \
gin_compare_prefix_##type(PG_FUNCTION_ARGS) \
{ \
cmp; \
\
cmp = DatumGetInt32(DirectFunctionCall2( \
- TypeInfo_##type.typecmp, \
- (data->strategy == BTLessStrategyNumber || \
+ TypeInfo_##type.typecmp, \
+ (data->strategy == BTLessStrategyNumber || \
data->strategy == BTLessEqualStrategyNumber) \
- ? data->datum : a, \
+ ? data->datum : a, \
b)); \
\
switch (data->strategy) \
res = 1; \
break; \
default: \
- elog(ERROR, "unrecognized strategy number: %d", \
+ elog(ERROR, "unrecognized strategy number: %d", \
data->strategy); \
res = 0; \
} \
PG_FUNCTION_INFO_V1(gin_btree_consistent);
-Datum gin_btree_consistent(PG_FUNCTION_ARGS);
+Datum gin_btree_consistent(PG_FUNCTION_ARGS);
Datum
gin_btree_consistent(PG_FUNCTION_ARGS)
{
- bool *recheck = (bool *) PG_GETARG_POINTER(5);
+ bool *recheck = (bool *) PG_GETARG_POINTER(5);
*recheck = false;
PG_RETURN_BOOL(true);
return Int16GetDatum(SHRT_MIN);
}
static TypeInfo TypeInfo_int2 = {false, leftmostvalue_int2, btint2cmp};
+
GIN_SUPPORT(int2)
static Datum
return Int32GetDatum(INT_MIN);
}
static TypeInfo TypeInfo_int4 = {false, leftmostvalue_int4, btint4cmp};
+
GIN_SUPPORT(int4)
static Datum
leftmostvalue_int8(void)
{
/*
- * Use sequence's definition to keep compatibility.
- * Another way may make a problem with INT64_IS_BUSTED
+ * Use sequence's definition to keep compatibility. Another way may make a
+ * problem with INT64_IS_BUSTED
*/
return Int64GetDatum(SEQ_MINVALUE);
}
static TypeInfo TypeInfo_int8 = {false, leftmostvalue_int8, btint8cmp};
+
GIN_SUPPORT(int8)
static Datum
return Float4GetDatum(-get_float4_infinity());
}
static TypeInfo TypeInfo_float4 = {false, leftmostvalue_float4, btfloat4cmp};
+
GIN_SUPPORT(float4)
static Datum
return Float8GetDatum(-get_float8_infinity());
}
static TypeInfo TypeInfo_float8 = {false, leftmostvalue_float8, btfloat8cmp};
+
GIN_SUPPORT(float8)
static Datum
leftmostvalue_money(void)
{
/*
- * Use sequence's definition to keep compatibility.
- * Another way may make a problem with INT64_IS_BUSTED
+ * Use sequence's definition to keep compatibility. Another way may make a
+ * problem with INT64_IS_BUSTED
*/
return Int64GetDatum(SEQ_MINVALUE);
}
static TypeInfo TypeInfo_money = {false, leftmostvalue_money, cash_cmp};
+
GIN_SUPPORT(money)
static Datum
return ObjectIdGetDatum(0);
}
static TypeInfo TypeInfo_oid = {false, leftmostvalue_oid, btoidcmp};
+
GIN_SUPPORT(oid)
static Datum
return TimestampGetDatum(DT_NOBEGIN);
}
static TypeInfo TypeInfo_timestamp = {false, leftmostvalue_timestamp, timestamp_cmp};
+
GIN_SUPPORT(timestamp)
static TypeInfo TypeInfo_timestamptz = {false, leftmostvalue_timestamp, timestamp_cmp};
+
GIN_SUPPORT(timestamptz)
static Datum
return TimeADTGetDatum(0);
}
static TypeInfo TypeInfo_time = {false, leftmostvalue_time, time_cmp};
+
GIN_SUPPORT(time)
static Datum
leftmostvalue_timetz(void)
{
- TimeTzADT *v = palloc(sizeof(TimeTzADT));
+ TimeTzADT *v = palloc(sizeof(TimeTzADT));
v->time = 0;
- v->zone = -24*3600; /* XXX is that true? */
+ v->zone = -24 * 3600; /* XXX is that true? */
return TimeTzADTPGetDatum(v);
}
static TypeInfo TypeInfo_timetz = {false, leftmostvalue_timetz, timetz_cmp};
+
GIN_SUPPORT(timetz)
static Datum
return DateADTGetDatum(DATEVAL_NOBEGIN);
}
static TypeInfo TypeInfo_date = {false, leftmostvalue_date, date_cmp};
+
GIN_SUPPORT(date)
static Datum
leftmostvalue_interval(void)
{
- Interval *v = palloc(sizeof(Interval));
+ Interval *v = palloc(sizeof(Interval));
v->time = DT_NOBEGIN;
v->day = 0;
return IntervalPGetDatum(v);
}
static TypeInfo TypeInfo_interval = {false, leftmostvalue_interval, interval_cmp};
+
GIN_SUPPORT(interval)
static Datum
leftmostvalue_macaddr(void)
{
- macaddr *v = palloc0(sizeof(macaddr));
+ macaddr *v = palloc0(sizeof(macaddr));
return MacaddrPGetDatum(v);
}
static TypeInfo TypeInfo_macaddr = {false, leftmostvalue_macaddr, macaddr_cmp};
+
GIN_SUPPORT(macaddr)
static Datum
Int32GetDatum(-1));
}
static TypeInfo TypeInfo_inet = {true, leftmostvalue_inet, network_cmp};
+
GIN_SUPPORT(inet)
static TypeInfo TypeInfo_cidr = {true, leftmostvalue_inet, network_cmp};
+
GIN_SUPPORT(cidr)
static Datum
return PointerGetDatum(cstring_to_text_with_len("", 0));
}
static TypeInfo TypeInfo_text = {true, leftmostvalue_text, bttextcmp};
+
GIN_SUPPORT(text)
static Datum
return CharGetDatum(SCHAR_MIN);
}
static TypeInfo TypeInfo_char = {false, leftmostvalue_char, btcharcmp};
+
GIN_SUPPORT(char)
static TypeInfo TypeInfo_bytea = {true, leftmostvalue_text, byteacmp};
+
GIN_SUPPORT(bytea)
static Datum
Int32GetDatum(-1));
}
static TypeInfo TypeInfo_bit = {true, leftmostvalue_bit, bitcmp};
+
GIN_SUPPORT(bit)
static Datum
Int32GetDatum(-1));
}
static TypeInfo TypeInfo_varbit = {true, leftmostvalue_varbit, bitcmp};
+
GIN_SUPPORT(varbit)
/*
#define NUMERIC_IS_LEFTMOST(x) ((x) == NULL)
PG_FUNCTION_INFO_V1(gin_numeric_cmp);
-Datum gin_numeric_cmp(PG_FUNCTION_ARGS);
+Datum gin_numeric_cmp(PG_FUNCTION_ARGS);
Datum
gin_numeric_cmp(PG_FUNCTION_ARGS)
{
- Numeric a = (Numeric)PG_GETARG_POINTER(0);
- Numeric b = (Numeric)PG_GETARG_POINTER(1);
- int res = 0;
+ Numeric a = (Numeric) PG_GETARG_POINTER(0);
+ Numeric b = (Numeric) PG_GETARG_POINTER(1);
+ int res = 0;
- if ( NUMERIC_IS_LEFTMOST(a) )
+ if (NUMERIC_IS_LEFTMOST(a))
{
- res = ( NUMERIC_IS_LEFTMOST(b) ) ? 0 : -1;
+ res = (NUMERIC_IS_LEFTMOST(b)) ? 0 : -1;
}
- else if ( NUMERIC_IS_LEFTMOST(b) )
+ else if (NUMERIC_IS_LEFTMOST(b))
{
res = 1;
}
}
static TypeInfo TypeInfo_numeric = {true, leftmostvalue_numeric, gin_numeric_cmp};
+
GIN_SUPPORT(numeric)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_var.h"
static GBT_VARKEY *
-gbt_bit_l2n(GBT_VARKEY * leaf)
+gbt_bit_l2n(GBT_VARKEY *leaf)
{
GBT_VARKEY *out = leaf;
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval = FALSE;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_var.h"
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
Cash lower;
Cash upper;
-} cashKEY;
+} cashKEY;
/*
** Cash ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Cash query = PG_GETARG_CASH(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
cashKEY *kkk = (cashKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
DateADT lower;
DateADT upper;
-} dateKEY;
+} dateKEY;
/*
** date ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
DateADT query = PG_GETARG_DATEADT(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
dateKEY *kkk = (dateKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
float4 lower;
float4 upper;
-} float4KEY;
+} float4KEY;
/*
** float4 ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
float4 query = PG_GETARG_FLOAT4(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
float8 lower;
float8 upper;
-} float8KEY;
+} float8KEY;
/*
** float8 ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
float8 query = PG_GETARG_FLOAT8(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#ifndef __BTREE_GIST_H__
#define __BTREE_GIST_H__
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
double lower;
double upper;
-} inetKEY;
+} inetKEY;
/*
** inet ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
double query = convert_network_to_scalar(PG_GETARG_DATUM(1), INETOID);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
inetKEY *kkk = (inetKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are inexact */
*recheck = true;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(gbt_num_consistent(&key, (void *) &query,
&strategy, GIST_LEAF(entry), &tinfo));
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
int16 lower;
int16 upper;
-} int16KEY;
+} int16KEY;
/*
** int16 ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int16 query = PG_GETARG_INT16(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
int16KEY *kkk = (int16KEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
int32 lower;
int32 upper;
-} int32KEY;
+} int32KEY;
/*
** int32 ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int32 query = PG_GETARG_INT32(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
int32KEY *kkk = (int32KEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
int64 lower;
int64 upper;
-} int64KEY;
+} int64KEY;
/*
** int64 ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
int64 query = PG_GETARG_INT64(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
int64KEY *kkk = (int64KEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
Interval lower,
upper;
-} intvKEY;
+} intvKEY;
/*
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Interval *query = PG_GETARG_INTERVAL_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
intvKEY *kkk = (intvKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
macaddr lower;
macaddr upper;
-} macKEY;
+} macKEY;
/*
** OID ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
macaddr *query = (macaddr *) PG_GETARG_POINTER(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
macKEY *kkk = (macKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
Oid lower;
Oid upper;
-} oidKEY;
+} oidKEY;
/*
** OID ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Oid query = PG_GETARG_OID(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
oidKEY *kkk = (oidKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_var.h"
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
TimeADT lower;
TimeADT upper;
-} timeKEY;
+} timeKEY;
/*
** time ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimeADT query = PG_GETARG_TIMEADT(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
TimeTzADT *query = PG_GETARG_TIMETZADT_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
timeKEY *kkk = (timeKEY *) DatumGetPointer(entry->key);
qqq = (query->time + query->zone);
#endif
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &qqq, &strategy, GIST_LEAF(entry), &tinfo)
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
- TimeADTGetDatumFast(newentry->upper),
- TimeADTGetDatumFast(origentry->upper)));
+ TimeADTGetDatumFast(newentry->upper),
+ TimeADTGetDatumFast(origentry->upper)));
res = INTERVAL_TO_SEC(intr);
res = Max(res, 0);
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
- TimeADTGetDatumFast(origentry->lower),
- TimeADTGetDatumFast(newentry->lower)));
+ TimeADTGetDatumFast(origentry->lower),
+ TimeADTGetDatumFast(newentry->lower)));
res2 = INTERVAL_TO_SEC(intr);
res2 = Max(res2, 0);
{
intr = DatumGetIntervalP(DirectFunctionCall2(
time_mi_time,
- TimeADTGetDatumFast(origentry->upper),
- TimeADTGetDatumFast(origentry->lower)));
+ TimeADTGetDatumFast(origentry->upper),
+ TimeADTGetDatumFast(origentry->lower)));
*result += FLT_MIN;
*result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
{
Timestamp lower;
Timestamp upper;
-} tsKEY;
+} tsKEY;
/*
** timestamp ops
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
Timestamp query = PG_GETARG_TIMESTAMP(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
tsKEY *kkk = (tsKEY *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk->lower;
- key.upper = (GBT_NUMKEY *) & kkk->upper;
+ key.lower = (GBT_NUMKEY *) &kkk->lower;
+ key.upper = (GBT_NUMKEY *) &kkk->upper;
PG_RETURN_BOOL(
gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
gbt_tstz_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- TimestampTz query = PG_GETARG_TIMESTAMPTZ(1);
+ TimestampTz query = PG_GETARG_TIMESTAMPTZ(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
char *kkk = (char *) DatumGetPointer(entry->key);
/* All cases served by this function are exact */
*recheck = false;
- key.lower = (GBT_NUMKEY *) & kkk[0];
- key.upper = (GBT_NUMKEY *) & kkk[MAXALIGN(tinfo.size)];
+ key.lower = (GBT_NUMKEY *) &kkk[0];
+ key.upper = (GBT_NUMKEY *) &kkk[MAXALIGN(tinfo.size)];
qqq = tstz_to_ts_gmt(query);
PG_RETURN_BOOL(
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
GISTENTRY *
-gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry, const gbtree_ninfo * tinfo)
+gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry, const gbtree_ninfo *tinfo)
{
if (entry->leafkey)
{
*/
void *
-gbt_num_union(GBT_NUMKEY * out, const GistEntryVector *entryvec, const gbtree_ninfo * tinfo)
+gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo)
{
int i,
numranges;
*/
bool
-gbt_num_same(const GBT_NUMKEY * a, const GBT_NUMKEY * b, const gbtree_ninfo * tinfo)
+gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo)
{
GBT_NUMKEY_R b1,
void
-gbt_num_bin_union(Datum *u, GBT_NUMKEY * e, const gbtree_ninfo * tinfo)
+gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo)
{
GBT_NUMKEY_R rd;
bool
gbt_num_consistent(
- const GBT_NUMKEY_R * key,
+ const GBT_NUMKEY_R *key,
const void *query,
const StrategyNumber *strategy,
bool is_leaf,
- const gbtree_ninfo * tinfo
+ const gbtree_ninfo *tinfo
)
{
GIST_SPLITVEC *
gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
- const gbtree_ninfo * tinfo)
+ const gbtree_ninfo *tinfo)
{
OffsetNumber i,
maxoff = entryvec->n - 1;
/*
- * $PostgreSQL$
+ * $PostgreSQL$
*/
#ifndef __BTREE_UTILS_NUM_H__
#define __BTREE_UTILS_NUM_H__
{
const GBT_NUMKEY *lower,
*upper;
-} GBT_NUMKEY_R;
+} GBT_NUMKEY_R;
/* for sorting */
{
int i;
GBT_NUMKEY *t;
-} Nsrt;
+} Nsrt;
/* type description */
bool (*f_le) (const void *, const void *); /* less equal */
bool (*f_lt) (const void *, const void *); /* less then */
int (*f_cmp) (const void *, const void *); /* key compare function */
-} gbtree_ninfo;
+} gbtree_ninfo;
/*
#endif
-extern bool gbt_num_consistent(const GBT_NUMKEY_R * key, const void *query,
+extern bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query,
const StrategyNumber *strategy, bool is_leaf,
- const gbtree_ninfo * tinfo);
+ const gbtree_ninfo *tinfo);
extern GIST_SPLITVEC *gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
- const gbtree_ninfo * tinfo);
+ const gbtree_ninfo *tinfo);
extern GISTENTRY *gbt_num_compress(GISTENTRY *retval, GISTENTRY *entry,
- const gbtree_ninfo * tinfo);
+ const gbtree_ninfo *tinfo);
-extern void *gbt_num_union(GBT_NUMKEY * out, const GistEntryVector *entryvec,
- const gbtree_ninfo * tinfo);
+extern void *gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec,
+ const gbtree_ninfo *tinfo);
-extern bool gbt_num_same(const GBT_NUMKEY * a, const GBT_NUMKEY * b,
- const gbtree_ninfo * tinfo);
+extern bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b,
+ const gbtree_ninfo *tinfo);
-extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY * e,
- const gbtree_ninfo * tinfo);
+extern void gbt_num_bin_union(Datum *u, GBT_NUMKEY *e,
+ const gbtree_ninfo *tinfo);
#endif
/*
- * $PostgreSQL$
+ * $PostgreSQL$
*/
#include "btree_gist.h"
/* Returns a better readable representaion of variable key ( sets pointer ) */
GBT_VARKEY_R
-gbt_var_key_readable(const GBT_VARKEY * k)
+gbt_var_key_readable(const GBT_VARKEY *k)
{
GBT_VARKEY_R r;
GBT_VARKEY *
-gbt_var_key_copy(const GBT_VARKEY_R * u, bool force_node)
+gbt_var_key_copy(const GBT_VARKEY_R *u, bool force_node)
{
GBT_VARKEY *r = NULL;
static GBT_VARKEY *
-gbt_var_leaf2node(GBT_VARKEY * leaf, const gbtree_vinfo * tinfo)
+gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo)
{
GBT_VARKEY *out = leaf;
* returns the common prefix length of a node key
*/
static int32
-gbt_var_node_cp_len(const GBT_VARKEY * node, const gbtree_vinfo * tinfo)
+gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
{
GBT_VARKEY_R r = gbt_var_key_readable(node);
* returns true, if query matches prefix ( common prefix )
*/
static bool
-gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo * tinfo)
+gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)
{
bool out = FALSE;
*/
static bool
-gbt_var_node_pf_match(const GBT_VARKEY_R * node, const bytea *query, const gbtree_vinfo * tinfo)
+gbt_var_node_pf_match(const GBT_VARKEY_R *node, const bytea *query, const gbtree_vinfo *tinfo)
{
return (tinfo->trnc && (
* cpf_length .. common prefix length
*/
static GBT_VARKEY *
-gbt_var_node_truncate(const GBT_VARKEY * node, int32 cpf_length, const gbtree_vinfo * tinfo)
+gbt_var_node_truncate(const GBT_VARKEY *node, int32 cpf_length, const gbtree_vinfo *tinfo)
{
GBT_VARKEY *out = NULL;
GBT_VARKEY_R r = gbt_var_key_readable(node);
void
-gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
+gbt_var_bin_union(Datum *u, GBT_VARKEY *e, const gbtree_vinfo *tinfo)
{
GBT_VARKEY *nk = NULL;
GISTENTRY *
-gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo * tinfo)
+gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
{
GISTENTRY *retval;
GBT_VARKEY *
-gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo * tinfo)
+gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo *tinfo)
{
int i = 0,
bool
-gbt_var_same(bool *result, const Datum d1, const Datum d2, const gbtree_vinfo * tinfo)
+gbt_var_same(bool *result, const Datum d1, const Datum d2, const gbtree_vinfo *tinfo)
{
GBT_VARKEY *t1 = (GBT_VARKEY *) DatumGetPointer(d1);
float *
-gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, const gbtree_vinfo * tinfo)
+gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, const gbtree_vinfo *tinfo)
{
GBT_VARKEY *orge = (GBT_VARKEY *) DatumGetPointer(o->key);
}
GIST_SPLITVEC *
-gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_vinfo * tinfo)
+gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_vinfo *tinfo)
{
OffsetNumber i,
maxoff = entryvec->n - 1;
*/
bool
gbt_var_consistent(
- GBT_VARKEY_R * key,
+ GBT_VARKEY_R *key,
const void *query,
const StrategyNumber *strategy,
bool is_leaf,
- const gbtree_vinfo * tinfo
+ const gbtree_vinfo *tinfo
)
{
bool retval = FALSE;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#ifndef __BTREE_UTILS_VAR_H__
#define __BTREE_UTILS_VAR_H__
{
bytea *lower,
*upper;
-} GBT_VARKEY_R;
+} GBT_VARKEY_R;
/* used for key sorting */
typedef struct
{
int i;
GBT_VARKEY *t;
-} Vsrt;
+} Vsrt;
/*
type description
bool (*f_lt) (const void *, const void *); /* less then */
int32 (*f_cmp) (const bytea *, const bytea *); /* node compare */
GBT_VARKEY *(*f_l2n) (GBT_VARKEY *); /* convert leaf to node */
-} gbtree_vinfo;
+} gbtree_vinfo;
-extern GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY * k);
+extern GBT_VARKEY_R gbt_var_key_readable(const GBT_VARKEY *k);
-extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R * u, bool force_node);
+extern GBT_VARKEY *gbt_var_key_copy(const GBT_VARKEY_R *u, bool force_node);
-extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo * tinfo);
+extern GISTENTRY *gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo);
extern GBT_VARKEY *gbt_var_union(const GistEntryVector *entryvec, int32 *size,
- const gbtree_vinfo * tinfo);
+ const gbtree_vinfo *tinfo);
extern bool gbt_var_same(bool *result, const Datum d1, const Datum d2,
- const gbtree_vinfo * tinfo);
+ const gbtree_vinfo *tinfo);
extern float *gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
- const gbtree_vinfo * tinfo);
+ const gbtree_vinfo *tinfo);
-extern bool gbt_var_consistent(GBT_VARKEY_R * key, const void *query,
+extern bool gbt_var_consistent(GBT_VARKEY_R *key, const void *query,
const StrategyNumber *strategy, bool is_leaf,
- const gbtree_vinfo * tinfo);
+ const gbtree_vinfo *tinfo);
extern GIST_SPLITVEC *gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
- const gbtree_vinfo * tinfo);
-extern void gbt_var_bin_union(Datum *u, GBT_VARKEY * e,
- const gbtree_vinfo * tinfo);
+ const gbtree_vinfo *tinfo);
+extern void gbt_var_bin_union(Datum *u, GBT_VARKEY *e,
+ const gbtree_vinfo *tinfo);
#endif
typedef struct chkpass
{
char password[16];
-} chkpass;
+} chkpass;
/*
* Various forward declarations:
#endif
/*
- * ====================
- * FORWARD DECLARATIONS
- * ====================
+ * ====================
+ * FORWARD DECLARATIONS
+ * ====================
*/
-static int32 citextcmp (text *left, text *right);
-extern Datum citext_cmp (PG_FUNCTION_ARGS);
-extern Datum citext_hash (PG_FUNCTION_ARGS);
-extern Datum citext_eq (PG_FUNCTION_ARGS);
-extern Datum citext_ne (PG_FUNCTION_ARGS);
-extern Datum citext_gt (PG_FUNCTION_ARGS);
-extern Datum citext_ge (PG_FUNCTION_ARGS);
-extern Datum citext_lt (PG_FUNCTION_ARGS);
-extern Datum citext_le (PG_FUNCTION_ARGS);
-extern Datum citext_smaller (PG_FUNCTION_ARGS);
-extern Datum citext_larger (PG_FUNCTION_ARGS);
+static int32 citextcmp(text *left, text *right);
+extern Datum citext_cmp(PG_FUNCTION_ARGS);
+extern Datum citext_hash(PG_FUNCTION_ARGS);
+extern Datum citext_eq(PG_FUNCTION_ARGS);
+extern Datum citext_ne(PG_FUNCTION_ARGS);
+extern Datum citext_gt(PG_FUNCTION_ARGS);
+extern Datum citext_ge(PG_FUNCTION_ARGS);
+extern Datum citext_lt(PG_FUNCTION_ARGS);
+extern Datum citext_le(PG_FUNCTION_ARGS);
+extern Datum citext_smaller(PG_FUNCTION_ARGS);
+extern Datum citext_larger(PG_FUNCTION_ARGS);
/*
- * =================
- * UTILITY FUNCTIONS
- * =================
+ * =================
+ * UTILITY FUNCTIONS
+ * =================
*/
/*
* Returns int32 negative, zero, or positive.
*/
static int32
-citextcmp (text *left, text *right)
+citextcmp(text *left, text *right)
{
- char *lcstr, *rcstr;
- int32 result;
+ char *lcstr,
+ *rcstr;
+ int32 result;
- lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left));
- rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right));
+ lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left));
+ rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right));
- result = varstr_cmp(lcstr, strlen(lcstr),
- rcstr, strlen(rcstr));
+ result = varstr_cmp(lcstr, strlen(lcstr),
+ rcstr, strlen(rcstr));
- pfree(lcstr);
- pfree(rcstr);
+ pfree(lcstr);
+ pfree(rcstr);
- return result;
+ return result;
}
/*
- * ==================
- * INDEXING FUNCTIONS
- * ==================
+ * ==================
+ * INDEXING FUNCTIONS
+ * ==================
*/
PG_FUNCTION_INFO_V1(citext_cmp);
Datum
citext_cmp(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- int32 result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ int32 result;
- result = citextcmp(left, right);
+ result = citextcmp(left, right);
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_INT32(result);
+ PG_RETURN_INT32(result);
}
PG_FUNCTION_INFO_V1(citext_hash);
Datum
citext_hash(PG_FUNCTION_ARGS)
{
- text *txt = PG_GETARG_TEXT_PP(0);
- char *str;
- Datum result;
+ text *txt = PG_GETARG_TEXT_PP(0);
+ char *str;
+ Datum result;
- str = str_tolower(VARDATA_ANY(txt), VARSIZE_ANY_EXHDR(txt));
- result = hash_any((unsigned char *) str, strlen(str));
- pfree(str);
+ str = str_tolower(VARDATA_ANY(txt), VARSIZE_ANY_EXHDR(txt));
+ result = hash_any((unsigned char *) str, strlen(str));
+ pfree(str);
- /* Avoid leaking memory for toasted inputs */
- PG_FREE_IF_COPY(txt, 0);
+ /* Avoid leaking memory for toasted inputs */
+ PG_FREE_IF_COPY(txt, 0);
- PG_RETURN_DATUM(result);
+ PG_RETURN_DATUM(result);
}
/*
- * ==================
- * OPERATOR FUNCTIONS
- * ==================
+ * ==================
+ * OPERATOR FUNCTIONS
+ * ==================
*/
PG_FUNCTION_INFO_V1(citext_eq);
Datum
citext_eq(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- char *lcstr, *rcstr;
- bool result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ char *lcstr,
+ *rcstr;
+ bool result;
- /* We can't compare lengths in advance of downcasing ... */
+ /* We can't compare lengths in advance of downcasing ... */
- lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left));
- rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right));
+ lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left));
+ rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right));
- /*
- * Since we only care about equality or not-equality, we can
- * avoid all the expense of strcoll() here, and just do bitwise
- * comparison.
- */
- result = (strcmp(lcstr, rcstr) == 0);
+ /*
+ * Since we only care about equality or not-equality, we can avoid all the
+ * expense of strcoll() here, and just do bitwise comparison.
+ */
+ result = (strcmp(lcstr, rcstr) == 0);
- pfree(lcstr);
- pfree(rcstr);
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ pfree(lcstr);
+ pfree(rcstr);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_BOOL(result);
+ PG_RETURN_BOOL(result);
}
PG_FUNCTION_INFO_V1(citext_ne);
Datum
citext_ne(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- char *lcstr, *rcstr;
- bool result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ char *lcstr,
+ *rcstr;
+ bool result;
- /* We can't compare lengths in advance of downcasing ... */
+ /* We can't compare lengths in advance of downcasing ... */
- lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left));
- rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right));
+ lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left));
+ rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right));
- /*
- * Since we only care about equality or not-equality, we can
- * avoid all the expense of strcoll() here, and just do bitwise
- * comparison.
- */
- result = (strcmp(lcstr, rcstr) != 0);
+ /*
+ * Since we only care about equality or not-equality, we can avoid all the
+ * expense of strcoll() here, and just do bitwise comparison.
+ */
+ result = (strcmp(lcstr, rcstr) != 0);
- pfree(lcstr);
- pfree(rcstr);
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ pfree(lcstr);
+ pfree(rcstr);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_BOOL(result);
+ PG_RETURN_BOOL(result);
}
PG_FUNCTION_INFO_V1(citext_lt);
Datum
citext_lt(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- bool result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
- result = citextcmp(left, right) < 0;
+ result = citextcmp(left, right) < 0;
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_BOOL(result);
+ PG_RETURN_BOOL(result);
}
PG_FUNCTION_INFO_V1(citext_le);
Datum
citext_le(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- bool result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
- result = citextcmp(left, right) <= 0;
+ result = citextcmp(left, right) <= 0;
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_BOOL(result);
+ PG_RETURN_BOOL(result);
}
PG_FUNCTION_INFO_V1(citext_gt);
Datum
citext_gt(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- bool result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
- result = citextcmp(left, right) > 0;
+ result = citextcmp(left, right) > 0;
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_BOOL(result);
+ PG_RETURN_BOOL(result);
}
PG_FUNCTION_INFO_V1(citext_ge);
Datum
citext_ge(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- bool result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
- result = citextcmp(left, right) >= 0;
+ result = citextcmp(left, right) >= 0;
- PG_FREE_IF_COPY(left, 0);
- PG_FREE_IF_COPY(right, 1);
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
- PG_RETURN_BOOL(result);
+ PG_RETURN_BOOL(result);
}
/*
- * ===================
- * AGGREGATE FUNCTIONS
- * ===================
+ * ===================
+ * AGGREGATE FUNCTIONS
+ * ===================
*/
PG_FUNCTION_INFO_V1(citext_smaller);
Datum
citext_smaller(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- text *result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ text *result;
- result = citextcmp(left, right) < 0 ? left : right;
- PG_RETURN_TEXT_P(result);
+ result = citextcmp(left, right) < 0 ? left : right;
+ PG_RETURN_TEXT_P(result);
}
PG_FUNCTION_INFO_V1(citext_larger);
Datum
citext_larger(PG_FUNCTION_ARGS)
{
- text *left = PG_GETARG_TEXT_PP(0);
- text *right = PG_GETARG_TEXT_PP(1);
- text *result;
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ text *result;
- result = citextcmp(left, right) > 0 ? left : right;
- PG_RETURN_TEXT_P(result);
+ result = citextcmp(left, right) > 0 ? left : right;
+ PG_RETURN_TEXT_P(result);
}
/*
** For internal use only
*/
-int32 cube_cmp_v0(NDBOX * a, NDBOX * b);
-bool cube_contains_v0(NDBOX * a, NDBOX * b);
-bool cube_overlap_v0(NDBOX * a, NDBOX * b);
-NDBOX *cube_union_v0(NDBOX * a, NDBOX * b);
-void rt_cube_size(NDBOX * a, double *sz);
-NDBOX *g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep);
-bool g_cube_leaf_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
-bool g_cube_internal_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
+int32 cube_cmp_v0(NDBOX *a, NDBOX *b);
+bool cube_contains_v0(NDBOX *a, NDBOX *b);
+bool cube_overlap_v0(NDBOX *a, NDBOX *b);
+NDBOX *cube_union_v0(NDBOX *a, NDBOX *b);
+void rt_cube_size(NDBOX *a, double *sz);
+NDBOX *g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep);
+bool g_cube_leaf_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy);
+bool g_cube_internal_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy);
/*
** Auxiliary funxtions
dur = ARRPTR(ur);
dll = ARRPTR(ll);
- size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = dim;
dur = ARRPTR(ur);
- size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = dim;
dx = (int4 *) ARR_DATA_PTR(idx);
dim = ARRNELEMS(idx);
- size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = dim;
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
NDBOX *query = PG_GETARG_NDBOX(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool res;
** SUPPORT ROUTINES
*/
bool
-g_cube_leaf_consistent(NDBOX * key,
- NDBOX * query,
+g_cube_leaf_consistent(NDBOX *key,
+ NDBOX *query,
StrategyNumber strategy)
{
bool retval;
}
bool
-g_cube_internal_consistent(NDBOX * key,
- NDBOX * query,
+g_cube_internal_consistent(NDBOX *key,
+ NDBOX *query,
StrategyNumber strategy)
{
bool retval;
}
NDBOX *
-g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep)
+g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep)
{
NDBOX *retval;
/* cube_union_v0 */
NDBOX *
-cube_union_v0(NDBOX * a, NDBOX * b)
+cube_union_v0(NDBOX *a, NDBOX *b)
{
int i;
NDBOX *result;
}
void
-rt_cube_size(NDBOX * a, double *size)
+rt_cube_size(NDBOX *a, double *size)
{
int i,
j;
/* make up a metric in which one box will be 'lower' than the other
-- this can be useful for sorting and to determine uniqueness */
int32
-cube_cmp_v0(NDBOX * a, NDBOX * b)
+cube_cmp_v0(NDBOX *a, NDBOX *b)
{
int i;
int dim;
/* Contains */
/* Box(A) CONTAINS Box(B) IFF pt(A) < pt(B) */
bool
-cube_contains_v0(NDBOX * a, NDBOX * b)
+cube_contains_v0(NDBOX *a, NDBOX *b)
{
int i;
/* Overlap */
/* Box(A) Overlap Box(B) IFF (pt(a)LL < pt(B)UR) && (pt(b)LL < pt(a)UR) */
bool
-cube_overlap_v0(NDBOX * a, NDBOX * b)
+cube_overlap_v0(NDBOX *a, NDBOX *b)
{
int i;
dim = n;
if (a->dim > dim)
dim = a->dim;
- size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * dim * 2;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = dim;
NDBOX *result;
int size;
- size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * 2;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = 1;
NDBOX *result;
int size;
- size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * 2;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = 1;
int size;
int i;
- size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * (c->dim + 1) *2;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = c->dim + 1;
int size;
int i;
- size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
+ size = offsetof(NDBOX, x[0]) +sizeof(double) * (c->dim + 1) *2;
result = (NDBOX *) palloc0(size);
SET_VARSIZE(result, size);
result->dim = c->dim + 1;
int32 vl_len_; /* varlena header (do not touch directly!) */
unsigned int dim;
double x[1];
-} NDBOX;
+} NDBOX;
#define DatumGetNDBOX(x) ((NDBOX*)DatumGetPointer(x))
#define PG_GETARG_NDBOX(x) DatumGetNDBOX( PG_DETOAST_DATUM(PG_GETARG_DATUM(x)) )
PGconn *conn; /* Hold the remote connection */
int openCursorCount; /* The number of open cursors */
bool newXactForCursor; /* Opened a transaction for a cursor */
-} remoteConn;
+} remoteConn;
/*
* Internal declarations
static Datum dblink_record_internal(FunctionCallInfo fcinfo, bool is_async);
static remoteConn *getConnectionByName(const char *name);
static HTAB *createConnHash(void);
-static void createNewConnection(const char *name, remoteConn * rconn);
+static void createNewConnection(const char *name, remoteConn *rconn);
static void deleteConnection(const char *name);
static char **get_pkey_attnames(Oid relid, int16 *numatts);
static char **get_text_array_contents(ArrayType *array, int *numitems);
{
char name[NAMEDATALEN];
remoteConn *rconn;
-} remoteConnHashEnt;
+} remoteConnHashEnt;
/* initial number of connection hashes */
#define NUMCONN 16
funcctx = SRF_FIRSTCALL_INIT();
/*
- * Try to execute the query. Note that since libpq uses malloc,
- * the PGresult will be long-lived even though we are still in
- * a short-lived memory context.
+ * Try to execute the query. Note that since libpq uses malloc, the
+ * PGresult will be long-lived even though we are still in a
+ * short-lived memory context.
*/
res = PQexec(conn, buf.data);
if (!res ||
"the specified FROM clause rowtype")));
/*
- * fast track when no results. We could exit earlier, but then
- * we'd not report error if the result tuple type is wrong.
+ * fast track when no results. We could exit earlier, but then we'd
+ * not report error if the result tuple type is wrong.
*/
if (funcctx->max_calls < 1)
{
/* shouldn't happen */
elog(ERROR, "wrong number of arguments");
}
- else /* is_async */
+ else /* is_async */
{
/* get async result */
if (PG_NARGS() == 2)
if (!conn)
DBLINK_CONN_NOT_AVAIL;
- /* synchronous query, or async result retrieval */
- if (!is_async)
- res = PQexec(conn, sql);
- else
- {
- res = PQgetResult(conn);
- /* NULL means we're all done with the async results */
- if (!res)
- {
- MemoryContextSwitchTo(oldcontext);
- SRF_RETURN_DONE(funcctx);
- }
- }
-
- if (!res ||
- (PQresultStatus(res) != PGRES_COMMAND_OK &&
- PQresultStatus(res) != PGRES_TUPLES_OK))
+ /* synchronous query, or async result retrieval */
+ if (!is_async)
+ res = PQexec(conn, sql);
+ else
+ {
+ res = PQgetResult(conn);
+ /* NULL means we're all done with the async results */
+ if (!res)
{
- dblink_res_error(conname, res, "could not execute query", fail);
- if (freeconn)
- PQfinish(conn);
MemoryContextSwitchTo(oldcontext);
SRF_RETURN_DONE(funcctx);
}
+ }
- if (PQresultStatus(res) == PGRES_COMMAND_OK)
- {
- is_sql_cmd = true;
-
- /* need a tuple descriptor representing one TEXT column */
- tupdesc = CreateTemplateTupleDesc(1, false);
- TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
- TEXTOID, -1, 0);
-
- /*
- * and save a copy of the command status string to return as
- * our result tuple
- */
- sql_cmd_status = PQcmdStatus(res);
- funcctx->max_calls = 1;
- }
- else
- funcctx->max_calls = PQntuples(res);
-
- /* got results, keep track of them */
- funcctx->user_fctx = res;
-
- /* if needed, close the connection to the database and cleanup */
+ if (!res ||
+ (PQresultStatus(res) != PGRES_COMMAND_OK &&
+ PQresultStatus(res) != PGRES_TUPLES_OK))
+ {
+ dblink_res_error(conname, res, "could not execute query", fail);
if (freeconn)
PQfinish(conn);
+ MemoryContextSwitchTo(oldcontext);
+ SRF_RETURN_DONE(funcctx);
+ }
- if (!is_sql_cmd)
- {
- /* get a tuple descriptor for our result type */
- switch (get_call_result_type(fcinfo, NULL, &tupdesc))
- {
- case TYPEFUNC_COMPOSITE:
- /* success */
- break;
- case TYPEFUNC_RECORD:
- /* failed to determine actual type of RECORD */
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("function returning record called in context "
- "that cannot accept type record")));
- break;
- default:
- /* result type isn't composite */
- elog(ERROR, "return type must be a row type");
- break;
- }
+ if (PQresultStatus(res) == PGRES_COMMAND_OK)
+ {
+ is_sql_cmd = true;
- /* make sure we have a persistent copy of the tupdesc */
- tupdesc = CreateTupleDescCopy(tupdesc);
- }
+ /* need a tuple descriptor representing one TEXT column */
+ tupdesc = CreateTemplateTupleDesc(1, false);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
+ TEXTOID, -1, 0);
/*
- * check result and tuple descriptor have the same number of
- * columns
+ * and save a copy of the command status string to return as our
+ * result tuple
*/
- if (PQnfields(res) != tupdesc->natts)
- ereport(ERROR,
- (errcode(ERRCODE_DATATYPE_MISMATCH),
- errmsg("remote query result rowtype does not match "
- "the specified FROM clause rowtype")));
+ sql_cmd_status = PQcmdStatus(res);
+ funcctx->max_calls = 1;
+ }
+ else
+ funcctx->max_calls = PQntuples(res);
- /* fast track when no results */
- if (funcctx->max_calls < 1)
+ /* got results, keep track of them */
+ funcctx->user_fctx = res;
+
+ /* if needed, close the connection to the database and cleanup */
+ if (freeconn)
+ PQfinish(conn);
+
+ if (!is_sql_cmd)
+ {
+ /* get a tuple descriptor for our result type */
+ switch (get_call_result_type(fcinfo, NULL, &tupdesc))
{
- if (res)
- PQclear(res);
- MemoryContextSwitchTo(oldcontext);
- SRF_RETURN_DONE(funcctx);
+ case TYPEFUNC_COMPOSITE:
+ /* success */
+ break;
+ case TYPEFUNC_RECORD:
+ /* failed to determine actual type of RECORD */
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("function returning record called in context "
+ "that cannot accept type record")));
+ break;
+ default:
+ /* result type isn't composite */
+ elog(ERROR, "return type must be a row type");
+ break;
}
- /* store needed metadata for subsequent calls */
- attinmeta = TupleDescGetAttInMetadata(tupdesc);
- funcctx->attinmeta = attinmeta;
+ /* make sure we have a persistent copy of the tupdesc */
+ tupdesc = CreateTupleDescCopy(tupdesc);
+ }
+ /*
+ * check result and tuple descriptor have the same number of columns
+ */
+ if (PQnfields(res) != tupdesc->natts)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("remote query result rowtype does not match "
+ "the specified FROM clause rowtype")));
+
+ /* fast track when no results */
+ if (funcctx->max_calls < 1)
+ {
+ if (res)
+ PQclear(res);
MemoryContextSwitchTo(oldcontext);
+ SRF_RETURN_DONE(funcctx);
+ }
+
+ /* store needed metadata for subsequent calls */
+ attinmeta = TupleDescGetAttInMetadata(tupdesc);
+ funcctx->attinmeta = attinmeta;
+
+ MemoryContextSwitchTo(oldcontext);
}
rawstr_text = cstring_to_text(rawstr);
result_text = DatumGetTextP(DirectFunctionCall1(quote_literal,
- PointerGetDatum(rawstr_text)));
+ PointerGetDatum(rawstr_text)));
result = text_to_cstring(result_text);
return result;
rawstr_text = cstring_to_text(rawstr);
result_text = DatumGetTextP(DirectFunctionCall1(quote_ident,
- PointerGetDatum(rawstr_text)));
+ PointerGetDatum(rawstr_text)));
result = text_to_cstring(result_text);
return result;
}
static void
-createNewConnection(const char *name, remoteConn * rconn)
+createNewConnection(const char *name, remoteConn *rconn)
{
remoteConnHashEnt *hentry;
bool found;
}
/*
- * For non-superusers, insist that the connstr specify a password. This
+ * For non-superusers, insist that the connstr specify a password. This
* prevents a password from being picked up from .pgpass, a service file,
* the environment, etc. We don't want the postgres user's passwords
* to be accessible to non-superusers.
{
if (!superuser())
{
- PQconninfoOption *options;
- PQconninfoOption *option;
- bool connstr_gives_password = false;
+ PQconninfoOption *options;
+ PQconninfoOption *option;
+ bool connstr_gives_password = false;
options = PQconninfoParse(connstr, NULL);
if (options)
if (!connstr_gives_password)
ereport(ERROR,
- (errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
- errmsg("password is required"),
- errdetail("Non-superusers must provide a password in the connection string.")));
+ (errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
+ errmsg("password is required"),
+ errdetail("Non-superusers must provide a password in the connection string.")));
}
}
dblink_context_conname = conname;
ereport(level,
- (errcode(sqlstate),
- message_primary ? errmsg("%s", message_primary) : errmsg("unknown error"),
- message_detail ? errdetail("%s", message_detail) : 0,
- message_hint ? errhint("%s", message_hint) : 0,
- message_context ? errcontext("%s", message_context) : 0,
- errcontext("Error occurred on dblink connection named \"%s\": %s.",
- dblink_context_conname, dblink_context_msg)));
+ (errcode(sqlstate),
+ message_primary ? errmsg("%s", message_primary) : errmsg("unknown error"),
+ message_detail ? errdetail("%s", message_detail) : 0,
+ message_hint ? errhint("%s", message_hint) : 0,
+ message_context ? errcontext("%s", message_context) : 0,
+ errcontext("Error occurred on dblink connection named \"%s\": %s.",
+ dblink_context_conname, dblink_context_msg)));
}
/*
static char *
get_connect_string(const char *servername)
{
- ForeignServer *foreign_server = NULL;
- UserMapping *user_mapping;
- ListCell *cell;
- StringInfo buf = makeStringInfo();
+ ForeignServer *foreign_server = NULL;
+ UserMapping *user_mapping;
+ ListCell *cell;
+ StringInfo buf = makeStringInfo();
ForeignDataWrapper *fdw;
- AclResult aclresult;
+ AclResult aclresult;
/* first gather the server connstr options */
if (strlen(servername) < NAMEDATALEN)
if (foreign_server)
{
- Oid serverid = foreign_server->serverid;
- Oid fdwid = foreign_server->fdwid;
- Oid userid = GetUserId();
+ Oid serverid = foreign_server->serverid;
+ Oid fdwid = foreign_server->fdwid;
+ Oid userid = GetUserId();
user_mapping = GetUserMapping(userid, serverid);
- fdw = GetForeignDataWrapper(fdwid);
+ fdw = GetForeignDataWrapper(fdwid);
/* Check permissions, user must have usage on the server. */
aclresult = pg_foreign_server_aclcheck(serverid, userid, ACL_USAGE);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_FOREIGN_SERVER, foreign_server->servername);
- foreach (cell, fdw->options)
+ foreach(cell, fdw->options)
{
- DefElem *def = lfirst(cell);
+ DefElem *def = lfirst(cell);
appendStringInfo(buf, "%s='%s' ", def->defname,
escape_param_str(strVal(def->arg)));
}
- foreach (cell, foreign_server->options)
+ foreach(cell, foreign_server->options)
{
- DefElem *def = lfirst(cell);
-
+ DefElem *def = lfirst(cell);
+
appendStringInfo(buf, "%s='%s' ", def->defname,
escape_param_str(strVal(def->arg)));
}
-
- foreach (cell, user_mapping->options)
+
+ foreach(cell, user_mapping->options)
{
-
- DefElem *def = lfirst(cell);
-
+
+ DefElem *def = lfirst(cell);
+
appendStringInfo(buf, "%s='%s' ", def->defname,
escape_param_str(strVal(def->arg)));
}
static char *
escape_param_str(const char *str)
{
- const char *cp;
- StringInfo buf = makeStringInfo();
+ const char *cp;
+ StringInfo buf = makeStringInfo();
for (cp = str; *cp; cp++)
{
{
int maxlen;
bool rejectlong;
-} DictInt;
+} DictInt;
PG_FUNCTION_INFO_V1(dintdict_init);
* distance between the points in miles on earth's surface
*
* If float8 is passed-by-value, the oldstyle version-0 calling convention
- * is unportable, so we use version-1. However, if it's passed-by-reference,
+ * is unportable, so we use version-1. However, if it's passed-by-reference,
* continue to use oldstyle. This is just because we'd like earthdistance
* to serve as a canary for any unintentional breakage of version-0 functions
* with float8 results.
#ifdef USE_FLOAT8_BYVAL
Datum geo_distance(PG_FUNCTION_ARGS);
+
PG_FUNCTION_INFO_V1(geo_distance);
Datum
result = geo_distance_internal(pt1, pt2);
PG_RETURN_FLOAT8(result);
}
-
-#else /* !USE_FLOAT8_BYVAL */
+#else /* !USE_FLOAT8_BYVAL */
double *geo_distance(Point *pt1, Point *pt2);
return resultp;
}
-#endif /* USE_FLOAT8_BYVAL */
+#endif /* USE_FLOAT8_BYVAL */
int free_string_on_destroy;
}
- metastring;
+metastring;
/*
* remaining perl module funcs unchanged except for declaring them static
static void
-DestroyMetaString(metastring * s)
+DestroyMetaString(metastring *s)
{
if (s == NULL)
return;
static void
-IncreaseBuffer(metastring * s, int chars_needed)
+IncreaseBuffer(metastring *s, int chars_needed)
{
META_REALLOC(s->str, (s->bufsize + chars_needed + 10), char);
assert(s->str != NULL);
static void
-MakeUpper(metastring * s)
+MakeUpper(metastring *s)
{
char *i;
static int
-IsVowel(metastring * s, int pos)
+IsVowel(metastring *s, int pos)
{
char c;
static int
-SlavoGermanic(metastring * s)
+SlavoGermanic(metastring *s)
{
if ((char *) strstr(s->str, "W"))
return 1;
static char
-GetAt(metastring * s, int pos)
+GetAt(metastring *s, int pos)
{
if ((pos < 0) || (pos >= s->length))
return '\0';
static void
-SetAt(metastring * s, int pos, char c)
+SetAt(metastring *s, int pos, char c)
{
if ((pos < 0) || (pos >= s->length))
return;
Caveats: the START value is 0 based
*/
static int
-StringAt(metastring * s, int start, int length,...)
+StringAt(metastring *s, int start, int length,...)
{
char *test;
char *pos;
static void
-MetaphAdd(metastring * s, char *new_str)
+MetaphAdd(metastring *s, char *new_str)
{
int add_length;
*/
#define MAX_LEVENSHTEIN_STRLEN 255
-static int levenshtein_internal(const char *s, const char *t,
- int ins_c, int del_c, int sub_c);
+static int levenshtein_internal(const char *s, const char *t,
+ int ins_c, int del_c, int sub_c);
/*
/*
* levenshtein_internal - Calculates Levenshtein distance metric
- * between supplied strings. Generally
- * (1, 1, 1) penalty costs suffices common
- * cases, but your mileage may vary.
+ * between supplied strings. Generally
+ * (1, 1, 1) penalty costs suffices common
+ * cases, but your mileage may vary.
*/
static int
levenshtein_internal(const char *s, const char *t,
int ins_c, int del_c, int sub_c)
{
- int m, n;
- int *prev;
- int *curr;
- int i, j;
+ int m,
+ n;
+ int *prev;
+ int *curr;
+ int i,
+ j;
const char *x;
const char *y;
n = strlen(t);
/*
- * If either m or n is 0, the answer is the other value. This makes
- * sense since it would take that many insertions to build a matching
- * string
+ * If either m or n is 0, the answer is the other value. This makes sense
+ * since it would take that many insertions to build a matching string
*/
if (!m)
return n;
++n;
/*
- * Instead of building an (m+1)x(n+1) array, we'll use two
- * different arrays of size m+1 for storing accumulated values.
- * At each step one represents the "previous" row and one is the
- * "current" row of the notional large array.
+ * Instead of building an (m+1)x(n+1) array, we'll use two different
+ * arrays of size m+1 for storing accumulated values. At each step one
+ * represents the "previous" row and one is the "current" row of the
+ * notional large array.
*/
prev = (int *) palloc(2 * m * sizeof(int));
curr = prev + m;
/* Loop through rows of the notional array */
for (y = t, j = 1; j < n; y++, j++)
{
- int *temp;
+ int *temp;
/*
- * First cell must increment sequentially, as we're on the
- * j'th row of the (m+1)x(n+1) array.
+ * First cell must increment sequentially, as we're on the j'th row of
+ * the (m+1)x(n+1) array.
*/
curr[0] = j;
-
+
for (x = s, i = 1; i < m; x++, i++)
{
- int ins;
- int del;
- int sub;
+ int ins;
+ int del;
+ int sub;
/* Calculate costs for probable operations. */
- ins = prev[i] + ins_c; /* Insertion */
- del = curr[i-1] + del_c; /* Deletion */
- sub = prev[i-1] + ((*x == *y) ? 0 : sub_c); /* Substitution */
+ ins = prev[i] + ins_c; /* Insertion */
+ del = curr[i - 1] + del_c; /* Deletion */
+ sub = prev[i - 1] + ((*x == *y) ? 0 : sub_c); /* Substitution */
/* Take the one with minimum cost. */
curr[i] = Min(ins, del);
}
/*
- * Because the final value was swapped from the previous row to
- * the current row, that's where we'll find it.
+ * Because the final value was swapped from the previous row to the
+ * current row, that's where we'll find it.
*/
- return prev[m-1];
+ return prev[m - 1];
}
Datum
levenshtein_with_costs(PG_FUNCTION_ARGS)
{
- char *src = TextDatumGetCString(PG_GETARG_DATUM(0));
- char *dst = TextDatumGetCString(PG_GETARG_DATUM(1));
- int ins_c = PG_GETARG_INT32(2);
- int del_c = PG_GETARG_INT32(3);
- int sub_c = PG_GETARG_INT32(4);
+ char *src = TextDatumGetCString(PG_GETARG_DATUM(0));
+ char *dst = TextDatumGetCString(PG_GETARG_DATUM(1));
+ int ins_c = PG_GETARG_INT32(2);
+ int del_c = PG_GETARG_INT32(3);
+ int sub_c = PG_GETARG_INT32(4);
PG_RETURN_INT32(levenshtein_internal(src, dst, ins_c, del_c, sub_c));
}
Datum
levenshtein(PG_FUNCTION_ARGS)
{
- char *src = TextDatumGetCString(PG_GETARG_DATUM(0));
- char *dst = TextDatumGetCString(PG_GETARG_DATUM(1));
+ char *src = TextDatumGetCString(PG_GETARG_DATUM(0));
+ char *dst = TextDatumGetCString(PG_GETARG_DATUM(1));
PG_RETURN_INT32(levenshtein_internal(src, dst, 1, 1, 1));
}
static int
-_metaphone(char *word, /* IN */
+_metaphone(char *word, /* IN */
int max_phonemes,
- char **phoned_word) /* OUT */
+ char **phoned_word) /* OUT */
{
int w_idx = 0; /* point in the phonization we're at. */
int p_idx = 0; /* end of the phoned phrase */
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*
* Both POSIX and CRC32 checksums */
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#ifndef _CRC32_H
#define _CRC32_H
uint32
valisnull:1,
pos:31;
-} HEntry;
+} HEntry;
/* these are determined by the sizes of the keylen and vallen fields */
/* in struct HEntry and struct Pairs */
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size;
char data[1];
-} HStore;
+} HStore;
#define HSHRDSIZE (VARHDRSZ + sizeof(int4))
#define CALCDATASIZE(x, lenstr) ( (x) * sizeof(HEntry) + HSHRDSIZE + (lenstr) )
uint16 vallen;
bool isnull;
bool needfree;
-} Pairs;
+} Pairs;
int comparePairs(const void *a, const void *b);
-int uniquePairs(Pairs * a, int4 l, int4 *buflen);
+int uniquePairs(Pairs *a, int4 l, int4 *buflen);
-size_t hstoreCheckKeyLen(size_t len);
-size_t hstoreCheckValLen(size_t len);
+size_t hstoreCheckKeyLen(size_t len);
+size_t hstoreCheckValLen(size_t len);
#define HStoreContainsStrategyNumber 7
#define HStoreExistsStrategyNumber 9
-#endif /* __HSTORE_H__ */
+#endif /* __HSTORE_H__ */
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
HStore *query = PG_GETARG_HS(2);
+
/* int32 nkeys = PG_GETARG_INT32(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
int i;
/*
- * Index lost information about correspondence of keys
- * and values, so we need recheck
+ * Index lost information about correspondence of keys and values, so
+ * we need recheck
*/
*recheck = true;
for (i = 0; res && i < 2 * query->size; i++)
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 flag;
char data[1];
-} GISTTYPE;
+} GISTTYPE;
#define ALLISTRUE 0x04
}
static int
-hemdist(GISTTYPE * a, GISTTYPE * b)
+hemdist(GISTTYPE *a, GISTTYPE *b)
{
if (ISALLTRUE(a))
{
}
static int4
-unionkey(BITVECP sbase, GISTTYPE * add)
+unionkey(BITVECP sbase, GISTTYPE *add)
{
int4 i;
BITVECP sadd = GETSIGN(add);
{
GISTTYPE *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool res = true;
Pairs *pairs;
int pcur;
int plen;
-} HSParser;
+} HSParser;
#define RESIZEPRSBUF \
do { \
#define GV_WAITESCESCIN 4
static bool
-get_val(HSParser * state, bool ignoreeq, bool *escaped)
+get_val(HSParser *state, bool ignoreeq, bool *escaped)
{
int st = GV_WAITVAL;
static void
-parse_hstore(HSParser * state)
+parse_hstore(HSParser *state)
{
int st = WKEY;
bool escaped = false;
}
int
-uniquePairs(Pairs * a, int4 l, int4 *buflen)
+uniquePairs(Pairs *a, int4 l, int4 *buflen)
{
Pairs *ptr,
*res;
}
static void
-freeHSParse(HSParser * state)
+freeHSParse(HSParser *state)
{
int i;
HStore *in = PG_GETARG_HS(0);
int buflen,
i,
- nnulls=0;
+ nnulls = 0;
char *out,
*ptr;
char *base = STRPTR(in);
if (entries[i].valisnull)
nnulls++;
- buflen = (4 /* " */ + 2 /* => */ ) * ( in->size - nnulls ) +
- ( 2 /* " */ + 2 /* => */ + 4 /* NULL */ ) * nnulls +
- 2 /* , */ * ( in->size - 1 ) +
- 2 /* esc */ * (VARSIZE(in) - CALCDATASIZE(in->size, 0)) +
- 1 /* \0 */;
+ buflen = (4 /* " */ + 2 /* => */ ) * (in->size - nnulls) +
+ (2 /* " */ + 2 /* => */ + 4 /* NULL */ ) * nnulls +
+ 2 /* , */ * (in->size - 1) +
+ 2 /* esc */ * (VARSIZE(in) - CALCDATASIZE(in->size, 0)) +
+ 1 /* \0 */ ;
out = ptr = palloc(buflen);
for (i = 0; i < in->size; i++)
static HEntry *
-findkey(HStore * hs, char *key, int keylen)
+findkey(HStore *hs, char *key, int keylen)
{
HEntry *StopLow = ARRPTR(hs);
HEntry *StopHigh = StopLow + hs->size;
{
HStore *hs;
int i;
-} AKStore;
+} AKStore;
static void
-setup_firstcall(FuncCallContext *funcctx, HStore * hs)
+setup_firstcall(FuncCallContext *funcctx, HStore *hs)
{
MemoryContext oldcontext;
AKStore *st;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#ifndef ___INT_H__
#define ___INT_H__
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 flag;
char data[1];
-} GISTTYPE;
+} GISTTYPE;
#define ALLISTRUE 0x04
int2 type;
int2 left;
int4 val;
-} ITEM;
+} ITEM;
typedef struct
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size;
char data[1];
-} QUERYTYPE;
+} QUERYTYPE;
#define HDRSIZEQT (VARHDRSZ + sizeof(int4))
#define COMPUTESIZE(size) ( HDRSIZEQT + size * sizeof(ITEM) )
#define OPEN 4
#define CLOSE 5
-bool signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot);
-bool execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot);
-bool ginconsistent(QUERYTYPE * query, bool *check);
-int4 shorterquery(ITEM * q, int4 len);
+bool signconsistent(QUERYTYPE *query, BITVEC sign, bool calcnot);
+bool execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot);
+bool ginconsistent(QUERYTYPE *query, bool *check);
+int4 shorterquery(ITEM *q, int4 len);
int compASC(const void *a, const void *b);
qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \
(direction) ? compASC : compDESC )
-#endif /* ___INT_H__ */
+#endif /* ___INT_H__ */
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "postgres.h"
NODE *str;
/* number in str */
int4 num;
-} WORKSTATE;
+} WORKSTATE;
/*
* get token from query string
*/
static int4
-gettoken(WORKSTATE * state, int4 *val)
+gettoken(WORKSTATE *state, int4 *val)
{
char nnn[16],
*curnnn;
* push new one in polish notation reverse view
*/
static void
-pushquery(WORKSTATE * state, int4 type, int4 val)
+pushquery(WORKSTATE *state, int4 type, int4 val)
{
NODE *tmp = (NODE *) palloc(sizeof(NODE));
* make polish notation of query
*/
static int4
-makepol(WORKSTATE * state)
+makepol(WORKSTATE *state)
{
int4 val,
type;
* is there value 'val' in array or not ?
*/
static bool
-checkcondition_arr(void *checkval, ITEM * item)
+checkcondition_arr(void *checkval, ITEM *item)
{
int4 *StopLow = ((CHKVAL *) checkval)->arrb;
int4 *StopHigh = ((CHKVAL *) checkval)->arre;
}
static bool
-checkcondition_bit(void *checkval, ITEM * item)
+checkcondition_bit(void *checkval, ITEM *item)
{
return GETBIT(checkval, HASHVAL(item->val));
}
* check for boolean condition
*/
static bool
-execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM * item))
+execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *item))
{
if (curitem->type == VAL)
* signconsistent & execconsistent called by *_consistent
*/
bool
-signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot)
+signconsistent(QUERYTYPE *query, BITVEC sign, bool calcnot)
{
return execute(
GETQUERY(query) + query->size - 1,
}
bool
-execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot)
+execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot)
{
CHKVAL chkval;
} GinChkVal;
static bool
-checkcondition_gin(void *checkval, ITEM * item)
+checkcondition_gin(void *checkval, ITEM *item)
{
GinChkVal *gcv = (GinChkVal *) checkval;
}
bool
-ginconsistent(QUERYTYPE * query, bool *check)
+ginconsistent(QUERYTYPE *query, bool *check)
{
GinChkVal gcv;
ITEM *items = GETQUERY(query);
}
static void
-findoprnd(ITEM * ptr, int4 *pos)
+findoprnd(ITEM *ptr, int4 *pos)
{
#ifdef BS_DEBUG
elog(DEBUG3, (ptr[*pos].type == OPR) ?
}
static int4
-countdroptree(ITEM * q, int4 pos)
+countdroptree(ITEM *q, int4 pos)
{
if (q[pos].type == VAL)
return 1;
* we can modify query tree for clearing
*/
int4
-shorterquery(ITEM * q, int4 len)
+shorterquery(ITEM *q, int4 len)
{
int4 index,
posnot,
/*
- * $PostgreSQL$
+ * $PostgreSQL$
*/
#include "postgres.h"
{
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
+
/* int32 nkeys = PG_GETARG_INT32(3); */
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "postgres.h"
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
ArrayType *query = (ArrayType *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "postgres.h"
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "postgres.h"
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*/
#include "postgres.h"
** intbig functions
*********************************************************************/
static bool
-_intbig_overlap(GISTTYPE * a, ArrayType *b)
+_intbig_overlap(GISTTYPE *a, ArrayType *b)
{
int num = ARRNELEMS(b);
int4 *ptr = ARRPTR(b);
}
static bool
-_intbig_contains(GISTTYPE * a, ArrayType *b)
+_intbig_contains(GISTTYPE *a, ArrayType *b)
{
int num = ARRNELEMS(b);
int4 *ptr = ARRPTR(b);
}
static int
-hemdist(GISTTYPE * a, GISTTYPE * b)
+hemdist(GISTTYPE *a, GISTTYPE *b)
{
if (ISALLTRUE(a))
{
}
static int4
-unionkey(BITVECP sbase, GISTTYPE * add)
+unionkey(BITVECP sbase, GISTTYPE *add)
{
int4 i;
BITVECP sadd = GETSIGN(add);
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
ArrayType *query = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool retval;
INVALID, ANY, EAN13, ISBN, ISMN, ISSN, UPC
};
-static const char * const isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC"};
+static const char *const isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC"};
static bool g_weak = false;
static bool g_initialized = false;
* If errorOK is true, just return "false" for bad input.
*/
static bool
-ean2isn(ean13 ean, bool errorOK, ean13 * result, enum isn_type accept)
+ean2isn(ean13 ean, bool errorOK, ean13 *result, enum isn_type accept)
{
enum isn_type type = INVALID;
* (even if the check digit is valid)
*/
static bool
-string2ean(const char *str, bool errorOK, ean13 * result,
+string2ean(const char *str, bool errorOK, ean13 *result,
enum isn_type accept)
{
bool digit,
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*
*
* GiST support for ltree[]
static void
-hashing(BITVECP sign, ltree * t)
+hashing(BITVECP sign, ltree *t)
{
int tlen = t->numlevel;
ltree_level *cur = LTREE_FIRST(t);
}
static int4
-unionkey(BITVECP sbase, ltree_gist * add)
+unionkey(BITVECP sbase, ltree_gist *add)
{
int4 i;
BITVECP sadd = LTG_SIGN(add);
}
static int
-hemdist(ltree_gist * a, ltree_gist * b)
+hemdist(ltree_gist *a, ltree_gist *b)
{
if (LTG_ISALLTRUE(a))
{
}
static bool
-gist_te(ltree_gist * key, ltree * query)
+gist_te(ltree_gist *key, ltree *query)
{
ltree_level *curq = LTREE_FIRST(query);
BITVECP sign = LTG_SIGN(key);
}
static bool
-checkcondition_bit(void *checkval, ITEM * val)
+checkcondition_bit(void *checkval, ITEM *val)
{
return (FLG_CANLOOKSIGN(val->flag)) ? GETBIT(checkval, AHASHVAL(val->val)) : true;
}
static bool
-gist_qtxt(ltree_gist * key, ltxtquery * query)
+gist_qtxt(ltree_gist *key, ltxtquery *query)
{
if (LTG_ISALLTRUE(key))
return true;
}
static bool
-gist_qe(ltree_gist * key, lquery * query)
+gist_qe(ltree_gist *key, lquery *query)
{
lquery_level *curq = LQUERY_FIRST(query);
BITVECP sign = LTG_SIGN(key);
}
static bool
-_arrq_cons(ltree_gist * key, ArrayType *_query)
+_arrq_cons(ltree_gist *key, ArrayType *_query)
{
lquery *query = (lquery *) ARR_DATA_PTR(_query);
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
char *query = (char *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
/*
- * $PostgreSQL:$
+ * $PostgreSQL$
*
*
* op function for ltree[]
#define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
static bool
-array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree ** found)
+array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
{
int num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));
ltree *item = (ltree *) ARR_DATA_PTR(la);
int nt;
int posq;
int post;
-} FieldNot;
+} FieldNot;
static char *
getlexeme(char *start, char *end, int *len)
{
char *ptr;
- int charlen;
-
- while (start < end && (charlen = pg_mblen(start)) == 1 && t_iseq(start,'_') )
+ int charlen;
+
+ while (start < end && (charlen = pg_mblen(start)) == 1 && t_iseq(start, '_'))
start += charlen;
ptr = start;
if (ptr >= end)
return NULL;
- while (ptr < end && !( (charlen = pg_mblen(ptr)) == 1 && t_iseq(ptr, '_') ) )
+ while (ptr < end && !((charlen = pg_mblen(ptr)) == 1 && t_iseq(ptr, '_')))
ptr += charlen;
*len = ptr - start;
}
bool
-compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
+ compare_subnode(ltree_level *t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
{
char *endt = t->name + t->len;
char *endq = qn + len;
int
ltree_strncasecmp(const char *a, const char *b, size_t s)
{
- char *al = str_tolower(a, s);
- char *bl = str_tolower(b, s);
- int res;
-
- res = strncmp(al, bl,s);
+ char *al = str_tolower(a, s);
+ char *bl = str_tolower(b, s);
+ int res;
+
+ res = strncmp(al, bl, s);
pfree(al);
pfree(bl);
}
static bool
-checkLevel(lquery_level * curq, ltree_level * curt)
+checkLevel(lquery_level *curq, ltree_level *curt)
{
int (*cmpptr) (const char *, const char *, size_t);
lquery_variant *curvar = LQL_FIRST(curq);
};
static bool
-checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_numlevel, FieldNot * ptr)
+checkCond(lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_numlevel, FieldNot *ptr)
{
uint32 low_pos = 0,
high_pos = 0,
{
uint16 len;
char name[1];
-} ltree_level;
+} ltree_level;
#define LEVEL_HDRSIZE (offsetof(ltree_level,name))
#define LEVEL_NEXT(x) ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) )
int32 vl_len_; /* varlena header (do not touch directly!) */
uint16 numlevel;
char data[1];
-} ltree;
+} ltree;
#define LTREE_HDRSIZE MAXALIGN( offsetof(ltree, data) )
#define LTREE_FIRST(x) ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) )
uint16 len;
uint8 flag;
char name[1];
-} lquery_variant;
+} lquery_variant;
#define LVAR_HDRSIZE MAXALIGN(offsetof(lquery_variant, name))
#define LVAR_NEXT(x) ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) )
uint16 low;
uint16 high;
char variants[1];
-} lquery_level;
+} lquery_level;
#define LQL_HDRSIZE MAXALIGN( offsetof(lquery_level,variants) )
#define LQL_NEXT(x) ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) )
uint16 firstgood;
uint16 flag;
char data[1];
-} lquery;
+} lquery;
#define LQUERY_HDRSIZE MAXALIGN( offsetof(lquery, data) )
#define LQUERY_FIRST(x) ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) )
#define LQUERY_HASNOT 0x01
-#define ISALNUM(x) ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
+#define ISALNUM(x) ( t_isalpha(x) || t_isdigit(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
/* full text query */
/* user-friendly value */
uint8 length;
uint16 distance;
-} ITEM;
+} ITEM;
/*
*Storage:
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size;
char data[1];
-} ltxtquery;
+} ltxtquery;
#define HDRSIZEQT MAXALIGN(VARHDRSZ + sizeof(int4))
#define COMPUTESIZE(size,lenofoperand) ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )
/* Util function */
Datum ltree_in(PG_FUNCTION_ARGS);
-bool ltree_execute(ITEM * curitem, void *checkval,
- bool calcnot, bool (*chkcond) (void *checkval, ITEM * val));
+bool ltree_execute(ITEM *curitem, void *checkval,
+ bool calcnot, bool (*chkcond) (void *checkval, ITEM *val));
-int ltree_compare(const ltree * a, const ltree * b);
-bool inner_isparent(const ltree * c, const ltree * p);
-bool compare_subnode(ltree_level * t, char *q, int len,
- int (*cmpptr) (const char *, const char *, size_t), bool anyend);
-ltree *lca_inner(ltree ** a, int len);
-int ltree_strncasecmp(const char *a, const char *b, size_t s);
+int ltree_compare(const ltree *a, const ltree *b);
+bool inner_isparent(const ltree *c, const ltree *p);
+bool compare_subnode(ltree_level *t, char *q, int len,
+ int (*cmpptr) (const char *, const char *, size_t), bool anyend);
+ltree *lca_inner(ltree **a, int len);
+int ltree_strncasecmp(const char *a, const char *b, size_t s);
#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
#define PG_GETARG_LTREE_COPY(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
int32 vl_len_; /* varlena header (do not touch directly!) */
uint32 flag;
char data[1];
-} ltree_gist;
+} ltree_gist;
#define LTG_ONENODE 0x01
#define LTG_ALLTRUE 0x02
}
static void
-hashing(BITVECP sign, ltree * t)
+hashing(BITVECP sign, ltree *t)
{
int tlen = t->numlevel;
ltree_level *cur = LTREE_FIRST(t);
{
int index;
ltree *r;
-} RIX;
+} RIX;
static int
treekey_cmp(const void *a, const void *b)
}
static bool
-gist_isparent(ltree_gist * key, ltree * query)
+gist_isparent(ltree_gist *key, ltree *query)
{
int4 numlevel = query->numlevel;
int i;
}
static ltree *
-copy_ltree(ltree * src)
+copy_ltree(ltree *src)
{
ltree *dst = (ltree *) palloc(VARSIZE(src));
}
static bool
-gist_ischild(ltree_gist * key, ltree * query)
+gist_ischild(ltree_gist *key, ltree *query)
{
ltree *left = copy_ltree(LTG_GETLNODE(key));
ltree *right = copy_ltree(LTG_GETRNODE(key));
}
static bool
-gist_qe(ltree_gist * key, lquery * query)
+gist_qe(ltree_gist *key, lquery *query)
{
lquery_level *curq = LQUERY_FIRST(query);
BITVECP sign = LTG_SIGN(key);
}
static int
-gist_tqcmp(ltree * t, lquery * q)
+gist_tqcmp(ltree *t, lquery *q)
{
ltree_level *al = LTREE_FIRST(t);
lquery_level *ql = LQUERY_FIRST(q);
}
static bool
-gist_between(ltree_gist * key, lquery * query)
+gist_between(ltree_gist *key, lquery *query)
{
if (query->firstgood == 0)
return true;
}
static bool
-checkcondition_bit(void *checkval, ITEM * val)
+checkcondition_bit(void *checkval, ITEM *val)
{
return (FLG_CANLOOKSIGN(val->flag)) ? GETBIT(checkval, HASHVAL(val->val)) : true;
}
static bool
-gist_qtxt(ltree_gist * key, ltxtquery * query)
+gist_qtxt(ltree_gist *key, ltxtquery *query)
{
if (LTG_ISALLTRUE(key))
return true;
}
static bool
-arrq_cons(ltree_gist * key, ArrayType *_query)
+arrq_cons(ltree_gist *key, ArrayType *_query)
{
lquery *query = (lquery *) ARR_DATA_PTR(_query);
int num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key);
typedef struct
{
char *start;
- int len; /* length in bytes */
+ int len; /* length in bytes */
int flag;
- int wlen; /* length in characters */
-} nodeitem;
+ int wlen; /* length in characters */
+} nodeitem;
#define LTPRS_WAITNAME 0
#define LTPRS_WAITDELIM 1
int state = LTPRS_WAITNAME;
ltree *result;
ltree_level *curlevel;
- int charlen;
- int pos=0;
+ int charlen;
+ int pos = 0;
ptr = buf;
while (*ptr)
{
charlen = pg_mblen(ptr);
- if ( charlen == 1 && t_iseq(ptr, '.') )
+ if (charlen == 1 && t_iseq(ptr, '.'))
num++;
- ptr+=charlen;
+ ptr += charlen;
}
list = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (num + 1));
}
else if (state == LTPRS_WAITDELIM)
{
- if ( charlen == 1 && t_iseq(ptr, '.') )
+ if (charlen == 1 && t_iseq(ptr, '.'))
{
lptr->len = ptr - lptr->start;
if (lptr->wlen > 255)
errmsg("name of level is too long"),
errdetail("Name length is %d, must "
"be < 256, in position %d.",
- lptr->wlen, pos)));
+ lptr->wlen, pos)));
totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE);
lptr++;
/* internal error */
elog(ERROR, "internal error in parser");
- ptr+=charlen;
+ ptr += charlen;
lptr->wlen++;
pos++;
}
bool hasnot = false;
bool wasbad = false;
int charlen;
- int pos=0;
+ int pos = 0;
ptr = buf;
while (*ptr)
{
charlen = pg_mblen(ptr);
- if ( charlen == 1 )
+ if (charlen == 1)
{
if (t_iseq(ptr, '.'))
num++;
numOR++;
}
- ptr+=charlen;
+ ptr += charlen;
}
num++;
state = LQPRS_WAITDELIM;
curqlevel->numvar = 1;
}
- else if (charlen==1 && t_iseq(ptr, '!'))
+ else if (charlen == 1 && t_iseq(ptr, '!'))
{
GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
lptr->start = ptr + 1;
curqlevel->flag |= LQL_NOT;
hasnot = true;
}
- else if (charlen==1 && t_iseq(ptr, '*'))
+ else if (charlen == 1 && t_iseq(ptr, '*'))
state = LQPRS_WAITOPEN;
else
UNCHAR;
}
else if (state == LQPRS_WAITDELIM)
{
- if (charlen==1 && t_iseq(ptr, '@'))
+ if (charlen == 1 && t_iseq(ptr, '@'))
{
if (lptr->start == ptr)
UNCHAR;
lptr->flag |= LVAR_INCASE;
curqlevel->flag |= LVAR_INCASE;
}
- else if (charlen==1 && t_iseq(ptr, '*'))
+ else if (charlen == 1 && t_iseq(ptr, '*'))
{
if (lptr->start == ptr)
UNCHAR;
lptr->flag |= LVAR_ANYEND;
curqlevel->flag |= LVAR_ANYEND;
}
- else if (charlen==1 && t_iseq(ptr, '%'))
+ else if (charlen == 1 && t_iseq(ptr, '%'))
{
if (lptr->start == ptr)
UNCHAR;
lptr->flag |= LVAR_SUBLEXEME;
curqlevel->flag |= LVAR_SUBLEXEME;
}
- else if (charlen==1 && t_iseq(ptr, '|'))
+ else if (charlen == 1 && t_iseq(ptr, '|'))
{
lptr->len = ptr - lptr->start -
((lptr->flag & LVAR_SUBLEXEME) ? 1 : 0) -
errmsg("name of level is too long"),
errdetail("Name length is %d, must "
"be < 256, in position %d.",
- lptr->wlen, pos)));
+ lptr->wlen, pos)));
state = LQPRS_WAITVAR;
}
- else if (charlen==1 && t_iseq(ptr, '.'))
+ else if (charlen == 1 && t_iseq(ptr, '.'))
{
lptr->len = ptr - lptr->start -
((lptr->flag & LVAR_SUBLEXEME) ? 1 : 0) -
errmsg("name of level is too long"),
errdetail("Name length is %d, must "
"be < 256, in position %d.",
- lptr->wlen, pos)));
+ lptr->wlen, pos)));
state = LQPRS_WAITLEVEL;
curqlevel = NEXTLEV(curqlevel);
}
else if (state == LQPRS_WAITOPEN)
{
- if (charlen==1 && t_iseq(ptr, '{'))
+ if (charlen == 1 && t_iseq(ptr, '{'))
state = LQPRS_WAITFNUM;
- else if (charlen==1 && t_iseq(ptr, '.'))
+ else if (charlen == 1 && t_iseq(ptr, '.'))
{
curqlevel->low = 0;
curqlevel->high = 0xffff;
}
else if (state == LQPRS_WAITFNUM)
{
- if (charlen==1 && t_iseq(ptr, ','))
+ if (charlen == 1 && t_iseq(ptr, ','))
state = LQPRS_WAITSNUM;
else if (t_isdigit(ptr))
{
curqlevel->high = atoi(ptr);
state = LQPRS_WAITCLOSE;
}
- else if (charlen==1 && t_iseq(ptr, '}'))
+ else if (charlen == 1 && t_iseq(ptr, '}'))
{
curqlevel->high = 0xffff;
state = LQPRS_WAITEND;
}
else if (state == LQPRS_WAITCLOSE)
{
- if (charlen==1 && t_iseq(ptr, '}'))
+ if (charlen == 1 && t_iseq(ptr, '}'))
state = LQPRS_WAITEND;
else if (!t_isdigit(ptr))
UNCHAR;
}
else if (state == LQPRS_WAITND)
{
- if (charlen==1 && t_iseq(ptr, '}'))
+ if (charlen == 1 && t_iseq(ptr, '}'))
{
curqlevel->high = curqlevel->low;
state = LQPRS_WAITEND;
}
- else if (charlen==1 && t_iseq(ptr, ','))
+ else if (charlen == 1 && t_iseq(ptr, ','))
state = LQPRS_WAITSNUM;
else if (!t_isdigit(ptr))
UNCHAR;
}
else if (state == LQPRS_WAITEND)
{
- if (charlen==1 && t_iseq(ptr, '.'))
+ if (charlen == 1 && t_iseq(ptr, '.'))
{
state = LQPRS_WAITLEVEL;
curqlevel = NEXTLEV(curqlevel);
/* internal error */
elog(ERROR, "internal error in parser");
- ptr+=charlen;
- if ( state == LQPRS_WAITDELIM )
+ ptr += charlen;
+ if (state == LQPRS_WAITDELIM)
lptr->wlen++;
pos++;
}
Datum ltreeparentsel(PG_FUNCTION_ARGS);
int
-ltree_compare(const ltree * a, const ltree * b)
+ltree_compare(const ltree *a, const ltree *b)
{
ltree_level *al = LTREE_FIRST(a);
ltree_level *bl = LTREE_FIRST(b);
}
bool
-inner_isparent(const ltree * c, const ltree * p)
+inner_isparent(const ltree *c, const ltree *p)
{
ltree_level *cl = LTREE_FIRST(c);
ltree_level *pl = LTREE_FIRST(p);
static ltree *
-inner_subltree(ltree * t, int4 startpos, int4 endpos)
+inner_subltree(ltree *t, int4 startpos, int4 endpos)
{
char *start = NULL,
*end = NULL;
}
static ltree *
-ltree_concat(ltree * a, ltree * b)
+ltree_concat(ltree *a, ltree *b)
{
ltree *r;
}
ltree *
-lca_inner(ltree ** a, int len)
+lca_inner(ltree **a, int len)
{
int tmp,
num = ((*a)->numlevel) ? (*a)->numlevel - 1 : 0;
else if (hist_size < 100)
{
/*
- * For histogram sizes from 10 to 100, we combine the
- * histogram and default selectivities, putting increasingly
- * more trust in the histogram for larger sizes.
+ * For histogram sizes from 10 to 100, we combine the histogram
+ * and default selectivities, putting increasingly more trust in
+ * the histogram for larger sizes.
*/
- double hist_weight = hist_size / 100.0;
+ double hist_weight = hist_size / 100.0;
selec = selec * hist_weight +
DEFAULT_PARENT_SEL * (1.0 - hist_weight);
int4 sumlen;
char *op;
char *curop;
-} QPRS_STATE;
+} QPRS_STATE;
/*
* get token from query string
*/
static int4
-gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint16 *flag)
+gettoken_query(QPRS_STATE *state, int4 *val, int4 *lenval, char **strval, uint16 *flag)
{
- int charlen;
+ int charlen;
- for(;;)
+ for (;;)
{
charlen = pg_mblen(state->buf);
switch (state->state)
{
case WAITOPERAND:
- if (charlen==1 && t_iseq(state->buf, '!'))
+ if (charlen == 1 && t_iseq(state->buf, '!'))
{
(state->buf)++;
*val = (int4) '!';
return OPR;
}
- else if (charlen==1 && t_iseq(state->buf, '('))
+ else if (charlen == 1 && t_iseq(state->buf, '('))
{
state->count++;
(state->buf)++;
errmsg("modificators syntax error")));
*lenval += charlen;
}
- else if (charlen==1 && t_iseq(state->buf, '%'))
+ else if (charlen == 1 && t_iseq(state->buf, '%'))
*flag |= LVAR_SUBLEXEME;
- else if (charlen==1 && t_iseq(state->buf, '@'))
+ else if (charlen == 1 && t_iseq(state->buf, '@'))
*flag |= LVAR_INCASE;
- else if (charlen==