* Copyright (c) 2008-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.4 2009/01/05 13:35:38 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.5 2009/06/11 14:48:50 momjian Exp $
*
*-------------------------------------------------------------------------
*/
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 */
/*
- * $PostgreSQL: pgsql/contrib/btree_gin/btree_gin.c,v 1.1 2009/03/25 23:20:01 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/btree_gin/btree_gin.c,v 1.2 2009/06/11 14:48:50 momjian Exp $
*/
#include "postgres.h"
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)