1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

pgindent run for 9.0

This commit is contained in:
Bruce Momjian
2010-02-26 02:01:40 +00:00
parent 16040575a0
commit 65e806cba1
403 changed files with 6786 additions and 6530 deletions

View File

@ -6,7 +6,7 @@
* Copyright (c) 2008-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.13 2010/02/16 22:19:59 adunstan Exp $
* $PostgreSQL: pgsql/contrib/auto_explain/auto_explain.c,v 1.14 2010/02/26 02:00:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -27,11 +27,11 @@ static int auto_explain_log_format = EXPLAIN_FORMAT_TEXT;
static bool auto_explain_log_nested_statements = false;
static const struct config_enum_entry format_options[] = {
{"text", EXPLAIN_FORMAT_TEXT, false},
{"xml", EXPLAIN_FORMAT_XML, false},
{"json", EXPLAIN_FORMAT_JSON, false},
{"yaml", EXPLAIN_FORMAT_YAML, false},
{NULL, 0, false}
{"text", EXPLAIN_FORMAT_TEXT, false},
{"xml", EXPLAIN_FORMAT_XML, false},
{"json", EXPLAIN_FORMAT_JSON, false},
{"yaml", EXPLAIN_FORMAT_YAML, false},
{NULL, 0, false}
};
/* Current nesting depth of ExecutorRun calls */
@ -231,7 +231,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
msec = queryDesc->totaltime->total * 1000.0;
if (msec >= auto_explain_log_min_duration)
{
ExplainState es;
ExplainState es;
ExplainInitState(&es);
es.analyze = (queryDesc->instrument_options && auto_explain_log_analyze);
@ -257,7 +257,7 @@ explain_ExecutorEnd(QueryDesc *queryDesc)
ereport(LOG,
(errmsg("duration: %.3f ms plan:\n%s",
msec, es.str->data),
errhidestmt(true)));
errhidestmt(true)));
pfree(es.str->data);
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.10 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_cash.c,v 1.11 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,8 +57,8 @@ gbt_cashlt(const void *a, const void *b)
static int
gbt_cashkey_cmp(const void *a, const void *b)
{
cashKEY *ia = (cashKEY*)(((Nsrt *) a)->t);
cashKEY *ib = (cashKEY*)(((Nsrt *) b)->t);
cashKEY *ia = (cashKEY *) (((Nsrt *) a)->t);
cashKEY *ib = (cashKEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.8 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_date.c,v 1.9 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -73,9 +73,9 @@ gbt_datelt(const void *a, const void *b)
static int
gbt_datekey_cmp(const void *a, const void *b)
{
dateKEY *ia = (dateKEY*)(((Nsrt *) a)->t);
dateKEY *ib = (dateKEY*)(((Nsrt *) b)->t);
int res;
dateKEY *ia = (dateKEY *) (((Nsrt *) a)->t);
dateKEY *ib = (dateKEY *) (((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(date_cmp, DateADTGetDatum(ia->lower), DateADTGetDatum(ib->lower)));
if (res == 0)

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float4.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -56,8 +56,8 @@ gbt_float4lt(const void *a, const void *b)
static int
gbt_float4key_cmp(const void *a, const void *b)
{
float4KEY *ia = (float4KEY*)(((Nsrt *) a)->t);
float4KEY *ib = (float4KEY*)(((Nsrt *) b)->t);
float4KEY *ia = (float4KEY *) (((Nsrt *) a)->t);
float4KEY *ib = (float4KEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_float8.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,8 +57,8 @@ gbt_float8lt(const void *a, const void *b)
static int
gbt_float8key_cmp(const void *a, const void *b)
{
float8KEY *ia = (float8KEY*)(((Nsrt *) a)->t);
float8KEY *ib = (float8KEY*)(((Nsrt *) b)->t);
float8KEY *ia = (float8KEY *) (((Nsrt *) a)->t);
float8KEY *ib = (float8KEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.11 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_inet.c,v 1.12 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -60,8 +60,8 @@ gbt_inetlt(const void *a, const void *b)
static int
gbt_inetkey_cmp(const void *a, const void *b)
{
inetKEY *ia = (inetKEY*)(((Nsrt *) a)->t);
inetKEY *ib = (inetKEY*)(((Nsrt *) b)->t);
inetKEY *ia = (inetKEY *) (((Nsrt *) a)->t);
inetKEY *ib = (inetKEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int2.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -56,8 +56,8 @@ gbt_int2lt(const void *a, const void *b)
static int
gbt_int2key_cmp(const void *a, const void *b)
{
int16KEY *ia = (int16KEY*)(((Nsrt *) a)->t);
int16KEY *ib = (int16KEY*)(((Nsrt *) b)->t);
int16KEY *ia = (int16KEY *) (((Nsrt *) a)->t);
int16KEY *ib = (int16KEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int4.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,8 +57,8 @@ gbt_int4lt(const void *a, const void *b)
static int
gbt_int4key_cmp(const void *a, const void *b)
{
int32KEY *ia = (int32KEY*)(((Nsrt *) a)->t);
int32KEY *ib = (int32KEY*)(((Nsrt *) b)->t);
int32KEY *ia = (int32KEY *) (((Nsrt *) a)->t);
int32KEY *ib = (int32KEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_int8.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,8 +57,8 @@ gbt_int8lt(const void *a, const void *b)
static int
gbt_int8key_cmp(const void *a, const void *b)
{
int64KEY *ia = (int64KEY*)(((Nsrt *) a)->t);
int64KEY *ib = (int64KEY*)(((Nsrt *) b)->t);
int64KEY *ia = (int64KEY *) (((Nsrt *) a)->t);
int64KEY *ib = (int64KEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.13 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_interval.c,v 1.14 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -65,9 +65,9 @@ gbt_intvlt(const void *a, const void *b)
static int
gbt_intvkey_cmp(const void *a, const void *b)
{
intvKEY *ia = (intvKEY*)(((Nsrt *) a)->t);
intvKEY *ib = (intvKEY*)(((Nsrt *) b)->t);
int res;
intvKEY *ia = (intvKEY *) (((Nsrt *) a)->t);
intvKEY *ib = (intvKEY *) (((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(interval_cmp, IntervalPGetDatum(&ia->lower), IntervalPGetDatum(&ib->lower)));
if (res == 0)

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_macaddr.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -63,9 +63,9 @@ gbt_macadlt(const void *a, const void *b)
static int
gbt_macadkey_cmp(const void *a, const void *b)
{
macKEY *ia = (macKEY*)(((Nsrt *) a)->t);
macKEY *ib = (macKEY*)(((Nsrt *) b)->t);
int res;
macKEY *ia = (macKEY *) (((Nsrt *) a)->t);
macKEY *ib = (macKEY *) (((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(macaddr_cmp, MacaddrPGetDatum(&ia->lower), MacaddrPGetDatum(&ib->lower)));
if (res == 0)

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.9 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_oid.c,v 1.10 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -57,8 +57,8 @@ gbt_oidlt(const void *a, const void *b)
static int
gbt_oidkey_cmp(const void *a, const void *b)
{
oidKEY *ia = (oidKEY*)(((Nsrt *) a)->t);
oidKEY *ib = (oidKEY*)(((Nsrt *) b)->t);
oidKEY *ia = (oidKEY *) (((Nsrt *) a)->t);
oidKEY *ib = (oidKEY *) (((Nsrt *) b)->t);
if (ia->lower == ib->lower)
{

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.17 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_time.c,v 1.18 2010/02/26 02:00:31 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -101,9 +101,9 @@ gbt_timelt(const void *a, const void *b)
static int
gbt_timekey_cmp(const void *a, const void *b)
{
timeKEY *ia = (timeKEY*)(((Nsrt *) a)->t);
timeKEY *ib = (timeKEY*)(((Nsrt *) b)->t);
int res;
timeKEY *ia = (timeKEY *) (((Nsrt *) a)->t);
timeKEY *ib = (timeKEY *) (((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower)));
if (res == 0)

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.18 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_ts.c,v 1.19 2010/02/26 02:00:32 momjian Exp $
*/
#include "btree_gist.h"
#include "btree_utils_num.h"
@ -99,9 +99,9 @@ gbt_tslt(const void *a, const void *b)
static int
gbt_tskey_cmp(const void *a, const void *b)
{
tsKEY *ia = (tsKEY*)(((Nsrt *) a)->t);
tsKEY *ib = (tsKEY*)(((Nsrt *) b)->t);
int res;
tsKEY *ia = (tsKEY *) (((Nsrt *) a)->t);
tsKEY *ib = (tsKEY *) (((Nsrt *) b)->t);
int res;
res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->lower), TimestampGetDatumFast(ib->lower)));
if (res == 0)

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.22 2009/12/02 13:13:24 teodor Exp $
* $PostgreSQL: pgsql/contrib/btree_gist/btree_utils_var.c,v 1.23 2010/02/26 02:00:32 momjian Exp $
*/
#include "btree_gist.h"
@ -444,7 +444,7 @@ gbt_vsrt_cmp(const void *a, const void *b, void *arg)
GBT_VARKEY_R ar = gbt_var_key_readable(((const Vsrt *) a)->t);
GBT_VARKEY_R br = gbt_var_key_readable(((const Vsrt *) b)->t);
const gbtree_vinfo *tinfo = (const gbtree_vinfo *) arg;
int res;
int res;
res = (*tinfo->f_cmp) (ar.lower, br.lower);
if (res == 0)

View File

@ -8,7 +8,7 @@
* Darko Prenosil <Darko.Prenosil@finteh.hr>
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
*
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.90 2010/02/24 05:20:49 itagaki Exp $
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.91 2010/02/26 02:00:32 momjian Exp $
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
* ALL RIGHTS RESERVED;
*
@ -101,7 +101,7 @@ static void dblink_security_check(PGconn *conn, remoteConn *rconn);
static void dblink_res_error(const char *conname, PGresult *res, const char *dblink_context_msg, bool fail);
static char *get_connect_string(const char *servername);
static char *escape_param_str(const char *from);
static int get_nondropped_natts(Oid relid);
static int get_nondropped_natts(Oid relid);
/* Global */
static remoteConn *pconn = NULL;
@ -506,15 +506,15 @@ PG_FUNCTION_INFO_V1(dblink_fetch);
Datum
dblink_fetch(PG_FUNCTION_ARGS)
{
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
PGresult *res = NULL;
char *conname = NULL;
remoteConn *rconn = NULL;
PGconn *conn = NULL;
StringInfoData buf;
char *curname = NULL;
int howmany = 0;
bool fail = true; /* default to backward compatible */
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
PGresult *res = NULL;
char *conname = NULL;
remoteConn *rconn = NULL;
PGconn *conn = NULL;
StringInfoData buf;
char *curname = NULL;
int howmany = 0;
bool fail = true; /* default to backward compatible */
DBLINK_INIT;
@ -572,8 +572,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
/*
* 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.
* PGresult will be long-lived even though we are still in a short-lived
* memory context.
*/
res = PQexec(conn, buf.data);
if (!res ||
@ -645,16 +645,16 @@ dblink_get_result(PG_FUNCTION_ARGS)
static Datum
dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
{
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
char *msg;
PGresult *res = NULL;
PGconn *conn = NULL;
char *connstr = NULL;
char *sql = NULL;
char *conname = NULL;
remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible */
bool freeconn = false;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
char *msg;
PGresult *res = NULL;
PGconn *conn = NULL;
char *connstr = NULL;
char *sql = NULL;
char *conname = NULL;
remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible */
bool freeconn = false;
/* check to see if caller supports us returning a tuplestore */
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
@ -764,7 +764,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
static void
materializeResult(FunctionCallInfo fcinfo, PGresult *res)
{
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
Assert(rsinfo->returnMode == SFRM_Materialize);
@ -780,8 +780,8 @@ materializeResult(FunctionCallInfo fcinfo, PGresult *res)
is_sql_cmd = true;
/*
* need a tuple descriptor representing one TEXT column to
* return the command status string as our result tuple
* need a tuple descriptor representing one TEXT column to return
* the command status string as our result tuple
*/
tupdesc = CreateTemplateTupleDesc(1, false);
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
@ -831,16 +831,16 @@ materializeResult(FunctionCallInfo fcinfo, PGresult *res)
if (ntuples > 0)
{
AttInMetadata *attinmeta;
Tuplestorestate *tupstore;
MemoryContext oldcontext;
int row;
char **values;
AttInMetadata *attinmeta;
Tuplestorestate *tupstore;
MemoryContext oldcontext;
int row;
char **values;
attinmeta = TupleDescGetAttInMetadata(tupdesc);
oldcontext = MemoryContextSwitchTo(
rsinfo->econtext->ecxt_per_query_memory);
rsinfo->econtext->ecxt_per_query_memory);
tupstore = tuplestore_begin_heap(true, false, work_mem);
rsinfo->setResult = tupstore;
rsinfo->setDesc = tupdesc;
@ -1281,13 +1281,13 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS)
"attributes too large")));
/*
* ensure we don't ask for more pk attributes than we have
* non-dropped columns
* ensure we don't ask for more pk attributes than we have non-dropped
* columns
*/
nondropped_natts = get_nondropped_natts(relid);
if (pknumatts > nondropped_natts)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("number of primary key fields exceeds number of specified relation attributes")));
errmsg("number of primary key fields exceeds number of specified relation attributes")));
/*
* Source array is made up of key values that will be used to locate the
@ -1388,13 +1388,13 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS)
"attributes too large")));
/*
* ensure we don't ask for more pk attributes than we have
* non-dropped columns
* ensure we don't ask for more pk attributes than we have non-dropped
* columns
*/
nondropped_natts = get_nondropped_natts(relid);
if (pknumatts > nondropped_natts)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("number of primary key fields exceeds number of specified relation attributes")));
errmsg("number of primary key fields exceeds number of specified relation attributes")));
/*
* Target array is made up of key values that will be used to build the
@ -1487,13 +1487,13 @@ dblink_build_sql_update(PG_FUNCTION_ARGS)
"attributes too large")));
/*
* ensure we don't ask for more pk attributes than we have
* non-dropped columns
* ensure we don't ask for more pk attributes than we have non-dropped
* columns
*/
nondropped_natts = get_nondropped_natts(relid);
if (pknumatts > nondropped_natts)
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("number of primary key fields exceeds number of specified relation attributes")));
errmsg("number of primary key fields exceeds number of specified relation attributes")));
/*
* Source array is made up of key values that will be used to locate the
@ -1551,7 +1551,7 @@ dblink_current_query(PG_FUNCTION_ARGS)
}
/*
* Retrieve async notifications for a connection.
* Retrieve async notifications for a connection.
*
* Returns an setof record of notifications, or an empty set if none recieved.
* Can optionally take a named connection as parameter, but uses the unnamed connection per default.
@ -1563,14 +1563,14 @@ PG_FUNCTION_INFO_V1(dblink_get_notify);
Datum
dblink_get_notify(PG_FUNCTION_ARGS)
{
PGconn *conn = NULL;
remoteConn *rconn = NULL;
PGnotify *notify;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
TupleDesc tupdesc;
Tuplestorestate *tupstore;
MemoryContext per_query_ctx;
MemoryContext oldcontext;
PGconn *conn = NULL;
remoteConn *rconn = NULL;
PGnotify *notify;
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
TupleDesc tupdesc;
Tuplestorestate *tupstore;
MemoryContext per_query_ctx;
MemoryContext oldcontext;
DBLINK_INIT;
if (PG_NARGS() == 1)
@ -2484,4 +2484,3 @@ get_nondropped_natts(Oid relid)
relation_close(rel, AccessShareLock);
return nondropped_natts;
}

View File

@ -6,7 +6,7 @@
* Copyright (c) 2007-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/dict_xsyn/dict_xsyn.c,v 1.8 2010/01/02 16:57:32 momjian Exp $
* $PostgreSQL: pgsql/contrib/dict_xsyn/dict_xsyn.c,v 1.9 2010/02/26 02:00:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -147,7 +147,7 @@ dxsyn_init(PG_FUNCTION_ARGS)
List *dictoptions = (List *) PG_GETARG_POINTER(0);
DictSyn *d;
ListCell *l;
char *filename = NULL;
char *filename = NULL;
d = (DictSyn *) palloc0(sizeof(DictSyn));
d->len = 0;

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.9 2009/09/30 19:50:22 tgl Exp $
* $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.10 2010/02/26 02:00:32 momjian Exp $
*/
#ifndef __HSTORE_H__
#define __HSTORE_H__
@ -12,7 +12,7 @@
* HEntry: there is one of these for each key _and_ value in an hstore
*
* the position offset points to the _end_ so that we can get the length
* by subtraction from the previous entry. the ISFIRST flag lets us tell
* by subtraction from the previous entry. the ISFIRST flag lets us tell
* whether there is a previous entry.
*/
typedef struct
@ -51,7 +51,7 @@ typedef struct
/*
* it's not possible to get more than 2^28 items into an hstore,
* so we reserve the top few bits of the size field. See hstore_compat.c
* for one reason why. Some bits are left for future use here.
* for one reason why. Some bits are left for future use here.
*/
#define HS_FLAG_NEWVERSION 0x80000000
@ -88,7 +88,7 @@ typedef struct
* evaluation here.
*/
#define HS_COPYITEM(dent_,dbuf_,dptr_,sptr_,klen_,vlen_,vnull_) \
do { \
do { \
memcpy((dptr_), (sptr_), (klen_)+(vlen_)); \
(dptr_) += (klen_)+(vlen_); \
(dent_)++->entry = ((dptr_) - (dbuf_) - (vlen_)) & HENTRY_POSMASK; \
@ -119,7 +119,7 @@ typedef struct
/* finalize a newly-constructed hstore */
#define HS_FINALIZE(hsp_,count_,buf_,ptr_) \
do { \
int buflen = (ptr_) - (buf_); \
int buflen = (ptr_) - (buf_); \
if ((count_)) \
ARRPTR(hsp_)[0].entry |= HENTRY_ISFIRST; \
if ((count_) != HS_COUNT((hsp_))) \
@ -133,7 +133,7 @@ typedef struct
/* ensure the varlena size of an existing hstore is correct */
#define HS_FIXSIZE(hsp_,count_) \
do { \
int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
SET_VARSIZE((hsp_), CALCDATASIZE((count_),bl)); \
} while (0)
@ -172,7 +172,7 @@ extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs);
#define HStoreExistsStrategyNumber 9
#define HStoreExistsAnyStrategyNumber 10
#define HStoreExistsAllStrategyNumber 11
#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */
#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */
/*
* defining HSTORE_POLLUTE_NAMESPACE=0 will prevent use of old function names;

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.1 2009/09/30 19:50:22 tgl Exp $
* $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.2 2010/02/26 02:00:32 momjian Exp $
*
* Notes on old/new hstore format disambiguation.
*
@ -106,24 +106,24 @@ typedef struct
pos:31;
} HOldEntry;
static int hstoreValidNewFormat(HStore *hs);
static int hstoreValidOldFormat(HStore *hs);
static int hstoreValidNewFormat(HStore *hs);
static int hstoreValidOldFormat(HStore *hs);
/*
* Validity test for a new-format hstore.
* 0 = not valid
* 1 = valid but with "slop" in the length
* 2 = exactly valid
* 0 = not valid
* 1 = valid but with "slop" in the length
* 2 = exactly valid
*/
static int
hstoreValidNewFormat(HStore *hs)
{
int count = HS_COUNT(hs);
HEntry *entries = ARRPTR(hs);
int buflen = (count) ? HSE_ENDPOS(entries[2*(count)-1]) : 0;
int vsize = CALCDATASIZE(count,buflen);
int i;
int count = HS_COUNT(hs);
HEntry *entries = ARRPTR(hs);
int buflen = (count) ? HSE_ENDPOS(entries[2 * (count) - 1]) : 0;
int vsize = CALCDATASIZE(count, buflen);
int i;
if (hs->size_ & HS_FLAG_NEWVERSION)
return 2;
@ -139,10 +139,10 @@ hstoreValidNewFormat(HStore *hs)
/* entry position must be nondecreasing */
for (i = 1; i < 2*count; ++i)
for (i = 1; i < 2 * count; ++i)
{
if (HSE_ISFIRST(entries[i])
|| (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i-1])))
|| (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i - 1])))
return 0;
}
@ -150,9 +150,9 @@ hstoreValidNewFormat(HStore *hs)
for (i = 1; i < count; ++i)
{
if (HS_KEYLEN(entries,i) < HS_KEYLEN(entries,i-1))
if (HS_KEYLEN(entries, i) < HS_KEYLEN(entries, i - 1))
return 0;
if (HSE_ISNULL(entries[2*i]))
if (HSE_ISNULL(entries[2 * i]))
return 0;
}
@ -164,18 +164,18 @@ hstoreValidNewFormat(HStore *hs)
/*
* Validity test for an old-format hstore.
* 0 = not valid
* 1 = valid but with "slop" in the length
* 2 = exactly valid
* 0 = not valid
* 1 = valid but with "slop" in the length
* 2 = exactly valid
*/
static int
hstoreValidOldFormat(HStore *hs)
{
int count = hs->size_;
HOldEntry *entries = (HOldEntry *) ARRPTR(hs);
int vsize;
int lastpos = 0;
int i;
int count = hs->size_;
HOldEntry *entries = (HOldEntry *) ARRPTR(hs);
int vsize;
int lastpos = 0;
int i;
if (hs->size_ & HS_FLAG_NEWVERSION)
return 0;
@ -188,7 +188,7 @@ hstoreValidOldFormat(HStore *hs)
if (count > 0xFFFFFFF)
return 0;
if (CALCDATASIZE(count,0) > VARSIZE(hs))
if (CALCDATASIZE(count, 0) > VARSIZE(hs))
return 0;
if (entries[0].pos != 0)
@ -198,14 +198,14 @@ hstoreValidOldFormat(HStore *hs)
for (i = 1; i < count; ++i)
{
if (entries[i].keylen < entries[i-1].keylen)
if (entries[i].keylen < entries[i - 1].keylen)
return 0;
}
/*
* entry position must be strictly increasing, except for the
* first entry (which can be ""=>"" and thus zero-length); and
* all entries must be properly contiguous
* entry position must be strictly increasing, except for the first entry
* (which can be ""=>"" and thus zero-length); and all entries must be
* properly contiguous
*/
for (i = 0; i < count; ++i)
@ -216,7 +216,7 @@ hstoreValidOldFormat(HStore *hs)
+ ((entries[i].valisnull) ? 0 : entries[i].vallen));
}
vsize = CALCDATASIZE(count,lastpos);
vsize = CALCDATASIZE(count, lastpos);
if (vsize > VARSIZE(hs))
return 0;
@ -255,108 +255,100 @@ hstoreUpgrade(Datum orig)
if (valid_new)
{
/*
* force the "new version" flag and the correct varlena
* length, but only if we have a writable copy already
* (which we almost always will, since short new-format
* values won't come through here)
* force the "new version" flag and the correct varlena length,
* but only if we have a writable copy already (which we almost
* always will, since short new-format values won't come through
* here)
*/
if (writable)
{
HS_SETCOUNT(hs,HS_COUNT(hs));
HS_FIXSIZE(hs,HS_COUNT(hs));
HS_SETCOUNT(hs, HS_COUNT(hs));
HS_FIXSIZE(hs, HS_COUNT(hs));
}
return hs;
}
else
{
elog(ERROR,"invalid hstore value found");
elog(ERROR, "invalid hstore value found");
}
}
/*
* this is the tricky edge case. It is only possible in some
* quite extreme cases (the hstore must have had a lot
* of wasted padding space at the end).
* But the only way a "new" hstore value could get here is if
* we're upgrading in place from a pre-release version of
* hstore-new (NOT contrib/hstore), so we work off the following
* assumptions:
* 1. If you're moving from old contrib/hstore to hstore-new,
* you're required to fix up any potential conflicts first,
* e.g. by running ALTER TABLE ... USING col::text::hstore;
* on all hstore columns before upgrading.
* 2. If you're moving from old contrib/hstore to new
* contrib/hstore, then "new" values are impossible here
* 3. If you're moving from pre-release hstore-new to hstore-new,
* then "old" values are impossible here
* 4. If you're moving from pre-release hstore-new to new
* contrib/hstore, you're not doing so as an in-place upgrade,
* so there is no issue
* So the upshot of all this is that we can treat all the edge
* cases as "new" if we're being built as hstore-new, and "old"
* if we're being built as contrib/hstore.
* this is the tricky edge case. It is only possible in some quite extreme
* cases (the hstore must have had a lot of wasted padding space at the
* end). But the only way a "new" hstore value could get here is if we're
* upgrading in place from a pre-release version of hstore-new (NOT
* contrib/hstore), so we work off the following assumptions: 1. If you're
* moving from old contrib/hstore to hstore-new, you're required to fix up
* any potential conflicts first, e.g. by running ALTER TABLE ... USING
* col::text::hstore; on all hstore columns before upgrading. 2. If you're
* moving from old contrib/hstore to new contrib/hstore, then "new" values
* are impossible here 3. If you're moving from pre-release hstore-new to
* hstore-new, then "old" values are impossible here 4. If you're moving
* from pre-release hstore-new to new contrib/hstore, you're not doing so
* as an in-place upgrade, so there is no issue So the upshot of all this
* is that we can treat all the edge cases as "new" if we're being built
* as hstore-new, and "old" if we're being built as contrib/hstore.
*
* XXX the WARNING can probably be downgraded to DEBUG1 once this
* has been beta-tested. But for now, it would be very useful to
* know if anyone can actually reach this case in a non-contrived
* setting.
* XXX the WARNING can probably be downgraded to DEBUG1 once this has been
* beta-tested. But for now, it would be very useful to know if anyone can
* actually reach this case in a non-contrived setting.
*/
if (valid_new)
{
#if HSTORE_IS_HSTORE_NEW
elog(WARNING,"ambiguous hstore value resolved as hstore-new");
elog(WARNING, "ambiguous hstore value resolved as hstore-new");
/*
* force the "new version" flag and the correct varlena
* length, but only if we have a writable copy already
* (which we almost always will, since short new-format
* values won't come through here)
* force the "new version" flag and the correct varlena length, but
* only if we have a writable copy already (which we almost always
* will, since short new-format values won't come through here)
*/
if (writable)
{
HS_SETCOUNT(hs,HS_COUNT(hs));
HS_FIXSIZE(hs,HS_COUNT(hs));
HS_SETCOUNT(hs, HS_COUNT(hs));
HS_FIXSIZE(hs, HS_COUNT(hs));
}
return hs;
#else
elog(WARNING,"ambiguous hstore value resolved as hstore-old");
elog(WARNING, "ambiguous hstore value resolved as hstore-old");
#endif
}
/*
* must have an old-style value. Overwrite it in place as a new-style
* one, making sure we have a writable copy first.
* must have an old-style value. Overwrite it in place as a new-style one,
* making sure we have a writable copy first.
*/
if (!writable)
hs = (HStore *) PG_DETOAST_DATUM_COPY(orig);
{
int count = hs->size_;
HEntry *new_entries = ARRPTR(hs);
HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs);
int i;
int count = hs->size_;
HEntry *new_entries = ARRPTR(hs);
HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs);
int i;
for (i = 0; i < count; ++i)
{
uint32 pos = old_entries[i].pos;
uint32 keylen = old_entries[i].keylen;
uint32 vallen = old_entries[i].vallen;
bool isnull = old_entries[i].valisnull;
uint32 pos = old_entries[i].pos;
uint32 keylen = old_entries[i].keylen;
uint32 vallen = old_entries[i].vallen;
bool isnull = old_entries[i].valisnull;
if (isnull)
vallen = 0;
new_entries[2*i].entry = (pos + keylen) & HENTRY_POSMASK;
new_entries[2*i+1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK)
| ((isnull) ? HENTRY_ISNULL : 0));
new_entries[2 * i].entry = (pos + keylen) & HENTRY_POSMASK;
new_entries[2 * i + 1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK)
| ((isnull) ? HENTRY_ISNULL : 0));
}
if (count)
new_entries[0].entry |= HENTRY_ISFIRST;
HS_SETCOUNT(hs,count);
HS_FIXSIZE(hs,count);
HS_SETCOUNT(hs, count);
HS_FIXSIZE(hs, count);
}
return hs;
@ -368,9 +360,9 @@ Datum hstore_version_diag(PG_FUNCTION_ARGS);
Datum
hstore_version_diag(PG_FUNCTION_ARGS)
{
HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
int valid_new = hstoreValidNewFormat(hs);
int valid_old = hstoreValidOldFormat(hs);
HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
int valid_new = hstoreValidNewFormat(hs);
int valid_old = hstoreValidOldFormat(hs);
PG_RETURN_INT32(valid_old*10 + valid_new);
PG_RETURN_INT32(valid_old * 10 + valid_new);
}

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.7 2009/09/30 19:50:22 tgl Exp $
* $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.8 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@ -36,10 +36,10 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
HStore *hs = PG_GETARG_HS(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
HEntry *hsent = ARRPTR(hs);
char *ptr = STRPTR(hs);
int count = HS_COUNT(hs);
int i;
HEntry *hsent = ARRPTR(hs);
char *ptr = STRPTR(hs);
int count = HS_COUNT(hs);
int i;
*nentries = 2 * count;
if (count)
@ -49,21 +49,21 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
{
text *item;
item = makeitem(HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i));
item = makeitem(HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i));
*VARDATA(item) = KEYFLAG;
entries[2*i] = PointerGetDatum(item);
entries[2 * i] = PointerGetDatum(item);
if (HS_VALISNULL(hsent,i))
if (HS_VALISNULL(hsent, i))
{
item = makeitem(NULL, 0);
*VARDATA(item) = NULLFLAG;
}
else
{
item = makeitem(HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i));
item = makeitem(HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i));
*VARDATA(item) = VALFLAG;
}
entries[2*i+1] = PointerGetDatum(item);
entries[2 * i + 1] = PointerGetDatum(item);
}
PG_RETURN_POINTER(entries);
@ -103,14 +103,15 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
else if (strategy == HStoreExistsAnyStrategyNumber ||
strategy == HStoreExistsAllStrategyNumber)
{
ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
Datum *key_datums;
bool *key_nulls;
int key_count;
int i,j;
ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
Datum *key_datums;
bool *key_nulls;
int key_count;
int i,
j;
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
text *item;
text *item;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
@ -145,8 +146,10 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
{
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);
bool res = true;
@ -178,7 +181,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
}
else if (strategy == HStoreExistsAllStrategyNumber)
{
int i;
int i;
for (i = 0; res && i < nkeys; ++i)
if (!check[i])

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.11 2009/09/30 19:50:22 tgl Exp $
* $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.12 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@ -118,20 +118,20 @@ ghstore_compress(PG_FUNCTION_ARGS)
HStore *val = DatumGetHStoreP(entry->key);
HEntry *hsent = ARRPTR(val);
char *ptr = STRPTR(val);
int count = HS_COUNT(val);
int i;
int count = HS_COUNT(val);
int i;
SET_VARSIZE(res, CALCGTSIZE(0));
for (i = 0; i < count; ++i)
{
int h;
int h;
h = crc32_sz((char *) HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i));
h = crc32_sz((char *) HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i));
HASH(GETSIGN(res), h);
if (!HS_VALISNULL(hsent,i))
if (!HS_VALISNULL(hsent, i))
{
h = crc32_sz((char *) HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i));
h = crc32_sz((char *) HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i));
HASH(GETSIGN(res), h);
}
}
@ -511,6 +511,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
{
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;
@ -530,18 +531,18 @@ ghstore_consistent(PG_FUNCTION_ARGS)
HStore *query = PG_GETARG_HS(1);
HEntry *qe = ARRPTR(query);
char *qv = STRPTR(query);
int count = HS_COUNT(query);
int i;
int count = HS_COUNT(query);
int i;
for (i = 0; res && i < count; ++i)
{
int crc = crc32_sz((char *) HS_KEY(qe,qv,i), HS_KEYLEN(qe,i));
int crc = crc32_sz((char *) HS_KEY(qe, qv, i), HS_KEYLEN(qe, i));
if (GETBIT(sign, HASHVAL(crc)))
{
if (!HS_VALISNULL(qe,i))
if (!HS_VALISNULL(qe, i))
{
crc = crc32_sz((char *) HS_VAL(qe,qv,i), HS_VALLEN(qe,i));
crc = crc32_sz((char *) HS_VAL(qe, qv, i), HS_VALLEN(qe, i));
if (!GETBIT(sign, HASHVAL(crc)))
res = false;
}
@ -559,11 +560,11 @@ ghstore_consistent(PG_FUNCTION_ARGS)
}
else if (strategy == HStoreExistsAllStrategyNumber)
{
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
Datum *key_datums;
bool *key_nulls;
int key_count;
int i;
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
Datum *key_datums;
bool *key_nulls;
int key_count;
int i;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
@ -571,7 +572,8 @@ ghstore_consistent(PG_FUNCTION_ARGS)
for (i = 0; res && i < key_count; ++i)
{
int crc;
int crc;
if (key_nulls[i])
continue;
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
@ -581,11 +583,11 @@ ghstore_consistent(PG_FUNCTION_ARGS)
}
else if (strategy == HStoreExistsAnyStrategyNumber)
{
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
Datum *key_datums;
bool *key_nulls;
int key_count;
int i;
ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
Datum *key_datums;
bool *key_nulls;
int key_count;
int i;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
@ -595,7 +597,8 @@ ghstore_consistent(PG_FUNCTION_ARGS)
for (i = 0; !res && i < key_count; ++i)
{
int crc;
int crc;
if (key_nulls[i])
continue;
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.12 2009/09/30 19:50:22 tgl Exp $
* $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.13 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@ -18,7 +18,7 @@
PG_MODULE_MAGIC;
/* old names for C functions */
HSTORE_POLLUTE(hstore_from_text,tconvert);
HSTORE_POLLUTE(hstore_from_text, tconvert);
typedef struct
@ -370,12 +370,12 @@ hstoreCheckValLen(size_t len)
HStore *
hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
{
HStore *out;
HStore *out;
HEntry *entry;
char *ptr;
char *buf;
int4 len;
int4 i;
int4 len;
int4 i;
len = CALCDATASIZE(pcount, buflen);
out = palloc(len);
@ -389,9 +389,9 @@ hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
buf = ptr = STRPTR(out);
for (i = 0; i < pcount; i++)
HS_ADDITEM(entry,buf,ptr,pairs[i]);
HS_ADDITEM(entry, buf, ptr, pairs[i]);
HS_FINALIZE(out,pcount,buf,ptr);
HS_FINALIZE(out, pcount, buf, ptr);
return out;
}
@ -426,9 +426,9 @@ hstore_recv(PG_FUNCTION_ARGS)
int4 buflen;
HStore *out;
Pairs *pairs;
int4 i;
int4 pcount;
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
int4 i;
int4 pcount;
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
pcount = pq_getmsgint(buf, 4);
@ -442,8 +442,8 @@ hstore_recv(PG_FUNCTION_ARGS)
for (i = 0; i < pcount; ++i)
{
int rawlen = pq_getmsgint(buf, 4);
int len;
int rawlen = pq_getmsgint(buf, 4);
int len;
if (rawlen < 0)
ereport(ERROR,
@ -482,9 +482,9 @@ Datum hstore_from_text(PG_FUNCTION_ARGS);
Datum
hstore_from_text(PG_FUNCTION_ARGS)
{
text *key;
text *val = NULL;
Pairs p;
text *key;
text *val = NULL;
Pairs p;
HStore *out;
if (PG_ARGISNULL(0))
@ -524,13 +524,13 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
Pairs *pairs;
Datum *key_datums;
bool *key_nulls;
int key_count;
int key_count;
Datum *value_datums;
bool *value_nulls;
int value_count;
int value_count;
ArrayType *key_array;
ArrayType *value_array;
int i;
int i;
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
@ -540,8 +540,8 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
Assert(ARR_ELEMTYPE(key_array) == TEXTOID);
/*
* must check >1 rather than != 1 because empty arrays have
* 0 dimensions, not 1
* must check >1 rather than != 1 because empty arrays have 0 dimensions,
* not 1
*/
if (ARR_NDIM(key_array) > 1)
@ -631,15 +631,15 @@ Datum
hstore_from_array(PG_FUNCTION_ARGS)
{
ArrayType *in_array = PG_GETARG_ARRAYTYPE_P(0);
int ndims = ARR_NDIM(in_array);
int count;
int ndims = ARR_NDIM(in_array);
int count;
int4 buflen;
HStore *out;
Pairs *pairs;
Datum *in_datums;
bool *in_nulls;
int in_count;
int i;
int in_count;
int i;
Assert(ARR_ELEMTYPE(in_array) == TEXTOID);
@ -667,7 +667,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("wrong number of array subscripts")));
}
}
deconstruct_array(in_array,
TEXTOID, -1, false, 'i',
@ -679,26 +679,26 @@ hstore_from_array(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i)
{
if (in_nulls[i*2])
if (in_nulls[i * 2])
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("null value not allowed for hstore key")));
if (in_nulls[i*2+1])
if (in_nulls[i * 2 + 1])
{
pairs[i].key = VARDATA_ANY(in_datums[i*2]);
pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
pairs[i].val = NULL;
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2]));
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
pairs[i].vallen = 4;
pairs[i].isnull = true;
pairs[i].needfree = false;
}
else
{
pairs[i].key = VARDATA_ANY(in_datums[i*2]);
pairs[i].val = VARDATA_ANY(in_datums[i*2+1]);
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2]));
pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i*2+1]));
pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
pairs[i].val = VARDATA_ANY(in_datums[i * 2 + 1]);
pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i * 2 + 1]));
pairs[i].isnull = false;
pairs[i].needfree = false;
}
@ -740,25 +740,26 @@ hstore_from_record(PG_FUNCTION_ARGS)
HeapTupleHeader rec;
int4 buflen;
HStore *out;
Pairs *pairs;
Pairs *pairs;
Oid tupType;
int32 tupTypmod;
TupleDesc tupdesc;
HeapTupleData tuple;
RecordIOData *my_extra;
int ncolumns;
int i,j;
int i,
j;
Datum *values;
bool *nulls;
if (PG_ARGISNULL(0))
{
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0);
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
/*
* have no tuple to look at, so the only source of type info
* is the argtype. The lookup_rowtype_tupdesc call below will
* error out if we don't have a known composite type oid here.
* have no tuple to look at, so the only source of type info is the
* argtype. The lookup_rowtype_tupdesc call below will error out if we
* don't have a known composite type oid here.
*/
tupType = argtype;
tupTypmod = -1;
@ -855,7 +856,7 @@ hstore_from_record(PG_FUNCTION_ARGS)
*/
if (column_info->column_type != column_type)
{
bool typIsVarlena;
bool typIsVarlena;
getTypeOutputInfo(column_type,
&column_info->typiofunc,
@ -889,18 +890,18 @@ Datum hstore_populate_record(PG_FUNCTION_ARGS);
Datum
hstore_populate_record(PG_FUNCTION_ARGS)
{
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0);
HStore *hs;
HEntry *entries;
char *ptr;
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
HStore *hs;
HEntry *entries;
char *ptr;
HeapTupleHeader rec;
Oid tupType;
int32 tupTypmod;
TupleDesc tupdesc;
HeapTupleData tuple;
HeapTuple rettuple;
HeapTuple rettuple;
RecordIOData *my_extra;
int ncolumns;
int ncolumns;
int i;
Datum *values;
bool *nulls;
@ -918,9 +919,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
rec = NULL;
/*
* have no tuple to look at, so the only source of type info
* is the argtype. The lookup_rowtype_tupdesc call below will
* error out if we don't have a known composite type oid here.
* have no tuple to look at, so the only source of type info is the
* argtype. The lookup_rowtype_tupdesc call below will error out if we
* don't have a known composite type oid here.
*/
tupType = argtype;
tupTypmod = -1;
@ -942,9 +943,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
ptr = STRPTR(hs);
/*
* if the input hstore is empty, we can only skip the rest if
* we were passed in a non-null record, since otherwise there
* may be issues with domain nulls.
* if the input hstore is empty, we can only skip the rest if we were
* passed in a non-null record, since otherwise there may be issues with
* domain nulls.
*/
if (HS_COUNT(hs) == 0 && rec)
@ -1012,8 +1013,8 @@ hstore_populate_record(PG_FUNCTION_ARGS)
ColumnIOData *column_info = &my_extra->columns[i];
Oid column_type = tupdesc->attrs[i]->atttypid;
char *value;
int idx;
int vallen;
int idx;
int vallen;
/* Ignore dropped columns in datatype */
if (tupdesc->attrs[i]->attisdropped)
@ -1025,14 +1026,14 @@ hstore_populate_record(PG_FUNCTION_ARGS)
idx = hstoreFindKey(hs, 0,
NameStr(tupdesc->attrs[i]->attname),
strlen(NameStr(tupdesc->attrs[i]->attname)));
/*
* we can't just skip here if the key wasn't found since we
* might have a domain to deal with. If we were passed in a
* non-null record datum, we assume that the existing values
* are valid (if they're not, then it's not our fault), but if
* we were passed in a null, then every field which we don't
* populate needs to be run through the input function just in
* case it's a domain type.
* we can't just skip here if the key wasn't found since we might have
* a domain to deal with. If we were passed in a non-null record
* datum, we assume that the existing values are valid (if they're
* not, then it's not our fault), but if we were passed in a null,
* then every field which we don't populate needs to be run through
* the input function just in case it's a domain type.
*/
if (idx < 0 && rec)
continue;
@ -1050,11 +1051,11 @@ hstore_populate_record(PG_FUNCTION_ARGS)
column_info->column_type = column_type;
}
if (idx < 0 || HS_VALISNULL(entries,idx))
if (idx < 0 || HS_VALISNULL(entries, idx))
{
/*
* need InputFunctionCall to happen even for nulls, so
* that domain checks are done
* need InputFunctionCall to happen even for nulls, so that domain
* checks are done
*/
values[i] = InputFunctionCall(&column_info->proc, NULL,
column_info->typioparam,
@ -1063,9 +1064,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
}
else
{
vallen = HS_VALLEN(entries,idx);
vallen = HS_VALLEN(entries, idx);
value = palloc(1 + vallen);
memcpy(value, HS_VAL(entries,ptr,idx), vallen);
memcpy(value, HS_VAL(entries, ptr, idx), vallen);
value[vallen] = 0;
values[i] = InputFunctionCall(&column_info->proc, value,
@ -1105,7 +1106,7 @@ hstore_out(PG_FUNCTION_ARGS)
HStore *in = PG_GETARG_HS(0);
int buflen,
i;
int count = HS_COUNT(in);
int count = HS_COUNT(in);
char *out,
*ptr;
char *base = STRPTR(in);
@ -1121,21 +1122,21 @@ hstore_out(PG_FUNCTION_ARGS)
buflen = 0;
/*
* this loop overestimates due to pessimistic assumptions about
* escaping, so very large hstore values can't be output. this
* could be fixed, but many other data types probably have the
* same issue. This replaced code that used the original varlena
* size for calculations, which was wrong in some subtle ways.
* this loop overestimates due to pessimistic assumptions about escaping,
* so very large hstore values can't be output. this could be fixed, but
* many other data types probably have the same issue. This replaced code
* that used the original varlena size for calculations, which was wrong
* in some subtle ways.
*/
for (i = 0; i < count; i++)
{
/* include "" and => and comma-space */
buflen += 6 + 2 * HS_KEYLEN(entries,i);
buflen += 6 + 2 * HS_KEYLEN(entries, i);
/* include "" only if nonnull */
buflen += 2 + (HS_VALISNULL(entries,i)
buflen += 2 + (HS_VALISNULL(entries, i)
? 2
: 2 * HS_VALLEN(entries,i));
: 2 * HS_VALLEN(entries, i));
}
out = ptr = palloc(buflen);
@ -1143,11 +1144,11 @@ hstore_out(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++)
{
*ptr++ = '"';
ptr = cpw(ptr, HS_KEY(entries,base,i), HS_KEYLEN(entries,i));
ptr = cpw(ptr, HS_KEY(entries, base, i), HS_KEYLEN(entries, i));
*ptr++ = '"';
*ptr++ = '=';
*ptr++ = '>';
if (HS_VALISNULL(entries,i))
if (HS_VALISNULL(entries, i))
{
*ptr++ = 'N';
*ptr++ = 'U';
@ -1157,7 +1158,7 @@ hstore_out(PG_FUNCTION_ARGS)
else
{
*ptr++ = '"';
ptr = cpw(ptr, HS_VAL(entries,base,i), HS_VALLEN(entries,i));
ptr = cpw(ptr, HS_VAL(entries, base, i), HS_VALLEN(entries, i));
*ptr++ = '"';
}
@ -1179,8 +1180,8 @@ Datum
hstore_send(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
int i;
int count = HS_COUNT(in);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
HEntry *entries = ARRPTR(in);
StringInfoData buf;
@ -1191,18 +1192,20 @@ hstore_send(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++)
{
int32 keylen = HS_KEYLEN(entries,i);
int32 keylen = HS_KEYLEN(entries, i);
pq_sendint(&buf, keylen, 4);
pq_sendtext(&buf, HS_KEY(entries,base,i), keylen);
if (HS_VALISNULL(entries,i))
pq_sendtext(&buf, HS_KEY(entries, base, i), keylen);
if (HS_VALISNULL(entries, i))
{
pq_sendint(&buf, -1, 4);
}
else
{
int32 vallen = HS_VALLEN(entries,i);
int32 vallen = HS_VALLEN(entries, i);
pq_sendint(&buf, vallen, 4);
pq_sendtext(&buf, HS_VAL(entries,base,i), vallen);
pq_sendtext(&buf, HS_VAL(entries, base, i), vallen);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,11 @@
* isn.c
* PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
*
* Author: German Mendez Bravo (Kronuz)
* Author: German Mendez Bravo (Kronuz)
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.13 2010/02/05 04:34:51 momjian Exp $
* $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.14 2010/02/26 02:00:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/

View File

@ -3,11 +3,11 @@
* isn.h
* PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
*
* Author: German Mendez Bravo (Kronuz)
* Author: German Mendez Bravo (Kronuz)
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.9 2010/02/05 04:34:51 momjian Exp $
* $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.10 2010/02/26 02:00:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/

View File

@ -5,7 +5,7 @@
* Originally by
* B. Palmer, bpalmer@crimelabs.net 1-17-2001
*
* $PostgreSQL: pgsql/contrib/oid2name/oid2name.c,v 1.37 2010/02/07 20:48:08 tgl Exp $
* $PostgreSQL: pgsql/contrib/oid2name/oid2name.c,v 1.38 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres_fe.h"
@ -440,7 +440,7 @@ sql_exec_dumpalldbs(PGconn *conn, struct options * opts)
/* get the oid and database name from the system pg_database table */
snprintf(todo, sizeof(todo),
"SELECT d.oid AS \"Oid\", datname AS \"Database Name\", "
"spcname AS \"Tablespace\" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t ON "
"spcname AS \"Tablespace\" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t ON "
"(dattablespace = t.oid) ORDER BY 2");
sql_exec(conn, todo, opts->quiet);
@ -456,10 +456,10 @@ sql_exec_dumpalltables(PGconn *conn, struct options * opts)
char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\" ";
snprintf(todo, sizeof(todo),
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s "
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s "
"FROM pg_class c "
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),"
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),"
" pg_catalog.pg_tablespace t "
"WHERE relkind IN ('r'%s%s) AND "
" %s"
@ -527,7 +527,7 @@ sql_exec_searchtables(PGconn *conn, struct options * opts)
/* now build the query */
todo = (char *) myalloc(650 + strlen(qualifiers));
snprintf(todo, 650 + strlen(qualifiers),
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s\n"
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s\n"
"FROM pg_catalog.pg_class c \n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),\n"

View File

@ -8,7 +8,7 @@
* Author: Laurenz Albe <laurenz.albe@wien.gv.at>
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/passwordcheck/passwordcheck.c,v 1.2 2010/01/02 16:57:32 momjian Exp $
* $PostgreSQL: pgsql/contrib/passwordcheck/passwordcheck.c,v 1.3 2010/02/26 02:00:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -66,12 +66,12 @@ check_password(const char *username,
switch (password_type)
{
case PASSWORD_TYPE_MD5:
/*
* Unfortunately we cannot perform exhaustive checks on
* encrypted passwords - we are restricted to guessing.
* (Alternatively, we could insist on the password being
* presented non-encrypted, but that has its own security
* disadvantages.)
* Unfortunately we cannot perform exhaustive checks on encrypted
* passwords - we are restricted to guessing. (Alternatively, we
* could insist on the password being presented non-encrypted, but
* that has its own security disadvantages.)
*
* We only check for username = password.
*/
@ -84,6 +84,7 @@ check_password(const char *username,
break;
case PASSWORD_TYPE_PLAINTEXT:
/*
* For unencrypted passwords we can perform better checks
*/
@ -106,8 +107,8 @@ check_password(const char *username,
for (i = 0; i < pwdlen; i++)
{
/*
* isalpha() does not work for multibyte encodings
* but let's consider non-ASCII characters non-letters
* isalpha() does not work for multibyte encodings but let's
* consider non-ASCII characters non-letters
*/
if (isalpha((unsigned char) password[i]))
pwd_has_letter = true;
@ -117,7 +118,7 @@ check_password(const char *username,
if (!pwd_has_letter || !pwd_has_nonletter)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("password must contain both letters and nonletters")));
errmsg("password must contain both letters and nonletters")));
#ifdef USE_CRACKLIB
/* call cracklib to check password */

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/contrib/pg_standby/pg_standby.c,v 1.27 2009/11/04 12:51:30 heikki Exp $
* $PostgreSQL: pgsql/contrib/pg_standby/pg_standby.c,v 1.28 2010/02/26 02:00:32 momjian Exp $
*
*
* pg_standby.c
@ -576,6 +576,7 @@ main(int argc, char **argv)
}
#ifndef WIN32
/*
* You can send SIGUSR1 to trigger failover.
*
@ -614,9 +615,10 @@ main(int argc, char **argv)
}
break;
case 'l': /* Use link */
/*
* Link feature disabled, possibly permanently. Linking
* causes a problem after recovery ends that is not currently
* Link feature disabled, possibly permanently. Linking causes
* a problem after recovery ends that is not currently
* resolved by PostgreSQL. 25 Jun 2009
*/
#ifdef NOT_USED

View File

@ -14,7 +14,7 @@
* Copyright (c) 2008-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.12 2010/01/08 00:38:19 itagaki Exp $
* $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.13 2010/02/26 02:00:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -76,18 +76,18 @@ typedef struct pgssHashKey
*/
typedef struct Counters
{
int64 calls; /* # of times executed */
double total_time; /* total execution time in seconds */
int64 rows; /* total # of retrieved or affected rows */
int64 calls; /* # of times executed */
double total_time; /* total execution time in seconds */
int64 rows; /* total # of retrieved or affected rows */
int64 shared_blks_hit; /* # of shared buffer hits */
int64 shared_blks_read; /* # of shared disk blocks read */
int64 shared_blks_written;/* # of shared disk blocks written */
int64 local_blks_hit; /* # of local buffer hits */
int64 shared_blks_read; /* # of shared disk blocks read */
int64 shared_blks_written; /* # of shared disk blocks written */
int64 local_blks_hit; /* # of local buffer hits */
int64 local_blks_read; /* # of local disk blocks read */
int64 local_blks_written; /* # of local disk blocks written */
int64 temp_blks_read; /* # of temp blocks read */
int64 temp_blks_written; /* # of temp blocks written */
double usage; /* usage factor */
int64 local_blks_written; /* # of local disk blocks written */
int64 temp_blks_read; /* # of temp blocks read */
int64 temp_blks_written; /* # of temp blocks written */
double usage; /* usage factor */
} Counters;
/*
@ -148,7 +148,7 @@ static const struct config_enum_entry track_options[] =
static int pgss_max; /* max # statements to track */
static int pgss_track; /* tracking level */
static bool pgss_track_utility; /* whether to track utility commands */
static bool pgss_track_utility; /* whether to track utility commands */
static bool pgss_save; /* whether to save stats across shutdown */
@ -175,12 +175,12 @@ static void pgss_ExecutorRun(QueryDesc *queryDesc,
long count);
static void pgss_ExecutorEnd(QueryDesc *queryDesc);
static void pgss_ProcessUtility(Node *parsetree,
const char *queryString, ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
const char *queryString, ParamListInfo params, bool isTopLevel,
DestReceiver *dest, char *completionTag);
static uint32 pgss_hash_fn(const void *key, Size keysize);
static int pgss_match_fn(const void *key1, const void *key2, Size keysize);
static void pgss_store(const char *query, double total_time, uint64 rows,
const BufferUsage *bufusage);
const BufferUsage *bufusage);
static Size pgss_memsize(void);
static pgssEntry *entry_alloc(pgssHashKey *key);
static void entry_dealloc(void);
@ -231,7 +231,7 @@ _PG_init(void)
NULL);
DefineCustomBoolVariable("pg_stat_statements.track_utility",
"Selects whether utility commands are tracked by pg_stat_statements.",
"Selects whether utility commands are tracked by pg_stat_statements.",
NULL,
&pgss_track_utility,
true,
@ -356,8 +356,8 @@ pgss_shmem_startup(void)
on_shmem_exit(pgss_shmem_shutdown, (Datum) 0);
/*
* Attempt to load old statistics from the dump file, if this is the
* first time through and we weren't told not to.
* Attempt to load old statistics from the dump file, if this is the first
* time through and we weren't told not to.
*/
if (found || !pgss_save)
return;
@ -592,7 +592,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
instr_time start;
instr_time duration;
uint64 rows = 0;
BufferUsage bufusage;
BufferUsage bufusage;
bufusage = pgBufferUsage;
INSTR_TIME_SET_CURRENT(start);

View File

@ -4,7 +4,7 @@
* A simple benchmark program for PostgreSQL
* Originally written by Tatsuo Ishii and enhanced by many contributors.
*
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.96 2010/01/06 01:30:03 itagaki Exp $
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.97 2010/02/26 02:00:32 momjian Exp $
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
* ALL RIGHTS RESERVED;
*
@ -28,7 +28,7 @@
*/
#ifdef WIN32
#define FD_SETSIZE 1024 /* set before winsock2.h is included */
#define FD_SETSIZE 1024 /* set before winsock2.h is included */
#endif /* ! WIN32 */
#include "postgres_fe.h"
@ -66,16 +66,14 @@
#ifdef WIN32
/* Use native win32 threads on Windows */
typedef struct win32_pthread *pthread_t;
typedef int pthread_attr_t;
static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void * (*start_routine)(void *), void *arg);
static int pthread_join(pthread_t th, void **thread_return);
typedef struct win32_pthread *pthread_t;
typedef int pthread_attr_t;
static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
static int pthread_join(pthread_t th, void **thread_return);
#elif defined(ENABLE_THREAD_SAFETY)
/* Use platform-dependent pthread capability */
#include <pthread.h>
#else
/* Use emulation with fork. Rename pthread identifiers to avoid conflicts */
@ -86,12 +84,11 @@ static int pthread_join(pthread_t th, void **thread_return);
#define pthread_create pg_pthread_create
#define pthread_join pg_pthread_join
typedef struct fork_pthread *pthread_t;
typedef int pthread_attr_t;
static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void * (*start_routine)(void *), void *arg);
static int pthread_join(pthread_t th, void **thread_return);
typedef struct fork_pthread *pthread_t;
typedef int pthread_attr_t;
static int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
static int pthread_join(pthread_t th, void **thread_return);
#endif
extern char *optarg;
@ -129,7 +126,8 @@ int fillfactor = 100;
* end of configurable parameters
*********************************************************************/
#define nbranches 1 /* Makes little sense to change this. Change -s instead */
#define nbranches 1 /* Makes little sense to change this. Change
* -s instead */
#define ntellers 10
#define naccounts 100000
@ -156,7 +154,7 @@ typedef struct
} Variable;
#define MAX_FILES 128 /* max number of SQL script files allowed */
#define SHELL_COMMAND_SIZE 256 /* maximum size allowed for shell command */
#define SHELL_COMMAND_SIZE 256 /* maximum size allowed for shell command */
/*
* structures used in custom query mode
@ -185,18 +183,18 @@ typedef struct
*/
typedef struct
{
pthread_t thread; /* thread handle */
CState *state; /* array of CState */
int nstate; /* length of state[] */
instr_time start_time; /* thread start time */
pthread_t thread; /* thread handle */
CState *state; /* array of CState */
int nstate; /* length of state[] */
instr_time start_time; /* thread start time */
} TState;
#define INVALID_THREAD ((pthread_t) 0)
typedef struct
{
instr_time conn_time;
int xacts;
instr_time conn_time;
int xacts;
} TResult;
/*
@ -224,9 +222,9 @@ typedef struct
char *argv[MAX_ARGS]; /* command list */
} Command;
static Command **sql_files[MAX_FILES]; /* SQL script files */
static int num_files; /* number of script files */
static int debug = 0; /* debug flag */
static Command **sql_files[MAX_FILES]; /* SQL script files */
static int num_files; /* number of script files */
static int debug = 0; /* debug flag */
/* default scenario */
static char *tpc_b = {
@ -271,7 +269,7 @@ static char *select_only = {
/* Function prototypes */
static void setalarm(int seconds);
static void* threadRun(void *arg);
static void *threadRun(void *arg);
static void
usage(const char *progname)
@ -432,7 +430,7 @@ getVariable(CState *st, char *name)
static bool
isLegalVariableName(const char *name)
{
int i;
int i;
for (i = 0; name[i] != '\0'; i++)
{
@ -624,29 +622,28 @@ getQueryParams(CState *st, const Command *command, const char **params)
static bool
runShellCommand(CState *st, char *variable, char **argv, int argc)
{
char command[SHELL_COMMAND_SIZE];
int i,
len = 0;
FILE *fp;
char res[64];
char *endptr;
int retval;
char command[SHELL_COMMAND_SIZE];
int i,
len = 0;
FILE *fp;
char res[64];
char *endptr;
int retval;
/*
* Join arguments with whilespace separaters. Arguments starting with
* exactly one colon are treated as variables:
* name - append a string "name"
* :var - append a variable named 'var'.
* ::name - append a string ":name"
* exactly one colon are treated as variables: name - append a string
* "name" :var - append a variable named 'var'. ::name - append a string
* ":name"
*/
for (i = 0; i < argc; i++)
{
char *arg;
int arglen;
char *arg;
int arglen;
if (argv[i][0] != ':')
{
arg = argv[i]; /* a string literal */
arg = argv[i]; /* a string literal */
}
else if (argv[i][1] == ':')
{
@ -732,14 +729,14 @@ preparedStatementName(char *buffer, int file, int state)
static bool
clientDone(CState *st, bool ok)
{
(void) ok; /* unused */
(void) ok; /* unused */
if (st->con != NULL)
{
PQfinish(st->con);
st->con = NULL;
}
return false; /* always false */
return false; /* always false */
}
/* return false iff client should be disconnected */
@ -811,10 +808,10 @@ top:
{
case PGRES_COMMAND_OK:
case PGRES_TUPLES_OK:
break; /* OK */
break; /* OK */
default:
fprintf(stderr, "Client %d aborted in state %d: %s",
st->id, st->state, PQerrorMessage(st->con));
st->id, st->state, PQerrorMessage(st->con));
PQclear(res);
return clientDone(st, false);
}
@ -847,7 +844,8 @@ top:
if (st->con == NULL)
{
instr_time start, end;
instr_time start,
end;
INSTR_TIME_SET_CURRENT(start);
if ((st->con = doConnect()) == NULL)
@ -1091,7 +1089,7 @@ top:
{
char *var;
int usec;
instr_time now;
instr_time now;
if (*argv[1] == ':')
{
@ -1124,9 +1122,9 @@ top:
}
else if (pg_strcasecmp(argv[0], "setshell") == 0)
{
bool ret = runShellCommand(st, argv[1], argv + 2, argc - 2);
bool ret = runShellCommand(st, argv[1], argv + 2, argc - 2);
if (timer_exceeded) /* timeout */
if (timer_exceeded) /* timeout */
return clientDone(st, true);
else if (!ret) /* on error */
{
@ -1138,9 +1136,9 @@ top:
}
else if (pg_strcasecmp(argv[0], "shell") == 0)
{
bool ret = runShellCommand(st, NULL, argv + 1, argc - 1);
bool ret = runShellCommand(st, NULL, argv + 1, argc - 1);
if (timer_exceeded) /* timeout */
if (timer_exceeded) /* timeout */
return clientDone(st, true);
else if (!ret) /* on error */
{
@ -1442,7 +1440,7 @@ process_commands(char *buf)
*/
if (my_commands->argv[1][0] != ':')
{
char *c = my_commands->argv[1];
char *c = my_commands->argv[1];
while (isdigit((unsigned char) *c))
c++;
@ -1667,7 +1665,7 @@ printResults(int ttype, int normal_xacts, int nclients, int nthreads,
time_include = INSTR_TIME_GET_DOUBLE(total_time);
tps_include = normal_xacts / time_include;
tps_exclude = normal_xacts / (time_include -
(INSTR_TIME_GET_DOUBLE(conn_total_time) / nthreads));
(INSTR_TIME_GET_DOUBLE(conn_total_time) / nthreads));
if (ttype == 0)
s = "TPC-B (sort of)";
@ -1704,8 +1702,8 @@ int
main(int argc, char **argv)
{
int c;
int nclients = 1; /* default number of simulated clients */
int nthreads = 1; /* default number of threads */
int nclients = 1; /* default number of simulated clients */
int nthreads = 1; /* default number of threads */
int is_init_mode = 0; /* initialize mode? */
int is_no_vacuum = 0; /* no vacuum at all before testing? */
int do_vacuum_accounts = 0; /* do vacuum accounts before testing? */
@ -1826,7 +1824,7 @@ main(int argc, char **argv)
}
#endif /* HAVE_GETRLIMIT */
break;
case 'j': /* jobs */
case 'j': /* jobs */
nthreads = atoi(optarg);
if (nthreads <= 0)
{
@ -2120,7 +2118,8 @@ main(int argc, char **argv)
/* the first thread (i = 0) is executed by main thread */
if (i > 0)
{
int err = pthread_create(&threads[i].thread, NULL, threadRun, &threads[i]);
int err = pthread_create(&threads[i].thread, NULL, threadRun, &threads[i]);
if (err != 0 || threads[i].thread == INVALID_THREAD)
{
fprintf(stderr, "cannot create thread: %s\n", strerror(err));
@ -2138,7 +2137,7 @@ main(int argc, char **argv)
INSTR_TIME_SET_ZERO(conn_total_time);
for (i = 0; i < nthreads; i++)
{
void *ret = NULL;
void *ret = NULL;
if (threads[i].thread == INVALID_THREAD)
ret = threadRun(&threads[i]);
@ -2147,7 +2146,8 @@ main(int argc, char **argv)
if (ret != NULL)
{
TResult *r = (TResult *) ret;
TResult *r = (TResult *) ret;
total_xacts += r->xacts;
INSTR_TIME_ADD(conn_total_time, r->conn_time);
free(ret);
@ -2170,10 +2170,11 @@ threadRun(void *arg)
{
TState *thread = (TState *) arg;
CState *state = thread->state;
TResult *result;
instr_time start, end;
TResult *result;
instr_time start,
end;
int nstate = thread->nstate;
int remains = nstate; /* number of remaining clients */
int remains = nstate; /* number of remaining clients */
int i;
result = malloc(sizeof(TResult));
@ -2202,7 +2203,7 @@ threadRun(void *arg)
st->use_file = getrand(0, num_files - 1);
if (!doCustom(st, &result->conn_time))
remains--; /* I've aborted */
remains--; /* I've aborted */
if (st->ecnt > prev_ecnt && commands[st->state]->type == META_COMMAND)
{
@ -2215,10 +2216,10 @@ threadRun(void *arg)
while (remains > 0)
{
fd_set input_mask;
int maxsock; /* max socket number to be waited */
int64 now_usec = 0;
int64 min_usec;
fd_set input_mask;
int maxsock; /* max socket number to be waited */
int64 now_usec = 0;
int64 min_usec;
FD_ZERO(&input_mask);
@ -2237,6 +2238,7 @@ threadRun(void *arg)
if (min_usec == INT64_MAX)
{
instr_time now;
INSTR_TIME_SET_CURRENT(now);
now_usec = INSTR_TIME_GET_MICROSEC(now);
}
@ -2262,18 +2264,20 @@ threadRun(void *arg)
goto done;
}
FD_SET(sock, &input_mask);
FD_SET (sock, &input_mask);
if (maxsock < sock)
maxsock = sock;
}
if (min_usec > 0 && maxsock != -1)
{
int nsocks; /* return from select(2) */
int nsocks; /* return from select(2) */
if (min_usec != INT64_MAX)
{
struct timeval timeout;
struct timeval timeout;
timeout.tv_sec = min_usec / 1000000;
timeout.tv_usec = min_usec % 1000000;
nsocks = select(maxsock + 1, &input_mask, NULL, NULL, &timeout);
@ -2298,10 +2302,10 @@ threadRun(void *arg)
int prev_ecnt = st->ecnt;
if (st->con && (FD_ISSET(PQsocket(st->con), &input_mask)
|| commands[st->state]->type == META_COMMAND))
|| commands[st->state]->type == META_COMMAND))
{
if (!doCustom(st, &result->conn_time))
remains--; /* I've aborted */
remains--; /* I've aborted */
}
if (st->ecnt > prev_ecnt && commands[st->state]->type == META_COMMAND)
@ -2353,30 +2357,30 @@ setalarm(int seconds)
typedef struct fork_pthread
{
pid_t pid;
int pipes[2];
} fork_pthread;
pid_t pid;
int pipes[2];
} fork_pthread;
static int
pthread_create(pthread_t *thread,
pthread_attr_t *attr,
void * (*start_routine)(void *),
void *(*start_routine) (void *),
void *arg)
{
fork_pthread *th;
void *ret;
instr_time start_time;
fork_pthread *th;
void *ret;
instr_time start_time;
th = (fork_pthread *) malloc(sizeof(fork_pthread));
pipe(th->pipes);
th->pid = fork();
if (th->pid == -1) /* error */
if (th->pid == -1) /* error */
{
free(th);
return errno;
}
if (th->pid != 0) /* in parent process */
if (th->pid != 0) /* in parent process */
{
close(th->pipes[1]);
*thread = th;
@ -2391,11 +2395,11 @@ pthread_create(pthread_t *thread,
setalarm(duration);
/*
* Set a different random seed in each child process. Otherwise they
* all inherit the parent's state and generate the same "random"
* sequence. (In the threaded case, the different threads will obtain
* subsets of the output of a single random() sequence, which should be
* okay for our purposes.)
* Set a different random seed in each child process. Otherwise they all
* inherit the parent's state and generate the same "random" sequence.
* (In the threaded case, the different threads will obtain subsets of the
* output of a single random() sequence, which should be okay for our
* purposes.)
*/
INSTR_TIME_SET_CURRENT(start_time);
srandom(((unsigned int) INSTR_TIME_GET_MICROSEC(start_time)) +
@ -2411,7 +2415,7 @@ pthread_create(pthread_t *thread,
static int
pthread_join(pthread_t th, void **thread_return)
{
int status;
int status;
while (waitpid(th->pid, &status, 0) != th->pid)
{
@ -2434,9 +2438,7 @@ pthread_join(pthread_t th, void **thread_return)
free(th);
return 0;
}
#endif
#else /* WIN32 */
static VOID CALLBACK
@ -2468,7 +2470,7 @@ setalarm(int seconds)
typedef struct win32_pthread
{
HANDLE handle;
void *(*routine)(void *);
void *(*routine) (void *);
void *arg;
void *result;
} win32_pthread;
@ -2486,11 +2488,11 @@ win32_pthread_run(void *arg)
static int
pthread_create(pthread_t *thread,
pthread_attr_t *attr,
void * (*start_routine)(void *),
void *(*start_routine) (void *),
void *arg)
{
int save_errno;
win32_pthread *th;
int save_errno;
win32_pthread *th;
th = (win32_pthread *) malloc(sizeof(win32_pthread));
th->routine = start_routine;

View File

@ -1,12 +1,12 @@
/*-------------------------------------------------------------------------
*
* unaccent.c
* Text search unaccent dictionary
* Text search unaccent dictionary
*
* Copyright (c) 2009-2010, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.4 2010/01/02 16:57:33 momjian Exp $
* $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.5 2010/02/26 02:00:32 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -25,26 +25,27 @@
PG_MODULE_MAGIC;
/*
* Unaccent dictionary uses uncompressed suffix tree to find a
* character to replace. Each node of tree is an array of
* Unaccent dictionary uses uncompressed suffix tree to find a
* character to replace. Each node of tree is an array of
* SuffixChar struct with length = 256 (n-th element of array
* corresponds to byte)
*/
typedef struct SuffixChar {
struct SuffixChar *nextChar;
char *replaceTo;
int replacelen;
typedef struct SuffixChar
{
struct SuffixChar *nextChar;
char *replaceTo;
int replacelen;
} SuffixChar;
/*
* placeChar - put str into tree's structure, byte by byte.
*/
static SuffixChar*
static SuffixChar *
placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int replacelen)
{
SuffixChar *curnode;
SuffixChar *curnode;
if ( !node )
if (!node)
{
node = palloc(sizeof(SuffixChar) * 256);
memset(node, 0, sizeof(SuffixChar) * 256);
@ -52,20 +53,20 @@ placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int
curnode = node + *str;
if ( lenstr == 1 )
if (lenstr == 1)
{
if ( curnode->replaceTo )
if (curnode->replaceTo)
elog(WARNING, "duplicate TO argument, use first one");
else
{
curnode->replacelen = replacelen;
curnode->replaceTo = palloc( replacelen );
curnode->replaceTo = palloc(replacelen);
memcpy(curnode->replaceTo, replaceTo, replacelen);
}
}
else
{
curnode->nextChar = placeChar( curnode->nextChar, str+1, lenstr-1, replaceTo, replacelen);
curnode->nextChar = placeChar(curnode->nextChar, str + 1, lenstr - 1, replaceTo, replacelen);
}
return node;
@ -75,13 +76,13 @@ placeChar(SuffixChar *node, unsigned char *str, int lenstr, char *replaceTo, int
* initSuffixTree - create suffix tree from file. Function converts
* UTF8-encoded file into current encoding.
*/
static SuffixChar*
initSuffixTree(char *filename)
static SuffixChar *
initSuffixTree(char *filename)
{
SuffixChar * volatile rootSuffixTree = NULL;
SuffixChar *volatile rootSuffixTree = NULL;
MemoryContext ccxt = CurrentMemoryContext;
tsearch_readline_state trst;
volatile bool skip;
tsearch_readline_state trst;
volatile bool skip;
filename = get_tsearch_config_filename(filename, "rules");
if (!tsearch_readline_begin(&trst, filename))
@ -90,34 +91,34 @@ initSuffixTree(char *filename)
errmsg("could not open unaccent file \"%s\": %m",
filename)));
do
do
{
char src[4096];
char trg[4096];
int srclen;
int trglen;
char *line = NULL;
char src[4096];
char trg[4096];
int srclen;
int trglen;
char *line = NULL;
skip = true;
PG_TRY();
{
/*
* pg_do_encoding_conversion() (called by tsearch_readline())
* will emit exception if it finds untranslatable characters in current locale.
* We just skip such characters.
* pg_do_encoding_conversion() (called by tsearch_readline()) will
* emit exception if it finds untranslatable characters in current
* locale. We just skip such characters.
*/
while ((line = tsearch_readline(&trst)) != NULL)
{
if ( sscanf(line, "%s\t%s\n", src, trg)!=2 )
if (sscanf(line, "%s\t%s\n", src, trg) != 2)
continue;
srclen = strlen(src);
trglen = strlen(trg);
rootSuffixTree = placeChar(rootSuffixTree,
(unsigned char*)src, srclen,
trg, trglen);
rootSuffixTree = placeChar(rootSuffixTree,
(unsigned char *) src, srclen,
trg, trglen);
skip = false;
pfree(line);
}
@ -141,7 +142,7 @@ initSuffixTree(char *filename)
}
PG_END_TRY();
}
while(skip);
while (skip);
tsearch_readline_end(&trst);
@ -151,13 +152,13 @@ initSuffixTree(char *filename)
/*
* findReplaceTo - find multibyte character in tree
*/
static SuffixChar *
findReplaceTo( SuffixChar *node, unsigned char *src, int srclen )
static SuffixChar *
findReplaceTo(SuffixChar *node, unsigned char *src, int srclen)
{
while( node )
while (node)
{
node = node + *src;
if ( srclen == 1 )
if (srclen == 1)
return node;
src++;
@ -169,13 +170,13 @@ findReplaceTo( SuffixChar *node, unsigned char *src, int srclen )
}
PG_FUNCTION_INFO_V1(unaccent_init);
Datum unaccent_init(PG_FUNCTION_ARGS);
Datum unaccent_init(PG_FUNCTION_ARGS);
Datum
unaccent_init(PG_FUNCTION_ARGS)
{
List *dictoptions = (List *) PG_GETARG_POINTER(0);
List *dictoptions = (List *) PG_GETARG_POINTER(0);
SuffixChar *rootSuffixTree = NULL;
bool fileloaded = false;
bool fileloaded = false;
ListCell *l;
foreach(l, dictoptions)
@ -188,8 +189,8 @@ unaccent_init(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("multiple Rules parameters")));
rootSuffixTree = initSuffixTree(defGetString(defel));
fileloaded = true;
rootSuffixTree = initSuffixTree(defGetString(defel));
fileloaded = true;
}
else
{
@ -211,51 +212,52 @@ unaccent_init(PG_FUNCTION_ARGS)
}
PG_FUNCTION_INFO_V1(unaccent_lexize);
Datum unaccent_lexize(PG_FUNCTION_ARGS);
Datum unaccent_lexize(PG_FUNCTION_ARGS);
Datum
unaccent_lexize(PG_FUNCTION_ARGS)
{
SuffixChar *rootSuffixTree = (SuffixChar*)PG_GETARG_POINTER(0);
char *srcchar = (char *) PG_GETARG_POINTER(1);
SuffixChar *rootSuffixTree = (SuffixChar *) PG_GETARG_POINTER(0);
char *srcchar = (char *) PG_GETARG_POINTER(1);
int32 len = PG_GETARG_INT32(2);
char *srcstart, *trgchar = NULL;
char *srcstart,
*trgchar = NULL;
int charlen;
TSLexeme *res = NULL;
SuffixChar *node;
srcstart = srcchar;
while( srcchar - srcstart < len )
while (srcchar - srcstart < len)
{
charlen = pg_mblen(srcchar);
node = findReplaceTo( rootSuffixTree, (unsigned char *) srcchar, charlen );
if ( node && node->replaceTo )
node = findReplaceTo(rootSuffixTree, (unsigned char *) srcchar, charlen);
if (node && node->replaceTo)
{
if ( !res )
if (!res)
{
/* allocate res only it it's needed */
res = palloc0(sizeof(TSLexeme) * 2);
res->lexeme = trgchar = palloc( len * pg_database_encoding_max_length() + 1 /* \0 */ );
res->lexeme = trgchar = palloc(len * pg_database_encoding_max_length() + 1 /* \0 */ );
res->flags = TSL_FILTER;
if ( srcchar != srcstart )
if (srcchar != srcstart)
{
memcpy(trgchar, srcstart, srcchar - srcstart);
trgchar += (srcchar - srcstart);
}
}
memcpy( trgchar, node->replaceTo, node->replacelen );
trgchar += node->replacelen;
memcpy(trgchar, node->replaceTo, node->replacelen);
trgchar += node->replacelen;
}
else if ( res )
else if (res)
{
memcpy( trgchar, srcchar, charlen );
memcpy(trgchar, srcchar, charlen);
trgchar += charlen;
}
srcchar += charlen;
}
if ( res )
if (res)
*trgchar = '\0';
PG_RETURN_POINTER(res);
@ -265,15 +267,15 @@ unaccent_lexize(PG_FUNCTION_ARGS)
* Function-like wrapper for dictionary
*/
PG_FUNCTION_INFO_V1(unaccent_dict);
Datum unaccent_dict(PG_FUNCTION_ARGS);
Datum unaccent_dict(PG_FUNCTION_ARGS);
Datum
unaccent_dict(PG_FUNCTION_ARGS)
{
text *str;
int strArg;
Oid dictOid;
TSDictionaryCacheEntry *dict;
TSLexeme *res;
text *str;
int strArg;
Oid dictOid;
TSDictionaryCacheEntry *dict;
TSLexeme *res;
if (PG_NARGS() == 1)
{
@ -290,25 +292,25 @@ unaccent_dict(PG_FUNCTION_ARGS)
dict = lookup_ts_dictionary_cache(dictOid);
res = (TSLexeme *) DatumGetPointer(FunctionCall4(&(dict->lexize),
PointerGetDatum(dict->dictData),
PointerGetDatum(VARDATA(str)),
Int32GetDatum(VARSIZE(str) - VARHDRSZ),
PointerGetDatum(dict->dictData),
PointerGetDatum(VARDATA(str)),
Int32GetDatum(VARSIZE(str) - VARHDRSZ),
PointerGetDatum(NULL)));
PG_FREE_IF_COPY(str, strArg);
if ( res == NULL )
if (res == NULL)
{
PG_RETURN_TEXT_P(PG_GETARG_TEXT_P_COPY(strArg));
}
else if ( res->lexeme == NULL )
else if (res->lexeme == NULL)
{
pfree(res);
PG_RETURN_TEXT_P(PG_GETARG_TEXT_P_COPY(strArg));
}
else
{
text *txt = cstring_to_text(res->lexeme);
text *txt = cstring_to_text(res->lexeme);
pfree(res->lexeme);
pfree(res);