diff options
author | Bruce Momjian | 2002-09-04 20:31:48 +0000 |
---|---|---|
committer | Bruce Momjian | 2002-09-04 20:31:48 +0000 |
commit | e50f52a074bdf0d6a9dc384840e641c4c0b0bb1a (patch) | |
tree | ab73e8c8ec94a6ddc774c1f9c49b87aa6b93fd13 | |
parent | c91ceec21d357d6d857163d897ac75a79c883dee (diff) |
pgindent run.
446 files changed, 15012 insertions, 13433 deletions
diff --git a/contrib/btree_gist/btree_gist.c b/contrib/btree_gist/btree_gist.c index c4eb852213..ec84ec5a5b 100644 --- a/contrib/btree_gist/btree_gist.c +++ b/contrib/btree_gist/btree_gist.c @@ -299,11 +299,12 @@ gts_compress(PG_FUNCTION_ARGS) if (entry->leafkey) { TSKEY *r = (TSKEY *) palloc(sizeof(TSKEY)); + retval = palloc(sizeof(GISTENTRY)); r->lower = r->upper = *(Timestamp *) (entry->key); gistentryinit(*retval, PointerGetDatum(r), - entry->rel, entry->page, - entry->offset, sizeof(TSKEY), FALSE); + entry->rel, entry->page, + entry->offset, sizeof(TSKEY), FALSE); } else retval = entry; @@ -398,8 +399,8 @@ gts_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( timestamp_mi, - TimestampGetDatumFast(newentry->upper), - TimestampGetDatumFast(origentry->upper))); + TimestampGetDatumFast(newentry->upper), + TimestampGetDatumFast(origentry->upper))); /* see interval_larger */ *result = Max(intr->time + intr->month * (30.0 * 86400), 0); @@ -407,8 +408,8 @@ gts_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( timestamp_mi, - TimestampGetDatumFast(origentry->lower), - TimestampGetDatumFast(newentry->lower))); + TimestampGetDatumFast(origentry->lower), + TimestampGetDatumFast(newentry->lower))); /* see interval_larger */ *result += Max(intr->time + intr->month * (30.0 * 86400), 0); @@ -473,8 +474,8 @@ tskey_cmp(const void *a, const void *b) return DatumGetInt32( DirectFunctionCall2( timestamp_cmp, - TimestampGetDatumFast(((TSKEY *) (((RIX *) a)->r))->lower), - TimestampGetDatumFast(((TSKEY *) (((RIX *) b)->r))->lower) + TimestampGetDatumFast(((TSKEY *) (((RIX *) a)->r))->lower), + TimestampGetDatumFast(((TSKEY *) (((RIX *) b)->r))->lower) ) ); } diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c index ddf6fb0fec..bf3dd8dfbf 100644 --- a/contrib/cube/cube.c +++ b/contrib/cube/cube.c @@ -73,11 +73,11 @@ bool cube_right(NDBOX * a, NDBOX * b); bool cube_lt(NDBOX * a, NDBOX * b); bool cube_gt(NDBOX * a, NDBOX * b); double *cube_distance(NDBOX * a, NDBOX * b); -int cube_dim(NDBOX *a); -double *cube_ll_coord(NDBOX * a, int n); -double *cube_ur_coord(NDBOX * a, int n); -bool cube_is_point(NDBOX * a); -NDBOX *cube_enlarge(NDBOX * a, double * r, int n); +int cube_dim(NDBOX * a); +double *cube_ll_coord(NDBOX * a, int n); +double *cube_ur_coord(NDBOX * a, int n); +bool cube_is_point(NDBOX * a); +NDBOX *cube_enlarge(NDBOX * a, double *r, int n); /* @@ -111,11 +111,11 @@ NDBOX * cube(text *str) { return cube_in(DatumGetCString(DirectFunctionCall1(textout, - PointerGetDatum(str)))); + PointerGetDatum(str)))); } char * -cube_out(NDBOX *cube) +cube_out(NDBOX * cube) { StringInfoData buf; bool equal = true; @@ -542,14 +542,14 @@ cube_union(NDBOX * a, NDBOX * b) if (a->dim >= b->dim) { result = palloc(a->size); - memset(result, 0, a->size); + memset(result, 0, a->size); result->size = a->size; result->dim = a->dim; } else { result = palloc(b->size); - memset(result, 0, b->size); + memset(result, 0, b->size); result->size = b->size; result->dim = b->dim; } @@ -580,12 +580,12 @@ cube_union(NDBOX * a, NDBOX * b) /* compute the union */ for (i = 0; i < a->dim; i++) - { + { result->x[i] = - min(min(a->x[i], a->x[i + a->dim]), result->x[i]); + min(min(a->x[i], a->x[i + a->dim]), result->x[i]); result->x[i + a->dim] = max(max(a->x[i], - a->x[i + a->dim]), result->x[i + a->dim]); - } + a->x[i + a->dim]), result->x[i + a->dim]); + } return (result); } @@ -600,14 +600,14 @@ cube_inter(NDBOX * a, NDBOX * b) if (a->dim >= b->dim) { result = palloc(a->size); - memset(result, 0, a->size); + memset(result, 0, a->size); result->size = a->size; result->dim = a->dim; } else { result = palloc(b->size); - memset(result, 0, b->size); + memset(result, 0, b->size); result->size = b->size; result->dim = b->dim; } @@ -638,12 +638,12 @@ cube_inter(NDBOX * a, NDBOX * b) /* compute the intersection */ for (i = 0; i < a->dim; i++) - { + { result->x[i] = - max(min(a->x[i], a->x[i + a->dim]), result->x[i]); + max(min(a->x[i], a->x[i + a->dim]), result->x[i]); result->x[i + a->dim] = min(max(a->x[i], - a->x[i + a->dim]), result->x[i + a->dim]); - } + a->x[i + a->dim]), result->x[i + a->dim]); + } /* * Is it OK to return a non-null intersection for non-overlapping @@ -700,8 +700,8 @@ cube_over_left(NDBOX * a, NDBOX * b) return (FALSE); return (min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) <= - min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) && - !cube_left(a, b) && !cube_right(a, b)); + min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) && + !cube_left(a, b) && !cube_right(a, b)); } /* is the left edge of (a) located to the right of @@ -713,8 +713,8 @@ cube_over_right(NDBOX * a, NDBOX * b) return (FALSE); return (min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) >= - min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) && - !cube_left(a, b) && !cube_right(a, b)); + min(b->x[b->dim - 1], b->x[2 * b->dim - 1]) && + !cube_left(a, b) && !cube_right(a, b)); } @@ -727,7 +727,7 @@ cube_left(NDBOX * a, NDBOX * b) return (FALSE); return (min(a->x[a->dim - 1], a->x[2 * a->dim - 1]) < - min(b->x[0], b->x[b->dim])); + min(b->x[0], b->x[b->dim])); } /* return 'true' if the projection of 'a' is @@ -739,7 +739,7 @@ cube_right(NDBOX * a, NDBOX * b) return (FALSE); return (min(a->x[0], a->x[a->dim]) > - min(b->x[b->dim - 1], b->x[2 * b->dim - 1])); + min(b->x[b->dim - 1], b->x[2 * b->dim - 1])); } /* make up a metric in which one box will be 'lower' than the other @@ -759,19 +759,19 @@ cube_lt(NDBOX * a, NDBOX * b) for (i = 0; i < dim; i++) { if (min(a->x[i], a->x[a->dim + i]) > - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (FALSE); if (min(a->x[i], a->x[a->dim + i]) < - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (TRUE); } for (i = 0; i < dim; i++) { if (max(a->x[i], a->x[a->dim + i]) > - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (FALSE); if (max(a->x[i], a->x[a->dim + i]) < - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (TRUE); } @@ -792,11 +792,12 @@ cube_lt(NDBOX * a, NDBOX * b) if (max(a->x[i], a->x[a->dim + i]) < 0) return (TRUE); } - /* - * if all common dimensions are equal, the cube with more - * dimensions wins - */ - return (FALSE); + + /* + * if all common dimensions are equal, the cube with more + * dimensions wins + */ + return (FALSE); } if (a->dim < b->dim) { @@ -814,11 +815,12 @@ cube_lt(NDBOX * a, NDBOX * b) if (max(b->x[i], b->x[b->dim + i]) < 0) return (FALSE); } - /* - * if all common dimensions are equal, the cube with more - * dimensions wins - */ - return (TRUE); + + /* + * if all common dimensions are equal, the cube with more + * dimensions wins + */ + return (TRUE); } return (FALSE); @@ -840,19 +842,19 @@ cube_gt(NDBOX * a, NDBOX * b) for (i = 0; i < dim; i++) { if (min(a->x[i], a->x[a->dim + i]) < - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (FALSE); if (min(a->x[i], a->x[a->dim + i]) > - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (TRUE); } for (i = 0; i < dim; i++) { if (max(a->x[i], a->x[a->dim + i]) < - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (FALSE); if (max(a->x[i], a->x[a->dim + i]) > - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (TRUE); } @@ -874,11 +876,12 @@ cube_gt(NDBOX * a, NDBOX * b) if (max(a->x[i], a->x[a->dim + i]) > 0) return (TRUE); } - /* - * if all common dimensions are equal, the cube with more - * dimensions wins - */ - return (TRUE); + + /* + * if all common dimensions are equal, the cube with more + * dimensions wins + */ + return (TRUE); } if (a->dim < b->dim) { @@ -896,11 +899,12 @@ cube_gt(NDBOX * a, NDBOX * b) if (max(b->x[i], b->x[b->dim + i]) > 0) return (FALSE); } - /* - * if all common dimensions are equal, the cube with more - * dimensions wins - */ - return (FALSE); + + /* + * if all common dimensions are equal, the cube with more + * dimensions wins + */ + return (FALSE); } return (FALSE); @@ -928,18 +932,18 @@ cube_same(NDBOX * a, NDBOX * b) for (i = 0; i < b->dim; i++) { if (min(a->x[i], a->x[a->dim + i]) != - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (FALSE); if (max(a->x[i], a->x[a->dim + i]) != - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (FALSE); } /* * all dimensions of (b) are compared to those of (a); instead of - * those in (a) absent in (b), compare (a) to zero - * Since both LL and UR coordinates are compared to zero, we can - * just check them all without worrying about which is which. + * those in (a) absent in (b), compare (a) to zero Since both LL and + * UR coordinates are compared to zero, we can just check them all + * without worrying about which is which. */ for (i = b->dim; i < a->dim; i++) { @@ -974,9 +978,9 @@ cube_contains(NDBOX * a, NDBOX * b) { /* * the further comparisons will make sense if the excess - * dimensions of (b) were zeroes - * Since both UL and UR coordinates must be zero, we can - * check them all without worrying about which is which. + * dimensions of (b) were zeroes Since both UL and UR coordinates + * must be zero, we can check them all without worrying about + * which is which. */ for (i = a->dim; i < b->dim; i++) { @@ -991,10 +995,10 @@ cube_contains(NDBOX * a, NDBOX * b) for (i = 0; i < min(a->dim, b->dim); i++) { if (min(a->x[i], a->x[a->dim + i]) > - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (FALSE); if (max(a->x[i], a->x[a->dim + i]) < - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (FALSE); } @@ -1039,10 +1043,10 @@ cube_overlap(NDBOX * a, NDBOX * b) for (i = 0; i < b->dim; i++) { if (min(a->x[i], a->x[a->dim + i]) > - max(b->x[i], b->x[b->dim + i])) + max(b->x[i], b->x[b->dim + i])) return (FALSE); if (max(a->x[i], a->x[a->dim + i]) < - min(b->x[i], b->x[b->dim + i])) + min(b->x[i], b->x[b->dim + i])) return (FALSE); } @@ -1122,87 +1126,94 @@ distance_1D(double a1, double a2, double b1, double b2) bool cube_is_point(NDBOX * a) { - int i, - j; + int i, + j; + for (i = 0, j = a->dim; i < a->dim; i++, j++) - { - if (a->x[i] != a->x[j]) return FALSE; - } + { + if (a->x[i] != a->x[j]) + return FALSE; + } - return TRUE; + return TRUE; } /* Return dimensions in use in the data structure */ int cube_dim(NDBOX * a) { - /* Other things will break before unsigned int doesn't fit. */ - return a->dim; + /* Other things will break before unsigned int doesn't fit. */ + return a->dim; } /* Return a specific normalized LL coordinate */ double * cube_ll_coord(NDBOX * a, int n) { - double *result; + double *result; + result = (double *) palloc(sizeof(double)); - *result = 0; - if (a->dim >= n && n > 0) - *result = min(a->x[n-1], a->x[a->dim + n-1]); - return result; + *result = 0; + if (a->dim >= n && n > 0) + *result = min(a->x[n - 1], a->x[a->dim + n - 1]); + return result; } /* Return a specific normalized UR coordinate */ double * cube_ur_coord(NDBOX * a, int n) { - double *result; + double *result; + result = (double *) palloc(sizeof(double)); - *result = 0; - if (a->dim >= n && n > 0) - *result = max(a->x[n-1], a->x[a->dim + n-1]); - return result; + *result = 0; + if (a->dim >= n && n > 0) + *result = max(a->x[n - 1], a->x[a->dim + n - 1]); + return result; } /* Increase or decrease box size by a radius in at least n dimensions. */ NDBOX * -cube_enlarge(NDBOX * a, double * r, int n) +cube_enlarge(NDBOX * a, double *r, int n) { - NDBOX *result; - int dim = 0; - int size; - int i, - j; - if (*r > 0 && n > 0) dim = n; - if (a->dim > dim) dim = a->dim; - size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2; - result = (NDBOX *) palloc(size); - memset(result, 0, size); - result->size = size; - result->dim = dim; + NDBOX *result; + int dim = 0; + int size; + int i, + j; + + if (*r > 0 && n > 0) + dim = n; + if (a->dim > dim) + dim = a->dim; + size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2; + result = (NDBOX *) palloc(size); + memset(result, 0, size); + result->size = size; + result->dim = dim; for (i = 0, j = dim; i < a->dim; i++, j++) - { - if (a->x[i] >= a->x[j]) - { - result->x[i] = a->x[j] - *r; - result->x[j] = a->x[i] + *r; - } - else - { - result->x[i] = a->x[i] - *r; - result->x[j] = a->x[j] + *r; - } - if (result->x[i] > result->x[j]) - { - result->x[i] = (result->x[i] + result->x[j]) / 2; - result->x[j] = result->x[i]; - } - } - /* dim > a->dim only if r > 0 */ + { + if (a->x[i] >= a->x[j]) + { + result->x[i] = a->x[j] - *r; + result->x[j] = a->x[i] + *r; + } + else + { + result->x[i] = a->x[i] - *r; + result->x[j] = a->x[j] + *r; + } + if (result->x[i] > result->x[j]) + { + result->x[i] = (result->x[i] + result->x[j]) / 2; + result->x[j] = result->x[i]; + } + } + /* dim > a->dim only if r > 0 */ for (; i < dim; i++, j++) - { - result->x[i] = -*r; - result->x[j] = *r; - } - return result; + { + result->x[i] = -*r; + result->x[j] = *r; + } + return result; } diff --git a/contrib/dbase/dbf2pg.c b/contrib/dbase/dbf2pg.c index 4522368e06..e179226cbe 100644 --- a/contrib/dbase/dbf2pg.c +++ b/contrib/dbase/dbf2pg.c @@ -309,7 +309,7 @@ do_create(PGconn *conn, char *table, dbhead * dbh) { strcat(query, " varchar"); snprintf(t, 20, "(%d)", - dbh->db_fields[i].db_flen); + dbh->db_fields[i].db_flen); strcat(query, t); } else @@ -468,8 +468,8 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh) if ((strlen(foo) == 8) && isinteger(foo)) { snprintf(pgdate, 11, "%c%c%c%c-%c%c-%c%c", - foo[0], foo[1], foo[2], foo[3], - foo[4], foo[5], foo[6], foo[7]); + foo[0], foo[1], foo[2], foo[3], + foo[4], foo[5], foo[6], foo[7]); strcat(query, pgdate); } else diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 44d5bf9134..899143adab 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -67,10 +67,10 @@ static char *quote_literal_cstr(char *rawstr); static char *quote_ident_cstr(char *rawstr); static int16 get_attnum_pk_pos(int16 *pkattnums, int16 pknumatts, int16 key); static HeapTuple get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals); -static Oid get_relid_from_relname(text *relname_text); +static Oid get_relid_from_relname(text *relname_text); static dblink_results *get_res_ptr(int32 res_id_index); -static void append_res_ptr(dblink_results *results); -static void remove_res_ptr(dblink_results *results); +static void append_res_ptr(dblink_results * results); +static void remove_res_ptr(dblink_results * results); static TupleDesc pgresultGetTupleDesc(PGresult *res); /* Global */ @@ -97,10 +97,10 @@ PG_FUNCTION_INFO_V1(dblink_connect); Datum dblink_connect(PG_FUNCTION_ARGS) { - char *connstr = GET_STR(PG_GETARG_TEXT_P(0)); - char *msg; - text *result_text; - MemoryContext oldcontext; + char *connstr = GET_STR(PG_GETARG_TEXT_P(0)); + char *msg; + text *result_text; + MemoryContext oldcontext; if (persistent_conn != NULL) PQfinish(persistent_conn); @@ -128,7 +128,7 @@ PG_FUNCTION_INFO_V1(dblink_disconnect); Datum dblink_disconnect(PG_FUNCTION_ARGS) { - text *result_text; + text *result_text; if (persistent_conn != NULL) PQfinish(persistent_conn); @@ -146,13 +146,13 @@ PG_FUNCTION_INFO_V1(dblink_open); Datum dblink_open(PG_FUNCTION_ARGS) { - char *msg; - PGresult *res = NULL; - PGconn *conn = NULL; - text *result_text; - char *curname = GET_STR(PG_GETARG_TEXT_P(0)); - char *sql = GET_STR(PG_GETARG_TEXT_P(1)); - StringInfo str = makeStringInfo(); + char *msg; + PGresult *res = NULL; + PGconn *conn = NULL; + text *result_text; + char *curname = GET_STR(PG_GETARG_TEXT_P(0)); + char *sql = GET_STR(PG_GETARG_TEXT_P(1)); + StringInfo str = makeStringInfo(); if (persistent_conn != NULL) conn = persistent_conn; @@ -199,12 +199,12 @@ PG_FUNCTION_INFO_V1(dblink_close); Datum dblink_close(PG_FUNCTION_ARGS) { - PGconn *conn = NULL; - PGresult *res = NULL; - char *curname = GET_STR(PG_GETARG_TEXT_P(0)); - StringInfo str = makeStringInfo(); - text *result_text; - char *msg; + PGconn *conn = NULL; + PGresult *res = NULL; + char *curname = GET_STR(PG_GETARG_TEXT_P(0)); + StringInfo str = makeStringInfo(); + text *result_text; + char *msg; if (persistent_conn != NULL) conn = persistent_conn; @@ -215,7 +215,7 @@ dblink_close(PG_FUNCTION_ARGS) /* close the cursor */ res = PQexec(conn, str->data); - if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { msg = pstrdup(PQerrorMessage(conn)); PQclear(res); @@ -253,31 +253,34 @@ PG_FUNCTION_INFO_V1(dblink_fetch); Datum dblink_fetch(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tupdesc = NULL; - int call_cntr; - int max_calls; - TupleTableSlot *slot; - AttInMetadata *attinmeta; - char *msg; - PGresult *res = NULL; - MemoryContext oldcontext; + FuncCallContext *funcctx; + TupleDesc tupdesc = NULL; + int call_cntr; + int max_calls; + TupleTableSlot *slot; + AttInMetadata *attinmeta; + char *msg; + PGresult *res = NULL; + MemoryContext oldcontext; /* stuff done only on the first call of the function */ - if(SRF_IS_FIRSTCALL()) - { - Oid functypeid; - char functyptype; - Oid funcid = fcinfo->flinfo->fn_oid; - PGconn *conn = NULL; - StringInfo str = makeStringInfo(); - char *curname = GET_STR(PG_GETARG_TEXT_P(0)); - int howmany = PG_GETARG_INT32(1); + if (SRF_IS_FIRSTCALL()) + { + Oid functypeid; + char functyptype; + Oid funcid = fcinfo->flinfo->fn_oid; + PGconn *conn = NULL; + StringInfo str = makeStringInfo(); + char *curname = GET_STR(PG_GETARG_TEXT_P(0)); + int howmany = PG_GETARG_INT32(1); /* create a function context for cross-call persistence */ - funcctx = SRF_FIRSTCALL_INIT(); + funcctx = SRF_FIRSTCALL_INIT(); - /* switch to memory context appropriate for multiple function calls */ + /* + * switch to memory context appropriate for multiple function + * calls + */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); if (persistent_conn != NULL) @@ -314,7 +317,7 @@ dblink_fetch(PG_FUNCTION_ARGS) /* fast track when no results */ if (funcctx->max_calls < 1) - SRF_RETURN_DONE(funcctx); + SRF_RETURN_DONE(funcctx); /* check typtype to see if we have a predetermined return type */ functypeid = get_func_rettype(funcid); @@ -336,10 +339,10 @@ dblink_fetch(PG_FUNCTION_ARGS) funcctx->attinmeta = attinmeta; MemoryContextSwitchTo(oldcontext); - } + } /* stuff done on every call of the function */ - funcctx = SRF_PERCALL_SETUP(); + funcctx = SRF_PERCALL_SETUP(); /* * initialize per-call variables @@ -354,12 +357,12 @@ dblink_fetch(PG_FUNCTION_ARGS) tupdesc = attinmeta->tupdesc; if (call_cntr < max_calls) /* do when there is more left to send */ - { + { char **values; HeapTuple tuple; Datum result; - int i; - int nfields = PQnfields(res); + int i; + int nfields = PQnfields(res); values = (char **) palloc(nfields * sizeof(char *)); for (i = 0; i < nfields; i++) @@ -376,12 +379,13 @@ dblink_fetch(PG_FUNCTION_ARGS) /* make the tuple into a datum */ result = TupleGetDatum(slot, tuple); - SRF_RETURN_NEXT(funcctx, result); + SRF_RETURN_NEXT(funcctx, result); } - else /* do when there is no more left */ + else +/* do when there is no more left */ { PQclear(res); - SRF_RETURN_DONE(funcctx); + SRF_RETURN_DONE(funcctx); } } @@ -392,32 +396,35 @@ PG_FUNCTION_INFO_V1(dblink_record); Datum dblink_record(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc tupdesc = NULL; - int call_cntr; - int max_calls; - TupleTableSlot *slot; - AttInMetadata *attinmeta; - char *msg; - PGresult *res = NULL; - bool is_sql_cmd = false; - char *sql_cmd_status = NULL; - MemoryContext oldcontext; + FuncCallContext *funcctx; + TupleDesc tupdesc = NULL; + int call_cntr; + int max_calls; + TupleTableSlot *slot; + AttInMetadata *attinmeta; + char *msg; + PGresult *res = NULL; + bool is_sql_cmd = false; + char *sql_cmd_status = NULL; + MemoryContext oldcontext; /* stuff done only on the first call of the function */ - if(SRF_IS_FIRSTCALL()) - { - Oid functypeid; - char functyptype; - Oid funcid = fcinfo->flinfo->fn_oid; - PGconn *conn = NULL; - char *connstr = NULL; - char *sql = NULL; + if (SRF_IS_FIRSTCALL()) + { + Oid functypeid; + char functyptype; + Oid funcid = fcinfo->flinfo->fn_oid; + PGconn *conn = NULL; + char *connstr = NULL; + char *sql = NULL; /* create a function context for cross-call persistence */ - funcctx = SRF_FIRSTCALL_INIT(); + funcctx = SRF_FIRSTCALL_INIT(); - /* switch to memory context appropriate for multiple function calls */ + /* + * switch to memory context appropriate for multiple function + * calls + */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); if (fcinfo->nargs == 2) @@ -487,7 +494,7 @@ dblink_record(PG_FUNCTION_ARGS) /* fast track when no results */ if (funcctx->max_calls < 1) - SRF_RETURN_DONE(funcctx); + SRF_RETURN_DONE(funcctx); /* check typtype to see if we have a predetermined return type */ functypeid = get_func_rettype(funcid); @@ -512,10 +519,10 @@ dblink_record(PG_FUNCTION_ARGS) funcctx->attinmeta = attinmeta; MemoryContextSwitchTo(oldcontext); - } + } /* stuff done on every call of the function */ - funcctx = SRF_PERCALL_SETUP(); + funcctx = SRF_PERCALL_SETUP(); /* * initialize per-call variables @@ -530,15 +537,15 @@ dblink_record(PG_FUNCTION_ARGS) tupdesc = attinmeta->tupdesc; if (call_cntr < max_calls) /* do when there is more left to send */ - { + { char **values; HeapTuple tuple; Datum result; if (!is_sql_cmd) { - int i; - int nfields = PQnfields(res); + int i; + int nfields = PQnfields(res); values = (char **) palloc(nfields * sizeof(char *)); for (i = 0; i < nfields; i++) @@ -561,12 +568,13 @@ dblink_record(PG_FUNCTION_ARGS) /* make the tuple into a datum */ result = TupleGetDatum(slot, tuple); - SRF_RETURN_NEXT(funcctx, result); + SRF_RETURN_NEXT(funcctx, result); } - else /* do when there is no more left */ + else +/* do when there is no more left */ { PQclear(res); - SRF_RETURN_DONE(funcctx); + SRF_RETURN_DONE(funcctx); } } @@ -577,14 +585,14 @@ PG_FUNCTION_INFO_V1(dblink_exec); Datum dblink_exec(PG_FUNCTION_ARGS) { - char *msg; - PGresult *res = NULL; - char *sql_cmd_status = NULL; - TupleDesc tupdesc = NULL; - text *result_text; - PGconn *conn = NULL; - char *connstr = NULL; - char *sql = NULL; + char *msg; + PGresult *res = NULL; + char *sql_cmd_status = NULL; + TupleDesc tupdesc = NULL; + text *result_text; + PGconn *conn = NULL; + char *connstr = NULL; + char *sql = NULL; if (fcinfo->nargs == 2) { @@ -633,8 +641,8 @@ dblink_exec(PG_FUNCTION_ARGS) TEXTOID, -1, 0, false); /* - * and save a copy of the command status string to return - * as our result tuple + * and save a copy of the command status string to return as + * our result tuple */ sql_cmd_status = PQcmdStatus(res); } @@ -659,15 +667,15 @@ PG_FUNCTION_INFO_V1(dblink); Datum dblink(PG_FUNCTION_ARGS) { - PGconn *conn = NULL; - PGresult *res = NULL; - dblink_results *results; - char *optstr; - char *sqlstatement; - char *execstatement; - char *msg; - int ntuples = 0; - ReturnSetInfo *rsi; + PGconn *conn = NULL; + PGresult *res = NULL; + dblink_results *results; + char *optstr; + char *sqlstatement; + char *execstatement; + char *msg; + int ntuples = 0; + ReturnSetInfo *rsi; if (fcinfo->resultinfo == NULL || !IsA(fcinfo->resultinfo, ReturnSetInfo)) elog(ERROR, "dblink: function called in context that does not accept a set result"); @@ -721,8 +729,8 @@ dblink(PG_FUNCTION_ARGS) results->res = res; /* - * Append node to res_id to hold pointer to results. - * Needed by dblink_tok to access the data + * Append node to res_id to hold pointer to results. Needed by + * dblink_tok to access the data */ append_res_ptr(results); @@ -797,11 +805,11 @@ Datum dblink_tok(PG_FUNCTION_ARGS) { dblink_results *results; - int fldnum; - text *result_text; - char *result; - int nfields = 0; - int text_len = 0; + int fldnum; + text *result_text; + char *result; + int nfields = 0; + int text_len = 0; results = get_res_ptr(PG_GETARG_INT32(0)); if (results == NULL) @@ -848,7 +856,7 @@ dblink_tok(PG_FUNCTION_ARGS) /* * dblink_get_pkey - * + * * Return list of primary key fields for the supplied relation, * or NULL if none exists. */ @@ -856,25 +864,28 @@ PG_FUNCTION_INFO_V1(dblink_get_pkey); Datum dblink_get_pkey(PG_FUNCTION_ARGS) { - int16 numatts; - Oid relid; - char **results; - FuncCallContext *funcctx; - int32 call_cntr; - int32 max_calls; - TupleTableSlot *slot; - AttInMetadata *attinmeta; - MemoryContext oldcontext; + int16 numatts; + Oid relid; + char **results; + FuncCallContext *funcctx; + int32 call_cntr; + int32 max_calls; + TupleTableSlot *slot; + AttInMetadata *attinmeta; + MemoryContext oldcontext; /* stuff done only on the first call of the function */ - if(SRF_IS_FIRSTCALL()) - { - TupleDesc tupdesc = NULL; + if (SRF_IS_FIRSTCALL()) + { + TupleDesc tupdesc = NULL; /* create a function context for cross-call persistence */ - funcctx = SRF_FIRSTCALL_INIT(); + funcctx = SRF_FIRSTCALL_INIT(); - /* switch to memory context appropriate for multiple function calls */ + /* + * switch to memory context appropriate for multiple function + * calls + */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); /* convert relname to rel Oid */ @@ -882,7 +893,10 @@ dblink_get_pkey(PG_FUNCTION_ARGS) if (!OidIsValid(relid)) elog(ERROR, "dblink_get_pkey: relation does not exist"); - /* need a tuple descriptor representing one INT and one TEXT column */ + /* + * need a tuple descriptor representing one INT and one TEXT + * column + */ tupdesc = CreateTemplateTupleDesc(2, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "position", INT4OID, -1, 0, false); @@ -896,8 +910,8 @@ dblink_get_pkey(PG_FUNCTION_ARGS) funcctx->slot = slot; /* - * Generate attribute metadata needed later to produce tuples from raw - * C strings + * Generate attribute metadata needed later to produce tuples from + * raw C strings */ attinmeta = TupleDescGetAttInMetadata(tupdesc); funcctx->attinmeta = attinmeta; @@ -912,14 +926,15 @@ dblink_get_pkey(PG_FUNCTION_ARGS) /* got results, keep track of them */ funcctx->user_fctx = results; } - else /* fast track when no results */ - SRF_RETURN_DONE(funcctx); + else +/* fast track when no results */ + SRF_RETURN_DONE(funcctx); MemoryContextSwitchTo(oldcontext); - } + } /* stuff done on every call of the function */ - funcctx = SRF_PERCALL_SETUP(); + funcctx = SRF_PERCALL_SETUP(); /* * initialize per-call variables @@ -933,13 +948,13 @@ dblink_get_pkey(PG_FUNCTION_ARGS) attinmeta = funcctx->attinmeta; if (call_cntr < max_calls) /* do when there is more left to send */ - { + { char **values; HeapTuple tuple; Datum result; values = (char **) palloc(2 * sizeof(char *)); - values[0] = (char *) palloc(12); /* sign, 10 digits, '\0' */ + values[0] = (char *) palloc(12); /* sign, 10 digits, '\0' */ sprintf(values[0], "%d", call_cntr + 1); @@ -951,10 +966,11 @@ dblink_get_pkey(PG_FUNCTION_ARGS) /* make the tuple into a datum */ result = TupleGetDatum(slot, tuple); - SRF_RETURN_NEXT(funcctx, result); + SRF_RETURN_NEXT(funcctx, result); } - else /* do when there is no more left */ - SRF_RETURN_DONE(funcctx); + else +/* do when there is no more left */ + SRF_RETURN_DONE(funcctx); } /* @@ -989,7 +1005,7 @@ dblink_last_oid(PG_FUNCTION_ARGS) /* * dblink_build_sql_insert - * + * * Used to generate an SQL insert statement * based on an existing tuple in a local relation. * This is useful for selectively replicating data @@ -1022,7 +1038,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) int *src_dim; int src_nitems; int tgt_ndim; - int *tgt_dim; + int *tgt_dim; int tgt_nitems; int i; char *ptr; @@ -1043,6 +1059,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) pkattnums = (int16 *) PG_GETARG_POINTER(1); pknumatts = PG_GETARG_INT16(2); + /* * There should be at least one key attribute */ @@ -1053,8 +1070,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4); /* - * Source array is made up of key values that will be used to - * locate the tuple of interest from the local system. + * Source array is made up of key values that will be used to locate + * the tuple of interest from the local system. */ src_ndim = ARR_NDIM(src_pkattvals_arry); src_dim = ARR_DIMS(src_pkattvals_arry); @@ -1071,7 +1088,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) */ Assert(ARR_ELEMTYPE(src_pkattvals_arry) == TEXTOID); get_typlenbyvalalign(ARR_ELEMTYPE(src_pkattvals_arry), - &typlen, &typbyval, &typalign); + &typlen, &typbyval, &typalign); src_pkattvals = (char **) palloc(src_nitems * sizeof(char *)); ptr = ARR_DATA_PTR(src_pkattvals_arry); @@ -1083,8 +1100,8 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) } /* - * Target array is made up of key values that will be used to - * build the SQL string for use on the remote system. + * Target array is made up of key values that will be used to build + * the SQL string for use on the remote system. */ tgt_ndim = ARR_NDIM(tgt_pkattvals_arry); tgt_dim = ARR_DIMS(tgt_pkattvals_arry); @@ -1101,7 +1118,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) */ Assert(ARR_ELEMTYPE(tgt_pkattvals_arry) == TEXTOID); get_typlenbyvalalign(ARR_ELEMTYPE(tgt_pkattvals_arry), - &typlen, &typbyval, &typalign); + &typlen, &typbyval, &typalign); tgt_pkattvals = (char **) palloc(tgt_nitems * sizeof(char *)); ptr = ARR_DATA_PTR(tgt_pkattvals_arry); @@ -1131,7 +1148,7 @@ dblink_build_sql_insert(PG_FUNCTION_ARGS) /* * dblink_build_sql_delete - * + * * Used to generate an SQL delete statement. * This is useful for selectively replicating a * delete to another server via dblink. @@ -1149,18 +1166,18 @@ Datum dblink_build_sql_delete(PG_FUNCTION_ARGS) { Oid relid; - text *relname_text; - int16 *pkattnums; + text *relname_text; + int16 *pkattnums; int16 pknumatts; - char **tgt_pkattvals; - ArrayType *tgt_pkattvals_arry; + char **tgt_pkattvals; + ArrayType *tgt_pkattvals_arry; int tgt_ndim; - int *tgt_dim; + int *tgt_dim; int tgt_nitems; int i; - char *ptr; - char *sql; - text *sql_text; + char *ptr; + char *sql; + text *sql_text; int16 typlen; bool typbyval; char typalign; @@ -1176,6 +1193,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) pkattnums = (int16 *) PG_GETARG_POINTER(1); pknumatts = PG_GETARG_INT16(2); + /* * There should be at least one key attribute */ @@ -1185,8 +1203,8 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(3); /* - * Target array is made up of key values that will be used to - * build the SQL string for use on the remote system. + * Target array is made up of key values that will be used to build + * the SQL string for use on the remote system. */ tgt_ndim = ARR_NDIM(tgt_pkattvals_arry); tgt_dim = ARR_DIMS(tgt_pkattvals_arry); @@ -1203,7 +1221,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) */ Assert(ARR_ELEMTYPE(tgt_pkattvals_arry) == TEXTOID); get_typlenbyvalalign(ARR_ELEMTYPE(tgt_pkattvals_arry), - &typlen, &typbyval, &typalign); + &typlen, &typbyval, &typalign); tgt_pkattvals = (char **) palloc(tgt_nitems * sizeof(char *)); ptr = ARR_DATA_PTR(tgt_pkattvals_arry); @@ -1233,7 +1251,7 @@ dblink_build_sql_delete(PG_FUNCTION_ARGS) /* * dblink_build_sql_update - * + * * Used to generate an SQL update statement * based on an existing tuple in a local relation. * This is useful for selectively replicating data @@ -1255,23 +1273,23 @@ Datum dblink_build_sql_update(PG_FUNCTION_ARGS) { Oid relid; - text *relname_text; - int16 *pkattnums; + text *relname_text; + int16 *pkattnums; int16 pknumatts; - char **src_pkattvals; - char **tgt_pkattvals; - ArrayType *src_pkattvals_arry; - ArrayType *tgt_pkattvals_arry; + char **src_pkattvals; + char **tgt_pkattvals; + ArrayType *src_pkattvals_arry; + ArrayType *tgt_pkattvals_arry; int src_ndim; - int *src_dim; + int *src_dim; int src_nitems; int tgt_ndim; - int *tgt_dim; + int *tgt_dim; int tgt_nitems; int i; - char *ptr; - char *sql; - text *sql_text; + char *ptr; + char *sql; + text *sql_text; int16 typlen; bool typbyval; char typalign; @@ -1287,6 +1305,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) pkattnums = (int16 *) PG_GETARG_POINTER(1); pknumatts = PG_GETARG_INT16(2); + /* * There should be one source array key values for each key attnum */ @@ -1297,8 +1316,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) tgt_pkattvals_arry = PG_GETARG_ARRAYTYPE_P(4); /* - * Source array is made up of key values that will be used to - * locate the tuple of interest from the local system. + * Source array is made up of key values that will be used to locate + * the tuple of interest from the local system. */ src_ndim = ARR_NDIM(src_pkattvals_arry); src_dim = ARR_DIMS(src_pkattvals_arry); @@ -1315,7 +1334,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) */ Assert(ARR_ELEMTYPE(src_pkattvals_arry) == TEXTOID); get_typlenbyvalalign(ARR_ELEMTYPE(src_pkattvals_arry), - &typlen, &typbyval, &typalign); + &typlen, &typbyval, &typalign); src_pkattvals = (char **) palloc(src_nitems * sizeof(char *)); ptr = ARR_DATA_PTR(src_pkattvals_arry); @@ -1327,8 +1346,8 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) } /* - * Target array is made up of key values that will be used to - * build the SQL string for use on the remote system. + * Target array is made up of key values that will be used to build + * the SQL string for use on the remote system. */ tgt_ndim = ARR_NDIM(tgt_pkattvals_arry); tgt_dim = ARR_DIMS(tgt_pkattvals_arry); @@ -1345,7 +1364,7 @@ dblink_build_sql_update(PG_FUNCTION_ARGS) */ Assert(ARR_ELEMTYPE(tgt_pkattvals_arry) == TEXTOID); get_typlenbyvalalign(ARR_ELEMTYPE(tgt_pkattvals_arry), - &typlen, &typbyval, &typalign); + &typlen, &typbyval, &typalign); tgt_pkattvals = (char **) palloc(tgt_nitems * sizeof(char *)); ptr = ARR_DATA_PTR(tgt_pkattvals_arry); @@ -1382,7 +1401,7 @@ PG_FUNCTION_INFO_V1(dblink_current_query); Datum dblink_current_query(PG_FUNCTION_ARGS) { - text *result_text; + text *result_text; result_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(debug_query_string))); PG_RETURN_TEXT_P(result_text); @@ -1410,7 +1429,7 @@ init_dblink_results(MemoryContext fn_mcxt) MemSet(retval, 0, sizeof(dblink_results)); retval->tup_num = -1; - retval->res_id_index =-1; + retval->res_id_index = -1; retval->res = NULL; MemoryContextSwitchTo(oldcontext); @@ -1420,21 +1439,21 @@ init_dblink_results(MemoryContext fn_mcxt) /* * get_pkey_attnames - * + * * Get the primary key attnames for the given relation. * Return NULL, and set numatts = 0, if no primary key exists. */ static char ** get_pkey_attnames(Oid relid, int16 *numatts) { - Relation indexRelation; - ScanKeyData entry; - HeapScanDesc scan; - HeapTuple indexTuple; - int i; - char **result = NULL; - Relation rel; - TupleDesc tupdesc; + Relation indexRelation; + ScanKeyData entry; + HeapScanDesc scan; + HeapTuple indexTuple; + int i; + char **result = NULL; + Relation rel; + TupleDesc tupdesc; /* open relation using relid, get tupdesc */ rel = relation_open(relid, AccessShareLock); @@ -1451,7 +1470,7 @@ get_pkey_attnames(Oid relid, int16 *numatts) while ((indexTuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { - Form_pg_index index = (Form_pg_index) GETSTRUCT(indexTuple); + Form_pg_index index = (Form_pg_index) GETSTRUCT(indexTuple); /* we're only interested if it is the primary key */ if (index->indisprimary == TRUE) @@ -1480,23 +1499,23 @@ get_pkey_attnames(Oid relid, int16 *numatts) static char * get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals) { - Relation rel; - char *relname; - HeapTuple tuple; - TupleDesc tupdesc; - int natts; - StringInfo str = makeStringInfo(); - char *sql; - char *val; - int16 key; - int i; - bool needComma; + Relation rel; + char *relname; + HeapTuple tuple; + TupleDesc tupdesc; + int natts; + StringInfo str = makeStringInfo(); + char *sql; + char *val; + int16 key; + int i; + bool needComma; /* * Open relation using relid */ rel = relation_open(relid, AccessShareLock); - relname = RelationGetRelationName(rel); + relname = RelationGetRelationName(rel); tupdesc = rel->rd_att; natts = tupdesc->natts; @@ -1516,7 +1535,7 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval appendStringInfo(str, ","); appendStringInfo(str, "%s", - quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname))); + quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname))); needComma = true; } @@ -1566,33 +1585,33 @@ get_sql_insert(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval static char * get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattvals) { - Relation rel; - char *relname; - TupleDesc tupdesc; - int natts; - StringInfo str = makeStringInfo(); - char *sql; - char *val; - int i; + Relation rel; + char *relname; + TupleDesc tupdesc; + int natts; + StringInfo str = makeStringInfo(); + char *sql; + char *val; + int i; /* * Open relation using relid */ rel = relation_open(relid, AccessShareLock); - relname = RelationGetRelationName(rel); + relname = RelationGetRelationName(rel); tupdesc = rel->rd_att; natts = tupdesc->natts; appendStringInfo(str, "DELETE FROM %s WHERE ", quote_ident_cstr(relname)); for (i = 0; i < pknumatts; i++) { - int16 pkattnum = pkattnums[i]; + int16 pkattnum = pkattnums[i]; if (i > 0) appendStringInfo(str, " AND "); appendStringInfo(str, "%s", - quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname))); + quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname))); if (tgt_pkattvals != NULL) val = pstrdup(tgt_pkattvals[i]); @@ -1622,23 +1641,23 @@ get_sql_delete(Oid relid, int16 *pkattnums, int16 pknumatts, char **tgt_pkattval static char * get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals) { - Relation rel; - char *relname; - HeapTuple tuple; - TupleDesc tupdesc; - int natts; - StringInfo str = makeStringInfo(); - char *sql; - char *val; - int16 key; - int i; - bool needComma; + Relation rel; + char *relname; + HeapTuple tuple; + TupleDesc tupdesc; + int natts; + StringInfo str = makeStringInfo(); + char *sql; + char *val; + int16 key; + int i; + bool needComma; /* * Open relation using relid */ rel = relation_open(relid, AccessShareLock); - relname = RelationGetRelationName(rel); + relname = RelationGetRelationName(rel); tupdesc = rel->rd_att; natts = tupdesc->natts; @@ -1658,7 +1677,7 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval appendStringInfo(str, ", "); appendStringInfo(str, "%s = ", - quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname))); + quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname))); if (tgt_pkattvals != NULL) key = get_attnum_pk_pos(pkattnums, pknumatts, i + 1); @@ -1684,13 +1703,13 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval for (i = 0; i < pknumatts; i++) { - int16 pkattnum = pkattnums[i]; + int16 pkattnum = pkattnums[i]; if (i > 0) appendStringInfo(str, " AND "); appendStringInfo(str, "%s", - quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname))); + quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname))); if (tgt_pkattvals != NULL) val = pstrdup(tgt_pkattvals[i]); @@ -1721,9 +1740,9 @@ get_sql_update(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattval static char * quote_literal_cstr(char *rawstr) { - text *rawstr_text; - text *result_text; - char *result; + text *rawstr_text; + text *result_text; + char *result; rawstr_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(rawstr))); result_text = DatumGetTextP(DirectFunctionCall1(quote_literal, PointerGetDatum(rawstr_text))); @@ -1739,9 +1758,9 @@ quote_literal_cstr(char *rawstr) static char * quote_ident_cstr(char *rawstr) { - text *rawstr_text; - text *result_text; - char *result; + text *rawstr_text; + text *result_text; + char *result; rawstr_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(rawstr))); result_text = DatumGetTextP(DirectFunctionCall1(quote_ident, PointerGetDatum(rawstr_text))); @@ -1753,11 +1772,10 @@ quote_ident_cstr(char *rawstr) static int16 get_attnum_pk_pos(int16 *pkattnums, int16 pknumatts, int16 key) { - int i; + int i; /* - * Not likely a long list anyway, so just scan for - * the value + * Not likely a long list anyway, so just scan for the value */ for (i = 0; i < pknumatts; i++) if (key == pkattnums[i]) @@ -1769,21 +1787,21 @@ get_attnum_pk_pos(int16 *pkattnums, int16 pknumatts, int16 key) static HeapTuple get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_pkattvals) { - Relation rel; - char *relname; - TupleDesc tupdesc; - StringInfo str = makeStringInfo(); - char *sql = NULL; - int ret; - HeapTuple tuple; - int i; - char *val = NULL; + Relation rel; + char *relname; + TupleDesc tupdesc; + StringInfo str = makeStringInfo(); + char *sql = NULL; + int ret; + HeapTuple tuple; + int i; + char *val = NULL; /* * Open relation using relid */ rel = relation_open(relid, AccessShareLock); - relname = RelationGetRelationName(rel); + relname = RelationGetRelationName(rel); tupdesc = CreateTupleDescCopy(rel->rd_att); relation_close(rel, AccessShareLock); @@ -1794,20 +1812,20 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p elog(ERROR, "get_tuple_of_interest: SPI_connect returned %d", ret); /* - * Build sql statement to look up tuple of interest - * Use src_pkattvals as the criteria. + * Build sql statement to look up tuple of interest Use src_pkattvals + * as the criteria. */ appendStringInfo(str, "SELECT * FROM %s WHERE ", quote_ident_cstr(relname)); for (i = 0; i < pknumatts; i++) { - int16 pkattnum = pkattnums[i]; + int16 pkattnum = pkattnums[i]; if (i > 0) appendStringInfo(str, " AND "); appendStringInfo(str, "%s", - quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname))); + quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname))); val = pstrdup(src_pkattvals[i]); if (val != NULL) @@ -1822,6 +1840,7 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p sql = pstrdup(str->data); pfree(str->data); pfree(str); + /* * Retrieve the desired tuple */ @@ -1832,12 +1851,11 @@ get_tuple_of_interest(Oid relid, int16 *pkattnums, int16 pknumatts, char **src_p * Only allow one qualifying tuple */ if ((ret == SPI_OK_SELECT) && (SPI_processed > 1)) - { elog(ERROR, "get_tuple_of_interest: Source criteria may not match more than one record."); - } else if (ret == SPI_OK_SELECT && SPI_processed == 1) { SPITupleTable *tuptable = SPI_tuptable; + tuple = SPI_copytuple(tuptable->vals[0]); return tuple; @@ -1871,15 +1889,15 @@ get_relid_from_relname(text *relname_text) return relid; } -static dblink_results * +static dblink_results * get_res_ptr(int32 res_id_index) { - List *ptr; + List *ptr; /* * short circuit empty list */ - if(res_id == NIL) + if (res_id == NIL) return NULL; /* @@ -1887,7 +1905,8 @@ get_res_ptr(int32 res_id_index) */ foreach(ptr, res_id) { - dblink_results *this_res_id = (dblink_results *) lfirst(ptr); + dblink_results *this_res_id = (dblink_results *) lfirst(ptr); + if (this_res_id->res_id_index == res_id_index) return this_res_id; } @@ -1898,7 +1917,7 @@ get_res_ptr(int32 res_id_index) * Add node to global List res_id */ static void -append_res_ptr(dblink_results *results) +append_res_ptr(dblink_results * results) { res_id = lappend(res_id, results); } @@ -1908,7 +1927,7 @@ append_res_ptr(dblink_results *results) * using res_id_index */ static void -remove_res_ptr(dblink_results *results) +remove_res_ptr(dblink_results * results) { res_id = lremove(results, res_id); @@ -1919,15 +1938,15 @@ remove_res_ptr(dblink_results *results) static TupleDesc pgresultGetTupleDesc(PGresult *res) { - int natts; - AttrNumber attnum; - TupleDesc desc; - char *attname; - int32 atttypmod; - int attdim; - bool attisset; - Oid atttypid; - int i; + int natts; + AttrNumber attnum; + TupleDesc desc; + char *attname; + int32 atttypmod; + int attdim; + bool attisset; + Oid atttypid; + int i; /* * allocate a new tuple descriptor @@ -1943,8 +1962,8 @@ pgresultGetTupleDesc(PGresult *res) for (i = 0; i < natts; i++) { /* - * for each field, get the name and type information from the query - * result and have TupleDescInitEntry fill in the attribute + * for each field, get the name and type information from the + * query result and have TupleDescInitEntry fill in the attribute * information we need. */ attnum++; @@ -1955,9 +1974,9 @@ pgresultGetTupleDesc(PGresult *res) if (PQfsize(res, i) != get_typlen(atttypid)) elog(ERROR, "Size of remote field \"%s\" does not match size " - "of local type \"%s\"", - attname, - format_type_with_typemod(atttypid, atttypmod)); + "of local type \"%s\"", + attname, + format_type_with_typemod(atttypid, atttypmod)); attdim = 0; attisset = false; diff --git a/contrib/dblink/dblink.h b/contrib/dblink/dblink.h index ddca6241c4..09f9321bd6 100644 --- a/contrib/dblink/dblink.h +++ b/contrib/dblink/dblink.h @@ -74,6 +74,6 @@ extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS); extern Datum dblink_build_sql_update(PG_FUNCTION_ARGS); extern Datum dblink_current_query(PG_FUNCTION_ARGS); -extern char *debug_query_string; +extern char *debug_query_string; #endif /* DBLINK_H */ diff --git a/contrib/dbmirror/pending.c b/contrib/dbmirror/pending.c index a9027dbe50..82aaffa15e 100644 --- a/contrib/dbmirror/pending.c +++ b/contrib/dbmirror/pending.c @@ -1,20 +1,20 @@ /**************************************************************************** * pending.c - * $Id: pending.c,v 1.1 2002/06/23 21:58:08 momjian Exp $ + * $Id: pending.c,v 1.2 2002/09/04 20:31:06 momjian Exp $ * * This file contains a trigger for Postgresql-7.x to record changes to tables * to a pending table for mirroring. * All tables that should be mirrored should have this trigger hooked up to it. * - * Written by Steven Singer ([email protected]) - * (c) 2001-2002 Navtech Systems Support Inc. - * Released under the GNU Public License version 2. See COPYING. + * Written by Steven Singer ([email protected]) + * (c) 2001-2002 Navtech Systems Support Inc. + * Released under the GNU Public License version 2. See COPYING. * * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * ***************************************************************************/ @@ -22,29 +22,33 @@ #include <commands/trigger.h> #include <postgres.h> -enum FieldUsage {PRIMARY=0,NONPRIMARY,ALL,NUM_FIELDUSAGE}; +enum FieldUsage +{ + PRIMARY = 0, NONPRIMARY, ALL, NUM_FIELDUSAGE +}; -int storePending(char * cpTableName, HeapTuple tBeforeTuple, - HeapTuple tAfterTuple, - TupleDesc tTupdesc, - TriggerData * tpTrigdata,char cOp); +int storePending(char *cpTableName, HeapTuple tBeforeTuple, + HeapTuple tAfterTuple, + TupleDesc tTupdesc, + TriggerData *tpTrigdata, char cOp); -int storeKeyInfo(char * cpTableName, HeapTuple tTupleData, TupleDesc tTuplDesc, - TriggerData * tpTrigdata); -int storeData(char * cpTableName,HeapTuple tTupleData,TupleDesc tTupleDesc, - TriggerData * tpTrigData,int iIncludeKeyData); - -int2vector * getPrimaryKey(Oid tblOid); +int storeKeyInfo(char *cpTableName, HeapTuple tTupleData, TupleDesc tTuplDesc, + TriggerData *tpTrigdata); +int storeData(char *cpTableName, HeapTuple tTupleData, TupleDesc tTupleDesc, + TriggerData *tpTrigData, int iIncludeKeyData); -char * packageData(HeapTuple tTupleData, TupleDesc tTupleDecs, - TriggerData * tTrigData, - enum FieldUsage eKeyUsage ); +int2vector *getPrimaryKey(Oid tblOid); + +char *packageData(HeapTuple tTupleData, TupleDesc tTupleDecs, + TriggerData *tTrigData, + enum FieldUsage eKeyUsage); #define BUFFER_SIZE 256 #define MAX_OID_LEN 10 extern Datum recordchange(PG_FUNCTION_ARGS); + PG_FUNCTION_INFO_V1(recordchange); @@ -54,394 +58,430 @@ PG_FUNCTION_INFO_V1(recordchange); * table the trigger was applied to. If this name is incorrect so will the * mirroring. ****************************************************************************/ -Datum recordchange(PG_FUNCTION_ARGS) { - TriggerData * trigdata; - TupleDesc tupdesc; - HeapTuple beforeTuple=NULL; - HeapTuple afterTuple=NULL; - HeapTuple retTuple=NULL; - char * tblname; - char op; - if(fcinfo->context!=NULL) { - - if(SPI_connect() < 0) { - elog(NOTICE,"storePending could not connect to SPI"); - return -1; - } - trigdata = (TriggerData*)fcinfo->context; - /* Extract the table name */ - tblname = SPI_getrelname(trigdata->tg_relation); - tupdesc = trigdata->tg_relation->rd_att; - if(TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) { - retTuple = trigdata->tg_newtuple; - beforeTuple = trigdata->tg_trigtuple; - afterTuple = trigdata->tg_newtuple; - op='u'; - - } - else if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event)) { - retTuple = trigdata->tg_trigtuple; - afterTuple = trigdata->tg_trigtuple; - op = 'i'; - } - else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) { - retTuple = trigdata->tg_trigtuple; - beforeTuple = trigdata->tg_trigtuple; - op = 'd'; - } - - if(storePending(tblname,beforeTuple,afterTuple,tupdesc,trigdata,op)) { - /* An error occoured. Skip the operation. */ - elog(ERROR,"Operation could not be mirrored"); - return PointerGetDatum(NULL); - - } +Datum +recordchange(PG_FUNCTION_ARGS) +{ + TriggerData *trigdata; + TupleDesc tupdesc; + HeapTuple beforeTuple = NULL; + HeapTuple afterTuple = NULL; + HeapTuple retTuple = NULL; + char *tblname; + char op; + + if (fcinfo->context != NULL) + { + + if (SPI_connect() < 0) + { + elog(NOTICE, "storePending could not connect to SPI"); + return -1; + } + trigdata = (TriggerData *) fcinfo->context; + /* Extract the table name */ + tblname = SPI_getrelname(trigdata->tg_relation); + tupdesc = trigdata->tg_relation->rd_att; + if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) + { + retTuple = trigdata->tg_newtuple; + beforeTuple = trigdata->tg_trigtuple; + afterTuple = trigdata->tg_newtuple; + op = 'u'; + + } + else if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event)) + { + retTuple = trigdata->tg_trigtuple; + afterTuple = trigdata->tg_trigtuple; + op = 'i'; + } + else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event)) + { + retTuple = trigdata->tg_trigtuple; + beforeTuple = trigdata->tg_trigtuple; + op = 'd'; + } + + if (storePending(tblname, beforeTuple, afterTuple, tupdesc, trigdata, op)) + { + /* An error occoured. Skip the operation. */ + elog(ERROR, "Operation could not be mirrored"); + return PointerGetDatum(NULL); + + } #if defined DEBUG_OUTPUT - elog(NOTICE,"Returning on success"); + elog(NOTICE, "Returning on success"); #endif - SPI_finish(); - return PointerGetDatum(retTuple); - } - else { - /* - * Not being called as a trigger. - */ - return PointerGetDatum(NULL); - } + SPI_finish(); + return PointerGetDatum(retTuple); + } + else + { + /* + * Not being called as a trigger. + */ + return PointerGetDatum(NULL); + } } /***************************************************************************** * Constructs and executes an SQL query to write a record of this tuple change - * to the pending table. + * to the pending table. *****************************************************************************/ -int storePending(char * cpTableName, HeapTuple tBeforeTuple, - HeapTuple tAfterTuple, - TupleDesc tTupDesc, - TriggerData * tpTrigData,char cOp) { - char * cpQueryBase = "INSERT INTO \"Pending\" (\"TableName\",\"Op\",\"XID\") VALUES ($1,$2,$3)"; - - int iResult=0; - HeapTuple tCurTuple; // Points the current tuple(before or after) - Datum saPlanData[4]; - Oid taPlanArgTypes[3] = {NAMEOID,CHAROID,INT4OID}; - void * vpPlan; - - tCurTuple = tBeforeTuple ? tBeforeTuple : tAfterTuple; - - - - - vpPlan = SPI_prepare(cpQueryBase,3,taPlanArgTypes); - if(vpPlan==NULL) { - elog(NOTICE,"Error creating plan"); - } - // SPI_saveplan(vpPlan); - - saPlanData[0] = PointerGetDatum(cpTableName); - saPlanData[1] = CharGetDatum(cOp); - saPlanData[2] = Int32GetDatum(GetCurrentTransactionId()); - - - iResult = SPI_execp(vpPlan,saPlanData,NULL,1); - if(iResult < 0) { - elog(NOTICE,"storedPending fired (%s) returned %d",cpQueryBase,iResult); - } - +int +storePending(char *cpTableName, HeapTuple tBeforeTuple, + HeapTuple tAfterTuple, + TupleDesc tTupDesc, + TriggerData *tpTrigData, char cOp) +{ + char *cpQueryBase = "INSERT INTO \"Pending\" (\"TableName\",\"Op\",\"XID\") VALUES ($1,$2,$3)"; + + int iResult = 0; + HeapTuple tCurTuple; + + //Points the current tuple(before or after) + Datum saPlanData[4]; + Oid taPlanArgTypes[3] = {NAMEOID, CHAROID, INT4OID}; + void *vpPlan; + + tCurTuple = tBeforeTuple ? tBeforeTuple : tAfterTuple; + + + + + vpPlan = SPI_prepare(cpQueryBase, 3, taPlanArgTypes); + if (vpPlan == NULL) + elog(NOTICE, "Error creating plan"); + /* SPI_saveplan(vpPlan); */ + + saPlanData[0] = PointerGetDatum(cpTableName); + saPlanData[1] = CharGetDatum(cOp); + saPlanData[2] = Int32GetDatum(GetCurrentTransactionId()); + + + iResult = SPI_execp(vpPlan, saPlanData, NULL, 1); + if (iResult < 0) + elog(NOTICE, "storedPending fired (%s) returned %d", cpQueryBase, iResult); + #if defined DEBUG_OUTPUT - elog(NOTICE,"row successfully stored in pending table"); + elog(NOTICE, "row successfully stored in pending table"); #endif - if(cOp=='d') { - /** - * This is a record of a delete operation. - * Just store the key data. - */ - iResult = storeKeyInfo(cpTableName,tBeforeTuple,tTupDesc,tpTrigData); - } - else if (cOp=='i') { - /** - * An Insert operation. - * Store all data - */ - iResult = storeData(cpTableName,tAfterTuple,tTupDesc,tpTrigData,TRUE); - - } - else { - /* op must be an update. */ - iResult = storeKeyInfo(cpTableName,tBeforeTuple,tTupDesc,tpTrigData); - iResult = iResult ? iResult : storeData(cpTableName,tAfterTuple,tTupDesc, - tpTrigData,TRUE); - } + if (cOp == 'd') + { + /** + * This is a record of a delete operation. + * Just store the key data. + */ + iResult = storeKeyInfo(cpTableName, tBeforeTuple, tTupDesc, tpTrigData); + } + else if (cOp == 'i') + { + /** + * An Insert operation. + * Store all data + */ + iResult = storeData(cpTableName, tAfterTuple, tTupDesc, tpTrigData, TRUE); + + } + else + { + /* op must be an update. */ + iResult = storeKeyInfo(cpTableName, tBeforeTuple, tTupDesc, tpTrigData); + iResult = iResult ? iResult : storeData(cpTableName, tAfterTuple, tTupDesc, + tpTrigData, TRUE); + } #if defined DEBUG_OUTPUT - elog(NOTICE,"DOne storing keyinfo"); + elog(NOTICE, "DOne storing keyinfo"); #endif - - return iResult; + + return iResult; } -int storeKeyInfo(char * cpTableName, HeapTuple tTupleData, - TupleDesc tTupleDesc, - TriggerData * tpTrigData) { - - Oid saPlanArgTypes[1] = {NAMEOID}; - char * insQuery = "INSERT INTO \"PendingData\" (\"SeqId\",\"IsKey\",\"Data\") VALUES(currval('\"Pending_SeqId_seq\"'),'t',$1)"; - void * pplan; - Datum saPlanData[1]; - char * cpKeyData; - int iRetCode; - - pplan = SPI_prepare(insQuery,1,saPlanArgTypes); - if(pplan==NULL) { - elog(NOTICE,"Could not prepare INSERT plan"); - return -1; - } - - // pplan = SPI_saveplan(pplan); - cpKeyData = packageData(tTupleData, tTupleDesc,tpTrigData,PRIMARY); +int +storeKeyInfo(char *cpTableName, HeapTuple tTupleData, + TupleDesc tTupleDesc, + TriggerData *tpTrigData) +{ + + Oid saPlanArgTypes[1] = {NAMEOID}; + char *insQuery = "INSERT INTO \"PendingData\" (\"SeqId\",\"IsKey\",\"Data\") VALUES(currval('\"Pending_SeqId_seq\"'),'t',$1)"; + void *pplan; + Datum saPlanData[1]; + char *cpKeyData; + int iRetCode; + + pplan = SPI_prepare(insQuery, 1, saPlanArgTypes); + if (pplan == NULL) + { + elog(NOTICE, "Could not prepare INSERT plan"); + return -1; + } + + /* pplan = SPI_saveplan(pplan); */ + cpKeyData = packageData(tTupleData, tTupleDesc, tpTrigData, PRIMARY); #if defined DEBUG_OUTPUT - elog(NOTICE,cpKeyData); + elog(NOTICE, cpKeyData); #endif - saPlanData[0] = PointerGetDatum(cpKeyData); - - iRetCode = SPI_execp(pplan,saPlanData,NULL,1); - - if(cpKeyData!=NULL) { - SPI_pfree(cpKeyData); - } - - if(iRetCode != SPI_OK_INSERT ) { - elog(NOTICE,"Error inserting row in pendingDelete"); - return -1; - } + saPlanData[0] = PointerGetDatum(cpKeyData); + + iRetCode = SPI_execp(pplan, saPlanData, NULL, 1); + + if (cpKeyData != NULL) + SPI_pfree(cpKeyData); + + if (iRetCode != SPI_OK_INSERT) + { + elog(NOTICE, "Error inserting row in pendingDelete"); + return -1; + } #if defined DEBUG_OUTPUT - elog(NOTICE,"INSERT SUCCESFULL"); + elog(NOTICE, "INSERT SUCCESFULL"); #endif - return 0; - + return 0; + } -int2vector * getPrimaryKey(Oid tblOid) { - char * queryBase; - char * query; - bool isNull; - int2vector * resultKey; - int2vector * tpResultKey; - HeapTuple resTuple; - Datum resDatum; - int ret; - queryBase = "SELECT indkey FROM pg_index WHERE indisprimary='t' AND indrelid="; - query = SPI_palloc(strlen(queryBase) + MAX_OID_LEN+1); - sprintf(query,"%s%d",queryBase,tblOid); - ret = SPI_exec(query,1); - if(ret != SPI_OK_SELECT || SPI_processed != 1 ) { - elog(NOTICE,"Could not select primary index key"); - return NULL; - } +int2vector * +getPrimaryKey(Oid tblOid) +{ + char *queryBase; + char *query; + bool isNull; + int2vector *resultKey; + int2vector *tpResultKey; + HeapTuple resTuple; + Datum resDatum; + int ret; + + queryBase = "SELECT indkey FROM pg_index WHERE indisprimary='t' AND indrelid="; + query = SPI_palloc(strlen(queryBase) + MAX_OID_LEN + 1); + sprintf(query, "%s%d", queryBase, tblOid); + ret = SPI_exec(query, 1); + if (ret != SPI_OK_SELECT || SPI_processed != 1) + { + elog(NOTICE, "Could not select primary index key"); + return NULL; + } - resTuple = SPI_tuptable->vals[0]; - resDatum = SPI_getbinval(resTuple,SPI_tuptable->tupdesc,1,&isNull); + resTuple = SPI_tuptable->vals[0]; + resDatum = SPI_getbinval(resTuple, SPI_tuptable->tupdesc, 1, &isNull); - tpResultKey = (int2vector*) DatumGetPointer(resDatum); - resultKey = SPI_palloc(sizeof(int2vector)); - memcpy(resultKey,tpResultKey,sizeof(int2vector)); + tpResultKey = (int2vector *) DatumGetPointer(resDatum); + resultKey = SPI_palloc(sizeof(int2vector)); + memcpy(resultKey, tpResultKey, sizeof(int2vector)); - SPI_pfree(query); - return resultKey; + SPI_pfree(query); + return resultKey; } /****************************************************************************** * Stores a copy of the non-key data for the row. *****************************************************************************/ -int storeData(char * cpTableName,HeapTuple tTupleData,TupleDesc tTupleDesc, - TriggerData * tpTrigData,int iIncludeKeyData) { - - Oid planArgTypes[1] = {NAMEOID}; - char * insQuery = "INSERT INTO \"PendingData\" (\"SeqId\",\"IsKey\",\"Data\") VALUES(currval('\"Pending_SeqId_seq\"'),'f',$1)"; - void * pplan; - Datum planData[1]; - char * cpKeyData; - int iRetValue; - - pplan = SPI_prepare(insQuery,1,planArgTypes); - if(pplan==NULL) { - elog(NOTICE,"Could not prepare INSERT plan"); - return -1; - } - - // pplan = SPI_saveplan(pplan); - if(iIncludeKeyData==0) { - cpKeyData = packageData(tTupleData, tTupleDesc,tpTrigData,NONPRIMARY); - } - else { - cpKeyData = packageData(tTupleData,tTupleDesc,tpTrigData,ALL); - } - - planData[0] = PointerGetDatum(cpKeyData); - iRetValue = SPI_execp(pplan,planData,NULL,1); - - if(cpKeyData!=0) { - SPI_pfree(cpKeyData); - } - - if(iRetValue != SPI_OK_INSERT ) { - elog(NOTICE,"Error inserting row in pendingDelete"); - return -1; - } +int +storeData(char *cpTableName, HeapTuple tTupleData, TupleDesc tTupleDesc, + TriggerData *tpTrigData, int iIncludeKeyData) +{ + + Oid planArgTypes[1] = {NAMEOID}; + char *insQuery = "INSERT INTO \"PendingData\" (\"SeqId\",\"IsKey\",\"Data\") VALUES(currval('\"Pending_SeqId_seq\"'),'f',$1)"; + void *pplan; + Datum planData[1]; + char *cpKeyData; + int iRetValue; + + pplan = SPI_prepare(insQuery, 1, planArgTypes); + if (pplan == NULL) + { + elog(NOTICE, "Could not prepare INSERT plan"); + return -1; + } + + /* pplan = SPI_saveplan(pplan); */ + if (iIncludeKeyData == 0) + cpKeyData = packageData(tTupleData, tTupleDesc, tpTrigData, NONPRIMARY); + else + cpKeyData = packageData(tTupleData, tTupleDesc, tpTrigData, ALL); + + planData[0] = PointerGetDatum(cpKeyData); + iRetValue = SPI_execp(pplan, planData, NULL, 1); + + if (cpKeyData != 0) + SPI_pfree(cpKeyData); + + if (iRetValue != SPI_OK_INSERT) + { + elog(NOTICE, "Error inserting row in pendingDelete"); + return -1; + } #if defined DEBUG_OUTPUT - elog(NOTICE,"INSERT SUCCESFULL"); + elog(NOTICE, "INSERT SUCCESFULL"); #endif - return 0; - + return 0; + } /** - * Packages the data in tTupleData into a string of the format + * Packages the data in tTupleData into a string of the format * FieldName='value text' where any quotes inside of value text * are escaped with a backslash and any backslashes in value text * are esacped by a second back slash. * - * tTupleDesc should be a description of the tuple stored in - * tTupleData. + * tTupleDesc should be a description of the tuple stored in + * tTupleData. * * eFieldUsage specifies which fields to use. - * PRIMARY implies include only primary key fields. - * NONPRIMARY implies include only non-primary key fields. - * ALL implies include all fields. + * PRIMARY implies include only primary key fields. + * NONPRIMARY implies include only non-primary key fields. + * ALL implies include all fields. */ -char * packageData(HeapTuple tTupleData, TupleDesc tTupleDesc, - TriggerData * tpTrigData, - enum FieldUsage eKeyUsage ) { - int iNumCols; - int2vector * tpPKeys=NULL; - int iColumnCounter; - char * cpDataBlock; - int iDataBlockSize; - int iUsedDataBlock; - - iNumCols = tTupleDesc->natts; - - if(eKeyUsage!=ALL) { - tpPKeys = getPrimaryKey(tpTrigData->tg_relation->rd_id); - if(tpPKeys==NULL) { - return NULL; - } - } -#if defined DEBUG_OUTPUT - if(tpPKeys!=NULL) { - elog(NOTICE,"Have primary keys"); - } -#endif - cpDataBlock = SPI_palloc(BUFFER_SIZE); - iDataBlockSize = BUFFER_SIZE; - iUsedDataBlock = 0; /* To account for the null */ - - for(iColumnCounter=1; iColumnCounter <=iNumCols; iColumnCounter++) { - int iIsPrimaryKey; - int iPrimaryKeyIndex; - char * cpUnFormatedPtr; - char * cpFormatedPtr; - - char * cpFieldName; - char * cpFieldData; - if(eKeyUsage!=ALL) { - //Determine if this is a primary key or not. - iIsPrimaryKey=0; - for(iPrimaryKeyIndex=0; (*tpPKeys)[iPrimaryKeyIndex]!=0; - iPrimaryKeyIndex++) { - if((*tpPKeys)[iPrimaryKeyIndex]==iColumnCounter) { - iIsPrimaryKey=1; - break; +char * +packageData(HeapTuple tTupleData, TupleDesc tTupleDesc, + TriggerData *tpTrigData, + enum FieldUsage eKeyUsage) +{ + int iNumCols; + int2vector *tpPKeys = NULL; + int iColumnCounter; + char *cpDataBlock; + int iDataBlockSize; + int iUsedDataBlock; + + iNumCols = tTupleDesc->natts; + + if (eKeyUsage != ALL) + { + tpPKeys = getPrimaryKey(tpTrigData->tg_relation->rd_id); + if (tpPKeys == NULL) + return NULL; } - } - if( iIsPrimaryKey ? (eKeyUsage!=PRIMARY) : (eKeyUsage!=NONPRIMARY)) { - /** - * Don't use. - */ #if defined DEBUG_OUTPUT - elog(NOTICE,"Skipping column"); + if (tpPKeys != NULL) + elog(NOTICE, "Have primary keys"); #endif - continue; - } - } /* KeyUsage!=ALL */ - cpFieldName = DatumGetPointer(NameGetDatum(&tTupleDesc->attrs - [iColumnCounter-1]->attname)); + cpDataBlock = SPI_palloc(BUFFER_SIZE); + iDataBlockSize = BUFFER_SIZE; + iUsedDataBlock = 0; /* To account for the null */ + + for (iColumnCounter = 1; iColumnCounter <= iNumCols; iColumnCounter++) + { + int iIsPrimaryKey; + int iPrimaryKeyIndex; + char *cpUnFormatedPtr; + char *cpFormatedPtr; + + char *cpFieldName; + char *cpFieldData; + + if (eKeyUsage != ALL) + { + /* Determine if this is a primary key or not. */ + iIsPrimaryKey = 0; + for (iPrimaryKeyIndex = 0; (*tpPKeys)[iPrimaryKeyIndex] != 0; + iPrimaryKeyIndex++) + { + if ((*tpPKeys)[iPrimaryKeyIndex] == iColumnCounter) + { + iIsPrimaryKey = 1; + break; + } + } + if (iIsPrimaryKey ? (eKeyUsage != PRIMARY) : (eKeyUsage != NONPRIMARY)) + { + /** + * Don't use. + */ #if defined DEBUG_OUTPUT - elog(NOTICE,cpFieldName); + elog(NOTICE, "Skipping column"); #endif - while(iDataBlockSize - iUsedDataBlock < strlen(cpFieldName) +4) { - cpDataBlock = SPI_repalloc(cpDataBlock,iDataBlockSize + BUFFER_SIZE); - iDataBlockSize = iDataBlockSize + BUFFER_SIZE; - } - sprintf(cpDataBlock+iUsedDataBlock,"\"%s\"=",cpFieldName); - iUsedDataBlock = iUsedDataBlock + strlen(cpFieldName)+3; - cpFieldData=SPI_getvalue(tTupleData,tTupleDesc,iColumnCounter); - - cpUnFormatedPtr = cpFieldData; - cpFormatedPtr = cpDataBlock + iUsedDataBlock; - if(cpFieldData!=NULL) { - *cpFormatedPtr='\''; - iUsedDataBlock++; - cpFormatedPtr++; - } - else { - *cpFormatedPtr=' '; - iUsedDataBlock++; - cpFormatedPtr++; - continue; - - } + continue; + } + } /* KeyUsage!=ALL */ + cpFieldName = DatumGetPointer(NameGetDatum(&tTupleDesc->attrs + [iColumnCounter - 1]->attname)); #if defined DEBUG_OUTPUT - elog(NOTICE,cpFieldData); - elog(NOTICE,"Starting format loop"); + elog(NOTICE, cpFieldName); #endif - while(*cpUnFormatedPtr!=0) { - while(iDataBlockSize - iUsedDataBlock < 2) { - cpDataBlock = SPI_repalloc(cpDataBlock,iDataBlockSize+BUFFER_SIZE); - iDataBlockSize = iDataBlockSize + BUFFER_SIZE; - cpFormatedPtr = cpDataBlock + iUsedDataBlock; - } - if(*cpUnFormatedPtr=='\\' || *cpUnFormatedPtr=='\'') { - *cpFormatedPtr='\\'; - cpFormatedPtr++; - iUsedDataBlock++; - } - *cpFormatedPtr=*cpUnFormatedPtr; - cpFormatedPtr++; - cpUnFormatedPtr++; - iUsedDataBlock++; - } - - SPI_pfree(cpFieldData); - - while(iDataBlockSize - iUsedDataBlock < 3) { - cpDataBlock = SPI_repalloc(cpDataBlock,iDataBlockSize+BUFFER_SIZE); - iDataBlockSize = iDataBlockSize + BUFFER_SIZE; - cpFormatedPtr = cpDataBlock + iUsedDataBlock; - } - sprintf(cpFormatedPtr,"' "); - iUsedDataBlock = iUsedDataBlock +2; + while (iDataBlockSize - iUsedDataBlock < strlen(cpFieldName) + 4) + { + cpDataBlock = SPI_repalloc(cpDataBlock, iDataBlockSize + BUFFER_SIZE); + iDataBlockSize = iDataBlockSize + BUFFER_SIZE; + } + sprintf(cpDataBlock + iUsedDataBlock, "\"%s\"=", cpFieldName); + iUsedDataBlock = iUsedDataBlock + strlen(cpFieldName) + 3; + cpFieldData = SPI_getvalue(tTupleData, tTupleDesc, iColumnCounter); + + cpUnFormatedPtr = cpFieldData; + cpFormatedPtr = cpDataBlock + iUsedDataBlock; + if (cpFieldData != NULL) + { + *cpFormatedPtr = '\''; + iUsedDataBlock++; + cpFormatedPtr++; + } + else + { + *cpFormatedPtr = ' '; + iUsedDataBlock++; + cpFormatedPtr++; + continue; + + } #if defined DEBUG_OUTPUT - elog(NOTICE,cpDataBlock); + elog(NOTICE, cpFieldData); + elog(NOTICE, "Starting format loop"); #endif - - } /* for iColumnCounter */ - if(tpPKeys!=NULL) { - SPI_pfree(tpPKeys); - } + while (*cpUnFormatedPtr != 0) + { + while (iDataBlockSize - iUsedDataBlock < 2) + { + cpDataBlock = SPI_repalloc(cpDataBlock, iDataBlockSize + BUFFER_SIZE); + iDataBlockSize = iDataBlockSize + BUFFER_SIZE; + cpFormatedPtr = cpDataBlock + iUsedDataBlock; + } + if (*cpUnFormatedPtr == '\\' || *cpUnFormatedPtr == '\'') + { + *cpFormatedPtr = '\\'; + cpFormatedPtr++; + iUsedDataBlock++; + } + *cpFormatedPtr = *cpUnFormatedPtr; + cpFormatedPtr++; + cpUnFormatedPtr++; + iUsedDataBlock++; + } + + SPI_pfree(cpFieldData); + + while (iDataBlockSize - iUsedDataBlock < 3) + { + cpDataBlock = SPI_repalloc(cpDataBlock, iDataBlockSize + BUFFER_SIZE); + iDataBlockSize = iDataBlockSize + BUFFER_SIZE; + cpFormatedPtr = cpDataBlock + iUsedDataBlock; + } + sprintf(cpFormatedPtr, "' "); + iUsedDataBlock = iUsedDataBlock + 2; #if defined DEBUG_OUTPUT - elog(NOTICE,"Returning"); + elog(NOTICE, cpDataBlock); #endif - memset(cpDataBlock + iUsedDataBlock,0,iDataBlockSize - iUsedDataBlock); - return cpDataBlock; - + } /* for iColumnCounter */ + if (tpPKeys != NULL) + SPI_pfree(tpPKeys); +#if defined DEBUG_OUTPUT + elog(NOTICE, "Returning"); +#endif + memset(cpDataBlock + iUsedDataBlock, 0, iDataBlockSize - iUsedDataBlock); + + return cpDataBlock; + } diff --git a/contrib/dbsize/dbsize.c b/contrib/dbsize/dbsize.c index 8bc216bf79..f97e7876c8 100644 --- a/contrib/dbsize/dbsize.c +++ b/contrib/dbsize/dbsize.c @@ -37,7 +37,7 @@ psnprintf(size_t len, const char *fmt,...) PG_FUNCTION_INFO_V1(database_size); -Datum database_size(PG_FUNCTION_ARGS); +Datum database_size(PG_FUNCTION_ARGS); Datum database_size(PG_FUNCTION_ARGS) @@ -97,7 +97,7 @@ database_size(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(relation_size); -Datum relation_size(PG_FUNCTION_ARGS); +Datum relation_size(PG_FUNCTION_ARGS); Datum relation_size(PG_FUNCTION_ARGS) @@ -111,7 +111,7 @@ relation_size(PG_FUNCTION_ARGS) unsigned int segcount; relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname, - "relation_size")); + "relation_size")); relation = heap_openrv(relrv, AccessShareLock); relnode = relation->rd_rel->relfilenode; diff --git a/contrib/findoidjoins/findoidjoins.c b/contrib/findoidjoins/findoidjoins.c index b3bef4d3cb..f83e5da189 100644 --- a/contrib/findoidjoins/findoidjoins.c +++ b/contrib/findoidjoins/findoidjoins.c @@ -73,7 +73,7 @@ main(int argc, char **argv) SELECT count(*)::int4 \ FROM \"%s\" t1, \"%s\" t2 \ WHERE t1.\"%s\" = t2.oid ", - relname, relname2, attname); + relname, relname2, attname); else sprintf(query, 4000, "\ DECLARE c_matches BINARY CURSOR FOR \ diff --git a/contrib/intagg/int_aggregate.c b/contrib/intagg/int_aggregate.c index 820ec8dd08..b9c39d400b 100644 --- a/contrib/intagg/int_aggregate.c +++ b/contrib/intagg/int_aggregate.c @@ -11,7 +11,7 @@ * This file is the property of the Digital Music Network (DMN). * It is being made available to users of the PostgreSQL system * under the BSD license. - * + * * NOTE: This module requires sizeof(void *) to be the same as sizeof(int) */ #include "postgres.h" @@ -45,31 +45,31 @@ typedef struct { - ArrayType a; - int items; - int lower; - int4 array[1]; -}PGARRAY; + ArrayType a; + int items; + int lower; + int4 array[1]; +} PGARRAY; /* This is used to keep track of our position during enumeration */ typedef struct callContext { - PGARRAY *p; - int num; - int flags; -}CTX; + PGARRAY *p; + int num; + int flags; +} CTX; #define TOASTED 1 -#define START_NUM 8 +#define START_NUM 8 #define PGARRAY_SIZE(n) (sizeof(PGARRAY) + ((n-1)*sizeof(int4))) -static PGARRAY * GetPGArray(int4 state, int fAdd); -static PGARRAY *ShrinkPGArray(PGARRAY *p); +static PGARRAY *GetPGArray(int4 state, int fAdd); +static PGARRAY *ShrinkPGArray(PGARRAY * p); -Datum int_agg_state(PG_FUNCTION_ARGS); -Datum int_agg_final_count(PG_FUNCTION_ARGS); -Datum int_agg_final_array(PG_FUNCTION_ARGS); -Datum int_enum(PG_FUNCTION_ARGS); +Datum int_agg_state(PG_FUNCTION_ARGS); +Datum int_agg_final_count(PG_FUNCTION_ARGS); +Datum int_agg_final_array(PG_FUNCTION_ARGS); +Datum int_enum(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(int_agg_state); PG_FUNCTION_INFO_V1(int_agg_final_count); @@ -80,20 +80,21 @@ PG_FUNCTION_INFO_V1(int_enum); * Manage the aggregation state of the array * You need to specify the correct memory context, or it will vanish! */ -static PGARRAY * GetPGArray(int4 state, int fAdd) +static PGARRAY * +GetPGArray(int4 state, int fAdd) { - PGARRAY *p = (PGARRAY *) state; + PGARRAY *p = (PGARRAY *) state; - if(!state) + if (!state) { /* New array */ - int cb = PGARRAY_SIZE(START_NUM); + int cb = PGARRAY_SIZE(START_NUM); p = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cb); - if(!p) + if (!p) { - elog(ERROR,"Integer aggregator, cant allocate TopTransactionContext memory"); + elog(ERROR, "Integer aggregator, cant allocate TopTransactionContext memory"); return 0; } @@ -104,22 +105,22 @@ static PGARRAY * GetPGArray(int4 state, int fAdd) p->a.elemtype = INT4OID; #endif p->items = 0; - p->lower= START_NUM; + p->lower = START_NUM; } - else if(fAdd) - { /* Ensure array has space */ - if(p->items >= p->lower) + else if (fAdd) + { /* Ensure array has space */ + if (p->items >= p->lower) { - PGARRAY *pn; - int n = p->lower + p->lower; - int cbNew = PGARRAY_SIZE(n); + PGARRAY *pn; + int n = p->lower + p->lower; + int cbNew = PGARRAY_SIZE(n); pn = (PGARRAY *) repalloc(p, cbNew); - if(!pn) - { /* Realloc failed! Reallocate new block. */ + if (!pn) + { /* Realloc failed! Reallocate new block. */ pn = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cbNew); - if(!pn) + if (!pn) { elog(ERROR, "Integer aggregator, REALLY REALLY can't alloc memory"); return (PGARRAY *) NULL; @@ -136,24 +137,29 @@ static PGARRAY * GetPGArray(int4 state, int fAdd) } /* Shrinks the array to its actual size and moves it into the standard - * memory allocation context, frees working memory */ -static PGARRAY *ShrinkPGArray(PGARRAY *p) + * memory allocation context, frees working memory */ +static PGARRAY * +ShrinkPGArray(PGARRAY * p) { - PGARRAY *pnew=NULL; - if(p) + PGARRAY *pnew = NULL; + + if (p) { /* get target size */ - int cb = PGARRAY_SIZE(p->items); + int cb = PGARRAY_SIZE(p->items); /* use current transaction context */ pnew = palloc(cb); - if(pnew) + if (pnew) { - /* Fix up the fields in the new structure, so Postgres understands */ + /* + * Fix up the fields in the new structure, so Postgres + * understands + */ memcpy(pnew, p, cb); pnew->a.size = cb; - pnew->a.ndim=1; + pnew->a.ndim = 1; pnew->a.flags = 0; #ifndef PG_7_2 pnew->a.elemtype = INT4OID; @@ -161,79 +167,72 @@ static PGARRAY *ShrinkPGArray(PGARRAY *p) pnew->lower = 0; } else - { elog(ERROR, "Integer aggregator, can't allocate memory"); - } pfree(p); } return pnew; } /* Called for each iteration during an aggregate function */ -Datum int_agg_state(PG_FUNCTION_ARGS) +Datum +int_agg_state(PG_FUNCTION_ARGS) { - int4 state = PG_GETARG_INT32(0); - int4 value = PG_GETARG_INT32(1); + int4 state = PG_GETARG_INT32(0); + int4 value = PG_GETARG_INT32(1); - PGARRAY *p = GetPGArray(state, 1); - if(!p) - { - elog(ERROR,"No aggregate storage"); - } - else if(p->items >= p->lower) - { - elog(ERROR,"aggregate storage too small"); - } + PGARRAY *p = GetPGArray(state, 1); + + if (!p) + elog(ERROR, "No aggregate storage"); + else if (p->items >= p->lower) + elog(ERROR, "aggregate storage too small"); else - { - p->array[p->items++]= value; - } + p->array[p->items++] = value; PG_RETURN_INT32(p); } /* This is the final function used for the integer aggregator. It returns all the integers * collected as a one dimentional integer array */ -Datum int_agg_final_array(PG_FUNCTION_ARGS) +Datum +int_agg_final_array(PG_FUNCTION_ARGS) { - PGARRAY *pnew = ShrinkPGArray(GetPGArray(PG_GETARG_INT32(0),0)); - if(pnew) - { + PGARRAY *pnew = ShrinkPGArray(GetPGArray(PG_GETARG_INT32(0), 0)); + + if (pnew) PG_RETURN_POINTER(pnew); - } else - { PG_RETURN_NULL(); - } } /* This function accepts an array, and returns one item for each entry in the array */ -Datum int_enum(PG_FUNCTION_ARGS) +Datum +int_enum(PG_FUNCTION_ARGS) { - PGARRAY *p = (PGARRAY *) PG_GETARG_POINTER(0); - CTX *pc; - ReturnSetInfo *rsi = (ReturnSetInfo *)fcinfo->resultinfo; + PGARRAY *p = (PGARRAY *) PG_GETARG_POINTER(0); + CTX *pc; + ReturnSetInfo *rsi = (ReturnSetInfo *) fcinfo->resultinfo; if (!rsi || !IsA(rsi, ReturnSetInfo)) elog(ERROR, "No ReturnSetInfo sent! function must be declared returning a 'setof' integer"); - if(!p) + if (!p) { elog(WARNING, "No data sent"); PG_RETURN_NULL(); } - if(!fcinfo->context) + if (!fcinfo->context) { /* Allocate a working context */ pc = (CTX *) palloc(sizeof(CTX)); /* Don't copy atribute if you don't need too */ - if(VARATT_IS_EXTENDED(p) ) + if (VARATT_IS_EXTENDED(p)) { /* Toasted!!! */ pc->p = (PGARRAY *) PG_DETOAST_DATUM_COPY(p); pc->flags = TOASTED; - if(!pc->p) + if (!pc->p) { elog(ERROR, "Error in toaster!!! no detoasting"); PG_RETURN_NULL(); @@ -246,25 +245,26 @@ Datum int_enum(PG_FUNCTION_ARGS) pc->flags = 0; } fcinfo->context = (Node *) pc; - pc->num=0; + pc->num = 0; } - else /* use an existing one */ - { + else +/* use an existing one */ pc = (CTX *) fcinfo->context; - } /* Are we done yet? */ - if(pc->num >= pc->p->items) + if (pc->num >= pc->p->items) { /* We are done */ - if(pc->flags & TOASTED) + if (pc->flags & TOASTED) pfree(pc->p); pfree(fcinfo->context); fcinfo->context = NULL; - rsi->isDone = ExprEndResult ; + rsi->isDone = ExprEndResult; } - else /* nope, return the next value */ + else +/* nope, return the next value */ { - int val = pc->p->array[pc->num++]; + int val = pc->p->array[pc->num++]; + rsi->isDone = ExprMultipleResult; PG_RETURN_INT32(val); } diff --git a/contrib/intarray/_int.c b/contrib/intarray/_int.c index 75ebf5d8dd..09590a2852 100644 --- a/contrib/intarray/_int.c +++ b/contrib/intarray/_int.c @@ -100,7 +100,7 @@ typedef char *BITVECP; static void printarr(ArrayType *a, int num) { - StringInfoData bbb; + StringInfoData bbb; char *cur; int l; int *d; @@ -108,9 +108,7 @@ printarr(ArrayType *a, int num) d = ARRPTR(a); initStringInfo(&bbb); for (l = 0; l < min(num, ARRNELEMS(a)); l++) - { appendStringInfo(&bbb, "%d ", d[l]); - } elog(DEBUG3, "\t\t%s", bbb.data); pfree(bbb.data); } @@ -125,7 +123,6 @@ printbitvec(BITVEC bv) elog(DEBUG3, "BV: %s", str); } - #endif /* @@ -163,78 +160,78 @@ static ArrayType *_int_common_union(bytea *entryvec, /* ** GiST support methods */ -PG_FUNCTION_INFO_V1( g_int_consistent ); -PG_FUNCTION_INFO_V1( g_int_compress ); -PG_FUNCTION_INFO_V1( g_int_decompress ); -PG_FUNCTION_INFO_V1( g_int_penalty ); -PG_FUNCTION_INFO_V1( g_int_picksplit ); -PG_FUNCTION_INFO_V1( g_int_union ); -PG_FUNCTION_INFO_V1( g_int_same ); - -Datum g_int_consistent(PG_FUNCTION_ARGS); -Datum g_int_compress(PG_FUNCTION_ARGS); -Datum g_int_decompress(PG_FUNCTION_ARGS); -Datum g_int_penalty(PG_FUNCTION_ARGS); -Datum g_int_picksplit(PG_FUNCTION_ARGS); -Datum g_int_union(PG_FUNCTION_ARGS); -Datum g_int_same(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(g_int_consistent); +PG_FUNCTION_INFO_V1(g_int_compress); +PG_FUNCTION_INFO_V1(g_int_decompress); +PG_FUNCTION_INFO_V1(g_int_penalty); +PG_FUNCTION_INFO_V1(g_int_picksplit); +PG_FUNCTION_INFO_V1(g_int_union); +PG_FUNCTION_INFO_V1(g_int_same); + +Datum g_int_consistent(PG_FUNCTION_ARGS); +Datum g_int_compress(PG_FUNCTION_ARGS); +Datum g_int_decompress(PG_FUNCTION_ARGS); +Datum g_int_penalty(PG_FUNCTION_ARGS); +Datum g_int_picksplit(PG_FUNCTION_ARGS); +Datum g_int_union(PG_FUNCTION_ARGS); +Datum g_int_same(PG_FUNCTION_ARGS); /* ** R-tree support functions */ -static bool inner_int_contains(ArrayType *a, ArrayType *b); -static bool inner_int_overlap(ArrayType *a, ArrayType *b); -static ArrayType *inner_int_union(ArrayType *a, ArrayType *b); -static ArrayType *inner_int_inter(ArrayType *a, ArrayType *b); -static void rt__int_size(ArrayType *a, float *sz); - -PG_FUNCTION_INFO_V1( _int_different ); -PG_FUNCTION_INFO_V1( _int_same ); -PG_FUNCTION_INFO_V1( _int_contains ); -PG_FUNCTION_INFO_V1( _int_contained ); -PG_FUNCTION_INFO_V1( _int_overlap ); -PG_FUNCTION_INFO_V1( _int_union ); -PG_FUNCTION_INFO_V1( _int_inter ); - -Datum _int_different(PG_FUNCTION_ARGS); -Datum _int_same(PG_FUNCTION_ARGS); -Datum _int_contains(PG_FUNCTION_ARGS); -Datum _int_contained(PG_FUNCTION_ARGS); -Datum _int_overlap(PG_FUNCTION_ARGS); -Datum _int_union(PG_FUNCTION_ARGS); -Datum _int_inter(PG_FUNCTION_ARGS); +static bool inner_int_contains(ArrayType *a, ArrayType *b); +static bool inner_int_overlap(ArrayType *a, ArrayType *b); +static ArrayType *inner_int_union(ArrayType *a, ArrayType *b); +static ArrayType *inner_int_inter(ArrayType *a, ArrayType *b); +static void rt__int_size(ArrayType *a, float *sz); + +PG_FUNCTION_INFO_V1(_int_different); +PG_FUNCTION_INFO_V1(_int_same); +PG_FUNCTION_INFO_V1(_int_contains); +PG_FUNCTION_INFO_V1(_int_contained); +PG_FUNCTION_INFO_V1(_int_overlap); +PG_FUNCTION_INFO_V1(_int_union); +PG_FUNCTION_INFO_V1(_int_inter); + +Datum _int_different(PG_FUNCTION_ARGS); +Datum _int_same(PG_FUNCTION_ARGS); +Datum _int_contains(PG_FUNCTION_ARGS); +Datum _int_contained(PG_FUNCTION_ARGS); +Datum _int_overlap(PG_FUNCTION_ARGS); +Datum _int_union(PG_FUNCTION_ARGS); +Datum _int_inter(PG_FUNCTION_ARGS); /* ** _intbig methods */ -PG_FUNCTION_INFO_V1( g_intbig_consistent ); -PG_FUNCTION_INFO_V1( g_intbig_compress ); -PG_FUNCTION_INFO_V1( g_intbig_decompress ); -PG_FUNCTION_INFO_V1( g_intbig_penalty ); -PG_FUNCTION_INFO_V1( g_intbig_picksplit ); -PG_FUNCTION_INFO_V1( g_intbig_union ); -PG_FUNCTION_INFO_V1( g_intbig_same ); - -Datum g_intbig_consistent(PG_FUNCTION_ARGS); -Datum g_intbig_compress(PG_FUNCTION_ARGS); -Datum g_intbig_decompress(PG_FUNCTION_ARGS); -Datum g_intbig_penalty(PG_FUNCTION_ARGS); -Datum g_intbig_picksplit(PG_FUNCTION_ARGS); -Datum g_intbig_union(PG_FUNCTION_ARGS); -Datum g_intbig_same(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(g_intbig_consistent); +PG_FUNCTION_INFO_V1(g_intbig_compress); +PG_FUNCTION_INFO_V1(g_intbig_decompress); +PG_FUNCTION_INFO_V1(g_intbig_penalty); +PG_FUNCTION_INFO_V1(g_intbig_picksplit); +PG_FUNCTION_INFO_V1(g_intbig_union); +PG_FUNCTION_INFO_V1(g_intbig_same); + +Datum g_intbig_consistent(PG_FUNCTION_ARGS); +Datum g_intbig_compress(PG_FUNCTION_ARGS); +Datum g_intbig_decompress(PG_FUNCTION_ARGS); +Datum g_intbig_penalty(PG_FUNCTION_ARGS); +Datum g_intbig_picksplit(PG_FUNCTION_ARGS); +Datum g_intbig_union(PG_FUNCTION_ARGS); +Datum g_intbig_same(PG_FUNCTION_ARGS); static bool _intbig_contains(ArrayType *a, ArrayType *b); static bool _intbig_overlap(ArrayType *a, ArrayType *b); static ArrayType *_intbig_union(ArrayType *a, ArrayType *b); -static ArrayType * _intbig_inter(ArrayType *a, ArrayType *b); +static ArrayType *_intbig_inter(ArrayType *a, ArrayType *b); static void rt__intbig_size(ArrayType *a, float *sz); /***************************************************************************** - * Boolean Search + * Boolean Search *****************************************************************************/ #define BooleanSearchStrategy 20 @@ -243,17 +240,19 @@ static void rt__intbig_size(ArrayType *a, float *sz); * item in polish notation with back link * to left operand */ -typedef struct ITEM { - int2 type; - int2 left; - int4 val; -} ITEM; - -typedef struct { - int4 len; - int4 size; - char data[1]; -} QUERYTYPE; +typedef struct ITEM +{ + int2 type; + int2 left; + int4 val; +} ITEM; + +typedef struct +{ + int4 len; + int4 size; + char data[1]; +} QUERYTYPE; #define HDRSIZEQT ( 2*sizeof(int4) ) #define COMPUTESIZE(size) ( HDRSIZEQT + size * sizeof(ITEM) ) @@ -261,20 +260,20 @@ typedef struct { PG_FUNCTION_INFO_V1(bqarr_in); PG_FUNCTION_INFO_V1(bqarr_out); -Datum bqarr_in(PG_FUNCTION_ARGS); -Datum bqarr_out(PG_FUNCTION_ARGS); +Datum bqarr_in(PG_FUNCTION_ARGS); +Datum bqarr_out(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(boolop); -Datum boolop(PG_FUNCTION_ARGS); +Datum boolop(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(rboolop); -Datum rboolop(PG_FUNCTION_ARGS); +Datum rboolop(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(querytree); -Datum querytree(PG_FUNCTION_ARGS); +Datum querytree(PG_FUNCTION_ARGS); -static bool signconsistent( QUERYTYPE *query, BITVEC sign, bool leaf ); -static bool execconsistent( QUERYTYPE *query, ArrayType *array, bool leaf ); +static bool signconsistent(QUERYTYPE * query, BITVEC sign, bool leaf); +static bool execconsistent(QUERYTYPE * query, ArrayType *array, bool leaf); /***************************************************************************** * GiST functions @@ -287,21 +286,22 @@ static bool execconsistent( QUERYTYPE *query, ArrayType *array, bool leaf ); ** corresponding to strategy in the pg_amop table. */ Datum -g_int_consistent(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); - ArrayType *query = ( ArrayType * )PG_GETARG_POINTER(1); +g_int_consistent(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + ArrayType *query = (ArrayType *) PG_GETARG_POINTER(1); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); bool retval; - if ( strategy == BooleanSearchStrategy ) - PG_RETURN_BOOL(execconsistent( (QUERYTYPE*)query, - (ArrayType *) DatumGetPointer(entry->key), - ISLEAFKEY( (ArrayType *) DatumGetPointer(entry->key) ) ) ); + if (strategy == BooleanSearchStrategy) + PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query, + (ArrayType *) DatumGetPointer(entry->key), + ISLEAFKEY((ArrayType *) DatumGetPointer(entry->key)))); /* XXX are we sure it's safe to scribble on the query object here? */ /* XXX what about toasted input? */ /* sort query for fast search, key is already sorted */ - if ( ARRISVOID( query ) ) + if (ARRISVOID(query)) PG_RETURN_BOOL(false); PREPAREARR(query); @@ -312,28 +312,28 @@ g_int_consistent(PG_FUNCTION_ARGS) { query); break; case RTSameStrategyNumber: - if ( GIST_LEAF(entry) ) + if (GIST_LEAF(entry)) DirectFunctionCall3( - g_int_same, - entry->key, - PointerGetDatum(query), - PointerGetDatum(&retval) - ); + g_int_same, + entry->key, + PointerGetDatum(query), + PointerGetDatum(&retval) + ); else retval = inner_int_contains((ArrayType *) DatumGetPointer(entry->key), - query); + query); break; case RTContainsStrategyNumber: retval = inner_int_contains((ArrayType *) DatumGetPointer(entry->key), query); break; case RTContainedByStrategyNumber: - if ( GIST_LEAF(entry) ) + if (GIST_LEAF(entry)) retval = inner_int_contains(query, - (ArrayType *) DatumGetPointer(entry->key) ); + (ArrayType *) DatumGetPointer(entry->key)); else retval = inner_int_overlap((ArrayType *) DatumGetPointer(entry->key), - query); + query); break; default: retval = FALSE; @@ -344,11 +344,11 @@ g_int_consistent(PG_FUNCTION_ARGS) { Datum g_int_union(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER( _int_common_union( - (bytea *) PG_GETARG_POINTER(0), - (int *) PG_GETARG_POINTER(1), - inner_int_union - ) ); + PG_RETURN_POINTER(_int_common_union( + (bytea *) PG_GETARG_POINTER(0), + (int *) PG_GETARG_POINTER(1), + inner_int_union + )); } /* @@ -357,7 +357,7 @@ g_int_union(PG_FUNCTION_ARGS) Datum g_int_compress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval; ArrayType *r; int len; @@ -366,26 +366,29 @@ g_int_compress(PG_FUNCTION_ARGS) min, cand; - if (entry->leafkey) { + if (entry->leafkey) + { r = (ArrayType *) PG_DETOAST_DATUM_COPY(entry->key); PREPAREARR(r); r->flags |= LEAFKEY; retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(r), - entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); + entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); PG_RETURN_POINTER(retval); } r = (ArrayType *) PG_DETOAST_DATUM(entry->key); - if ( ISLEAFKEY( r ) || ARRISVOID(r) ) { - if ( r != (ArrayType*)DatumGetPointer(entry->key) ) + if (ISLEAFKEY(r) || ARRISVOID(r)) + { + if (r != (ArrayType *) DatumGetPointer(entry->key)) pfree(r); PG_RETURN_POINTER(entry); } - if ( (len=ARRNELEMS(r)) >= 2 * MAXNUMRANGE) { /* compress */ - if ( r == (ArrayType*)DatumGetPointer( entry->key) ) + if ((len = ARRNELEMS(r)) >= 2 * MAXNUMRANGE) + { /* compress */ + if (r == (ArrayType *) DatumGetPointer(entry->key)) r = (ArrayType *) PG_DETOAST_DATUM_COPY(entry->key); r = resize_intArrayType(r, 2 * (len)); @@ -411,11 +414,11 @@ g_int_compress(PG_FUNCTION_ARGS) r = resize_intArrayType(r, len); retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(r), - entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); + entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); PG_RETURN_POINTER(retval); - } else { - PG_RETURN_POINTER(entry); } + else + PG_RETURN_POINTER(entry); PG_RETURN_POINTER(entry); } @@ -423,7 +426,7 @@ g_int_compress(PG_FUNCTION_ARGS) Datum g_int_decompress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval; ArrayType *r; int *dr, @@ -436,17 +439,18 @@ g_int_decompress(PG_FUNCTION_ARGS) in = (ArrayType *) PG_DETOAST_DATUM(entry->key); - if ( ARRISVOID(in) ) { + if (ARRISVOID(in)) PG_RETURN_POINTER(entry); - } lenin = ARRNELEMS(in); - if (lenin < 2 * MAXNUMRANGE || ISLEAFKEY( in ) ) { /* not comressed value */ - if ( in != (ArrayType *) DatumGetPointer(entry->key)) { + if (lenin < 2 * MAXNUMRANGE || ISLEAFKEY(in)) + { /* not comressed value */ + if (in != (ArrayType *) DatumGetPointer(entry->key)) + { retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(in), - entry->rel, entry->page, entry->offset, VARSIZE(in), FALSE); + entry->rel, entry->page, entry->offset, VARSIZE(in), FALSE); PG_RETURN_POINTER(retval); } @@ -468,7 +472,7 @@ g_int_decompress(PG_FUNCTION_ARGS) pfree(in); retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(r), - entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); + entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); PG_RETURN_POINTER(retval); } @@ -479,26 +483,26 @@ g_int_decompress(PG_FUNCTION_ARGS) Datum g_int_penalty(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER( _int_common_penalty( - (GISTENTRY *)PG_GETARG_POINTER(0), - (GISTENTRY *)PG_GETARG_POINTER(1), - (float *) PG_GETARG_POINTER(2), - inner_int_union, rt__int_size - ) ); + PG_RETURN_POINTER(_int_common_penalty( + (GISTENTRY *) PG_GETARG_POINTER(0), + (GISTENTRY *) PG_GETARG_POINTER(1), + (float *) PG_GETARG_POINTER(2), + inner_int_union, rt__int_size + )); } Datum g_int_picksplit(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER( _int_common_picksplit( - (bytea *)PG_GETARG_POINTER(0), - (GIST_SPLITVEC *)PG_GETARG_POINTER(1), - inner_int_union, - inner_int_inter, - rt__int_size, - 0.01 - ) ); + PG_RETURN_POINTER(_int_common_picksplit( + (bytea *) PG_GETARG_POINTER(0), + (GIST_SPLITVEC *) PG_GETARG_POINTER(1), + inner_int_union, + inner_int_inter, + rt__int_size, + 0.01 + )); } /* @@ -509,21 +513,24 @@ g_int_picksplit(PG_FUNCTION_ARGS) Datum g_int_same(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)PointerGetDatum(PG_GETARG_POINTER(0)); - ArrayType *b = (ArrayType*)PointerGetDatum(PG_GETARG_POINTER(1)); - bool *result = (bool *)PG_GETARG_POINTER(2); - int4 n = ARRNELEMS(a); - int4 *da, *db; + ArrayType *a = (ArrayType *) PointerGetDatum(PG_GETARG_POINTER(0)); + ArrayType *b = (ArrayType *) PointerGetDatum(PG_GETARG_POINTER(1)); + bool *result = (bool *) PG_GETARG_POINTER(2); + int4 n = ARRNELEMS(a); + int4 *da, + *db; - if ( n != ARRNELEMS(b) ) { + if (n != ARRNELEMS(b)) + { *result = false; PG_RETURN_POINTER(result); } *result = TRUE; da = ARRPTR(a); db = ARRPTR(b); - while(n--) - if (*da++ != *db++) { + while (n--) + if (*da++ != *db++) + { *result = FALSE; break; } @@ -534,20 +541,20 @@ g_int_same(PG_FUNCTION_ARGS) Datum _int_contained(PG_FUNCTION_ARGS) { - PG_RETURN_BOOL( DatumGetBool( - DirectFunctionCall2( - _int_contains, - PointerGetDatum(PG_GETARG_POINTER(1)), - PointerGetDatum(PG_GETARG_POINTER(0)) - ) - )); + PG_RETURN_BOOL(DatumGetBool( + DirectFunctionCall2( + _int_contains, + PointerGetDatum(PG_GETARG_POINTER(1)), + PointerGetDatum(PG_GETARG_POINTER(0)) + ) + )); } Datum _int_contains(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); bool res; if (ARRISVOID(a) || ARRISVOID(b)) @@ -558,7 +565,7 @@ _int_contains(PG_FUNCTION_ARGS) res = inner_int_contains(a, b); pfree(a); pfree(b); - PG_RETURN_BOOL( res ); + PG_RETURN_BOOL(res); } static bool @@ -607,20 +614,20 @@ inner_int_contains(ArrayType *a, ArrayType *b) Datum _int_different(PG_FUNCTION_ARGS) { - PG_RETURN_BOOL( ! DatumGetBool( - DirectFunctionCall2( - _int_same, - PointerGetDatum(PG_GETARG_POINTER(0)), - PointerGetDatum(PG_GETARG_POINTER(1)) - ) - )); + PG_RETURN_BOOL(!DatumGetBool( + DirectFunctionCall2( + _int_same, + PointerGetDatum(PG_GETARG_POINTER(0)), + PointerGetDatum(PG_GETARG_POINTER(1)) + ) + )); } Datum _int_same(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); int na, nb; int n; @@ -664,8 +671,8 @@ _int_same(PG_FUNCTION_ARGS) Datum _int_overlap(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); bool result; if (ARRISVOID(a) || ARRISVOID(b)) @@ -679,7 +686,7 @@ _int_overlap(PG_FUNCTION_ARGS) pfree(a); pfree(b); - PG_RETURN_BOOL( result ); + PG_RETURN_BOOL(result); } static bool @@ -719,8 +726,8 @@ inner_int_overlap(ArrayType *a, ArrayType *b) Datum _int_union(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); ArrayType *result; if (!ARRISVOID(a)) @@ -735,10 +742,10 @@ _int_union(PG_FUNCTION_ARGS) if (b) pfree(b); - PG_RETURN_POINTER( result ); + PG_RETURN_POINTER(result); } -static ArrayType * +static ArrayType * inner_int_union(ArrayType *a, ArrayType *b) { ArrayType *r = NULL; @@ -794,8 +801,8 @@ inner_int_union(ArrayType *a, ArrayType *b) Datum _int_inter(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType *)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); ArrayType *result; if (ARRISVOID(a) || ARRISVOID(b)) @@ -809,10 +816,10 @@ _int_inter(PG_FUNCTION_ARGS) pfree(a); pfree(b); - PG_RETURN_POINTER( result ); + PG_RETURN_POINTER(result); } -static ArrayType * +static ArrayType * inner_int_inter(ArrayType *a, ArrayType *b) { ArrayType *r; @@ -874,9 +881,9 @@ rt__int_size(ArrayType *a, float *size) static bool isort(int4 *a, int len) { - int4 tmp, + int4 tmp, index; - int4 *cur, + int4 *cur, *end; bool r = FALSE; @@ -1030,16 +1037,16 @@ rt__intbig_size(ArrayType *a, float *sz) BITVECP bv = SIGPTR(a); LOOPBYTE( - len += - GETBITBYTE(bv,0) + - GETBITBYTE(bv,1) + - GETBITBYTE(bv,2) + - GETBITBYTE(bv,3) + - GETBITBYTE(bv,4) + - GETBITBYTE(bv,5) + - GETBITBYTE(bv,6) + - GETBITBYTE(bv,7) ; - bv = (BITVECP) ( ((char*)bv) + 1 ); + len += + GETBITBYTE(bv, 0) + + GETBITBYTE(bv, 1) + + GETBITBYTE(bv, 2) + + GETBITBYTE(bv, 3) + + GETBITBYTE(bv, 4) + + GETBITBYTE(bv, 5) + + GETBITBYTE(bv, 6) + + GETBITBYTE(bv, 7); + bv = (BITVECP) (((char *) bv) + 1); ); *sz = (float) len; @@ -1089,9 +1096,9 @@ _intbig_inter(ArrayType *a, ArrayType *b) Datum g_intbig_same(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType *)PG_GETARG_POINTER(0); - ArrayType *b = (ArrayType *)PG_GETARG_POINTER(1); - bool *result = (bool *)PG_GETARG_POINTER(2); + ArrayType *a = (ArrayType *) PG_GETARG_POINTER(0); + ArrayType *b = (ArrayType *) PG_GETARG_POINTER(1); + bool *result = (bool *) PG_GETARG_POINTER(2); BITVECP da, db; int i; @@ -1100,59 +1107,62 @@ g_intbig_same(PG_FUNCTION_ARGS) db = SIGPTR(b); LOOPBYTE( - if (da[i] != db[i]) - { + if (da[i] != db[i]) + { *result = FALSE; - PG_RETURN_POINTER( result ); + PG_RETURN_POINTER(result); } ); *result = TRUE; - PG_RETURN_POINTER( result ); + PG_RETURN_POINTER(result); } Datum g_intbig_compress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval; ArrayType *r, *in; - bool maycompress = true; - int i; + bool maycompress = true; + int i; if (DatumGetPointer(entry->key) != NULL) in = (ArrayType *) PG_DETOAST_DATUM(entry->key); else in = NULL; - if (!entry->leafkey) { + if (!entry->leafkey) + { LOOPBYTE( - if ( ( ((char*)ARRPTR(in))[i] & 0xff ) != 0xff ) { - maycompress = false; - break; - } + if ((((char *) ARRPTR(in))[i] & 0xff) != 0xff) + { + maycompress = false; + break; + } ); - if ( maycompress ) { + if (maycompress) + { retval = palloc(sizeof(GISTENTRY)); r = new_intArrayType(1); gistentryinit(*retval, PointerGetDatum(r), - entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); - PG_RETURN_POINTER( retval ); + entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); + PG_RETURN_POINTER(retval); } - PG_RETURN_POINTER( entry ); + PG_RETURN_POINTER(entry); } retval = palloc(sizeof(GISTENTRY)); - r = new_intArrayType( SIGLENINT ); + r = new_intArrayType(SIGLENINT); if (ARRISVOID(in)) { gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); if (in != (ArrayType *) DatumGetPointer(entry->key)) - pfree(in); - PG_RETURN_POINTER (retval); + pfree(in); + PG_RETURN_POINTER(retval); } gensign(SIGPTR(r), @@ -1160,104 +1170,108 @@ g_intbig_compress(PG_FUNCTION_ARGS) ARRNELEMS(in)); LOOPBYTE( - if( ( ((char*)ARRPTR(in))[i] & 0xff ) != 0xff ) { - maycompress = false; - break; - } + if ((((char *) ARRPTR(in))[i] & 0xff) != 0xff) + { + maycompress = false; + break; + } ); - if ( maycompress ) { + if (maycompress) + { pfree(r); r = new_intArrayType(1); } gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page, entry->offset, VARSIZE(r), FALSE); - if ( in != (ArrayType *) DatumGetPointer(entry->key)) - pfree(in); + if (in != (ArrayType *) DatumGetPointer(entry->key)) + pfree(in); - PG_RETURN_POINTER (retval); + PG_RETURN_POINTER(retval); } Datum g_intbig_decompress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); ArrayType *key; key = (ArrayType *) PG_DETOAST_DATUM(entry->key); - if ( key != (ArrayType *) DatumGetPointer(entry->key)) + if (key != (ArrayType *) DatumGetPointer(entry->key)) { GISTENTRY *retval; retval = palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(key), - entry->rel, entry->page, entry->offset, (key) ? VARSIZE(key) : 0, FALSE); - PG_RETURN_POINTER( retval ); + entry->rel, entry->page, entry->offset, (key) ? VARSIZE(key) : 0, FALSE); + PG_RETURN_POINTER(retval); } - if ( ARRNELEMS(key) == 1 ) { + if (ARRNELEMS(key) == 1) + { GISTENTRY *retval; ArrayType *newkey; retval = palloc(sizeof(GISTENTRY)); newkey = new_intArrayType(SIGLENINT); - MemSet( (void*)ARRPTR(newkey), 0xff, SIGLEN ); + MemSet((void *) ARRPTR(newkey), 0xff, SIGLEN); gistentryinit(*retval, PointerGetDatum(newkey), - entry->rel, entry->page, entry->offset, VARSIZE(newkey), FALSE); - PG_RETURN_POINTER( retval ); + entry->rel, entry->page, entry->offset, VARSIZE(newkey), FALSE); + PG_RETURN_POINTER(retval); } - PG_RETURN_POINTER( entry ); + PG_RETURN_POINTER(entry); } Datum g_intbig_picksplit(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER( _int_common_picksplit( - (bytea *)PG_GETARG_POINTER(0), - (GIST_SPLITVEC *)PG_GETARG_POINTER(1), - _intbig_union, - _intbig_inter, - rt__intbig_size, - 0.1 - ) ); + PG_RETURN_POINTER(_int_common_picksplit( + (bytea *) PG_GETARG_POINTER(0), + (GIST_SPLITVEC *) PG_GETARG_POINTER(1), + _intbig_union, + _intbig_inter, + rt__intbig_size, + 0.1 + )); } Datum g_intbig_union(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER( _int_common_union( - (bytea *) PG_GETARG_POINTER(0), - (int *) PG_GETARG_POINTER(1), - _intbig_union - ) ); + PG_RETURN_POINTER(_int_common_union( + (bytea *) PG_GETARG_POINTER(0), + (int *) PG_GETARG_POINTER(1), + _intbig_union + )); } Datum g_intbig_penalty(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER( _int_common_penalty( - (GISTENTRY *)PG_GETARG_POINTER(0), - (GISTENTRY *)PG_GETARG_POINTER(1), - (float *) PG_GETARG_POINTER(2), - _intbig_union, rt__intbig_size - ) ); + PG_RETURN_POINTER(_int_common_penalty( + (GISTENTRY *) PG_GETARG_POINTER(0), + (GISTENTRY *) PG_GETARG_POINTER(1), + (float *) PG_GETARG_POINTER(2), + _intbig_union, rt__intbig_size + )); } Datum -g_intbig_consistent(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); - ArrayType *query = ( ArrayType * )PG_GETARG_POINTER(1); - StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); +g_intbig_consistent(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + ArrayType *query = (ArrayType *) PG_GETARG_POINTER(1); + StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); bool retval; ArrayType *q; - if ( strategy == BooleanSearchStrategy ) - PG_RETURN_BOOL(signconsistent( (QUERYTYPE*)query, - SIGPTR((ArrayType *) DatumGetPointer(entry->key)), - false ) ); + if (strategy == BooleanSearchStrategy) + PG_RETURN_BOOL(signconsistent((QUERYTYPE *) query, + SIGPTR((ArrayType *) DatumGetPointer(entry->key)), + false)); /* XXX what about toasted input? */ if (ARRISVOID(query)) @@ -1274,13 +1288,13 @@ g_intbig_consistent(PG_FUNCTION_ARGS) { retval = _intbig_overlap((ArrayType *) DatumGetPointer(entry->key), q); break; case RTSameStrategyNumber: - if ( GIST_LEAF(entry) ) + if (GIST_LEAF(entry)) DirectFunctionCall3( - g_intbig_same, - entry->key, - PointerGetDatum(q), - PointerGetDatum(&retval) - ); + g_intbig_same, + entry->key, + PointerGetDatum(q), + PointerGetDatum(&retval) + ); else retval = _intbig_contains((ArrayType *) DatumGetPointer(entry->key), q); break; @@ -1305,7 +1319,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS) { ** The GiST Union method for _intments ** returns the minimal set that encloses all the entries in entryvec */ -static ArrayType * +static ArrayType * _int_common_union(bytea *entryvec, int *sizep, formarray unionf) { int numranges, @@ -1323,7 +1337,7 @@ _int_common_union(bytea *entryvec, int *sizep, formarray unionf) for (i = 1; i < numranges; i++) { out = (*unionf) (tmp, (ArrayType *) - DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key)); + DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key)); if (i > 1 && tmp) pfree(tmp); tmp = out; @@ -1376,17 +1390,19 @@ _int_common_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result, return (result); } -typedef struct { - OffsetNumber pos; +typedef struct +{ + OffsetNumber pos; float cost; } SPLITCOST; static int -comparecost( const void *a, const void *b ) { - if ( ((SPLITCOST*)a)->cost == ((SPLITCOST*)b)->cost ) +comparecost(const void *a, const void *b) +{ + if (((SPLITCOST *) a)->cost == ((SPLITCOST *) b)->cost) return 0; else - return ( ((SPLITCOST*)a)->cost > ((SPLITCOST*)b)->cost ) ? 1 : -1; + return (((SPLITCOST *) a)->cost > ((SPLITCOST *) b)->cost) ? 1 : -1; } /* @@ -1426,7 +1442,7 @@ _int_common_picksplit(bytea *entryvec, OffsetNumber *left, *right; OffsetNumber maxoff; - SPLITCOST *costvector; + SPLITCOST *costvector; #ifdef GIST_DEBUG elog(DEBUG3, "--------picksplit %d", (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)); @@ -1478,7 +1494,8 @@ _int_common_picksplit(bytea *entryvec, v->spl_nleft = 0; right = v->spl_right; v->spl_nright = 0; - if ( seed_1 == 0 || seed_2 == 0 ) { + if (seed_1 == 0 || seed_2 == 0) + { seed_1 = 1; seed_2 = 2; } @@ -1491,22 +1508,24 @@ _int_common_picksplit(bytea *entryvec, (*sizef) (datum_r, &size_r); maxoff = OffsetNumberNext(maxoff); + /* - * sort entries + * sort entries */ - costvector=(SPLITCOST*)palloc( sizeof(SPLITCOST)*maxoff ); - for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { - costvector[i-1].pos = i; + costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff); + for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) + { + costvector[i - 1].pos = i; datum_alpha = (ArrayType *) DatumGetPointer(((GISTENTRY *) VARDATA(entryvec))[i].key); - union_d = (*unionf)(datum_l, datum_alpha); - (*sizef)(union_d, &size_alpha); - pfree( union_d ); - union_d = (*unionf)(datum_r, datum_alpha); - (*sizef)(union_d, &size_beta); - pfree( union_d ); - costvector[i-1].cost = abs( (size_alpha - size_l) - (size_beta - size_r) ); + union_d = (*unionf) (datum_l, datum_alpha); + (*sizef) (union_d, &size_alpha); + pfree(union_d); + union_d = (*unionf) (datum_r, datum_alpha); + (*sizef) (union_d, &size_beta); + pfree(union_d); + costvector[i - 1].cost = abs((size_alpha - size_l) - (size_beta - size_r)); } - qsort( (void*)costvector, maxoff, sizeof(SPLITCOST), comparecost ); + qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost); /* * Now split up the regions between the two seeds. An important @@ -1521,7 +1540,8 @@ _int_common_picksplit(bytea *entryvec, */ - for (j = 0; j < maxoff; j++) { + for (j = 0; j < maxoff; j++) + { i = costvector[j].pos; /* @@ -1574,7 +1594,7 @@ _int_common_picksplit(bytea *entryvec, v->spl_nright++; } } - pfree( costvector ); + pfree(costvector); *right = *left = FirstOffsetNumber; datum_l->flags &= ~LEAFKEY; @@ -1589,19 +1609,19 @@ _int_common_picksplit(bytea *entryvec, } /***************************************************************************** - * BoolSearch + * BoolSearch *****************************************************************************/ -#define END 0 -#define ERR 1 -#define VAL 2 -#define OPR 3 -#define OPEN 4 -#define CLOSE 5 +#define END 0 +#define ERR 1 +#define VAL 2 +#define OPR 3 +#define OPEN 4 +#define CLOSE 5 /* parser's states */ -#define WAITOPERAND 1 +#define WAITOPERAND 1 #define WAITENDOPERAND 2 #define WAITOPERATOR 3 @@ -1609,75 +1629,94 @@ _int_common_picksplit(bytea *entryvec, * node of query tree, also used * for storing polish notation in parser */ -typedef struct NODE { - int4 type; - int4 val; - struct NODE *next; -} NODE; - -typedef struct { - char *buf; - int4 state; - int4 count; - /* reverse polish notation in list (for temprorary usage)*/ - NODE *str; +typedef struct NODE +{ + int4 type; + int4 val; + struct NODE *next; +} NODE; + +typedef struct +{ + char *buf; + int4 state; + int4 count; + /* reverse polish notation in list (for temprorary usage) */ + NODE *str; /* number in str */ - int4 num; -} WORKSTATE; + int4 num; +} WORKSTATE; /* * get token from query string */ static int4 -gettoken( WORKSTATE* state, int4* val ) { - char nnn[16], *curnnn; +gettoken(WORKSTATE * state, int4 *val) +{ + char nnn[16], + *curnnn; - curnnn=nnn; - while(1) { - switch(state->state) { + curnnn = nnn; + while (1) + { + switch (state->state) + { case WAITOPERAND: - curnnn=nnn; - if ( (*(state->buf)>='0' && *(state->buf)<='9') || - *(state->buf)=='-' ) { + curnnn = nnn; + if ((*(state->buf) >= '0' && *(state->buf) <= '9') || + *(state->buf) == '-') + { state->state = WAITENDOPERAND; *curnnn = *(state->buf); curnnn++; - } else if ( *(state->buf) == '!' ) { + } + else if (*(state->buf) == '!') + { (state->buf)++; - *val = (int4)'!'; + *val = (int4) '!'; return OPR; - } else if ( *(state->buf) == '(' ) { + } + else if (*(state->buf) == '(') + { state->count++; (state->buf)++; return OPEN; - } else if ( *(state->buf) != ' ' ) + } + else if (*(state->buf) != ' ') return ERR; break; case WAITENDOPERAND: - if ( *(state->buf)>='0' && *(state->buf)<='9' ) { + if (*(state->buf) >= '0' && *(state->buf) <= '9') + { *curnnn = *(state->buf); curnnn++; - } else { + } + else + { *curnnn = '\0'; - *val=(int4)atoi( nnn ); + *val = (int4) atoi(nnn); state->state = WAITOPERATOR; - return ( state->count && *(state->buf) == '\0' ) + return (state->count && *(state->buf) == '\0') ? ERR : VAL; } break; case WAITOPERATOR: - if ( *(state->buf) == '&' || *(state->buf) == '|' ) { + if (*(state->buf) == '&' || *(state->buf) == '|') + { state->state = WAITOPERAND; *val = (int4) *(state->buf); (state->buf)++; return OPR; - } else if ( *(state->buf) == ')' ) { + } + else if (*(state->buf) == ')') + { (state->buf)++; state->count--; - return ( state->count <0 ) ? ERR : CLOSE; - } else if ( *(state->buf) == '\0' ) { - return ( state->count ) ? ERR : END; - } else if ( *(state->buf) != ' ' ) + return (state->count < 0) ? ERR : CLOSE; + } + else if (*(state->buf) == '\0') + return (state->count) ? ERR : END; + else if (*(state->buf) != ' ') return ERR; break; default: @@ -1693,10 +1732,12 @@ gettoken( WORKSTATE* state, int4* val ) { * push new one in polish notation reverse view */ static void -pushquery( WORKSTATE *state, int4 type, int4 val ) { - NODE *tmp = (NODE*)palloc(sizeof(NODE)); - tmp->type=type; - tmp->val =val; +pushquery(WORKSTATE * state, int4 type, int4 val) +{ + NODE *tmp = (NODE *) palloc(sizeof(NODE)); + + tmp->type = type; + tmp->val = val; tmp->next = state->str; state->str = tmp; state->num++; @@ -1708,82 +1749,95 @@ pushquery( WORKSTATE *state, int4 type, int4 val ) { * make polish notaion of query */ static int4 -makepol(WORKSTATE *state) { - int4 val,type; - int4 stack[STACKDEPTH]; - int4 lenstack=0; +makepol(WORKSTATE * state) +{ + int4 val, + type; + int4 stack[STACKDEPTH]; + int4 lenstack = 0; - while( (type=gettoken(state, &val))!=END ) { - switch(type) { + while ((type = gettoken(state, &val)) != END) + { + switch (type) + { case VAL: pushquery(state, type, val); - while ( lenstack && (stack[ lenstack-1 ] == (int4)'&' || - stack[ lenstack-1 ] == (int4)'!') ) { + while (lenstack && (stack[lenstack - 1] == (int4) '&' || + stack[lenstack - 1] == (int4) '!')) + { lenstack--; - pushquery(state, OPR, stack[ lenstack ]); + pushquery(state, OPR, stack[lenstack]); } break; case OPR: - if ( lenstack && val == (int4) '|' ) { + if (lenstack && val == (int4) '|') pushquery(state, OPR, val); - } else { - if ( lenstack == STACKDEPTH ) - elog(ERROR,"Stack too short"); - stack[ lenstack ] = val; + else + { + if (lenstack == STACKDEPTH) + elog(ERROR, "Stack too short"); + stack[lenstack] = val; lenstack++; } break; case OPEN: - if ( makepol( state ) == ERR ) return ERR; - if ( lenstack && (stack[ lenstack-1 ] == (int4)'&' || - stack[ lenstack-1 ] == (int4)'!') ) { + if (makepol(state) == ERR) + return ERR; + if (lenstack && (stack[lenstack - 1] == (int4) '&' || + stack[lenstack - 1] == (int4) '!')) + { lenstack--; - pushquery(state, OPR, stack[ lenstack ]); + pushquery(state, OPR, stack[lenstack]); } break; case CLOSE: - while ( lenstack ) { + while (lenstack) + { lenstack--; - pushquery(state, OPR, stack[ lenstack ]); + pushquery(state, OPR, stack[lenstack]); }; return END; break; case ERR: default: - elog(ERROR,"Syntax error"); + elog(ERROR, "Syntax error"); return ERR; } } - while (lenstack) { + while (lenstack) + { lenstack--; - pushquery(state, OPR, stack[ lenstack ]); + pushquery(state, OPR, stack[lenstack]); }; return END; } -typedef struct { - int4 *arrb; - int4 *arre; -} CHKVAL; +typedef struct +{ + int4 *arrb; + int4 *arre; +} CHKVAL; /* * is there value 'val' in array or not ? */ static bool -checkcondition_arr( void *checkval, int4 val ) { - int4 *StopLow = ((CHKVAL*)checkval)->arrb; - int4 *StopHigh = ((CHKVAL*)checkval)->arre; - int4 *StopMiddle; +checkcondition_arr(void *checkval, int4 val) +{ + int4 *StopLow = ((CHKVAL *) checkval)->arrb; + int4 *StopHigh = ((CHKVAL *) checkval)->arre; + int4 *StopMiddle; /* Loop invariant: StopLow <= val < StopHigh */ - while (StopLow < StopHigh) { + while (StopLow < StopHigh) + { StopMiddle = StopLow + (StopHigh - StopLow) / 2; if (*StopMiddle == val) return (true); - else if (*StopMiddle < val ) + else if (*StopMiddle < val) StopLow = StopMiddle + 1; else StopHigh = StopMiddle; @@ -1792,29 +1846,36 @@ checkcondition_arr( void *checkval, int4 val ) { } static bool -checkcondition_bit( void *checkval, int4 val ) { - return GETBIT( checkval, HASHVAL( val ) ); +checkcondition_bit(void *checkval, int4 val) +{ + return GETBIT(checkval, HASHVAL(val)); } /* * check for boolean condition */ static bool -execute( ITEM* curitem, void *checkval, bool calcnot, bool (*chkcond)(void *checkval, int4 val )) { +execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, int4 val)) +{ - if ( curitem->type == VAL ) { - return (*chkcond)( checkval, curitem->val ); - } else if ( curitem->val == (int4)'!' ) { - return ( calcnot ) ? - ( ( execute(curitem - 1, checkval, calcnot, chkcond) ) ? false : true ) + if (curitem->type == VAL) + return (*chkcond) (checkval, curitem->val); + else if (curitem->val == (int4) '!') + { + return (calcnot) ? + ((execute(curitem - 1, checkval, calcnot, chkcond)) ? false : true) : true; - } else if ( curitem->val == (int4)'&' ) { - if ( execute(curitem + curitem->left, checkval, calcnot, chkcond) ) + } + else if (curitem->val == (int4) '&') + { + if (execute(curitem + curitem->left, checkval, calcnot, chkcond)) return execute(curitem - 1, checkval, calcnot, chkcond); else return false; - } else { /* |-operator */ - if ( execute(curitem + curitem->left, checkval, calcnot, chkcond) ) + } + else + { /* |-operator */ + if (execute(curitem + curitem->left, checkval, calcnot, chkcond)) return true; else return execute(curitem - 1, checkval, calcnot, chkcond); @@ -1826,86 +1887,98 @@ execute( ITEM* curitem, void *checkval, bool calcnot, bool (*chkcond)(void *chec * signconsistent & execconsistent called by *_consistent */ static bool -signconsistent( QUERYTYPE *query, BITVEC sign, bool calcnot ) { +signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot) +{ return execute( - GETQUERY(query) + query->size-1 , - (void*)sign, calcnot, - checkcondition_bit + GETQUERY(query) + query->size - 1, + (void *) sign, calcnot, + checkcondition_bit ); } static bool -execconsistent( QUERYTYPE *query, ArrayType *array, bool calcnot ) { - CHKVAL chkval; +execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot) +{ + CHKVAL chkval; chkval.arrb = ARRPTR(array); chkval.arre = chkval.arrb + ARRNELEMS(array); return execute( - GETQUERY(query) + query->size-1 , - (void*)&chkval, calcnot, - checkcondition_arr - ); + GETQUERY(query) + query->size - 1, + (void *) &chkval, calcnot, + checkcondition_arr + ); } /* * boolean operations */ Datum -rboolop(PG_FUNCTION_ARGS) { +rboolop(PG_FUNCTION_ARGS) +{ return DirectFunctionCall2( - boolop, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) + boolop, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) ); } Datum -boolop(PG_FUNCTION_ARGS) { - ArrayType *val = ( ArrayType * )PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0)); - QUERYTYPE *query = ( QUERYTYPE * )PG_DETOAST_DATUM(PG_GETARG_POINTER(1)); - CHKVAL chkval; - bool result; +boolop(PG_FUNCTION_ARGS) +{ + ArrayType *val = (ArrayType *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0)); + QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(1)); + CHKVAL chkval; + bool result; - if ( ARRISVOID( val ) ) { + if (ARRISVOID(val)) + { pfree(val); - PG_FREE_IF_COPY(query,1); - PG_RETURN_BOOL( false ); + PG_FREE_IF_COPY(query, 1); + PG_RETURN_BOOL(false); } PREPAREARR(val); chkval.arrb = ARRPTR(val); chkval.arre = chkval.arrb + ARRNELEMS(val); result = execute( - GETQUERY(query) + query->size-1 , - &chkval, true, - checkcondition_arr - ); + GETQUERY(query) + query->size - 1, + &chkval, true, + checkcondition_arr + ); pfree(val); - PG_FREE_IF_COPY(query,1); - PG_RETURN_BOOL( result ); + PG_FREE_IF_COPY(query, 1); + PG_RETURN_BOOL(result); } static void -findoprnd( ITEM *ptr, int4 *pos ) { +findoprnd(ITEM * ptr, int4 *pos) +{ #ifdef BS_DEBUG - elog(DEBUG3, ( ptr[*pos].type == OPR ) ? - "%d %c" : "%d %d ", *pos, ptr[*pos].val ); + elog(DEBUG3, (ptr[*pos].type == OPR) ? + "%d %c" : "%d %d ", *pos, ptr[*pos].val); #endif - if ( ptr[*pos].type == VAL ) { + if (ptr[*pos].type == VAL) + { ptr[*pos].left = 0; (*pos)--; - } else if ( ptr[*pos].val == (int4)'!' ) { + } + else if (ptr[*pos].val == (int4) '!') + { ptr[*pos].left = -1; (*pos)--; - findoprnd( ptr, pos ); - } else { - ITEM *curitem = &ptr[*pos]; - int4 tmp = *pos; + findoprnd(ptr, pos); + } + else + { + ITEM *curitem = &ptr[*pos]; + int4 tmp = *pos; + (*pos)--; - findoprnd(ptr,pos); + findoprnd(ptr, pos); curitem->left = *pos - tmp; - findoprnd(ptr,pos); + findoprnd(ptr, pos); } } @@ -1914,71 +1987,76 @@ findoprnd( ITEM *ptr, int4 *pos ) { * input */ Datum -bqarr_in(PG_FUNCTION_ARGS) { - char *buf=(char*)PG_GETARG_POINTER(0); - WORKSTATE state; - int4 i; - QUERYTYPE *query; - int4 commonlen; - ITEM *ptr; - NODE *tmp; - int4 pos=0; +bqarr_in(PG_FUNCTION_ARGS) +{ + char *buf = (char *) PG_GETARG_POINTER(0); + WORKSTATE state; + int4 i; + QUERYTYPE *query; + int4 commonlen; + ITEM *ptr; + NODE *tmp; + int4 pos = 0; + #ifdef BS_DEBUG - StringInfoData pbuf; + StringInfoData pbuf; #endif state.buf = buf; state.state = WAITOPERAND; state.count = 0; state.num = 0; - state.str=NULL; + state.str = NULL; /* make polish notation (postfix, but in reverse order) */ - makepol( &state ); + makepol(&state); if (!state.num) - elog( ERROR,"Empty query"); + elog(ERROR, "Empty query"); commonlen = COMPUTESIZE(state.num); - query = (QUERYTYPE*) palloc( commonlen ); + query = (QUERYTYPE *) palloc(commonlen); query->len = commonlen; query->size = state.num; ptr = GETQUERY(query); - for(i=state.num-1; i>=0; i-- ) { + for (i = state.num - 1; i >= 0; i--) + { ptr[i].type = state.str->type; ptr[i].val = state.str->val; tmp = state.str->next; - pfree( state.str ); + pfree(state.str); state.str = tmp; } - pos = query->size-1; - findoprnd( ptr, &pos ); + pos = query->size - 1; + findoprnd(ptr, &pos); #ifdef BS_DEBUG initStringInfo(&pbuf); - for( i=0;i<query->size;i++ ) { - if ( ptr[i].type == OPR ) + for (i = 0; i < query->size; i++) + { + if (ptr[i].type == OPR) appendStringInfo(&pbuf, "%c(%d) ", ptr[i].val, ptr[i].left); else - appendStringInfo(&pbuf, "%d ", ptr[i].val ); + appendStringInfo(&pbuf, "%d ", ptr[i].val); } - elog(DEBUG3,"POR: %s", pbuf.data); + elog(DEBUG3, "POR: %s", pbuf.data); pfree(pbuf.data); #endif - PG_RETURN_POINTER( query ); + PG_RETURN_POINTER(query); } /* * out function */ -typedef struct { - ITEM *curpol; - char *buf; - char *cur; - int4 buflen; -} INFIX; +typedef struct +{ + ITEM *curpol; + char *buf; + char *cur; + int4 buflen; +} INFIX; #define RESIZEBUF(inf,addsize) while( ( inf->cur - inf->buf ) + addsize + 1 >= inf->buflen ) { \ int4 len = inf->cur - inf->buf; \ @@ -1988,94 +2066,106 @@ typedef struct { } static void -infix(INFIX *in, bool first) { - if ( in->curpol->type == VAL ) { +infix(INFIX * in, bool first) +{ + if (in->curpol->type == VAL) + { RESIZEBUF(in, 11); - sprintf(in->cur, "%d", in->curpol->val ); - in->cur = strchr( in->cur, '\0' ); + sprintf(in->cur, "%d", in->curpol->val); + in->cur = strchr(in->cur, '\0'); in->curpol--; - } else if ( in->curpol->val == (int4)'!' ) { - bool isopr = false; + } + else if (in->curpol->val == (int4) '!') + { + bool isopr = false; + RESIZEBUF(in, 1); *(in->cur) = '!'; in->cur++; *(in->cur) = '\0'; in->curpol--; - if ( in->curpol->type == OPR ) { + if (in->curpol->type == OPR) + { isopr = true; RESIZEBUF(in, 2); sprintf(in->cur, "( "); - in->cur = strchr( in->cur, '\0' ); + in->cur = strchr(in->cur, '\0'); } - infix( in, isopr ); - if ( isopr ) { + infix(in, isopr); + if (isopr) + { RESIZEBUF(in, 2); sprintf(in->cur, " )"); - in->cur = strchr( in->cur, '\0' ); + in->cur = strchr(in->cur, '\0'); } - } else { - int4 op = in->curpol->val; - INFIX nrm; + } + else + { + int4 op = in->curpol->val; + INFIX nrm; in->curpol--; - if ( op == (int4)'|' && ! first) { + if (op == (int4) '|' && !first) + { RESIZEBUF(in, 2); sprintf(in->cur, "( "); - in->cur = strchr( in->cur, '\0' ); + in->cur = strchr(in->cur, '\0'); } nrm.curpol = in->curpol; nrm.buflen = 16; - nrm.cur = nrm.buf = (char*)palloc( sizeof(char) * nrm.buflen ); + nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen); /* get right operand */ - infix( &nrm, false ); + infix(&nrm, false); /* get & print left operand */ in->curpol = nrm.curpol; - infix( in, false ); + infix(in, false); - /* print operator & right operand*/ - RESIZEBUF(in, 3 + (nrm.cur - nrm.buf) ); + /* print operator & right operand */ + RESIZEBUF(in, 3 + (nrm.cur - nrm.buf)); sprintf(in->cur, " %c %s", op, nrm.buf); - in->cur = strchr( in->cur, '\0' ); - pfree( nrm.buf ); + in->cur = strchr(in->cur, '\0'); + pfree(nrm.buf); - if ( op == (int4)'|' && ! first) { + if (op == (int4) '|' && !first) + { RESIZEBUF(in, 2); sprintf(in->cur, " )"); - in->cur = strchr( in->cur, '\0' ); + in->cur = strchr(in->cur, '\0'); } } } Datum -bqarr_out(PG_FUNCTION_ARGS) { - QUERYTYPE *query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(0)); - INFIX nrm; +bqarr_out(PG_FUNCTION_ARGS) +{ + QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0)); + INFIX nrm; - if ( query->size == 0 ) - elog(ERROR,"Empty"); + if (query->size == 0) + elog(ERROR, "Empty"); nrm.curpol = GETQUERY(query) + query->size - 1; nrm.buflen = 32; - nrm.cur = nrm.buf = (char*)palloc( sizeof(char) * nrm.buflen ); + nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen); *(nrm.cur) = '\0'; - infix( &nrm, true ); + infix(&nrm, true); - PG_FREE_IF_COPY(query,0); - PG_RETURN_POINTER( nrm.buf ); + PG_FREE_IF_COPY(query, 0); + PG_RETURN_POINTER(nrm.buf); } static int4 -countdroptree( ITEM *q, int4 pos ) { - if ( q[pos].type == VAL ) { +countdroptree(ITEM * q, int4 pos) +{ + if (q[pos].type == VAL) return 1; - } else if ( q[pos].val == (int4)'!' ) { - return 1+countdroptree(q, pos-1); - } else { - return 1 + countdroptree(q, pos-1) + countdroptree(q, pos + q[pos].left); - } + else if (q[pos].val == (int4) '!') + return 1 + countdroptree(q, pos - 1); + else + return 1 + countdroptree(q, pos - 1) + countdroptree(q, pos + q[pos].left); } /* @@ -2084,137 +2174,161 @@ countdroptree( ITEM *q, int4 pos ) { * we can modify query tree for clearing */ static int4 -shorterquery( ITEM *q, int4 len ) { - int4 index,posnot,poscor; - bool notisleft = false; - int4 drop,i; +shorterquery(ITEM * q, int4 len) +{ + int4 index, + posnot, + poscor; + bool notisleft = false; + int4 drop, + i; /* out all '!' */ - do { - index=0; - drop=0; + do + { + index = 0; + drop = 0; /* find ! */ - for(posnot=0; posnot < len; posnot++) - if ( q[posnot].type == OPR && q[posnot].val == (int4)'!') { - index=1; + for (posnot = 0; posnot < len; posnot++) + if (q[posnot].type == OPR && q[posnot].val == (int4) '!') + { + index = 1; break; } - if ( posnot == len ) + if (posnot == len) return len; /* last operator is ! */ - if ( posnot == len-1 ) + if (posnot == len - 1) return 0; /* find operator for this operand */ - for( poscor=posnot+1; poscor<len; poscor++) { - if ( q[poscor].type == OPR ) { - if ( poscor == posnot+1 ) { + for (poscor = posnot + 1; poscor < len; poscor++) + { + if (q[poscor].type == OPR) + { + if (poscor == posnot + 1) + { notisleft = false; break; - } else if ( q[poscor].left + poscor == posnot ) { + } + else if (q[poscor].left + poscor == posnot) + { notisleft = true; break; } } } - if ( q[poscor].val == (int4)'!' ) { + if (q[poscor].val == (int4) '!') + { drop = countdroptree(q, poscor); - q[poscor-1].type=VAL; - for(i=poscor+1;i<len;i++) - if ( q[i].type == OPR && q[i].left + i <= poscor ) + q[poscor - 1].type = VAL; + for (i = poscor + 1; i < len; i++) + if (q[i].type == OPR && q[i].left + i <= poscor) q[i].left += drop - 2; - memcpy( (void*)&q[poscor-drop+1], - (void*)&q[poscor-1], - sizeof(ITEM) * ( len - (poscor-1) )); + memcpy((void *) &q[poscor - drop + 1], + (void *) &q[poscor - 1], + sizeof(ITEM) * (len - (poscor - 1))); len -= drop - 2; - } else if ( q[poscor].val == (int4)'|' ) { + } + else if (q[poscor].val == (int4) '|') + { drop = countdroptree(q, poscor); - q[poscor-1].type=VAL; - q[poscor].val=(int4)'!'; - q[poscor].left=-1; - for(i=poscor+1;i<len;i++) - if ( q[i].type == OPR && q[i].left + i < poscor ) + q[poscor - 1].type = VAL; + q[poscor].val = (int4) '!'; + q[poscor].left = -1; + for (i = poscor + 1; i < len; i++) + if (q[i].type == OPR && q[i].left + i < poscor) q[i].left += drop - 2; - memcpy( (void*)&q[poscor-drop+1], - (void*)&q[poscor-1], - sizeof(ITEM) * ( len - (poscor-1) )); + memcpy((void *) &q[poscor - drop + 1], + (void *) &q[poscor - 1], + sizeof(ITEM) * (len - (poscor - 1))); len -= drop - 2; - } else { /* &-operator */ + } + else + { /* &-operator */ if ( - (notisleft && q[poscor-1].type == OPR && - q[poscor-1].val == (int4)'!' ) || - (!notisleft && q[poscor+q[poscor].left].type == OPR && - q[poscor+q[poscor].left].val == (int4)'!' ) - ) { /* drop subtree */ + (notisleft && q[poscor - 1].type == OPR && + q[poscor - 1].val == (int4) '!') || + (!notisleft && q[poscor + q[poscor].left].type == OPR && + q[poscor + q[poscor].left].val == (int4) '!') + ) + { /* drop subtree */ drop = countdroptree(q, poscor); - q[poscor-1].type=VAL; - q[poscor].val=(int4)'!'; - q[poscor].left=-1; - for(i=poscor+1;i<len;i++) - if ( q[i].type == OPR && q[i].left + i < poscor ) + q[poscor - 1].type = VAL; + q[poscor].val = (int4) '!'; + q[poscor].left = -1; + for (i = poscor + 1; i < len; i++) + if (q[i].type == OPR && q[i].left + i < poscor) q[i].left += drop - 2; - memcpy( (void*)&q[poscor-drop+1], - (void*)&q[poscor-1], - sizeof(ITEM) * ( len - (poscor-1) )); + memcpy((void *) &q[poscor - drop + 1], + (void *) &q[poscor - 1], + sizeof(ITEM) * (len - (poscor - 1))); len -= drop - 2; - } else { /* drop only operator */ - int4 subtreepos = ( notisleft ) ? - poscor-1 : poscor+q[poscor].left; - int4 subtreelen = countdroptree( q, subtreepos ); + } + else + { /* drop only operator */ + int4 subtreepos = (notisleft) ? + poscor - 1 : poscor + q[poscor].left; + int4 subtreelen = countdroptree(q, subtreepos); + drop = countdroptree(q, poscor); - for(i=poscor+1;i<len;i++) - if ( q[i].type == OPR && q[i].left + i < poscor ) + for (i = poscor + 1; i < len; i++) + if (q[i].type == OPR && q[i].left + i < poscor) q[i].left += drop - subtreelen; - memcpy( (void*)&q[ subtreepos+1 ], - (void*)&q[poscor+1], - sizeof(ITEM)*( len - (poscor-1) ) ); - memcpy( (void*)&q[ poscor-drop+1 ], - (void*)&q[subtreepos-subtreelen+1], - sizeof(ITEM)*( len - (drop-subtreelen) ) ); + memcpy((void *) &q[subtreepos + 1], + (void *) &q[poscor + 1], + sizeof(ITEM) * (len - (poscor - 1))); + memcpy((void *) &q[poscor - drop + 1], + (void *) &q[subtreepos - subtreelen + 1], + sizeof(ITEM) * (len - (drop - subtreelen))); len -= drop - subtreelen; } } - } while( index ); + } while (index); return len; } Datum -querytree(PG_FUNCTION_ARGS) { - QUERYTYPE *query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(0)); - INFIX nrm; - text *res; - ITEM *q; - int4 len; - - if ( query->size == 0 ) - elog(ERROR,"Empty"); - - q = (ITEM*)palloc( sizeof(ITEM) * query->size ); - memcpy( (void*)q, GETQUERY(query), sizeof(ITEM) * query->size ); - len = shorterquery( q, query->size ); - PG_FREE_IF_COPY(query,0); - - if ( len == 0 ) { - res = (text*) palloc( 1 + VARHDRSZ ); +querytree(PG_FUNCTION_ARGS) +{ + QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0)); + INFIX nrm; + text *res; + ITEM *q; + int4 len; + + if (query->size == 0) + elog(ERROR, "Empty"); + + q = (ITEM *) palloc(sizeof(ITEM) * query->size); + memcpy((void *) q, GETQUERY(query), sizeof(ITEM) * query->size); + len = shorterquery(q, query->size); + PG_FREE_IF_COPY(query, 0); + + if (len == 0) + { + res = (text *) palloc(1 + VARHDRSZ); VARATT_SIZEP(res) = 1 + VARHDRSZ; - *((char*)VARDATA(res)) = 'T'; - } else { + *((char *) VARDATA(res)) = 'T'; + } + else + { nrm.curpol = q + len - 1; nrm.buflen = 32; - nrm.cur = nrm.buf = (char*)palloc( sizeof(char) * nrm.buflen ); + nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen); *(nrm.cur) = '\0'; - infix( &nrm, true ); + infix(&nrm, true); - res = (text*) palloc( nrm.cur-nrm.buf + VARHDRSZ ); - VARATT_SIZEP(res) = nrm.cur-nrm.buf + VARHDRSZ; - strncpy( VARDATA(res), nrm.buf, nrm.cur-nrm.buf ); + res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ); + VARATT_SIZEP(res) = nrm.cur - nrm.buf + VARHDRSZ; + strncpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf); } pfree(q); - PG_RETURN_POINTER( res ); + PG_RETURN_POINTER(res); } /* @@ -2225,72 +2339,84 @@ static ArrayType *intarray_add_elem(ArrayType *a, int32 elem); static ArrayType *intarray_concat_arrays(ArrayType *a, ArrayType *b); static ArrayType *int_to_intset(int32 elem); -PG_FUNCTION_INFO_V1( intset ); -PG_FUNCTION_INFO_V1( icount ); -PG_FUNCTION_INFO_V1( sort ); -PG_FUNCTION_INFO_V1( sort_asc ); -PG_FUNCTION_INFO_V1( sort_desc ); -PG_FUNCTION_INFO_V1( uniq ); -PG_FUNCTION_INFO_V1( idx ); -PG_FUNCTION_INFO_V1( subarray ); -PG_FUNCTION_INFO_V1( intarray_push_elem ); -PG_FUNCTION_INFO_V1( intarray_push_array ); -PG_FUNCTION_INFO_V1( intarray_del_elem ); -PG_FUNCTION_INFO_V1( intset_union_elem ); -PG_FUNCTION_INFO_V1( intset_subtract ); -Datum intset(PG_FUNCTION_ARGS); -Datum icount(PG_FUNCTION_ARGS); -Datum sort(PG_FUNCTION_ARGS); -Datum sort_asc(PG_FUNCTION_ARGS); -Datum sort_desc(PG_FUNCTION_ARGS); -Datum uniq(PG_FUNCTION_ARGS); -Datum idx(PG_FUNCTION_ARGS); -Datum subarray(PG_FUNCTION_ARGS); -Datum intarray_push_elem(PG_FUNCTION_ARGS); -Datum intarray_push_array(PG_FUNCTION_ARGS); -Datum intarray_del_elem(PG_FUNCTION_ARGS); -Datum intset_union_elem(PG_FUNCTION_ARGS); -Datum intset_subtract(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(intset); +PG_FUNCTION_INFO_V1(icount); +PG_FUNCTION_INFO_V1(sort); +PG_FUNCTION_INFO_V1(sort_asc); +PG_FUNCTION_INFO_V1(sort_desc); +PG_FUNCTION_INFO_V1(uniq); +PG_FUNCTION_INFO_V1(idx); +PG_FUNCTION_INFO_V1(subarray); +PG_FUNCTION_INFO_V1(intarray_push_elem); +PG_FUNCTION_INFO_V1(intarray_push_array); +PG_FUNCTION_INFO_V1(intarray_del_elem); +PG_FUNCTION_INFO_V1(intset_union_elem); +PG_FUNCTION_INFO_V1(intset_subtract); +Datum intset(PG_FUNCTION_ARGS); +Datum icount(PG_FUNCTION_ARGS); +Datum sort(PG_FUNCTION_ARGS); +Datum sort_asc(PG_FUNCTION_ARGS); +Datum sort_desc(PG_FUNCTION_ARGS); +Datum uniq(PG_FUNCTION_ARGS); +Datum idx(PG_FUNCTION_ARGS); +Datum subarray(PG_FUNCTION_ARGS); +Datum intarray_push_elem(PG_FUNCTION_ARGS); +Datum intarray_push_array(PG_FUNCTION_ARGS); +Datum intarray_del_elem(PG_FUNCTION_ARGS); +Datum intset_union_elem(PG_FUNCTION_ARGS); +Datum intset_subtract(PG_FUNCTION_ARGS); static int32 -intarray_match_first(ArrayType *a, int32 elem) { - int32 *aa, c, i; - c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); +intarray_match_first(ArrayType *a, int32 elem) +{ + int32 *aa, + c, + i; + + c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); aa = ARRPTR(a); for (i = 0; i < c; i++) - if (aa[i] == elem) return (i + 1); + if (aa[i] == elem) + return (i + 1); return 0; } static ArrayType * -intarray_add_elem(ArrayType *a, int32 elem) { - ArrayType *result; - int32 *r; - int32 c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); +intarray_add_elem(ArrayType *a, int32 elem) +{ + ArrayType *result; + int32 *r; + int32 c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); + result = new_intArrayType(c + 1); r = ARRPTR(result); - if (c > 0) memcpy(r, ARRPTR(a), c * sizeof(int32)); + if (c > 0) + memcpy(r, ARRPTR(a), c * sizeof(int32)); r[c] = elem; return result; } static ArrayType * -intarray_concat_arrays(ArrayType *a, ArrayType *b) { - ArrayType *result; - int32 ac = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); - int32 bc = (ARRISVOID(b)) ? 0 : ARRNELEMS(b); - result = new_intArrayType(ac+bc); - if ( ac ) +intarray_concat_arrays(ArrayType *a, ArrayType *b) +{ + ArrayType *result; + int32 ac = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); + int32 bc = (ARRISVOID(b)) ? 0 : ARRNELEMS(b); + + result = new_intArrayType(ac + bc); + if (ac) memcpy(ARRPTR(result), ARRPTR(a), ac * sizeof(int32)); - if ( bc ) + if (bc) memcpy(ARRPTR(result) + ac, ARRPTR(b), bc * sizeof(int32)); return result; } static ArrayType * -int_to_intset(int32 n) { - ArrayType *result; - int32 *aa; +int_to_intset(int32 n) +{ + ArrayType *result; + int32 *aa; + result = new_intArrayType(1); aa = ARRPTR(result); aa[0] = n; @@ -2298,67 +2424,82 @@ int_to_intset(int32 n) { } static int -compASC(const void *a, const void *b) { - if ( *(int4*)a == *(int4*)b ) return 0; - return ( *(int4*)a > *(int4*)b ) ? 1 : -1; +compASC(const void *a, const void *b) +{ + if (*(int4 *) a == *(int4 *) b) + return 0; + return (*(int4 *) a > *(int4 *) b) ? 1 : -1; } static int -compDESC(const void *a, const void *b) { - if ( *(int4*)a == *(int4*)b ) return 0; - return ( *(int4*)a < *(int4*)b ) ? 1 : -1; +compDESC(const void *a, const void *b) +{ + if (*(int4 *) a == *(int4 *) b) + return 0; + return (*(int4 *) a < *(int4 *) b) ? 1 : -1; } -#define QSORT(a, direction) \ +#define QSORT(a, direction) \ if (ARRNELEMS(a) > 1) \ - qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \ + qsort((void*)ARRPTR(a), ARRNELEMS(a),sizeof(int4), \ (direction) ? compASC : compDESC ) #define UNIX_UNIQ(a) a = resize_intArrayType(a, unix_uniq(ARRPTR(a), ARRNELEMS(a))) static int32 -unix_uniq(int32 *array, int32 count) { - register int32 i, k = 0; +unix_uniq(int32 *array, int32 count) +{ + register int32 i, + k = 0; + for (i = 1; i < count; i++) - if (array[k] != array[i]) { + if (array[k] != array[i]) + { k++; - if (i > k) array[k] = array[i]; + if (i > k) + array[k] = array[i]; } - return (k+1); + return (k + 1); } Datum -intset(PG_FUNCTION_ARGS) { - PG_RETURN_POINTER(int_to_intset(PG_GETARG_INT32(0))); +intset(PG_FUNCTION_ARGS) +{ + PG_RETURN_POINTER(int_to_intset(PG_GETARG_INT32(0))); } Datum -icount(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); - int32 count = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); +icount(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); + int32 count = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); + PG_FREE_IF_COPY(a, 0); PG_RETURN_INT32(count); } Datum -sort(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - text *dirstr = ( fcinfo->nargs==2 ) ? PG_GETARG_TEXT_P(1) : NULL; - int32 dc = ( dirstr ) ? VARSIZE(dirstr)-VARHDRSZ : 0; - char *d = ( dirstr ) ? VARDATA(dirstr) : NULL; - int dir = -1; - if (ARRISVOID(a) || ARRNELEMS(a) < 2) PG_RETURN_POINTER(a); - - if (dirstr==NULL || (dc == 3 - && (d[0] == 'A' || d[0] == 'a') - && (d[1] == 'S' || d[1] == 's') - && (d[2] == 'C' || d[2] == 'c'))) +sort(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + text *dirstr = (fcinfo->nargs == 2) ? PG_GETARG_TEXT_P(1) : NULL; + int32 dc = (dirstr) ? VARSIZE(dirstr) - VARHDRSZ : 0; + char *d = (dirstr) ? VARDATA(dirstr) : NULL; + int dir = -1; + + if (ARRISVOID(a) || ARRNELEMS(a) < 2) + PG_RETURN_POINTER(a); + + if (dirstr == NULL || (dc == 3 + && (d[0] == 'A' || d[0] == 'a') + && (d[1] == 'S' || d[1] == 's') + && (d[2] == 'C' || d[2] == 'c'))) dir = 1; else if (dc == 4 - && (d[0] == 'D' || d[0] == 'd') - && (d[1] == 'E' || d[1] == 'e') - && (d[2] == 'S' || d[2] == 's') - && (d[3] == 'C' || d[3] == 'c')) + && (d[0] == 'D' || d[0] == 'd') + && (d[1] == 'E' || d[1] == 'e') + && (d[2] == 'S' || d[2] == 's') + && (d[3] == 'C' || d[3] == 'c')) dir = 0; if (dir == -1) elog(ERROR, "Invalid second parameter in function sort. It must be 'ASC' or 'DESC'."); @@ -2367,97 +2508,116 @@ sort(PG_FUNCTION_ARGS) { } Datum -sort_asc(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - if (ARRISVOID(a)) PG_RETURN_POINTER(a); +sort_asc(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + + if (ARRISVOID(a)) + PG_RETURN_POINTER(a); QSORT(a, 1); PG_RETURN_POINTER(a); } Datum -sort_desc(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - if (ARRISVOID(a)) PG_RETURN_POINTER(a); +sort_desc(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + + if (ARRISVOID(a)) + PG_RETURN_POINTER(a); QSORT(a, 0); PG_RETURN_POINTER(a); } Datum -uniq(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - if (ARRISVOID(a) || ARRNELEMS(a) < 2) PG_RETURN_POINTER(a); +uniq(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + + if (ARRISVOID(a) || ARRNELEMS(a) < 2) + PG_RETURN_POINTER(a); UNIX_UNIQ(a); PG_RETURN_POINTER(a); } Datum -idx(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); - int32 result = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); - if (result) result = intarray_match_first(a, PG_GETARG_INT32(1)); +idx(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); + int32 result = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); + + if (result) + result = intarray_match_first(a, PG_GETARG_INT32(1)); PG_FREE_IF_COPY(a, 0); PG_RETURN_INT32(result); } Datum -subarray(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); - ArrayType *result; - int32 start = ( PG_GETARG_INT32(1) > 0 ) ? PG_GETARG_INT32(1)-1 : PG_GETARG_INT32(1); - int32 len = ( fcinfo->nargs==3 ) ? PG_GETARG_INT32(2) : 0; - int32 end = 0; - int32 c; - - if ( ARRISVOID(a) ) { +subarray(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); + ArrayType *result; + int32 start = (PG_GETARG_INT32(1) > 0) ? PG_GETARG_INT32(1) - 1 : PG_GETARG_INT32(1); + int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0; + int32 end = 0; + int32 c; + + if (ARRISVOID(a)) + { PG_FREE_IF_COPY(a, 0); - PG_RETURN_POINTER( new_intArrayType(0) ); + PG_RETURN_POINTER(new_intArrayType(0)); } c = ARRNELEMS(a); - - if ( start < 0 ) + + if (start < 0) start = c + start; - if ( len < 0 ) + if (len < 0) end = c + len; - else if ( len == 0 ) + else if (len == 0) end = c; else end = start + len; - if ( end > c ) - end = c; + if (end > c) + end = c; - if ( start < 0 ) + if (start < 0) start = 0; - if ( start >= end || end <= 0 ) { + if (start >= end || end <= 0) + { PG_FREE_IF_COPY(a, 0); - PG_RETURN_POINTER( new_intArrayType(0) ); + PG_RETURN_POINTER(new_intArrayType(0)); } - result = new_intArrayType(end-start); - if (end-start > 0) - memcpy(ARRPTR(result), ARRPTR(a) + start, (end-start) * sizeof(int32)); + result = new_intArrayType(end - start); + if (end - start > 0) + memcpy(ARRPTR(result), ARRPTR(a) + start, (end - start) * sizeof(int32)); PG_FREE_IF_COPY(a, 0); PG_RETURN_POINTER(result); } Datum -intarray_push_elem(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); - ArrayType *result; +intarray_push_elem(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); + ArrayType *result; + result = intarray_add_elem(a, PG_GETARG_INT32(1)); PG_FREE_IF_COPY(a, 0); PG_RETURN_POINTER(result); } Datum -intarray_push_array(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); - ArrayType *result; +intarray_push_array(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); + ArrayType *result; + result = intarray_concat_arrays(a, b); PG_FREE_IF_COPY(a, 0); PG_FREE_IF_COPY(b, 1); @@ -2465,25 +2625,34 @@ intarray_push_array(PG_FUNCTION_ARGS) { } Datum -intarray_del_elem(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - int32 c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); - int32 *aa = ARRPTR(a); - int32 n = 0, i; - int32 elem = PG_GETARG_INT32(1); +intarray_del_elem(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + int32 c = (ARRISVOID(a)) ? 0 : ARRNELEMS(a); + int32 *aa = ARRPTR(a); + int32 n = 0, + i; + int32 elem = PG_GETARG_INT32(1); + for (i = 0; i < c; i++) - if (aa[i] != elem) { - if (i > n) aa[n++] = aa[i]; - else n++; + if (aa[i] != elem) + { + if (i > n) + aa[n++] = aa[i]; + else + n++; } - if (c > 0) a = resize_intArrayType(a, n); + if (c > 0) + a = resize_intArrayType(a, n); PG_RETURN_POINTER(a); } Datum -intset_union_elem(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); - ArrayType *result; +intset_union_elem(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); + ArrayType *result; + result = intarray_add_elem(a, PG_GETARG_INT32(1)); PG_FREE_IF_COPY(a, 0); QSORT(result, 1); @@ -2492,27 +2661,44 @@ intset_union_elem(PG_FUNCTION_ARGS) { } Datum -intset_subtract(PG_FUNCTION_ARGS) { - ArrayType *a = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); - ArrayType *b = (ArrayType*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); - ArrayType *result; - int32 ca = ARRISVOID(a); - int32 cb = ARRISVOID(b); - int32 *aa, *bb, *r; - int32 n = 0, i = 0, k = 0; - QSORT(a, 1); UNIX_UNIQ(a); ca = ARRNELEMS(a); - QSORT(b, 1); UNIX_UNIQ(b); cb = ARRNELEMS(b); +intset_subtract(PG_FUNCTION_ARGS) +{ + ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); + ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); + ArrayType *result; + int32 ca = ARRISVOID(a); + int32 cb = ARRISVOID(b); + int32 *aa, + *bb, + *r; + int32 n = 0, + i = 0, + k = 0; + + QSORT(a, 1); + UNIX_UNIQ(a); + ca = ARRNELEMS(a); + QSORT(b, 1); + UNIX_UNIQ(b); + cb = ARRNELEMS(b); result = new_intArrayType(ca); aa = ARRPTR(a); bb = ARRPTR(b); r = ARRPTR(result); - while (i < ca) { - if (k == cb || aa[i] < bb[k]) r[n++] = aa[i++]; - else if (aa[i] == bb[k]) { i++; k++; } - else k++; + while (i < ca) + { + if (k == cb || aa[i] < bb[k]) + r[n++] = aa[i++]; + else if (aa[i] == bb[k]) + { + i++; + k++; + } + else + k++; } result = resize_intArrayType(result, n); - pfree(a); pfree(b); + pfree(a); + pfree(b); PG_RETURN_POINTER(result); } - diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c index 27bd057a56..d8efd8096d 100644 --- a/contrib/ltree/_ltree_gist.c +++ b/contrib/ltree/_ltree_gist.c @@ -1,5 +1,5 @@ /* - * GiST support for ltree[] + * GiST support for ltree[] * Teodor Sigaev <[email protected]> */ @@ -11,22 +11,27 @@ #include "crc32.h" -PG_FUNCTION_INFO_V1( _ltree_compress ); -Datum _ltree_compress(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( _ltree_same ); -Datum _ltree_same(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( _ltree_union ); -Datum _ltree_union(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( _ltree_penalty ); -Datum _ltree_penalty(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( _ltree_picksplit ); -Datum _ltree_picksplit(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( _ltree_consistent ); -Datum _ltree_consistent(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_ltree_compress); +Datum _ltree_compress(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(_ltree_same); +Datum _ltree_same(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(_ltree_union); +Datum _ltree_union(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(_ltree_penalty); +Datum _ltree_penalty(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(_ltree_picksplit); +Datum _ltree_picksplit(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(_ltree_consistent); +Datum _ltree_consistent(PG_FUNCTION_ARGS); #define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key)) #define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) ) -#define SUMBIT(val) ( \ +#define SUMBIT(val) ( \ GETBITBYTE(val,0) + \ GETBITBYTE(val,1) + \ GETBITBYTE(val,2) + \ @@ -34,235 +39,280 @@ Datum _ltree_consistent(PG_FUNCTION_ARGS); GETBITBYTE(val,4) + \ GETBITBYTE(val,5) + \ GETBITBYTE(val,6) + \ - GETBITBYTE(val,7) \ + GETBITBYTE(val,7) \ ) #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) ) static void -hashing(BITVECP sign, ltree *t) { - int tlen = t->numlevel; +hashing(BITVECP sign, ltree * t) +{ + int tlen = t->numlevel; ltree_level *cur = LTREE_FIRST(t); - int hash; + int hash; - while(tlen > 0) { - hash = ltree_crc32_sz( cur->name, cur->len ); - AHASH( sign, hash ); + while (tlen > 0) + { + hash = ltree_crc32_sz(cur->name, cur->len); + AHASH(sign, hash); cur = LEVEL_NEXT(cur); tlen--; } } -Datum -_ltree_compress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); +Datum +_ltree_compress(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = entry; - if ( entry->leafkey ) { /* ltree */ - ltree_gist *key; - ArrayType *val = DatumGetArrayTypeP(entry->key); - int4 len = LTG_HDRSIZE + ASIGLEN; - int num=ArrayGetNItems( ARR_NDIM(val), ARR_DIMS(val) ); - ltree *item = (ltree*)ARR_DATA_PTR(val); + if (entry->leafkey) + { /* ltree */ + ltree_gist *key; + ArrayType *val = DatumGetArrayTypeP(entry->key); + int4 len = LTG_HDRSIZE + ASIGLEN; + int num = ArrayGetNItems(ARR_NDIM(val), ARR_DIMS(val)); + ltree *item = (ltree *) ARR_DATA_PTR(val); - if ( ARR_NDIM(val) != 1 ) - elog(ERROR,"Dimension of array != 1"); + if (ARR_NDIM(val) != 1) + elog(ERROR, "Dimension of array != 1"); - key = (ltree_gist*)palloc( len ); + key = (ltree_gist *) palloc(len); key->len = len; key->flag = 0; - MemSet( LTG_SIGN(key), 0, sizeof(ASIGLEN) ); - while( num>0 ) { + MemSet(LTG_SIGN(key), 0, sizeof(ASIGLEN)); + while (num > 0) + { hashing(LTG_SIGN(key), item); num--; item = NEXTVAL(item); } - if ( PointerGetDatum(val) != entry->key ) + if (PointerGetDatum(val) != entry->key) pfree(val); - retval = (GISTENTRY*)palloc( sizeof(GISTENTRY) ); + retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(key), - entry->rel, entry->page, - entry->offset, key->len, FALSE); - } else { - int4 i,len; - ltree_gist *key; + entry->rel, entry->page, + entry->offset, key->len, FALSE); + } + else + { + int4 i, + len; + ltree_gist *key; - BITVECP sign = LTG_SIGN(DatumGetPointer( entry->key ) ); + BITVECP sign = LTG_SIGN(DatumGetPointer(entry->key)); ALOOPBYTE( - if ( sign[i] != 0xff ) - PG_RETURN_POINTER(retval); + if (sign[i] != 0xff) + PG_RETURN_POINTER(retval); ); - len = LTG_HDRSIZE; - key = (ltree_gist*)palloc( len ); + len = LTG_HDRSIZE; + key = (ltree_gist *) palloc(len); key->len = len; key->flag = LTG_ALLTRUE; - retval = (GISTENTRY*)palloc( sizeof(GISTENTRY) ); + retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(key), - entry->rel, entry->page, - entry->offset, key->len, FALSE); + entry->rel, entry->page, + entry->offset, key->len, FALSE); } PG_RETURN_POINTER(retval); } -Datum -_ltree_same(PG_FUNCTION_ARGS) { - ltree_gist* a=(ltree_gist*)PG_GETARG_POINTER(0); - ltree_gist* b=(ltree_gist*)PG_GETARG_POINTER(1); - bool *result = (bool *)PG_GETARG_POINTER(2); +Datum +_ltree_same(PG_FUNCTION_ARGS) +{ + ltree_gist *a = (ltree_gist *) PG_GETARG_POINTER(0); + ltree_gist *b = (ltree_gist *) PG_GETARG_POINTER(1); + bool *result = (bool *) PG_GETARG_POINTER(2); - if ( LTG_ISALLTRUE(a) && LTG_ISALLTRUE(b) ) { + if (LTG_ISALLTRUE(a) && LTG_ISALLTRUE(b)) *result = true; - } else if ( LTG_ISALLTRUE(a) ) { + else if (LTG_ISALLTRUE(a)) *result = false; - } else if ( LTG_ISALLTRUE(b) ) { + else if (LTG_ISALLTRUE(b)) *result = false; - } else { - int4 i; - BITVECP sa=LTG_SIGN(a), sb=LTG_SIGN(b); + else + { + int4 i; + BITVECP sa = LTG_SIGN(a), + sb = LTG_SIGN(b); + *result = true; ALOOPBYTE( - if ( sa[i] != sb[i] ) { - *result = false; - break; - } + if (sa[i] != sb[i]) + { + *result = false; + break; + } ); - } - PG_RETURN_POINTER(result); + } + PG_RETURN_POINTER(result); } -static int4 -unionkey( BITVECP sbase, ltree_gist *add ) { - int4 i; - BITVECP sadd = LTG_SIGN( add ); +static int4 +unionkey(BITVECP sbase, ltree_gist * add) +{ + int4 i; + BITVECP sadd = LTG_SIGN(add); - if ( LTG_ISALLTRUE(add) ) + if (LTG_ISALLTRUE(add)) return 1; ALOOPBYTE( - sbase[i] |= sadd[i]; + sbase[i] |= sadd[i]; ); return 0; } -Datum -_ltree_union(PG_FUNCTION_ARGS) { - bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); - int *size = (int *) PG_GETARG_POINTER(1); - ABITVEC base; - int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY); - int4 i; - int4 flag = 0; - ltree_gist *result; - - MemSet( (void*)base, 0, sizeof(ABITVEC) ); - for(i=0;i<len;i++) { - if ( unionkey( base, GETENTRY(entryvec, i) ) ) { +Datum +_ltree_union(PG_FUNCTION_ARGS) +{ + bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); + int *size = (int *) PG_GETARG_POINTER(1); + ABITVEC base; + int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY); + int4 i; + int4 flag = 0; + ltree_gist *result; + + MemSet((void *) base, 0, sizeof(ABITVEC)); + for (i = 0; i < len; i++) + { + if (unionkey(base, GETENTRY(entryvec, i))) + { flag = LTG_ALLTRUE; break; } } - len = LTG_HDRSIZE + ( ( flag & LTG_ALLTRUE ) ? 0 : ASIGLEN ); - result = (ltree_gist*)palloc( len ); + len = LTG_HDRSIZE + ((flag & LTG_ALLTRUE) ? 0 : ASIGLEN); + result = (ltree_gist *) palloc(len); *size = result->len = len; result->flag = flag; - if ( ! LTG_ISALLTRUE(result) ) - memcpy((void*)LTG_SIGN(result), (void*)base, sizeof( ABITVEC ) ); + if (!LTG_ISALLTRUE(result)) + memcpy((void *) LTG_SIGN(result), (void *) base, sizeof(ABITVEC)); - PG_RETURN_POINTER(result); + PG_RETURN_POINTER(result); } static int4 -sizebitvec( BITVECP sign ) { - int4 size=0, i; +sizebitvec(BITVECP sign) +{ + int4 size = 0, + i; + ALOOPBYTE( - size += SUMBIT(*(char*)sign); - sign = (BITVECP) ( ((char*)sign) + 1 ); + size += SUMBIT(*(char *) sign); + sign = (BITVECP) (((char *) sign) + 1); ); return size; } -Datum -_ltree_penalty(PG_FUNCTION_ARGS) { - ltree_gist *origval = (ltree_gist*)DatumGetPointer( ( (GISTENTRY *)PG_GETARG_POINTER(0) )->key ); - ltree_gist *newval = (ltree_gist*)DatumGetPointer( ( (GISTENTRY *)PG_GETARG_POINTER(1) )->key ); - float *penalty = (float *) PG_GETARG_POINTER(2); - BITVECP orig = LTG_SIGN(origval); +Datum +_ltree_penalty(PG_FUNCTION_ARGS) +{ + ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); + ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); + float *penalty = (float *) PG_GETARG_POINTER(2); + BITVECP orig = LTG_SIGN(origval); - if ( LTG_ISALLTRUE(origval) ) { + if (LTG_ISALLTRUE(origval)) + { *penalty = 0.0; - PG_RETURN_POINTER( penalty ); + PG_RETURN_POINTER(penalty); } - if ( LTG_ISALLTRUE(newval) ) { - *penalty = (float) (ASIGLENBIT - sizebitvec( orig ) ); - } else { + if (LTG_ISALLTRUE(newval)) + *penalty = (float) (ASIGLENBIT - sizebitvec(orig)); + else + { unsigned char valtmp; - BITVECP nval = LTG_SIGN(newval); - int4 i, unionsize=0; + BITVECP nval = LTG_SIGN(newval); + int4 i, + unionsize = 0; ALOOPBYTE( - valtmp = nval[i] | orig[i]; - unionsize += SUMBIT(valtmp) - SUMBIT(orig[i]); + valtmp = nval[i] | orig[i]; + unionsize += SUMBIT(valtmp) - SUMBIT(orig[i]); ); - *penalty = (float)unionsize; + *penalty = (float) unionsize; } - PG_RETURN_POINTER( penalty ); + PG_RETURN_POINTER(penalty); } -typedef struct { - OffsetNumber pos; - int4 cost; +typedef struct +{ + OffsetNumber pos; + int4 cost; } SPLITCOST; static int -comparecost( const void *a, const void *b ) { - return ((SPLITCOST*)a)->cost - ((SPLITCOST*)b)->cost; +comparecost(const void *a, const void *b) +{ + return ((SPLITCOST *) a)->cost - ((SPLITCOST *) b)->cost; } -Datum -_ltree_picksplit(PG_FUNCTION_ARGS) { - bytea *entryvec = (bytea*) PG_GETARG_POINTER(0); - GIST_SPLITVEC *v = (GIST_SPLITVEC*) PG_GETARG_POINTER(1); - OffsetNumber k,j; - ltree_gist *datum_l, *datum_r; - ABITVEC union_l, union_r; - bool firsttime = true; - int4 size_alpha,size_beta,sizeu,sizei; - int4 size_waste, waste = 0.0; - int4 size_l, size_r; - int4 nbytes; - OffsetNumber seed_1=0, seed_2=0; - OffsetNumber *left, *right; +Datum +_ltree_picksplit(PG_FUNCTION_ARGS) +{ + bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); + GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); + OffsetNumber k, + j; + ltree_gist *datum_l, + *datum_r; + ABITVEC union_l, + union_r; + bool firsttime = true; + int4 size_alpha, + size_beta, + sizeu, + sizei; + int4 size_waste, + waste = 0.0; + int4 size_l, + size_r; + int4 nbytes; + OffsetNumber seed_1 = 0, + seed_2 = 0; + OffsetNumber *left, + *right; OffsetNumber maxoff; - BITVECP ptra, ptrb, ptrc; - int i; - unsigned char valtmp; - SPLITCOST *costvector; - ltree_gist *_k, *_j; + BITVECP ptra, + ptrb, + ptrc; + int i; + unsigned char valtmp; + SPLITCOST *costvector; + ltree_gist *_k, + *_j; maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2; nbytes = (maxoff + 2) * sizeof(OffsetNumber); v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes); - for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) { - _k = GETENTRY(entryvec,k); - for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) { - _j = GETENTRY(entryvec,j); - if ( LTG_ISALLTRUE(_k) || LTG_ISALLTRUE(_j) ) { + for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) + { + _k = GETENTRY(entryvec, k); + for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) + { + _j = GETENTRY(entryvec, j); + if (LTG_ISALLTRUE(_k) || LTG_ISALLTRUE(_j)) + { sizeu = ASIGLENBIT; - if ( LTG_ISALLTRUE(_k) && LTG_ISALLTRUE(_j) ) + if (LTG_ISALLTRUE(_k) && LTG_ISALLTRUE(_j)) sizei = ASIGLENBIT; else - sizei = ( LTG_ISALLTRUE(_k) ) ? - sizebitvec( LTG_SIGN(_j) ) : sizebitvec( LTG_SIGN(_k) ); - } else { + sizei = (LTG_ISALLTRUE(_k)) ? + sizebitvec(LTG_SIGN(_j)) : sizebitvec(LTG_SIGN(_k)); + } + else + { sizeu = sizei = 0; ptra = LTG_SIGN(_j); ptrb = LTG_SIGN(_k); @@ -278,20 +328,21 @@ _ltree_picksplit(PG_FUNCTION_ARGS) { } while(0) ALOOPBYTE( - COUNT(0); - COUNT(1); - COUNT(2); - COUNT(3); - COUNT(4); - COUNT(5); - COUNT(6); - COUNT(7); - ptra = (BITVECP) ( ((char*)ptra) + 1 ); - ptrb = (BITVECP) ( ((char*)ptrb) + 1 ); + COUNT(0); + COUNT(1); + COUNT(2); + COUNT(3); + COUNT(4); + COUNT(5); + COUNT(6); + COUNT(7); + ptra = (BITVECP) (((char *) ptra) + 1); + ptrb = (BITVECP) (((char *) ptrb) + 1); ); } size_waste = sizeu - sizei; - if (size_waste > waste || firsttime) { + if (size_waste > waste || firsttime) + { waste = size_waste; seed_1 = k; seed_2 = j; @@ -305,129 +356,166 @@ _ltree_picksplit(PG_FUNCTION_ARGS) { right = v->spl_right; v->spl_nright = 0; - if ( seed_1 == 0 || seed_2 == 0 ) { + if (seed_1 == 0 || seed_2 == 0) + { seed_1 = 1; seed_2 = 2; } /* form initial .. */ - if ( LTG_ISALLTRUE(GETENTRY(entryvec,seed_1)) ) { - datum_l = (ltree_gist*)palloc( LTG_HDRSIZE ); - datum_l->len = LTG_HDRSIZE; datum_l->flag = LTG_ALLTRUE; + if (LTG_ISALLTRUE(GETENTRY(entryvec, seed_1))) + { + datum_l = (ltree_gist *) palloc(LTG_HDRSIZE); + datum_l->len = LTG_HDRSIZE; + datum_l->flag = LTG_ALLTRUE; size_l = ASIGLENBIT; - } else { - datum_l = (ltree_gist*)palloc( LTG_HDRSIZE + ASIGLEN ); - datum_l->len = LTG_HDRSIZE + ASIGLEN; datum_l->flag = 0; - memcpy((void*)LTG_SIGN(datum_l), (void*)LTG_SIGN(GETENTRY(entryvec,seed_1)), sizeof(ABITVEC)); - size_l = sizebitvec( LTG_SIGN(datum_l) ); } - if ( LTG_ISALLTRUE(GETENTRY(entryvec,seed_2)) ) { - datum_r = (ltree_gist*)palloc( LTG_HDRSIZE ); - datum_r->len = LTG_HDRSIZE; datum_r->flag = LTG_ALLTRUE; + else + { + datum_l = (ltree_gist *) palloc(LTG_HDRSIZE + ASIGLEN); + datum_l->len = LTG_HDRSIZE + ASIGLEN; + datum_l->flag = 0; + memcpy((void *) LTG_SIGN(datum_l), (void *) LTG_SIGN(GETENTRY(entryvec, seed_1)), sizeof(ABITVEC)); + size_l = sizebitvec(LTG_SIGN(datum_l)); + } + if (LTG_ISALLTRUE(GETENTRY(entryvec, seed_2))) + { + datum_r = (ltree_gist *) palloc(LTG_HDRSIZE); + datum_r->len = LTG_HDRSIZE; + datum_r->flag = LTG_ALLTRUE; size_r = ASIGLENBIT; - } else { - datum_r = (ltree_gist*)palloc( LTG_HDRSIZE + ASIGLEN ); - datum_r->len = LTG_HDRSIZE + ASIGLEN; datum_r->flag = 0; - memcpy((void*)LTG_SIGN(datum_r), (void*)LTG_SIGN(GETENTRY(entryvec,seed_2)), sizeof(ABITVEC)); - size_r = sizebitvec( LTG_SIGN(datum_r) ); + } + else + { + datum_r = (ltree_gist *) palloc(LTG_HDRSIZE + ASIGLEN); + datum_r->len = LTG_HDRSIZE + ASIGLEN; + datum_r->flag = 0; + memcpy((void *) LTG_SIGN(datum_r), (void *) LTG_SIGN(GETENTRY(entryvec, seed_2)), sizeof(ABITVEC)); + size_r = sizebitvec(LTG_SIGN(datum_r)); } maxoff = OffsetNumberNext(maxoff); /* sort before ... */ - costvector=(SPLITCOST*)palloc( sizeof(SPLITCOST)*maxoff ); - for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) { - costvector[j-1].pos = j; - _j = GETENTRY(entryvec,j); - if ( LTG_ISALLTRUE(_j) ) { + costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff); + for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) + { + costvector[j - 1].pos = j; + _j = GETENTRY(entryvec, j); + if (LTG_ISALLTRUE(_j)) + { size_alpha = ASIGLENBIT - size_l; - size_beta = ASIGLENBIT - size_r; - } else { - ptra = LTG_SIGN( datum_l ); - ptrb = LTG_SIGN( datum_r ); - ptrc = LTG_SIGN( _j ); + size_beta = ASIGLENBIT - size_r; + } + else + { + ptra = LTG_SIGN(datum_l); + ptrb = LTG_SIGN(datum_r); + ptrc = LTG_SIGN(_j); size_beta = size_alpha = 0; - if ( LTG_ISALLTRUE(datum_l) ) { - if ( !LTG_ISALLTRUE(datum_r) ) { + if (LTG_ISALLTRUE(datum_l)) + { + if (!LTG_ISALLTRUE(datum_r)) + { ALOOPBIT( - if ( GETBIT(ptrc,i) && ! GETBIT(ptrb,i) ) - size_beta++; + if (GETBIT(ptrc, i) && !GETBIT(ptrb, i)) + size_beta++; ); } - } else if ( LTG_ISALLTRUE(datum_r) ) { - if ( !LTG_ISALLTRUE(datum_l) ) { + } + else if (LTG_ISALLTRUE(datum_r)) + { + if (!LTG_ISALLTRUE(datum_l)) + { ALOOPBIT( - if ( GETBIT(ptrc,i) && ! GETBIT(ptra,i) ) - size_alpha++; + if (GETBIT(ptrc, i) && !GETBIT(ptra, i)) + size_alpha++; ); } - } else { + } + else + { ALOOPBIT( - if ( GETBIT(ptrc,i) && ! GETBIT(ptra,i) ) - size_alpha++; - if ( GETBIT(ptrc,i) && ! GETBIT(ptrb,i) ) - size_beta++; + if (GETBIT(ptrc, i) && !GETBIT(ptra, i)) + size_alpha++; + if (GETBIT(ptrc, i) && !GETBIT(ptrb, i)) + size_beta++; ); } } - costvector[j-1].cost = abs( size_alpha - size_beta ); + costvector[j - 1].cost = abs(size_alpha - size_beta); } - qsort( (void*)costvector, maxoff, sizeof(SPLITCOST), comparecost ); + qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost); - for (k = 0; k < maxoff; k++) { + for (k = 0; k < maxoff; k++) + { j = costvector[k].pos; - _j = GETENTRY(entryvec,j); - if ( j == seed_1 ) { + _j = GETENTRY(entryvec, j); + if (j == seed_1) + { *left++ = j; v->spl_nleft++; continue; - } else if ( j == seed_2 ) { + } + else if (j == seed_2) + { *right++ = j; v->spl_nright++; continue; } - if ( LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j) ) { + if (LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j)) size_alpha = ASIGLENBIT; - } else { + else + { ptra = LTG_SIGN(_j); ptrb = LTG_SIGN(datum_l); size_alpha = 0; ALOOPBYTE( - valtmp = union_l[i] = ptra[i] | ptrb[i]; - size_alpha += SUMBIT( valtmp ); + valtmp = union_l[i] = ptra[i] | ptrb[i]; + size_alpha += SUMBIT(valtmp); ); } - if ( LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j) ) { + if (LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j)) size_beta = ASIGLENBIT; - } else { + else + { ptra = LTG_SIGN(_j); ptrb = LTG_SIGN(datum_r); size_beta = 0; ALOOPBYTE( - valtmp = union_r[i] = ptra[i] | ptrb[i]; - size_beta += SUMBIT( valtmp ); + valtmp = union_r[i] = ptra[i] | ptrb[i]; + size_beta += SUMBIT(valtmp); ); } - if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.1)) { - if ( ! LTG_ISALLTRUE( datum_l ) ) { - if ( size_alpha == ASIGLENBIT ) { - if ( size_alpha != size_l ) - MemSet( (void*)LTG_SIGN(datum_l),0xff, sizeof(ABITVEC)); - } else - memcpy( (void*)LTG_SIGN(datum_l), (void*)union_l, sizeof(ABITVEC) ); + if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.1)) + { + if (!LTG_ISALLTRUE(datum_l)) + { + if (size_alpha == ASIGLENBIT) + { + if (size_alpha != size_l) + MemSet((void *) LTG_SIGN(datum_l), 0xff, sizeof(ABITVEC)); + } + else + memcpy((void *) LTG_SIGN(datum_l), (void *) union_l, sizeof(ABITVEC)); } size_l = size_alpha; *left++ = j; v->spl_nleft++; - } else { - if ( ! LTG_ISALLTRUE( datum_r ) ) { - if ( size_beta == ASIGLENBIT ) { - if ( size_beta != size_r ) - MemSet( (void*)LTG_SIGN(datum_r),0xff, sizeof(ABITVEC)); - } else - memcpy( (void*)LTG_SIGN(datum_r), (void*)union_r, sizeof(ABITVEC) ); + } + else + { + if (!LTG_ISALLTRUE(datum_r)) + { + if (size_beta == ASIGLENBIT) + { + if (size_beta != size_r) + MemSet((void *) LTG_SIGN(datum_r), 0xff, sizeof(ABITVEC)); + } + else + memcpy((void *) LTG_SIGN(datum_r), (void *) union_r, sizeof(ABITVEC)); } size_r = size_beta; *right++ = j; @@ -441,23 +529,25 @@ _ltree_picksplit(PG_FUNCTION_ARGS) { v->spl_ldatum = PointerGetDatum(datum_l); v->spl_rdatum = PointerGetDatum(datum_r); - PG_RETURN_POINTER( v ); + PG_RETURN_POINTER(v); } static bool -gist_te(ltree_gist *key, ltree* query) { - ltree_level *curq = LTREE_FIRST(query); - BITVECP sign = LTG_SIGN(key); - int qlen = query->numlevel; +gist_te(ltree_gist * key, ltree * query) +{ + ltree_level *curq = LTREE_FIRST(query); + BITVECP sign = LTG_SIGN(key); + int qlen = query->numlevel; unsigned int hv; - if ( LTG_ISALLTRUE(key) ) + if (LTG_ISALLTRUE(key)) return true; - while( qlen>0 ) { - hv = ltree_crc32_sz(curq->name,curq->len); - if ( ! GETBIT( sign, AHASHVAL(hv) ) ) - return false; + while (qlen > 0) + { + hv = ltree_crc32_sz(curq->name, curq->len); + if (!GETBIT(sign, AHASHVAL(hv))) + return false; curq = LEVEL_NEXT(curq); qlen--; } @@ -466,48 +556,56 @@ gist_te(ltree_gist *key, ltree* query) { } static bool -checkcondition_bit(void *checkval, ITEM* val ) { - return ( FLG_CANLOOKSIGN(val->flag) ) ? GETBIT( checkval, AHASHVAL( val->val ) ) : true; +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) { - if ( LTG_ISALLTRUE(key) ) +gist_qtxt(ltree_gist * key, ltxtquery * query) +{ + if (LTG_ISALLTRUE(key)) return true; - + return ltree_execute( - GETQUERY(query), - (void*)LTG_SIGN(key), false, - checkcondition_bit - ); + GETQUERY(query), + (void *) LTG_SIGN(key), false, + checkcondition_bit + ); } static bool -gist_qe(ltree_gist *key, lquery* query) { - lquery_level *curq = LQUERY_FIRST(query); - BITVECP sign = LTG_SIGN(key); - int qlen = query->numlevel; - - if ( LTG_ISALLTRUE(key) ) +gist_qe(ltree_gist * key, lquery * query) +{ + lquery_level *curq = LQUERY_FIRST(query); + BITVECP sign = LTG_SIGN(key); + int qlen = query->numlevel; + + if (LTG_ISALLTRUE(key)) return true; - - while( qlen>0 ) { - if ( curq->numvar && LQL_CANLOOKSIGN(curq) ) { - bool isexist=false; - int vlen = curq->numvar; + + while (qlen > 0) + { + if (curq->numvar && LQL_CANLOOKSIGN(curq)) + { + bool isexist = false; + int vlen = curq->numvar; lquery_variant *curv = LQL_FIRST(curq); - while( vlen>0 ) { - if ( GETBIT( sign, AHASHVAL( curv->val ) ) ) { - isexist=true; + + while (vlen > 0) + { + if (GETBIT(sign, AHASHVAL(curv->val))) + { + isexist = true; break; } curv = LVAR_NEXT(curv); vlen--; } - if ( !isexist ) + if (!isexist) return false; } - + curq = LQL_NEXT(curq); qlen--; } @@ -516,34 +614,35 @@ gist_qe(ltree_gist *key, lquery* query) { } -Datum -_ltree_consistent(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY*)PG_GETARG_POINTER(0); - char *query = (char*)DatumGetPointer( PG_DETOAST_DATUM(PG_GETARG_DATUM(1)) ); - ltree_gist *key = (ltree_gist*)DatumGetPointer( entry->key ); +Datum +_ltree_consistent(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + char *query = (char *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); + ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); - bool res = false; + bool res = false; -#ifndef assert_enabled +#ifndef assert_enabled #define assert_enabled 0 #endif - - switch( strategy ) { + + switch (strategy) + { case 10: case 11: - res = gist_te(key, (ltree*)query); + res = gist_te(key, (ltree *) query); break; case 12: case 13: - res = gist_qe(key, (lquery*)query); - break; + res = gist_qe(key, (lquery *) query); + break; case 14: case 15: - res = gist_qtxt(key, (ltxtquery*)query); - break; + res = gist_qtxt(key, (ltxtquery *) query); + break; default: - elog(ERROR,"Unknown StrategyNumber: %d", strategy); + elog(ERROR, "Unknown StrategyNumber: %d", strategy); } PG_RETURN_BOOL(res); } - diff --git a/contrib/ltree/_ltree_op.c b/contrib/ltree/_ltree_op.c index 336b83820c..59de0a51e4 100644 --- a/contrib/ltree/_ltree_op.c +++ b/contrib/ltree/_ltree_op.c @@ -1,5 +1,5 @@ /* - * op function for ltree[] + * op function for ltree[] * Teodor Sigaev <[email protected]> */ @@ -16,223 +16,253 @@ PG_FUNCTION_INFO_V1(_ltq_rregex); PG_FUNCTION_INFO_V1(_ltxtq_exec); PG_FUNCTION_INFO_V1(_ltxtq_rexec); -Datum _ltree_r_isparent(PG_FUNCTION_ARGS); -Datum _ltree_r_risparent(PG_FUNCTION_ARGS); +Datum _ltree_r_isparent(PG_FUNCTION_ARGS); +Datum _ltree_r_risparent(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_ltree_extract_isparent); PG_FUNCTION_INFO_V1(_ltree_extract_risparent); PG_FUNCTION_INFO_V1(_ltq_extract_regex); PG_FUNCTION_INFO_V1(_ltxtq_extract_exec); -Datum _ltree_extract_isparent(PG_FUNCTION_ARGS); -Datum _ltree_extract_risparent(PG_FUNCTION_ARGS); -Datum _ltq_extract_regex(PG_FUNCTION_ARGS); -Datum _ltxtq_extract_exec(PG_FUNCTION_ARGS); +Datum _ltree_extract_isparent(PG_FUNCTION_ARGS); +Datum _ltree_extract_risparent(PG_FUNCTION_ARGS); +Datum _ltq_extract_regex(PG_FUNCTION_ARGS); +Datum _ltxtq_extract_exec(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(_lca); -Datum _lca(PG_FUNCTION_ARGS); +Datum _lca(PG_FUNCTION_ARGS); + +typedef Datum (*PGCALL2) (PG_FUNCTION_ARGS); -typedef Datum (*PGCALL2)(PG_FUNCTION_ARGS); #define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) ) static bool -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); - - if ( ARR_NDIM(la) !=1 ) - elog(ERROR,"Dimension of array != 1"); - - if ( found ) - *found=NULL; - while( num>0 ) { - if ( DatumGetBool( DirectFunctionCall2( callback, - PointerGetDatum(item), PointerGetDatum(param) ) ) ) { - - if ( 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); + + if (ARR_NDIM(la) != 1) + elog(ERROR, "Dimension of array != 1"); + + if (found) + *found = NULL; + while (num > 0) + { + if (DatumGetBool(DirectFunctionCall2(callback, + PointerGetDatum(item), PointerGetDatum(param)))) + { + + if (found) *found = item; return true; } num--; - item = NEXTVAL(item); + item = NEXTVAL(item); } return false; } Datum -_ltree_isparent(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - ltree *query = PG_GETARG_LTREE(1); - bool res = array_iterator( la, ltree_isparent, (void*)query, NULL ); - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +_ltree_isparent(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + ltree *query = PG_GETARG_LTREE(1); + bool res = array_iterator(la, ltree_isparent, (void *) query, NULL); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_BOOL(res); } Datum -_ltree_r_isparent(PG_FUNCTION_ARGS) { - PG_RETURN_DATUM( DirectFunctionCall2( _ltree_isparent, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) ); +_ltree_r_isparent(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall2(_ltree_isparent, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + )); } Datum -_ltree_risparent(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - ltree *query = PG_GETARG_LTREE(1); - bool res = array_iterator( la, ltree_risparent, (void*)query, NULL ); - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +_ltree_risparent(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + ltree *query = PG_GETARG_LTREE(1); + bool res = array_iterator(la, ltree_risparent, (void *) query, NULL); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_BOOL(res); } Datum -_ltree_r_risparent(PG_FUNCTION_ARGS) { - PG_RETURN_DATUM( DirectFunctionCall2( _ltree_risparent, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) ); +_ltree_r_risparent(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall2(_ltree_risparent, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + )); } Datum -_ltq_regex(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - lquery *query = PG_GETARG_LQUERY(1); - bool res = array_iterator( la, ltq_regex, (void*)query, NULL ); - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +_ltq_regex(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + lquery *query = PG_GETARG_LQUERY(1); + bool res = array_iterator(la, ltq_regex, (void *) query, NULL); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_BOOL(res); } Datum -_ltq_rregex(PG_FUNCTION_ARGS) { - PG_RETURN_DATUM( DirectFunctionCall2( _ltq_regex, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) ); +_ltq_rregex(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall2(_ltq_regex, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + )); } -Datum -_ltxtq_exec(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - ltxtquery *query = PG_GETARG_LTXTQUERY(1); - bool res = array_iterator( la, ltxtq_exec, (void*)query, NULL ); - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +Datum +_ltxtq_exec(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + ltxtquery *query = PG_GETARG_LTXTQUERY(1); + bool res = array_iterator(la, ltxtq_exec, (void *) query, NULL); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_BOOL(res); } Datum -_ltxtq_rexec(PG_FUNCTION_ARGS) { - PG_RETURN_DATUM( DirectFunctionCall2( _ltxtq_exec, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) ); +_ltxtq_rexec(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall2(_ltxtq_exec, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + )); } -Datum -_ltree_extract_isparent(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - ltree *query = PG_GETARG_LTREE(1); - ltree *found,*item; - - if ( !array_iterator( la, ltree_isparent, (void*)query, &found ) ) { - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +Datum +_ltree_extract_isparent(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + ltree *query = PG_GETARG_LTREE(1); + ltree *found, + *item; + + if (!array_iterator(la, ltree_isparent, (void *) query, &found)) + { + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_NULL(); } - item = (ltree*)palloc( found->len ); - memcpy( item, found, found->len ); - - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); + item = (ltree *) palloc(found->len); + memcpy(item, found, found->len); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_POINTER(item); } -Datum -_ltree_extract_risparent(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - ltree *query = PG_GETARG_LTREE(1); - ltree *found,*item; - - if ( !array_iterator( la, ltree_risparent, (void*)query, &found ) ) { - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +Datum +_ltree_extract_risparent(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + ltree *query = PG_GETARG_LTREE(1); + ltree *found, + *item; + + if (!array_iterator(la, ltree_risparent, (void *) query, &found)) + { + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_NULL(); } - item = (ltree*)palloc( found->len ); - memcpy( item, found, found->len ); - - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); + item = (ltree *) palloc(found->len); + memcpy(item, found, found->len); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_POINTER(item); } -Datum -_ltq_extract_regex(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - lquery *query = PG_GETARG_LQUERY(1); - ltree *found,*item; - - if ( !array_iterator( la, ltq_regex, (void*)query, &found ) ) { - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +Datum +_ltq_extract_regex(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + lquery *query = PG_GETARG_LQUERY(1); + ltree *found, + *item; + + if (!array_iterator(la, ltq_regex, (void *) query, &found)) + { + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_NULL(); } - item = (ltree*)palloc( found->len ); - memcpy( item, found, found->len ); - - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); + item = (ltree *) palloc(found->len); + memcpy(item, found, found->len); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_POINTER(item); } -Datum -_ltxtq_extract_exec(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - ltxtquery *query = PG_GETARG_LTXTQUERY(1); - ltree *found,*item; - - if ( !array_iterator( la, ltxtq_exec, (void*)query, &found ) ) { - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); +Datum +_ltxtq_extract_exec(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + ltxtquery *query = PG_GETARG_LTXTQUERY(1); + ltree *found, + *item; + + if (!array_iterator(la, ltxtq_exec, (void *) query, &found)) + { + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_NULL(); } - item = (ltree*)palloc( found->len ); - memcpy( item, found, found->len ); - - PG_FREE_IF_COPY(la,0); - PG_FREE_IF_COPY(query,1); + item = (ltree *) palloc(found->len); + memcpy(item, found, found->len); + + PG_FREE_IF_COPY(la, 0); + PG_FREE_IF_COPY(query, 1); PG_RETURN_POINTER(item); } Datum -_lca(PG_FUNCTION_ARGS) { - ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); - int num=ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la)); - ltree *item = (ltree*)ARR_DATA_PTR(la); - ltree **a,*res; - - a=(ltree**)palloc( sizeof(ltree*) * num ); - while( num>0 ) { +_lca(PG_FUNCTION_ARGS) +{ + ArrayType *la = PG_GETARG_ARRAYTYPE_P(0); + int num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la)); + ltree *item = (ltree *) ARR_DATA_PTR(la); + ltree **a, + *res; + + a = (ltree **) palloc(sizeof(ltree *) * num); + while (num > 0) + { num--; a[num] = item; item = NEXTVAL(item); } - res = lca_inner(a, ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la))); + res = lca_inner(a, ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la))); pfree(a); - PG_FREE_IF_COPY(la,0); + PG_FREE_IF_COPY(la, 0); - if ( res ) - PG_RETURN_POINTER(res); - else - PG_RETURN_NULL(); + if (res) + PG_RETURN_POINTER(res); + else + PG_RETURN_NULL(); } - diff --git a/contrib/ltree/crc32.c b/contrib/ltree/crc32.c index 5cbde4135b..8a4f27b306 100644 --- a/contrib/ltree/crc32.c +++ b/contrib/ltree/crc32.c @@ -105,6 +105,6 @@ ltree_crc32_sz(char *buf, int size) len = 0; nr = size; for (len += nr, p = buf; nr--; ++p) - _CRC32_(crc, TOLOWER((unsigned int)*p)); + _CRC32_(crc, TOLOWER((unsigned int) *p)); return ~crc; } diff --git a/contrib/ltree/lquery_op.c b/contrib/ltree/lquery_op.c index 83b380d97a..e24cc8559f 100644 --- a/contrib/ltree/lquery_op.c +++ b/contrib/ltree/lquery_op.c @@ -1,5 +1,5 @@ /* - * op function for ltree and lquery + * op function for ltree and lquery * Teodor Sigaev <[email protected]> */ @@ -9,27 +9,29 @@ PG_FUNCTION_INFO_V1(ltq_regex); PG_FUNCTION_INFO_V1(ltq_rregex); -typedef struct { - lquery_level *q; - int nq; - ltree_level *t; - int nt; - int posq; - int post; -} FieldNot; +typedef struct +{ + lquery_level *q; + int nq; + ltree_level *t; + int nt; + int posq; + int post; +} FieldNot; static char * -getlexem(char *start, char *end, int *len) { - char *ptr; - - while( start<end && *start == '_' ) +getlexem(char *start, char *end, int *len) +{ + char *ptr; + + while (start < end && *start == '_') start++; ptr = start; - if ( ptr == end ) + if (ptr == end) return NULL; - while( ptr < end && *ptr != '_') + while (ptr < end && *ptr != '_') ptr++; *len = ptr - start; @@ -37,31 +39,36 @@ getlexem(char *start, char *end, int *len) { } bool -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; - char *tn; - int lent,lenq; - bool isok; - - while( (qn=getlexem(qn,endq,&lenq)) != NULL ) { - tn=t->name; + 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; + char *tn; + int lent, + lenq; + bool isok; + + while ((qn = getlexem(qn, endq, &lenq)) != NULL) + { + tn = t->name; isok = false; - while( (tn=getlexem(tn,endt,&lent)) != NULL ) { - if ( + while ((tn = getlexem(tn, endt, &lent)) != NULL) + { + if ( ( - lent == lenq || - ( lent > lenq && anyend ) - ) && - (*cmpptr)(qn,tn,lenq) == 0 ) { - - isok = true; + lent == lenq || + (lent > lenq && anyend) + ) && + (*cmpptr) (qn, tn, lenq) == 0) + { + + isok = true; break; } tn += lent; } - if ( !isok ) + if (!isok) return false; qn += lenq; } @@ -70,27 +77,32 @@ compare_subnode( ltree_level *t, char *qn, int len, int (*cmpptr)(const char *,c } static bool -checkLevel( lquery_level *curq, ltree_level *curt ) { - int (*cmpptr)(const char *,const char *,size_t); +checkLevel(lquery_level * curq, ltree_level * curt) +{ + int (*cmpptr) (const char *, const char *, size_t); lquery_variant *curvar = LQL_FIRST(curq); - int i; - - for(i=0;i<curq->numvar;i++) { - cmpptr = ( curvar->flag & LVAR_INCASE ) ? strncasecmp : strncmp; + int i; - if ( curvar->flag & LVAR_SUBLEXEM ) { - if ( compare_subnode(curt, curvar->name, curvar->len, cmpptr, (curvar->flag & LVAR_ANYEND) ) ) + for (i = 0; i < curq->numvar; i++) + { + cmpptr = (curvar->flag & LVAR_INCASE) ? strncasecmp : strncmp; + + if (curvar->flag & LVAR_SUBLEXEM) + { + if (compare_subnode(curt, curvar->name, curvar->len, cmpptr, (curvar->flag & LVAR_ANYEND))) return true; - } else if ( - ( - curvar->len == curt->len || - ( curt->len > curvar->len && (curvar->flag & LVAR_ANYEND) ) - ) && - (*cmpptr)( curvar->name, curt->name, curvar->len) == 0 ) { + } + else if ( + ( + curvar->len == curt->len || + (curt->len > curvar->len && (curvar->flag & LVAR_ANYEND)) + ) && + (*cmpptr) (curvar->name, curt->name, curvar->len) == 0) + { return true; } - curvar = LVAR_NEXT(curvar); + curvar = LVAR_NEXT(curvar); } return false; } @@ -102,78 +114,97 @@ printFieldNot(FieldNot *fn ) { elog(NOTICE,"posQ:%d lenQ:%d posT:%d lenT:%d", fn->posq,fn->nq,fn->post,fn->nt); fn++; } -} +} */ static bool -checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_numlevel, FieldNot *ptr ) { - uint32 low_pos=0,high_pos=0,cur_tpos=0; - int tlen = tree_numlevel, qlen = query_numlevel; - int isok; - lquery_level *prevq=NULL; - ltree_level *prevt=NULL; - - while( tlen >0 && qlen>0 ) { - if ( curq->numvar ) { +checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_numlevel, FieldNot * ptr) +{ + uint32 low_pos = 0, + high_pos = 0, + cur_tpos = 0; + int tlen = tree_numlevel, + qlen = query_numlevel; + int isok; + lquery_level *prevq = NULL; + ltree_level *prevt = NULL; + + while (tlen > 0 && qlen > 0) + { + if (curq->numvar) + { prevt = curt; - while ( cur_tpos < low_pos ) { + while (cur_tpos < low_pos) + { curt = LEVEL_NEXT(curt); tlen--; cur_tpos++; - if ( tlen==0 ) + if (tlen == 0) return false; - if ( ptr && ptr->q ) + if (ptr && ptr->q) ptr->nt++; } - - if ( ptr && curq->flag & LQL_NOT ) { - if ( !(prevq && prevq->numvar == 0) ) + + if (ptr && curq->flag & LQL_NOT) + { + if (!(prevq && prevq->numvar == 0)) prevq = curq; - if ( ptr->q == NULL ) { + if (ptr->q == NULL) + { ptr->t = prevt; ptr->q = prevq; - ptr->nt=1; - ptr->nq=1 + ( (prevq==curq) ? 0 : 1 ); - ptr->posq = query_numlevel - qlen - ( (prevq==curq) ? 0 : 1 ); + ptr->nt = 1; + ptr->nq = 1 + ((prevq == curq) ? 0 : 1); + ptr->posq = query_numlevel - qlen - ((prevq == curq) ? 0 : 1); ptr->post = cur_tpos; - } else { + } + else + { ptr->nt++; ptr->nq++; } - if ( qlen == 1 && ptr->q->numvar==0 ) - ptr->nt = tree_numlevel - ptr->post; + if (qlen == 1 && ptr->q->numvar == 0) + ptr->nt = tree_numlevel - ptr->post; curt = LEVEL_NEXT(curt); tlen--; cur_tpos++; - if ( high_pos < cur_tpos ) + if (high_pos < cur_tpos) high_pos++; - } else { + } + else + { isok = false; - while( cur_tpos <= high_pos && tlen > 0 && !isok) { + while (cur_tpos <= high_pos && tlen > 0 && !isok) + { isok = checkLevel(curq, curt); curt = LEVEL_NEXT(curt); tlen--; cur_tpos++; - if ( !isok && ptr ) + if (!isok && ptr) ptr->nt++; } - if ( !isok ) + if (!isok) return false; - if (ptr && ptr->q) { - if ( checkCond(ptr->q,ptr->nq,ptr->t,ptr->nt,NULL) ) + if (ptr && ptr->q) + { + if (checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL)) return false; ptr->q = NULL; } - low_pos=cur_tpos; high_pos=cur_tpos; + low_pos = cur_tpos; + high_pos = cur_tpos; } - } else { + } + else + { low_pos = cur_tpos + curq->low; high_pos = cur_tpos + curq->high; - if ( ptr && ptr->q ) { + if (ptr && ptr->q) + { ptr->nq++; - if ( qlen==1 ) + if (qlen == 1) ptr->nt = tree_numlevel - ptr->post; } } @@ -181,16 +212,20 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n prevq = curq; curq = LQL_NEXT(curq); qlen--; - } + } - if ( low_pos > tree_numlevel || tree_numlevel > high_pos ) + if (low_pos > tree_numlevel || tree_numlevel > high_pos) return false; - while( qlen>0 ) { - if ( curq->numvar ) { - if ( ! (curq->flag & LQL_NOT) ) + while (qlen > 0) + { + if (curq->numvar) + { + if (!(curq->flag & LQL_NOT)) return false; - } else { + } + else + { low_pos = cur_tpos + curq->low; high_pos = cur_tpos + curq->high; } @@ -199,42 +234,47 @@ checkCond( lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_n qlen--; } - if ( low_pos > tree_numlevel || tree_numlevel > high_pos ) + if (low_pos > tree_numlevel || tree_numlevel > high_pos) return false; - - if ( ptr && ptr->q && checkCond(ptr->q,ptr->nq,ptr->t,ptr->nt,NULL) ) + + if (ptr && ptr->q && checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL)) return false; - + return true; } Datum -ltq_regex(PG_FUNCTION_ARGS) { - ltree *tree = PG_GETARG_LTREE(0); - lquery *query = PG_GETARG_LQUERY(1); - bool res= false; +ltq_regex(PG_FUNCTION_ARGS) +{ + ltree *tree = PG_GETARG_LTREE(0); + lquery *query = PG_GETARG_LQUERY(1); + bool res = false; - if ( query->flag & LQUERY_HASNOT ) { + if (query->flag & LQUERY_HASNOT) + { FieldNot fn; - fn.q=NULL; + fn.q = NULL; - res = checkCond( LQUERY_FIRST(query), query->numlevel, - LTREE_FIRST(tree), tree->numlevel, &fn ); - } else { - res = checkCond( LQUERY_FIRST(query), query->numlevel, - LTREE_FIRST(tree), tree->numlevel, NULL ); + res = checkCond(LQUERY_FIRST(query), query->numlevel, + LTREE_FIRST(tree), tree->numlevel, &fn); + } + else + { + res = checkCond(LQUERY_FIRST(query), query->numlevel, + LTREE_FIRST(tree), tree->numlevel, NULL); } - PG_FREE_IF_COPY(tree,0); - PG_FREE_IF_COPY(query,1); - PG_RETURN_BOOL(res); + PG_FREE_IF_COPY(tree, 0); + PG_FREE_IF_COPY(query, 1); + PG_RETURN_BOOL(res); } -Datum -ltq_rregex(PG_FUNCTION_ARGS) { - PG_RETURN_DATUM( DirectFunctionCall2( ltq_regex, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) ); +Datum +ltq_rregex(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall2(ltq_regex, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + )); } diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h index 0c92deeea4..606b3e3a74 100644 --- a/contrib/ltree/ltree.h +++ b/contrib/ltree/ltree.h @@ -6,19 +6,21 @@ #include "utils/palloc.h" #include "utils/builtins.h" -typedef struct { - uint8 len; - char name[1]; -} ltree_level; +typedef struct +{ + uint8 len; + char name[1]; +} ltree_level; -#define LEVEL_HDRSIZE (sizeof(uint8)) +#define LEVEL_HDRSIZE (sizeof(uint8)) #define LEVEL_NEXT(x) ( (ltree_level*)( ((char*)(x)) + MAXALIGN(((ltree_level*)(x))->len + LEVEL_HDRSIZE) ) ) -typedef struct { - int32 len; - uint16 numlevel; - char data[1]; -} ltree; +typedef struct +{ + int32 len; + uint16 numlevel; + char data[1]; +} ltree; #define LTREE_HDRSIZE MAXALIGN( sizeof(int32) + sizeof(uint16) ) #define LTREE_FIRST(x) ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) ) @@ -26,31 +28,33 @@ typedef struct { /* lquery */ -typedef struct { - int4 val; - uint8 len; - uint8 flag; - char name[1]; -} lquery_variant; +typedef struct +{ + int4 val; + uint8 len; + uint8 flag; + char name[1]; +} lquery_variant; #define LVAR_HDRSIZE MAXALIGN(sizeof(uint8)*2 + sizeof(int4)) #define LVAR_NEXT(x) ( (lquery_variant*)( ((char*)(x)) + MAXALIGN(((lquery_variant*)(x))->len) + LVAR_HDRSIZE ) ) -#define LVAR_ANYEND 0x01 -#define LVAR_INCASE 0x02 +#define LVAR_ANYEND 0x01 +#define LVAR_INCASE 0x02 #define LVAR_SUBLEXEM 0x04 -typedef struct { - uint16 totallen; - uint16 flag; - uint16 numvar; - uint16 low; - uint16 high; - char variants[1]; -} lquery_level; - -#define LQL_HDRSIZE MAXALIGN( sizeof(uint16)*5 ) -#define LQL_NEXT(x) ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) ) +typedef struct +{ + uint16 totallen; + uint16 flag; + uint16 numvar; + uint16 low; + uint16 high; + char variants[1]; +} lquery_level; + +#define LQL_HDRSIZE MAXALIGN( sizeof(uint16)*5 ) +#define LQL_NEXT(x) ( (lquery_level*)( ((char*)(x)) + MAXALIGN(((lquery_level*)(x))->totallen) ) ) #define LQL_FIRST(x) ( (lquery_variant*)( ((char*)(x))+LQL_HDRSIZE ) ) #define LQL_NOT 0x10 @@ -59,29 +63,30 @@ typedef struct { #else #define FLG_CANLOOKSIGN(x) ( ( (x) & ( LQL_NOT | LVAR_ANYEND | LVAR_SUBLEXEM | LVAR_INCASE ) ) == 0 ) #endif -#define LQL_CANLOOKSIGN(x) FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag ) - -typedef struct { - int32 len; - uint16 numlevel; - uint16 firstgood; - uint16 flag; - char data[1]; -} lquery; +#define LQL_CANLOOKSIGN(x) FLG_CANLOOKSIGN( ((lquery_level*)(x))->flag ) -#define LQUERY_HDRSIZE MAXALIGN( sizeof(int32) + 3*sizeof(uint16) ) +typedef struct +{ + int32 len; + uint16 numlevel; + uint16 firstgood; + uint16 flag; + char data[1]; +} lquery; + +#define LQUERY_HDRSIZE MAXALIGN( sizeof(int32) + 3*sizeof(uint16) ) #define LQUERY_FIRST(x) ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) ) #define LQUERY_HASNOT 0x01 -#ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) +#ifndef max +#define max(a,b) ((a) > (b) ? (a) : (b)) #endif #ifndef min -#define min(a,b) ((a) <= (b) ? (a) : (b)) +#define min(a,b) ((a) <= (b) ? (a) : (b)) #endif #ifndef abs -#define abs(a) ((a) < (0) ? -(a) : (a)) +#define abs(a) ((a) < (0) ? -(a) : (a)) #endif #define ISALNUM(x) ( isalnum((unsigned int)(x)) || (x) == '_' ) @@ -93,75 +98,75 @@ typedef struct { */ typedef struct ITEM { - int2 type; - int2 left; - int4 val; + int2 type; + int2 left; + int4 val; uint8 flag; - /* user-friendly value */ - uint8 length; - uint16 distance; -} ITEM; + /* user-friendly value */ + uint8 length; + uint16 distance; +} ITEM; /* *Storage: - * (len)(size)(array of ITEM)(array of operand in user-friendly form) + * (len)(size)(array of ITEM)(array of operand in user-friendly form) */ typedef struct { - int4 len; - int4 size; - char data[1]; -} ltxtquery; + int4 len; + int4 size; + char data[1]; +} ltxtquery; -#define HDRSIZEQT MAXALIGN( 2*sizeof(int4) ) -#define COMPUTESIZE(size,lenofoperand) ( HDRSIZEQT + size * sizeof(ITEM) + lenofoperand ) +#define HDRSIZEQT MAXALIGN( 2*sizeof(int4) ) +#define COMPUTESIZE(size,lenofoperand) ( HDRSIZEQT + size * sizeof(ITEM) + lenofoperand ) #define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT ) -#define GETOPERAND(x) ( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) ) +#define GETOPERAND(x) ( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) ) #define ISOPERATOR(x) ( (x)=='!' || (x)=='&' || (x)=='|' || (x)=='(' || (x)==')' ) -#define END 0 -#define ERR 1 -#define VAL 2 -#define OPR 3 -#define OPEN 4 -#define CLOSE 5 -#define VALTRUE 6 /* for stop words */ -#define VALFALSE 7 +#define END 0 +#define ERR 1 +#define VAL 2 +#define OPR 3 +#define OPEN 4 +#define CLOSE 5 +#define VALTRUE 6 /* for stop words */ +#define VALFALSE 7 /* use in array iterator */ -Datum ltree_isparent(PG_FUNCTION_ARGS); -Datum ltree_risparent(PG_FUNCTION_ARGS); -Datum ltq_regex(PG_FUNCTION_ARGS); -Datum ltq_rregex(PG_FUNCTION_ARGS); -Datum ltxtq_exec(PG_FUNCTION_ARGS); -Datum ltxtq_rexec(PG_FUNCTION_ARGS); -Datum _ltq_regex(PG_FUNCTION_ARGS); -Datum _ltq_rregex(PG_FUNCTION_ARGS); -Datum _ltxtq_exec(PG_FUNCTION_ARGS); -Datum _ltxtq_rexec(PG_FUNCTION_ARGS); -Datum _ltree_isparent(PG_FUNCTION_ARGS); -Datum _ltree_risparent(PG_FUNCTION_ARGS); +Datum ltree_isparent(PG_FUNCTION_ARGS); +Datum ltree_risparent(PG_FUNCTION_ARGS); +Datum ltq_regex(PG_FUNCTION_ARGS); +Datum ltq_rregex(PG_FUNCTION_ARGS); +Datum ltxtq_exec(PG_FUNCTION_ARGS); +Datum ltxtq_rexec(PG_FUNCTION_ARGS); +Datum _ltq_regex(PG_FUNCTION_ARGS); +Datum _ltq_rregex(PG_FUNCTION_ARGS); +Datum _ltxtq_exec(PG_FUNCTION_ARGS); +Datum _ltxtq_rexec(PG_FUNCTION_ARGS); +Datum _ltree_isparent(PG_FUNCTION_ARGS); +Datum _ltree_risparent(PG_FUNCTION_ARGS); /* Concatenation functions */ -Datum ltree_addltree(PG_FUNCTION_ARGS); -Datum ltree_addtext(PG_FUNCTION_ARGS); -Datum ltree_textadd(PG_FUNCTION_ARGS); +Datum ltree_addltree(PG_FUNCTION_ARGS); +Datum ltree_addtext(PG_FUNCTION_ARGS); +Datum ltree_textadd(PG_FUNCTION_ARGS); /* Util function */ -Datum ltree_in(PG_FUNCTION_ARGS); +Datum ltree_in(PG_FUNCTION_ARGS); bool ltree_execute(ITEM * curitem, void *checkval, - bool calcnot, bool (*chkcond) (void *checkval, ITEM * val)); + 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_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); -#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) +#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) #define PG_GETARG_LQUERY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) #define PG_GETARG_LTXTQUERY(x) ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) @@ -169,7 +174,7 @@ ltree* lca_inner(ltree** a, int len); #define BITBYTE 8 #define SIGLENINT 8 -#define SIGLEN ( sizeof(int4)*SIGLENINT ) +#define SIGLEN ( sizeof(int4)*SIGLENINT ) #define SIGLENBIT (SIGLEN*BITBYTE) typedef unsigned char BITVEC[SIGLEN]; typedef unsigned char *BITVECP; @@ -195,43 +200,44 @@ typedef unsigned char *BITVECP; /* * type of index key for ltree. Tree are combined B-Tree and R-Tree * Storage: - * Leaf pages + * Leaf pages * (len)(flag)(ltree) * Non-Leaf - * (len)(flag)(sign)(left_ltree)(right_ltree) + * (len)(flag)(sign)(left_ltree)(right_ltree) * ALLTRUE: (len)(flag)(left_ltree)(right_ltree) - * + * */ -typedef struct { - int4 len; - uint32 flag; - char data[1]; -} ltree_gist; - -#define LTG_ONENODE 0x01 -#define LTG_ALLTRUE 0x02 -#define LTG_NORIGHT 0x04 - -#define LTG_HDRSIZE MAXALIGN( sizeof(int4) + sizeof(uint32) ) -#define LTG_SIGN(x) ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) ) -#define LTG_NODE(x) ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) ) -#define LTG_ISONENODE(x) ( ((ltree_gist*)(x))->flag & LTG_ONENODE ) -#define LTG_ISALLTRUE(x) ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE ) -#define LTG_ISNORIGHT(x) ( ((ltree_gist*)(x))->flag & LTG_NORIGHT ) +typedef struct +{ + int4 len; + uint32 flag; + char data[1]; +} ltree_gist; + +#define LTG_ONENODE 0x01 +#define LTG_ALLTRUE 0x02 +#define LTG_NORIGHT 0x04 + +#define LTG_HDRSIZE MAXALIGN( sizeof(int4) + sizeof(uint32) ) +#define LTG_SIGN(x) ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) ) +#define LTG_NODE(x) ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) ) +#define LTG_ISONENODE(x) ( ((ltree_gist*)(x))->flag & LTG_ONENODE ) +#define LTG_ISALLTRUE(x) ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE ) +#define LTG_ISNORIGHT(x) ( ((ltree_gist*)(x))->flag & LTG_NORIGHT ) #define LTG_LNODE(x) ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : SIGLEN ) ) ) #define LTG_RENODE(x) ( (ltree*)( ((char*)LTG_LNODE(x)) + LTG_LNODE(x)->len) ) #define LTG_RNODE(x) ( LTG_ISNORIGHT(x) ? LTG_LNODE(x) : LTG_RENODE(x) ) -#define LTG_GETLNODE(x) ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) ) -#define LTG_GETRNODE(x) ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x) ) +#define LTG_GETLNODE(x) ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) ) +#define LTG_GETRNODE(x) ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_RNODE(x) ) /* GiST support for ltree[] */ -#define ASIGLENINT (2*SIGLENINT) +#define ASIGLENINT (2*SIGLENINT) #define ASIGLEN (sizeof(int4)*ASIGLENINT) -#define ASIGLENBIT (ASIGLEN*BITBYTE) +#define ASIGLENBIT (ASIGLEN*BITBYTE) typedef unsigned char ABITVEC[ASIGLEN]; #define ALOOPBYTE(a) \ @@ -249,4 +255,3 @@ typedef unsigned char ABITVEC[ASIGLEN]; /* type of key is the same to ltree_gist */ #endif - diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c index 5a4c7bbf51..5c5f4c7d6d 100644 --- a/contrib/ltree/ltree_gist.c +++ b/contrib/ltree/ltree_gist.c @@ -1,5 +1,5 @@ /* - * GiST support for ltree + * GiST support for ltree * Teodor Sigaev <[email protected]> */ @@ -10,252 +10,297 @@ #include "crc32.h" -PG_FUNCTION_INFO_V1( ltree_gist_in ); -Datum ltree_gist_in(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_gist_out ); -Datum ltree_gist_out(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(ltree_gist_in); +Datum ltree_gist_in(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_gist_out); +Datum ltree_gist_out(PG_FUNCTION_ARGS); Datum -ltree_gist_in(PG_FUNCTION_ARGS) { - elog(ERROR,"Unimplemented"); +ltree_gist_in(PG_FUNCTION_ARGS) +{ + elog(ERROR, "Unimplemented"); PG_RETURN_DATUM(0); } Datum -ltree_gist_out(PG_FUNCTION_ARGS) { - elog(ERROR,"Unimplemented"); +ltree_gist_out(PG_FUNCTION_ARGS) +{ + elog(ERROR, "Unimplemented"); PG_RETURN_DATUM(0); } -PG_FUNCTION_INFO_V1( ltree_compress ); -Datum ltree_compress(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_decompress ); -Datum ltree_decompress(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_same ); -Datum ltree_same(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_union ); -Datum ltree_union(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_penalty ); -Datum ltree_penalty(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_picksplit ); -Datum ltree_picksplit(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( ltree_consistent ); -Datum ltree_consistent(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(ltree_compress); +Datum ltree_compress(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_decompress); +Datum ltree_decompress(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_same); +Datum ltree_same(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_union); +Datum ltree_union(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_penalty); +Datum ltree_penalty(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_picksplit); +Datum ltree_picksplit(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(ltree_consistent); +Datum ltree_consistent(PG_FUNCTION_ARGS); #define ISEQ(a,b) ( (a)->numlevel == (b)->numlevel && ltree_compare(a,b)==0 ) #define GETENTRY(vec,pos) ((ltree_gist *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key)) -Datum -ltree_compress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); +Datum +ltree_compress(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = entry; - if ( entry->leafkey ) { /* ltree */ - ltree_gist *key; - ltree *val = (ltree*)DatumGetPointer(PG_DETOAST_DATUM(entry->key)); - int4 len = LTG_HDRSIZE + val->len; + if (entry->leafkey) + { /* ltree */ + ltree_gist *key; + ltree *val = (ltree *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); + int4 len = LTG_HDRSIZE + val->len; - key = (ltree_gist*)palloc( len ); + key = (ltree_gist *) palloc(len); key->len = len; key->flag = LTG_ONENODE; - memcpy( (void*)LTG_NODE(key), (void*)val, val->len); + memcpy((void *) LTG_NODE(key), (void *) val, val->len); - if ( PointerGetDatum(val) != entry->key ) + if (PointerGetDatum(val) != entry->key) pfree(val); - retval = (GISTENTRY*)palloc( sizeof(GISTENTRY) ); + retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(key), - entry->rel, entry->page, - entry->offset, key->len, FALSE); + entry->rel, entry->page, + entry->offset, key->len, FALSE); } PG_RETURN_POINTER(retval); } -Datum -ltree_decompress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); - ltree_gist *key = (ltree_gist*)DatumGetPointer( PG_DETOAST_DATUM(entry->key) ); +Datum +ltree_decompress(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + ltree_gist *key = (ltree_gist *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); + + if (PointerGetDatum(key) != entry->key) + { + GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); - if ( PointerGetDatum(key) != entry->key ) { - GISTENTRY *retval = (GISTENTRY*)palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(key), - entry->rel, entry->page, - entry->offset, key->len, FALSE); + entry->rel, entry->page, + entry->offset, key->len, FALSE); PG_RETURN_POINTER(retval); } - PG_RETURN_POINTER(entry); + PG_RETURN_POINTER(entry); } -Datum -ltree_same(PG_FUNCTION_ARGS) { - ltree_gist* a=(ltree_gist*)PG_GETARG_POINTER(0); - ltree_gist* b=(ltree_gist*)PG_GETARG_POINTER(1); - bool *result = (bool *)PG_GETARG_POINTER(2); +Datum +ltree_same(PG_FUNCTION_ARGS) +{ + ltree_gist *a = (ltree_gist *) PG_GETARG_POINTER(0); + ltree_gist *b = (ltree_gist *) PG_GETARG_POINTER(1); + bool *result = (bool *) PG_GETARG_POINTER(2); *result = false; - if ( LTG_ISONENODE(a) != LTG_ISONENODE(b) ) - PG_RETURN_POINTER(result); - - if ( LTG_ISONENODE(a) ) { - *result = ( ISEQ(LTG_NODE(a), LTG_NODE(b)) ) ? true : false; - } else { - int4 i; - BITVECP sa=LTG_SIGN(a), sb=LTG_SIGN(b); - - if ( LTG_ISALLTRUE(a) != LTG_ISALLTRUE(b) ) - PG_RETURN_POINTER(result); - - if ( !ISEQ(LTG_LNODE(a), LTG_LNODE(b)) ) - PG_RETURN_POINTER(result); - if ( !ISEQ(LTG_RNODE(a), LTG_RNODE(b)) ) + if (LTG_ISONENODE(a) != LTG_ISONENODE(b)) + PG_RETURN_POINTER(result); + + if (LTG_ISONENODE(a)) + *result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false; + else + { + int4 i; + BITVECP sa = LTG_SIGN(a), + sb = LTG_SIGN(b); + + if (LTG_ISALLTRUE(a) != LTG_ISALLTRUE(b)) + PG_RETURN_POINTER(result); + + if (!ISEQ(LTG_LNODE(a), LTG_LNODE(b))) + PG_RETURN_POINTER(result); + if (!ISEQ(LTG_RNODE(a), LTG_RNODE(b))) PG_RETURN_POINTER(result); *result = true; - if ( !LTG_ISALLTRUE(a) ) + if (!LTG_ISALLTRUE(a)) LOOPBYTE( - if ( sa[i] != sb[i] ) { - *result = false; - break; - } - ); + if (sa[i] != sb[i]) + { + *result = false; + break; + } + ); } - - PG_RETURN_POINTER(result); + + PG_RETURN_POINTER(result); } static void -hashing(BITVECP sign, ltree *t) { - int tlen = t->numlevel; +hashing(BITVECP sign, ltree * t) +{ + int tlen = t->numlevel; ltree_level *cur = LTREE_FIRST(t); - int hash; + int hash; - while(tlen > 0) { - hash = ltree_crc32_sz( cur->name, cur->len ); - HASH( sign, hash ); + while (tlen > 0) + { + hash = ltree_crc32_sz(cur->name, cur->len); + HASH(sign, hash); cur = LEVEL_NEXT(cur); tlen--; } } -Datum -ltree_union(PG_FUNCTION_ARGS) { - bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); - int *size = (int *) PG_GETARG_POINTER(1); - BITVEC base; - int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY); - int4 i,j; - ltree_gist *result,*cur; - ltree *left=NULL, *right=NULL, *curtree; - bool isalltrue = false; - bool isleqr; - - MemSet( (void*)base, 0, sizeof(BITVEC) ); - for(j=0;j<len;j++) { +Datum +ltree_union(PG_FUNCTION_ARGS) +{ + bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); + int *size = (int *) PG_GETARG_POINTER(1); + BITVEC base; + int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY); + int4 i, + j; + ltree_gist *result, + *cur; + ltree *left = NULL, + *right = NULL, + *curtree; + bool isalltrue = false; + bool isleqr; + + MemSet((void *) base, 0, sizeof(BITVEC)); + for (j = 0; j < len; j++) + { cur = GETENTRY(entryvec, j); - if ( LTG_ISONENODE(cur) ) { + if (LTG_ISONENODE(cur)) + { curtree = LTG_NODE(cur); - hashing(base,curtree); - if ( !left || ltree_compare( left, curtree ) > 0 ) - left = curtree; - if ( !right || ltree_compare( right, curtree ) < 0 ) + hashing(base, curtree); + if (!left || ltree_compare(left, curtree) > 0) + left = curtree; + if (!right || ltree_compare(right, curtree) < 0) right = curtree; - } else { - if ( isalltrue || LTG_ISALLTRUE(cur) ) + } + else + { + if (isalltrue || LTG_ISALLTRUE(cur)) isalltrue = true; - else { - BITVECP sc=LTG_SIGN(cur); + else + { + BITVECP sc = LTG_SIGN(cur); + LOOPBYTE( - ((unsigned char*)base)[i] |= sc[i]; + ((unsigned char *) base)[i] |= sc[i]; ); } curtree = LTG_LNODE(cur); - if ( !left || ltree_compare( left, curtree ) > 0 ) - left = curtree; + if (!left || ltree_compare(left, curtree) > 0) + left = curtree; curtree = LTG_RNODE(cur); - if ( !right || ltree_compare( right, curtree ) < 0 ) + if (!right || ltree_compare(right, curtree) < 0) right = curtree; - } + } } - - if ( isalltrue == false ) { + + if (isalltrue == false) + { isalltrue = true; LOOPBYTE( - if ( ((unsigned char*)base)[i] != 0xff ) { - isalltrue = false; - break; - } - ); + if (((unsigned char *) base)[i] != 0xff) + { + isalltrue = false; + break; + } + ); } - isleqr = ( left==right || ISEQ(left,right) ) ? true : false; - *size = LTG_HDRSIZE + ( (isalltrue) ? 0 : SIGLEN ) + left->len + ( (isleqr) ? 0 : right->len ); + isleqr = (left == right || ISEQ(left, right)) ? true : false; + *size = LTG_HDRSIZE + ((isalltrue) ? 0 : SIGLEN) + left->len + ((isleqr) ? 0 : right->len); - result = (ltree_gist*)palloc( *size ); + result = (ltree_gist *) palloc(*size); result->len = *size; result->flag = 0; - if ( isalltrue ) + if (isalltrue) result->flag |= LTG_ALLTRUE; else - memcpy( (void*)LTG_SIGN(result), base, SIGLEN ); + memcpy((void *) LTG_SIGN(result), base, SIGLEN); - memcpy( (void*)LTG_LNODE(result), (void*)left, left->len ); - if ( isleqr ) + memcpy((void *) LTG_LNODE(result), (void *) left, left->len); + if (isleqr) result->flag |= LTG_NORIGHT; else - memcpy( (void*)LTG_RNODE(result), (void*)right, right->len ); + memcpy((void *) LTG_RNODE(result), (void *) right, right->len); - PG_RETURN_POINTER(result); + PG_RETURN_POINTER(result); } -Datum -ltree_penalty(PG_FUNCTION_ARGS) { - ltree_gist *origval = (ltree_gist*)DatumGetPointer( ( (GISTENTRY *)PG_GETARG_POINTER(0) )->key ); - ltree_gist *newval = (ltree_gist*)DatumGetPointer( ( (GISTENTRY *)PG_GETARG_POINTER(1) )->key ); - float *penalty = (float *) PG_GETARG_POINTER(2); - int4 cmpr,cmpl; +Datum +ltree_penalty(PG_FUNCTION_ARGS) +{ + ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key); + ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key); + float *penalty = (float *) PG_GETARG_POINTER(2); + int4 cmpr, + cmpl; - cmpl = ltree_compare( LTG_GETLNODE(origval), LTG_GETLNODE(newval) ); - cmpr = ltree_compare( LTG_GETRNODE(newval), LTG_GETRNODE(origval)); + cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval)); + cmpr = ltree_compare(LTG_GETRNODE(newval), LTG_GETRNODE(origval)); - *penalty = max( cmpl, 0 ) + max( cmpr, 0 ); + *penalty = max(cmpl, 0) + max(cmpr, 0); PG_RETURN_POINTER(penalty); } /* used for sorting */ -typedef struct rix { - int index; - ltree *r; -} RIX; +typedef struct rix +{ + int index; + ltree *r; +} RIX; static int -treekey_cmp(const void *a, const void *b) { +treekey_cmp(const void *a, const void *b) +{ return ltree_compare( - ((RIX *) a)->r, - ((RIX *) b)->r + ((RIX *) a)->r, + ((RIX *) b)->r ); } -Datum -ltree_picksplit(PG_FUNCTION_ARGS) { - bytea *entryvec = (bytea*) PG_GETARG_POINTER(0); - GIST_SPLITVEC *v = (GIST_SPLITVEC*) PG_GETARG_POINTER(1); +Datum +ltree_picksplit(PG_FUNCTION_ARGS) +{ + bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); + GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); OffsetNumber j; - int4 i; - RIX *array; + int4 i; + RIX *array; OffsetNumber maxoff; - int nbytes; - int size; - ltree *lu_l,*lu_r, *ru_l, *ru_r; - ltree_gist *lu, *ru; - BITVEC ls,rs; - bool lisat=false, risat=false, isleqr; - - memset( (void*)ls,0,sizeof(BITVEC) ); - memset( (void*)rs,0,sizeof(BITVEC) ); + int nbytes; + int size; + ltree *lu_l, + *lu_r, + *ru_l, + *ru_r; + ltree_gist *lu, + *ru; + BITVEC ls, + rs; + bool lisat = false, + risat = false, + isleqr; + + memset((void *) ls, 0, sizeof(BITVEC)); + memset((void *) rs, 0, sizeof(BITVEC)); maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 1; nbytes = (maxoff + 2) * sizeof(OffsetNumber); v->spl_left = (OffsetNumber *) palloc(nbytes); @@ -263,109 +308,124 @@ ltree_picksplit(PG_FUNCTION_ARGS) { v->spl_nleft = 0; v->spl_nright = 0; array = (RIX *) palloc(sizeof(RIX) * (maxoff + 1)); - + /* copy the data into RIXes, and sort the RIXes */ - for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) { + for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) + { array[j].index = j; - lu = GETENTRY( entryvec, j ); /* use as tmp val */ + lu = GETENTRY(entryvec, j); /* use as tmp val */ array[j].r = LTG_GETLNODE(lu); } qsort((void *) &array[FirstOffsetNumber], maxoff - FirstOffsetNumber + 1, - sizeof(RIX), treekey_cmp); + sizeof(RIX), treekey_cmp); lu_l = lu_r = ru_l = ru_r = NULL; - for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) { - lu = GETENTRY( entryvec, array[j].index ); /* use as tmp val */ - if (j <= (maxoff - FirstOffsetNumber + 1) / 2) { + for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) + { + lu = GETENTRY(entryvec, array[j].index); /* use as tmp val */ + if (j <= (maxoff - FirstOffsetNumber + 1) / 2) + { v->spl_left[v->spl_nleft] = array[j].index; v->spl_nleft++; - if ( lu_r==NULL || ltree_compare( LTG_GETRNODE(lu), lu_r ) > 0 ) + if (lu_r == NULL || ltree_compare(LTG_GETRNODE(lu), lu_r) > 0) lu_r = LTG_GETRNODE(lu); - if ( LTG_ISONENODE(lu) ) - hashing(ls,LTG_NODE(lu)); - else { - if ( lisat || LTG_ISALLTRUE(lu) ) + if (LTG_ISONENODE(lu)) + hashing(ls, LTG_NODE(lu)); + else + { + if (lisat || LTG_ISALLTRUE(lu)) lisat = true; - else { - BITVECP sc=LTG_SIGN(lu); + else + { + BITVECP sc = LTG_SIGN(lu); + LOOPBYTE( - ((unsigned char*)ls)[i] |= sc[i]; + ((unsigned char *) ls)[i] |= sc[i]; ); } } - } else { + } + else + { v->spl_right[v->spl_nright] = array[j].index; v->spl_nright++; - if ( ru_r==NULL || ltree_compare( LTG_GETRNODE(lu), ru_r ) > 0 ) + if (ru_r == NULL || ltree_compare(LTG_GETRNODE(lu), ru_r) > 0) ru_r = LTG_GETRNODE(lu); - if ( LTG_ISONENODE(lu) ) - hashing(rs,LTG_NODE(lu)); - else { - if ( risat || LTG_ISALLTRUE(lu) ) + if (LTG_ISONENODE(lu)) + hashing(rs, LTG_NODE(lu)); + else + { + if (risat || LTG_ISALLTRUE(lu)) risat = true; - else { - BITVECP sc=LTG_SIGN(lu); + else + { + BITVECP sc = LTG_SIGN(lu); + LOOPBYTE( - ((unsigned char*)rs)[i] |= sc[i]; + ((unsigned char *) rs)[i] |= sc[i]; ); } } } } - - if ( lisat == false ) { + + if (lisat == false) + { lisat = true; LOOPBYTE( - if ( ((unsigned char*)ls)[i] != 0xff ) { - lisat = false; - break; - } - ); + if (((unsigned char *) ls)[i] != 0xff) + { + lisat = false; + break; + } + ); } - if ( risat == false ) { + if (risat == false) + { risat = true; LOOPBYTE( - if ( ((unsigned char*)rs)[i] != 0xff ) { - risat = false; - break; - } - ); + if (((unsigned char *) rs)[i] != 0xff) + { + risat = false; + break; + } + ); } - lu_l = LTG_GETLNODE( GETENTRY( entryvec, array[FirstOffsetNumber].index ) ); - isleqr = ( lu_l==lu_r || ISEQ(lu_l,lu_r) ) ? true : false; - size = LTG_HDRSIZE + ( (lisat) ? 0 : SIGLEN ) + lu_l->len + ( (isleqr) ? 0 : lu_r->len ); - lu = (ltree_gist*)palloc( size ); + lu_l = LTG_GETLNODE(GETENTRY(entryvec, array[FirstOffsetNumber].index)); + isleqr = (lu_l == lu_r || ISEQ(lu_l, lu_r)) ? true : false; + size = LTG_HDRSIZE + ((lisat) ? 0 : SIGLEN) + lu_l->len + ((isleqr) ? 0 : lu_r->len); + lu = (ltree_gist *) palloc(size); lu->len = size; lu->flag = 0; - if ( lisat ) + if (lisat) lu->flag |= LTG_ALLTRUE; else - memcpy( (void*)LTG_SIGN(lu), ls, SIGLEN ); - memcpy( (void*)LTG_LNODE(lu), (void*)lu_l, lu_l->len ); - if ( isleqr ) + memcpy((void *) LTG_SIGN(lu), ls, SIGLEN); + memcpy((void *) LTG_LNODE(lu), (void *) lu_l, lu_l->len); + if (isleqr) lu->flag |= LTG_NORIGHT; else - memcpy( (void*)LTG_RNODE(lu), (void*)lu_r, lu_r->len ); + memcpy((void *) LTG_RNODE(lu), (void *) lu_r, lu_r->len); - ru_l = LTG_GETLNODE( GETENTRY( entryvec, array[ 1 + ((maxoff - FirstOffsetNumber + 1) / 2) ].index ) ); - isleqr = ( ru_l==ru_r || ISEQ(ru_l,ru_r) ) ? true : false; - size = LTG_HDRSIZE + ( (risat) ? 0 : SIGLEN ) + ru_l->len + ( (isleqr) ? 0 : ru_r->len ); - ru = (ltree_gist*)palloc( size ); + ru_l = LTG_GETLNODE(GETENTRY(entryvec, array[1 + ((maxoff - FirstOffsetNumber + 1) / 2)].index)); + isleqr = (ru_l == ru_r || ISEQ(ru_l, ru_r)) ? true : false; + size = LTG_HDRSIZE + ((risat) ? 0 : SIGLEN) + ru_l->len + ((isleqr) ? 0 : ru_r->len); + ru = (ltree_gist *) palloc(size); ru->len = size; ru->flag = 0; - if ( risat ) + if (risat) ru->flag |= LTG_ALLTRUE; else - memcpy( (void*)LTG_SIGN(ru), rs, SIGLEN ); - memcpy( (void*)LTG_LNODE(ru), (void*)ru_l, ru_l->len ); - if ( isleqr ) + memcpy((void *) LTG_SIGN(ru), rs, SIGLEN); + memcpy((void *) LTG_LNODE(ru), (void *) ru_l, ru_l->len); + if (isleqr) ru->flag |= LTG_NORIGHT; else - memcpy( (void*)LTG_RNODE(ru), (void*)ru_r, ru_r->len ); + memcpy((void *) LTG_RNODE(ru), (void *) ru_r, ru_r->len); pfree(array); v->spl_ldatum = PointerGetDatum(lu); @@ -375,13 +435,16 @@ ltree_picksplit(PG_FUNCTION_ARGS) { } static bool -gist_isparent(ltree_gist *key, ltree *query) { - int4 numlevel = query->numlevel; - int i; - - for(i=query->numlevel;i>=0;i--) { - query->numlevel=i; - if ( ltree_compare(query,LTG_GETLNODE(key)) >=0 && ltree_compare(query,LTG_GETRNODE(key)) <= 0 ) { +gist_isparent(ltree_gist * key, ltree * query) +{ + int4 numlevel = query->numlevel; + int i; + + for (i = query->numlevel; i >= 0; i--) + { + query->numlevel = i; + if (ltree_compare(query, LTG_GETLNODE(key)) >= 0 && ltree_compare(query, LTG_GETRNODE(key)) <= 0) + { query->numlevel = numlevel; return true; } @@ -392,23 +455,24 @@ gist_isparent(ltree_gist *key, ltree *query) { } static bool -gist_ischild(ltree_gist *key, ltree *query) { - ltree *left = LTG_GETLNODE(key); - ltree *right = LTG_GETRNODE(key); - int4 numlevelL = left->numlevel; - int4 numlevelR = right->numlevel; - bool res = true; - - if ( numlevelL > query->numlevel ) +gist_ischild(ltree_gist * key, ltree * query) +{ + ltree *left = LTG_GETLNODE(key); + ltree *right = LTG_GETRNODE(key); + int4 numlevelL = left->numlevel; + int4 numlevelR = right->numlevel; + bool res = true; + + if (numlevelL > query->numlevel) left->numlevel = query->numlevel; - if ( ltree_compare(query,left) < 0 ) + if (ltree_compare(query, left) < 0) res = false; - if ( numlevelR > query->numlevel ) + if (numlevelR > query->numlevel) right->numlevel = query->numlevel; - if ( res && ltree_compare(query,right) > 0 ) + if (res && ltree_compare(query, right) > 0) res = false; left->numlevel = numlevelL; @@ -417,29 +481,35 @@ gist_ischild(ltree_gist *key, ltree *query) { } static bool -gist_qe(ltree_gist *key, lquery* query) { - lquery_level *curq = LQUERY_FIRST(query); - BITVECP sign = LTG_SIGN(key); - int qlen = query->numlevel; +gist_qe(ltree_gist * key, lquery * query) +{ + lquery_level *curq = LQUERY_FIRST(query); + BITVECP sign = LTG_SIGN(key); + int qlen = query->numlevel; - if ( LTG_ISALLTRUE(key) ) + if (LTG_ISALLTRUE(key)) return true; - while( qlen>0 ) { - if ( curq->numvar && LQL_CANLOOKSIGN(curq) ) { - bool isexist=false; - int vlen = curq->numvar; + while (qlen > 0) + { + if (curq->numvar && LQL_CANLOOKSIGN(curq)) + { + bool isexist = false; + int vlen = curq->numvar; lquery_variant *curv = LQL_FIRST(curq); - while( vlen>0 ) { - if ( GETBIT( sign, HASHVAL( curv->val ) ) ) { - isexist=true; + + while (vlen > 0) + { + if (GETBIT(sign, HASHVAL(curv->val))) + { + isexist = true; break; } curv = LVAR_NEXT(curv); vlen--; } - if ( !isexist ) - return false; + if (!isexist) + return false; } curq = LQL_NEXT(curq); @@ -450,22 +520,27 @@ gist_qe(ltree_gist *key, lquery* query) { } 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); lquery_variant *bl; - int an = t->numlevel; - int bn = q->firstgood; - int res = 0; + int an = t->numlevel; + int bn = q->firstgood; + int res = 0; - while( an>0 && bn>0 ) { + while (an > 0 && bn > 0) + { bl = LQL_FIRST(ql); - if ( (res = strncmp( al->name, bl->name, min(al->len, bl->len))) == 0 ) { - if ( al->len != bl->len ) + if ((res = strncmp(al->name, bl->name, min(al->len, bl->len))) == 0) + { + if (al->len != bl->len) return al->len - bl->len; - } else + } + else return res; - an--; bn--; + an--; + bn--; al = LEVEL_NEXT(al); ql = LQL_NEXT(ql); } @@ -474,26 +549,27 @@ gist_tqcmp(ltree* t, lquery* q) { } static bool -gist_between(ltree_gist *key, lquery* query) { - ltree *left = LTG_GETLNODE(key); - ltree *right = LTG_GETRNODE(key); - int4 numlevelL = left->numlevel; - int4 numlevelR = right->numlevel; - bool res = true; - - if ( query->firstgood == 0 ) +gist_between(ltree_gist * key, lquery * query) +{ + ltree *left = LTG_GETLNODE(key); + ltree *right = LTG_GETRNODE(key); + int4 numlevelL = left->numlevel; + int4 numlevelR = right->numlevel; + bool res = true; + + if (query->firstgood == 0) return true; - if ( numlevelL > query->firstgood ) + if (numlevelL > query->firstgood) left->numlevel = query->firstgood; - if ( gist_tqcmp(left,query) > 0 ) + if (gist_tqcmp(left, query) > 0) res = false; - if ( numlevelR > query->firstgood ) + if (numlevelR > query->firstgood) right->numlevel = query->firstgood; - if ( res && gist_tqcmp(right,query) < 0 ) + if (res && gist_tqcmp(right, query) < 0) res = false; left->numlevel = numlevelL; @@ -502,99 +578,102 @@ gist_between(ltree_gist *key, lquery* query) { } static bool -checkcondition_bit(void *checkval, ITEM* val ) { - return ( FLG_CANLOOKSIGN(val->flag) ) ? GETBIT( checkval, HASHVAL( val->val ) ) : true; +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) { - if ( LTG_ISALLTRUE(key) ) +gist_qtxt(ltree_gist * key, ltxtquery * query) +{ + if (LTG_ISALLTRUE(key)) return true; - + return ltree_execute( - GETQUERY(query), - (void*)LTG_SIGN(key), false, - checkcondition_bit - ); + GETQUERY(query), + (void *) LTG_SIGN(key), false, + checkcondition_bit + ); } -Datum -ltree_consistent(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY*)PG_GETARG_POINTER(0); - char *query = (char*)DatumGetPointer( PG_DETOAST_DATUM(PG_GETARG_DATUM(1)) ); - ltree_gist *key = (ltree_gist*)DatumGetPointer( entry->key ); +Datum +ltree_consistent(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + char *query = (char *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); + ltree_gist *key = (ltree_gist *) DatumGetPointer(entry->key); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); - bool res = false; + bool res = false; -#ifndef assert_enabled +#ifndef assert_enabled #define assert_enabled 0 #endif - - switch( strategy ) { + + switch (strategy) + { case BTLessStrategyNumber: - res = ( GIST_LEAF( entry ) ) ? - ( ltree_compare((ltree*)query,LTG_NODE(key)) > 0 ) + res = (GIST_LEAF(entry)) ? + (ltree_compare((ltree *) query, LTG_NODE(key)) > 0) : - ( ltree_compare((ltree*)query,LTG_GETLNODE(key)) >= 0 ); + (ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0); break; case BTLessEqualStrategyNumber: - res = ( ltree_compare((ltree*)query,LTG_GETLNODE(key)) >= 0 ); + res = (ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0); break; case BTEqualStrategyNumber: - if ( GIST_LEAF( entry ) ) - res = ( ltree_compare((ltree*)query,LTG_NODE(key)) == 0 ); + if (GIST_LEAF(entry)) + res = (ltree_compare((ltree *) query, LTG_NODE(key)) == 0); else res = ( - ltree_compare((ltree*)query,LTG_GETLNODE(key)) >= 0 - && - ltree_compare((ltree*)query,LTG_GETRNODE(key)) <= 0 - ); + ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0 + && + ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0 + ); break; case BTGreaterEqualStrategyNumber: - res = ( ltree_compare((ltree*)query,LTG_GETRNODE(key)) <= 0 ); + res = (ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0); break; case BTGreaterStrategyNumber: - res = ( GIST_LEAF( entry ) ) ? - ( ltree_compare((ltree*)query,LTG_GETRNODE(key)) < 0 ) + res = (GIST_LEAF(entry)) ? + (ltree_compare((ltree *) query, LTG_GETRNODE(key)) < 0) : - ( ltree_compare((ltree*)query,LTG_GETRNODE(key)) <= 0 ); + (ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0); break; case 10: - res = ( GIST_LEAF( entry ) ) ? - inner_isparent( (ltree*)query, LTG_NODE(key) ) + res = (GIST_LEAF(entry)) ? + inner_isparent((ltree *) query, LTG_NODE(key)) : - gist_isparent( key, (ltree*)query); + gist_isparent(key, (ltree *) query); break; case 11: - res = ( GIST_LEAF( entry ) ) ? - inner_isparent( LTG_NODE(key), (ltree*)query) + res = (GIST_LEAF(entry)) ? + inner_isparent(LTG_NODE(key), (ltree *) query) : - gist_ischild( key, (ltree*)query); + gist_ischild(key, (ltree *) query); break; case 12: case 13: - if ( GIST_LEAF( entry ) ) - res = DatumGetBool( DirectFunctionCall2( ltq_regex, - PointerGetDatum( LTG_NODE(key) ), - PointerGetDatum( (lquery*)query ) - ) ); - else - res = ( gist_qe(key, (lquery*)query) && gist_between(key, (lquery*)query) ); - break; + if (GIST_LEAF(entry)) + res = DatumGetBool(DirectFunctionCall2(ltq_regex, + PointerGetDatum(LTG_NODE(key)), + PointerGetDatum((lquery *) query) + )); + else + res = (gist_qe(key, (lquery *) query) && gist_between(key, (lquery *) query)); + break; case 14: case 15: - if ( GIST_LEAF( entry ) ) - res = DatumGetBool( DirectFunctionCall2( ltxtq_exec, - PointerGetDatum( LTG_NODE(key) ), - PointerGetDatum( (lquery*)query ) - ) ); - else - res = gist_qtxt(key, (ltxtquery*)query); - break; + if (GIST_LEAF(entry)) + res = DatumGetBool(DirectFunctionCall2(ltxtq_exec, + PointerGetDatum(LTG_NODE(key)), + PointerGetDatum((lquery *) query) + )); + else + res = gist_qtxt(key, (ltxtquery *) query); + break; default: - elog(ERROR,"Unknown StrategyNumber: %d", strategy); + elog(ERROR, "Unknown StrategyNumber: %d", strategy); } PG_RETURN_BOOL(res); } - diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c index 6fb6d3db9e..5e9dac48c0 100644 --- a/contrib/ltree/ltree_io.c +++ b/contrib/ltree/ltree_io.c @@ -5,91 +5,110 @@ #include "ltree.h" #include <ctype.h> -#include "crc32.h" +#include "crc32.h" PG_FUNCTION_INFO_V1(ltree_in); -Datum ltree_in(PG_FUNCTION_ARGS); +Datum ltree_in(PG_FUNCTION_ARGS); + PG_FUNCTION_INFO_V1(ltree_out); -Datum ltree_out(PG_FUNCTION_ARGS); +Datum ltree_out(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(lquery_in); -Datum lquery_in(PG_FUNCTION_ARGS); +Datum lquery_in(PG_FUNCTION_ARGS); + PG_FUNCTION_INFO_V1(lquery_out); -Datum lquery_out(PG_FUNCTION_ARGS); +Datum lquery_out(PG_FUNCTION_ARGS); #define UNCHAR elog(ERROR,"Syntax error in position %d near '%c'", (int)(ptr-buf), *ptr) -typedef struct { - char* start; - int len; - int flag; -} nodeitem; +typedef struct +{ + char *start; + int len; + int flag; +} nodeitem; #define LTPRS_WAITNAME 0 -#define LTPRS_WAITDELIM 1 - -Datum -ltree_in(PG_FUNCTION_ARGS) { - char *buf = (char *) PG_GETARG_POINTER(0); - char *ptr; - nodeitem *list, *lptr; - int num=0, totallen = 0; - int state = LTPRS_WAITNAME; - ltree *result; - ltree_level *curlevel; - - ptr=buf; - while( *ptr ) { - if ( *ptr == '.' ) +#define LTPRS_WAITDELIM 1 + +Datum +ltree_in(PG_FUNCTION_ARGS) +{ + char *buf = (char *) PG_GETARG_POINTER(0); + char *ptr; + nodeitem *list, + *lptr; + int num = 0, + totallen = 0; + int state = LTPRS_WAITNAME; + ltree *result; + ltree_level *curlevel; + + ptr = buf; + while (*ptr) + { + if (*ptr == '.') num++; ptr++; } - list = lptr = (nodeitem*) palloc( sizeof(nodeitem)*(num+1) ); - ptr=buf; - while( *ptr ) { - if ( state == LTPRS_WAITNAME ) { - if ( ISALNUM(*ptr) ) { + list = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (num + 1)); + ptr = buf; + while (*ptr) + { + if (state == LTPRS_WAITNAME) + { + if (ISALNUM(*ptr)) + { lptr->start = ptr; state = LTPRS_WAITDELIM; - } else + } + else UNCHAR; - } else if ( state == LTPRS_WAITDELIM ) { - if ( *ptr == '.' ) { + } + else if (state == LTPRS_WAITDELIM) + { + if (*ptr == '.') + { lptr->len = ptr - lptr->start; - if ( lptr->len > 255 ) - elog(ERROR,"Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int)(lptr->start - buf)); + if (lptr->len > 255) + elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", + lptr->len, (int) (lptr->start - buf)); totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE); lptr++; state = LTPRS_WAITNAME; - } else if ( !ISALNUM(*ptr) ) + } + else if (!ISALNUM(*ptr)) UNCHAR; - } else - elog(ERROR,"Inner error in parser"); + } + else + elog(ERROR, "Inner error in parser"); ptr++; } - if ( state == LTPRS_WAITDELIM ) { + if (state == LTPRS_WAITDELIM) + { lptr->len = ptr - lptr->start; - if ( lptr->len > 255 ) - elog(ERROR,"Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int)(lptr->start - buf)); + if (lptr->len > 255) + elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", + lptr->len, (int) (lptr->start - buf)); totallen += MAXALIGN(lptr->len + LEVEL_HDRSIZE); lptr++; - } else if ( ! (state == LTPRS_WAITNAME && lptr == list) ) - elog(ERROR,"Unexpected end of line"); + } + else if (!(state == LTPRS_WAITNAME && lptr == list)) + elog(ERROR, "Unexpected end of line"); - result = (ltree*)palloc( LTREE_HDRSIZE + totallen ); + result = (ltree *) palloc(LTREE_HDRSIZE + totallen); result->len = LTREE_HDRSIZE + totallen; - result->numlevel = lptr-list; + result->numlevel = lptr - list; curlevel = LTREE_FIRST(result); - lptr=list; - while( lptr-list < result->numlevel ) { + lptr = list; + while (lptr - list < result->numlevel) + { curlevel->len = (uint8) lptr->len; - memcpy( curlevel->name, lptr->start, lptr->len); - curlevel = LEVEL_NEXT(curlevel); + memcpy(curlevel->name, lptr->start, lptr->len); + curlevel = LEVEL_NEXT(curlevel); lptr++; } @@ -97,254 +116,323 @@ ltree_in(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(result); } -Datum -ltree_out(PG_FUNCTION_ARGS) { - ltree *in = PG_GETARG_LTREE(0); - char *buf,*ptr; - int i; - ltree_level *curlevel; - - ptr = buf = (char*)palloc( in->len ); +Datum +ltree_out(PG_FUNCTION_ARGS) +{ + ltree *in = PG_GETARG_LTREE(0); + char *buf, + *ptr; + int i; + ltree_level *curlevel; + + ptr = buf = (char *) palloc(in->len); curlevel = LTREE_FIRST(in); - for(i=0;i<in->numlevel;i++) { - if ( i!=0 ) { + for (i = 0; i < in->numlevel; i++) + { + if (i != 0) + { *ptr = '.'; ptr++; } - memcpy( ptr, curlevel->name, curlevel->len ); - ptr+=curlevel->len; + memcpy(ptr, curlevel->name, curlevel->len); + ptr += curlevel->len; curlevel = LEVEL_NEXT(curlevel); } - *ptr='\0'; - PG_FREE_IF_COPY(in,0); + *ptr = '\0'; + PG_FREE_IF_COPY(in, 0); PG_RETURN_POINTER(buf); } -#define LQPRS_WAITLEVEL 0 -#define LQPRS_WAITDELIM 1 -#define LQPRS_WAITOPEN 2 -#define LQPRS_WAITFNUM 3 -#define LQPRS_WAITSNUM 4 -#define LQPRS_WAITND 5 -#define LQPRS_WAITCLOSE 6 +#define LQPRS_WAITLEVEL 0 +#define LQPRS_WAITDELIM 1 +#define LQPRS_WAITOPEN 2 +#define LQPRS_WAITFNUM 3 +#define LQPRS_WAITSNUM 4 +#define LQPRS_WAITND 5 +#define LQPRS_WAITCLOSE 6 #define LQPRS_WAITEND 7 #define LQPRS_WAITVAR 8 -#define GETVAR(x) ( *((nodeitem**)LQL_FIRST(x)) ) -#define ITEMSIZE MAXALIGN(LQL_HDRSIZE+sizeof(nodeitem*)) -#define NEXTLEV(x) ( (lquery_level*)( ((char*)(x)) + ITEMSIZE) ) - -Datum -lquery_in(PG_FUNCTION_ARGS) { - char *buf = (char *) PG_GETARG_POINTER(0); - char *ptr; - int num=0, totallen = 0, numOR=0; - int state = LQPRS_WAITLEVEL; - lquery *result; - nodeitem *lptr=NULL; - lquery_level *cur,*curqlevel, *tmpql; - lquery_variant *lrptr=NULL; - bool hasnot=false; - bool wasbad=false; - - ptr=buf; - while( *ptr ) { - if ( *ptr == '.' ) +#define GETVAR(x) ( *((nodeitem**)LQL_FIRST(x)) ) +#define ITEMSIZE MAXALIGN(LQL_HDRSIZE+sizeof(nodeitem*)) +#define NEXTLEV(x) ( (lquery_level*)( ((char*)(x)) + ITEMSIZE) ) + +Datum +lquery_in(PG_FUNCTION_ARGS) +{ + char *buf = (char *) PG_GETARG_POINTER(0); + char *ptr; + int num = 0, + totallen = 0, + numOR = 0; + int state = LQPRS_WAITLEVEL; + lquery *result; + nodeitem *lptr = NULL; + lquery_level *cur, + *curqlevel, + *tmpql; + lquery_variant *lrptr = NULL; + bool hasnot = false; + bool wasbad = false; + + ptr = buf; + while (*ptr) + { + if (*ptr == '.') num++; - else if ( *ptr == '|' ) + else if (*ptr == '|') numOR++; ptr++; } - + num++; - curqlevel = tmpql = (lquery_level*) palloc( ITEMSIZE*num ); - memset((void*)tmpql,0, ITEMSIZE*num ); - ptr=buf; - while( *ptr ) { - if ( state==LQPRS_WAITLEVEL ) { - if ( ISALNUM(*ptr) ) { - GETVAR(curqlevel) = lptr = (nodeitem*)palloc( sizeof(nodeitem)*(numOR+1) ); - memset((void*)GETVAR(curqlevel), 0,sizeof(nodeitem)*(numOR+1) ); + curqlevel = tmpql = (lquery_level *) palloc(ITEMSIZE * num); + memset((void *) tmpql, 0, ITEMSIZE * num); + ptr = buf; + while (*ptr) + { + if (state == LQPRS_WAITLEVEL) + { + if (ISALNUM(*ptr)) + { + GETVAR(curqlevel) = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (numOR + 1)); + memset((void *) GETVAR(curqlevel), 0, sizeof(nodeitem) * (numOR + 1)); lptr->start = ptr; state = LQPRS_WAITDELIM; curqlevel->numvar = 1; - } else if ( *ptr == '!' ) { - GETVAR(curqlevel) = lptr = (nodeitem*)palloc( sizeof(nodeitem)*(numOR+1) ); - memset((void*)GETVAR(curqlevel), 0,sizeof(nodeitem)*(numOR+1) ); - lptr->start = ptr+1; + } + else if (*ptr == '!') + { + GETVAR(curqlevel) = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (numOR + 1)); + memset((void *) GETVAR(curqlevel), 0, sizeof(nodeitem) * (numOR + 1)); + lptr->start = ptr + 1; state = LQPRS_WAITDELIM; curqlevel->numvar = 1; curqlevel->flag |= LQL_NOT; - hasnot=true; - } else if ( *ptr == '*' ) { + hasnot = true; + } + else if (*ptr == '*') state = LQPRS_WAITOPEN; - } else + else UNCHAR; - } else if ( state==LQPRS_WAITVAR ) { - if ( ISALNUM(*ptr) ) { + } + else if (state == LQPRS_WAITVAR) + { + if (ISALNUM(*ptr)) + { lptr++; lptr->start = ptr; state = LQPRS_WAITDELIM; curqlevel->numvar++; - } else + } + else UNCHAR; - } else if ( state==LQPRS_WAITDELIM ) { - if ( *ptr == '@' ) { - if ( lptr->start == ptr ) + } + else if (state == LQPRS_WAITDELIM) + { + if (*ptr == '@') + { + if (lptr->start == ptr) UNCHAR; lptr->flag |= LVAR_INCASE; curqlevel->flag |= LVAR_INCASE; - } else if ( *ptr == '*' ) { - if ( lptr->start == ptr ) + } + else if (*ptr == '*') + { + if (lptr->start == ptr) UNCHAR; lptr->flag |= LVAR_ANYEND; curqlevel->flag |= LVAR_ANYEND; - } else if ( *ptr == '%' ) { - if ( lptr->start == ptr ) + } + else if (*ptr == '%') + { + if (lptr->start == ptr) UNCHAR; lptr->flag |= LVAR_SUBLEXEM; curqlevel->flag |= LVAR_SUBLEXEM; - } else if ( *ptr == '|' ) { - lptr->len = ptr - lptr->start - - ( ( lptr->flag & LVAR_SUBLEXEM ) ? 1 : 0 ) - - ( ( lptr->flag & LVAR_INCASE ) ? 1 : 0 ) - - ( ( lptr->flag & LVAR_ANYEND ) ? 1 : 0 ); - if ( lptr->len > 255 ) - elog(ERROR,"Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int)(lptr->start - buf)); + } + else if (*ptr == '|') + { + lptr->len = ptr - lptr->start - + ((lptr->flag & LVAR_SUBLEXEM) ? 1 : 0) - + ((lptr->flag & LVAR_INCASE) ? 1 : 0) - + ((lptr->flag & LVAR_ANYEND) ? 1 : 0); + if (lptr->len > 255) + elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", + lptr->len, (int) (lptr->start - buf)); state = LQPRS_WAITVAR; - } else if ( *ptr == '.' ) { - lptr->len = ptr - lptr->start - - ( ( lptr->flag & LVAR_SUBLEXEM ) ? 1 : 0 ) - - ( ( lptr->flag & LVAR_INCASE ) ? 1 : 0 ) - - ( ( lptr->flag & LVAR_ANYEND ) ? 1 : 0 ); - if ( lptr->len > 255 ) - elog(ERROR,"Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int)(lptr->start - buf)); + } + else if (*ptr == '.') + { + lptr->len = ptr - lptr->start - + ((lptr->flag & LVAR_SUBLEXEM) ? 1 : 0) - + ((lptr->flag & LVAR_INCASE) ? 1 : 0) - + ((lptr->flag & LVAR_ANYEND) ? 1 : 0); + if (lptr->len > 255) + elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", + lptr->len, (int) (lptr->start - buf)); state = LQPRS_WAITLEVEL; curqlevel = NEXTLEV(curqlevel); - } else if ( ISALNUM(*ptr) ) { - if ( lptr->flag ) + } + else if (ISALNUM(*ptr)) + { + if (lptr->flag) UNCHAR; - } else + } + else UNCHAR; - } else if ( state == LQPRS_WAITOPEN ) { - if ( *ptr == '{' ) { + } + else if (state == LQPRS_WAITOPEN) + { + if (*ptr == '{') state = LQPRS_WAITFNUM; - } else if ( *ptr == '.' ) { - curqlevel->low=0; - curqlevel->high=0xffff; + else if (*ptr == '.') + { + curqlevel->low = 0; + curqlevel->high = 0xffff; curqlevel = NEXTLEV(curqlevel); state = LQPRS_WAITLEVEL; - } else + } + else UNCHAR; - } else if ( state == LQPRS_WAITFNUM ) { - if ( *ptr == ',' ) { - state = LQPRS_WAITSNUM; - } else if ( isdigit((unsigned int)*ptr) ) { - curqlevel->low = atoi( ptr ); + } + else if (state == LQPRS_WAITFNUM) + { + if (*ptr == ',') + state = LQPRS_WAITSNUM; + else if (isdigit((unsigned int) *ptr)) + { + curqlevel->low = atoi(ptr); state = LQPRS_WAITND; - } else - UNCHAR; - } else if ( state == LQPRS_WAITSNUM ) { - if ( isdigit((unsigned int)*ptr) ) { - curqlevel->high = atoi( ptr ); - state = LQPRS_WAITCLOSE; - } else if ( *ptr == '}' ) { + } + else + UNCHAR; + } + else if (state == LQPRS_WAITSNUM) + { + if (isdigit((unsigned int) *ptr)) + { + curqlevel->high = atoi(ptr); + state = LQPRS_WAITCLOSE; + } + else if (*ptr == '}') + { curqlevel->high = 0xffff; state = LQPRS_WAITEND; - } else + } + else UNCHAR; - } else if ( state == LQPRS_WAITCLOSE ) { - if ( *ptr == '}' ) + } + else if (state == LQPRS_WAITCLOSE) + { + if (*ptr == '}') state = LQPRS_WAITEND; - else if ( !isdigit((unsigned int)*ptr) ) + else if (!isdigit((unsigned int) *ptr)) UNCHAR; - } else if ( state == LQPRS_WAITND ) { - if ( *ptr == '}' ) { + } + else if (state == LQPRS_WAITND) + { + if (*ptr == '}') + { curqlevel->high = curqlevel->low; state = LQPRS_WAITEND; - } else if ( *ptr == ',' ) + } + else if (*ptr == ',') state = LQPRS_WAITSNUM; - else if ( !isdigit((unsigned int)*ptr) ) + else if (!isdigit((unsigned int) *ptr)) UNCHAR; - } else if ( state == LQPRS_WAITEND ) { - if ( *ptr == '.' ) { + } + else if (state == LQPRS_WAITEND) + { + if (*ptr == '.') + { state = LQPRS_WAITLEVEL; curqlevel = NEXTLEV(curqlevel); - } else + } + else UNCHAR; - } else - elog(ERROR,"Inner error in parser"); + } + else + elog(ERROR, "Inner error in parser"); ptr++; } - - if ( state==LQPRS_WAITDELIM ) { - if ( lptr->start == ptr ) - elog(ERROR,"Unexpected end of line"); + + if (state == LQPRS_WAITDELIM) + { + if (lptr->start == ptr) + elog(ERROR, "Unexpected end of line"); lptr->len = ptr - lptr->start - - ( ( lptr->flag & LVAR_SUBLEXEM ) ? 1 : 0 ) - - ( ( lptr->flag & LVAR_INCASE ) ? 1 : 0 ) - - ( ( lptr->flag & LVAR_ANYEND ) ? 1 : 0 ); - if ( lptr->len==0 ) - elog(ERROR,"Unexpected end of line"); - if ( lptr->len > 255 ) - elog(ERROR,"Name of level is too long (%d, must be < 256) in position %d", - lptr->len, (int)(lptr->start - buf)); - } else if ( state == LQPRS_WAITOPEN ) { + ((lptr->flag & LVAR_SUBLEXEM) ? 1 : 0) - + ((lptr->flag & LVAR_INCASE) ? 1 : 0) - + ((lptr->flag & LVAR_ANYEND) ? 1 : 0); + if (lptr->len == 0) + elog(ERROR, "Unexpected end of line"); + if (lptr->len > 255) + elog(ERROR, "Name of level is too long (%d, must be < 256) in position %d", + lptr->len, (int) (lptr->start - buf)); + } + else if (state == LQPRS_WAITOPEN) curqlevel->high = 0xffff; - } else if ( state != LQPRS_WAITEND ) - elog(ERROR,"Unexpected end of line"); - + else if (state != LQPRS_WAITEND) + elog(ERROR, "Unexpected end of line"); + curqlevel = tmpql; - totallen = LQUERY_HDRSIZE; - while( (char*)curqlevel-(char*)tmpql < num*ITEMSIZE ) { - totallen += LQL_HDRSIZE; - if ( curqlevel->numvar ) { + totallen = LQUERY_HDRSIZE; + while ((char *) curqlevel - (char *) tmpql < num * ITEMSIZE) + { + totallen += LQL_HDRSIZE; + if (curqlevel->numvar) + { lptr = GETVAR(curqlevel); - while( lptr-GETVAR(curqlevel) < curqlevel->numvar ) { + while (lptr - GETVAR(curqlevel) < curqlevel->numvar) + { totallen += MAXALIGN(LVAR_HDRSIZE + lptr->len); lptr++; } - } else if ( curqlevel->low > curqlevel->high ) - elog(ERROR,"Low limit(%d) is greater than upper(%d)",curqlevel->low,curqlevel->high ); + } + else if (curqlevel->low > curqlevel->high) + elog(ERROR, "Low limit(%d) is greater than upper(%d)", curqlevel->low, curqlevel->high); curqlevel = NEXTLEV(curqlevel); } - result = (lquery*)palloc( totallen ); + result = (lquery *) palloc(totallen); result->len = totallen; result->numlevel = num; result->firstgood = 0; - result->flag=0; - if ( hasnot ) + result->flag = 0; + if (hasnot) result->flag |= LQUERY_HASNOT; cur = LQUERY_FIRST(result); curqlevel = tmpql; - while( (char*)curqlevel-(char*)tmpql < num*ITEMSIZE ) { - memcpy(cur,curqlevel,LQL_HDRSIZE); - cur->totallen=LQL_HDRSIZE; - if ( curqlevel->numvar ) { + while ((char *) curqlevel - (char *) tmpql < num * ITEMSIZE) + { + memcpy(cur, curqlevel, LQL_HDRSIZE); + cur->totallen = LQL_HDRSIZE; + if (curqlevel->numvar) + { lrptr = LQL_FIRST(cur); lptr = GETVAR(curqlevel); - while( lptr-GETVAR(curqlevel) < curqlevel->numvar ) { + while (lptr - GETVAR(curqlevel) < curqlevel->numvar) + { cur->totallen += MAXALIGN(LVAR_HDRSIZE + lptr->len); - lrptr->len = lptr->len; + lrptr->len = lptr->len; lrptr->flag = lptr->flag; lrptr->val = ltree_crc32_sz((uint8 *) lptr->start, lptr->len); - memcpy( lrptr->name, lptr->start, lptr->len); + memcpy(lrptr->name, lptr->start, lptr->len); lptr++; - lrptr = LVAR_NEXT( lrptr ); + lrptr = LVAR_NEXT(lrptr); } - pfree( GETVAR(curqlevel) ); - if ( cur->numvar > 1 || cur->flag != 0 ) - wasbad=true; - else if ( wasbad==false ) - (result->firstgood)++; - } else - wasbad=true; + pfree(GETVAR(curqlevel)); + if (cur->numvar > 1 || cur->flag != 0) + wasbad = true; + else if (wasbad == false) + (result->firstgood)++; + } + else + wasbad = true; curqlevel = NEXTLEV(curqlevel); cur = LQL_NEXT(cur); } @@ -353,82 +441,104 @@ lquery_in(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(result); } -Datum -lquery_out(PG_FUNCTION_ARGS) { - lquery *in = PG_GETARG_LQUERY(0); - char *buf,*ptr; - int i,j,totallen=0; - lquery_level *curqlevel; - lquery_variant *curtlevel; +Datum +lquery_out(PG_FUNCTION_ARGS) +{ + lquery *in = PG_GETARG_LQUERY(0); + char *buf, + *ptr; + int i, + j, + totallen = 0; + lquery_level *curqlevel; + lquery_variant *curtlevel; curqlevel = LQUERY_FIRST(in); - for(i=0;i<in->numlevel;i++) { - if ( curqlevel->numvar ) - totallen = (curqlevel->numvar*4) + 1 + curqlevel->totallen; + for (i = 0; i < in->numlevel; i++) + { + if (curqlevel->numvar) + totallen = (curqlevel->numvar * 4) + 1 + curqlevel->totallen; else - totallen = 2*11 + 4; + totallen = 2 * 11 + 4; totallen++; curqlevel = LQL_NEXT(curqlevel); } - - - ptr = buf = (char*)palloc( totallen ); + + + ptr = buf = (char *) palloc(totallen); curqlevel = LQUERY_FIRST(in); - for(i=0;i<in->numlevel;i++) { - if ( i!=0 ) { + for (i = 0; i < in->numlevel; i++) + { + if (i != 0) + { *ptr = '.'; ptr++; } - if ( curqlevel->numvar ) { - if ( curqlevel->flag & LQL_NOT ) { + if (curqlevel->numvar) + { + if (curqlevel->flag & LQL_NOT) + { *ptr = '!'; ptr++; } curtlevel = LQL_FIRST(curqlevel); - for(j=0;j<curqlevel->numvar;j++) { - if ( j!=0 ) { + for (j = 0; j < curqlevel->numvar; j++) + { + if (j != 0) + { *ptr = '|'; ptr++; } - memcpy( ptr, curtlevel->name, curtlevel->len ); - ptr+=curtlevel->len; - if ( (curtlevel->flag & LVAR_SUBLEXEM) ) { + memcpy(ptr, curtlevel->name, curtlevel->len); + ptr += curtlevel->len; + if ((curtlevel->flag & LVAR_SUBLEXEM)) + { *ptr = '%'; ptr++; } - if ( (curtlevel->flag & LVAR_INCASE) ) { + if ((curtlevel->flag & LVAR_INCASE)) + { *ptr = '@'; ptr++; } - if ( (curtlevel->flag & LVAR_ANYEND) ) { + if ((curtlevel->flag & LVAR_ANYEND)) + { *ptr = '*'; ptr++; } curtlevel = LVAR_NEXT(curtlevel); } - } else { - if ( curqlevel->low == curqlevel->high ) { - sprintf(ptr,"*{%d}",curqlevel->low); - } else if ( curqlevel->low == 0 ) { - if ( curqlevel->high == 0xffff ) { - *ptr='*'; - *(ptr+1)='\0'; - } else - sprintf(ptr,"*{,%d}",curqlevel->high); - } else if ( curqlevel->high == 0xffff ) { - sprintf(ptr,"*{%d,}",curqlevel->low); - } else - sprintf(ptr,"*{%d,%d}", curqlevel->low, curqlevel->high); - ptr = strchr(ptr,'\0'); + } + else + { + if (curqlevel->low == curqlevel->high) + { + sprintf(ptr, "*{%d}", curqlevel->low); + } + else if (curqlevel->low == 0) + { + if (curqlevel->high == 0xffff) + { + *ptr = '*'; + *(ptr + 1) = '\0'; + } + else + sprintf(ptr, "*{,%d}", curqlevel->high); + } + else if (curqlevel->high == 0xffff) + { + sprintf(ptr, "*{%d,}", curqlevel->low); + } + else + sprintf(ptr, "*{%d,%d}", curqlevel->low, curqlevel->high); + ptr = strchr(ptr, '\0'); } curqlevel = LQL_NEXT(curqlevel); } - *ptr='\0'; - PG_FREE_IF_COPY(in,0); + *ptr = '\0'; + PG_FREE_IF_COPY(in, 0); PG_RETURN_POINTER(buf); } - - diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c index b954908b6c..4dcf6f7363 100644 --- a/contrib/ltree/ltree_op.c +++ b/contrib/ltree/ltree_op.c @@ -1,5 +1,5 @@ /* - * op function for ltree + * op function for ltree * Teodor Sigaev <[email protected]> */ @@ -23,45 +23,50 @@ PG_FUNCTION_INFO_V1(ltree_addltree); PG_FUNCTION_INFO_V1(ltree_addtext); PG_FUNCTION_INFO_V1(ltree_textadd); PG_FUNCTION_INFO_V1(lca); -Datum ltree_cmp(PG_FUNCTION_ARGS); -Datum ltree_lt(PG_FUNCTION_ARGS); -Datum ltree_le(PG_FUNCTION_ARGS); -Datum ltree_eq(PG_FUNCTION_ARGS); -Datum ltree_ne(PG_FUNCTION_ARGS); -Datum ltree_ge(PG_FUNCTION_ARGS); -Datum ltree_gt(PG_FUNCTION_ARGS); -Datum nlevel(PG_FUNCTION_ARGS); -Datum subltree(PG_FUNCTION_ARGS); -Datum subpath(PG_FUNCTION_ARGS); -Datum ltree_addltree(PG_FUNCTION_ARGS); -Datum ltree_addtext(PG_FUNCTION_ARGS); -Datum ltree_textadd(PG_FUNCTION_ARGS); -Datum lca(PG_FUNCTION_ARGS); +Datum ltree_cmp(PG_FUNCTION_ARGS); +Datum ltree_lt(PG_FUNCTION_ARGS); +Datum ltree_le(PG_FUNCTION_ARGS); +Datum ltree_eq(PG_FUNCTION_ARGS); +Datum ltree_ne(PG_FUNCTION_ARGS); +Datum ltree_ge(PG_FUNCTION_ARGS); +Datum ltree_gt(PG_FUNCTION_ARGS); +Datum nlevel(PG_FUNCTION_ARGS); +Datum subltree(PG_FUNCTION_ARGS); +Datum subpath(PG_FUNCTION_ARGS); +Datum ltree_addltree(PG_FUNCTION_ARGS); +Datum ltree_addtext(PG_FUNCTION_ARGS); +Datum ltree_textadd(PG_FUNCTION_ARGS); +Datum lca(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); - int an = a->numlevel; - int bn = b->numlevel; - int res = 0; - - while( an>0 && bn>0 ) { - if ( (res = strncmp( al->name, bl->name, min(al->len, bl->len))) == 0 ) { - if ( al->len != bl->len ) - return (al->len - bl->len)*10*(an+1); - } else - return res*10*(an+1); - - an--; bn--; - al = LEVEL_NEXT(al); - bl = LEVEL_NEXT(bl); + int an = a->numlevel; + int bn = b->numlevel; + int res = 0; + + while (an > 0 && bn > 0) + { + if ((res = strncmp(al->name, bl->name, min(al->len, bl->len))) == 0) + { + if (al->len != bl->len) + return (al->len - bl->len) * 10 * (an + 1); + } + else + return res * 10 * (an + 1); + + an--; + bn--; + al = LEVEL_NEXT(al); + bl = LEVEL_NEXT(bl); } - return (a->numlevel - b->numlevel)*10*(an+1); -} + return (a->numlevel - b->numlevel) * 10 * (an + 1); +} -#define RUNCMP \ +#define RUNCMP \ ltree *a = PG_GETARG_LTREE(0); \ ltree *b = PG_GETARG_LTREE(1); \ int res = ltree_compare(a,b); \ @@ -69,320 +74,360 @@ PG_FREE_IF_COPY(a,0); \ PG_FREE_IF_COPY(b,1); \ Datum -ltree_cmp(PG_FUNCTION_ARGS) { +ltree_cmp(PG_FUNCTION_ARGS) +{ RUNCMP PG_RETURN_INT32(res); } Datum -ltree_lt(PG_FUNCTION_ARGS) { +ltree_lt(PG_FUNCTION_ARGS) +{ RUNCMP - PG_RETURN_BOOL( (res<0) ? true : false ); + PG_RETURN_BOOL((res < 0) ? true : false); } Datum -ltree_le(PG_FUNCTION_ARGS) { +ltree_le(PG_FUNCTION_ARGS) +{ RUNCMP - PG_RETURN_BOOL( (res<=0) ? true : false ); + PG_RETURN_BOOL((res <= 0) ? true : false); } Datum -ltree_eq(PG_FUNCTION_ARGS) { +ltree_eq(PG_FUNCTION_ARGS) +{ RUNCMP - PG_RETURN_BOOL( (res==0) ? true : false ); + PG_RETURN_BOOL((res == 0) ? true : false); } Datum -ltree_ge(PG_FUNCTION_ARGS) { +ltree_ge(PG_FUNCTION_ARGS) +{ RUNCMP - PG_RETURN_BOOL( (res>=0) ? true : false ); + PG_RETURN_BOOL((res >= 0) ? true : false); } Datum -ltree_gt(PG_FUNCTION_ARGS) { +ltree_gt(PG_FUNCTION_ARGS) +{ RUNCMP - PG_RETURN_BOOL( (res>0) ? true : false ); + PG_RETURN_BOOL((res > 0) ? true : false); } Datum -ltree_ne(PG_FUNCTION_ARGS) { +ltree_ne(PG_FUNCTION_ARGS) +{ RUNCMP - PG_RETURN_BOOL( (res!=0) ? true : false ); + PG_RETURN_BOOL((res != 0) ? true : false); } Datum -nlevel(PG_FUNCTION_ARGS) { - ltree *a = PG_GETARG_LTREE(0); - int res = a->numlevel; - PG_FREE_IF_COPY(a,0); +nlevel(PG_FUNCTION_ARGS) +{ + ltree *a = PG_GETARG_LTREE(0); + int res = a->numlevel; + + PG_FREE_IF_COPY(a, 0); PG_RETURN_INT32(res); } 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); - int pn = p->numlevel; + int pn = p->numlevel; - if ( pn > c->numlevel ) + if (pn > c->numlevel) return false; - while( pn>0 ) { - if ( cl->len != pl->len ) + while (pn > 0) + { + if (cl->len != pl->len) return false; - if ( strncmp( cl->name, pl->name, cl->len ) ) + if (strncmp(cl->name, pl->name, cl->len)) return false; pn--; - cl = LEVEL_NEXT(cl); - pl = LEVEL_NEXT(pl); + cl = LEVEL_NEXT(cl); + pl = LEVEL_NEXT(pl); } return true; } -Datum -ltree_isparent(PG_FUNCTION_ARGS) { - ltree *c = PG_GETARG_LTREE(1); - ltree *p = PG_GETARG_LTREE(0); - bool res = inner_isparent(c,p); - PG_FREE_IF_COPY(c,1); - PG_FREE_IF_COPY(p,0); - PG_RETURN_BOOL( res ); +Datum +ltree_isparent(PG_FUNCTION_ARGS) +{ + ltree *c = PG_GETARG_LTREE(1); + ltree *p = PG_GETARG_LTREE(0); + bool res = inner_isparent(c, p); + + PG_FREE_IF_COPY(c, 1); + PG_FREE_IF_COPY(p, 0); + PG_RETURN_BOOL(res); } -Datum -ltree_risparent(PG_FUNCTION_ARGS) { - ltree *c = PG_GETARG_LTREE(0); - ltree *p = PG_GETARG_LTREE(1); - bool res = inner_isparent(c,p); - PG_FREE_IF_COPY(c,0); - PG_FREE_IF_COPY(p,1); - PG_RETURN_BOOL( res ); +Datum +ltree_risparent(PG_FUNCTION_ARGS) +{ + ltree *c = PG_GETARG_LTREE(0); + ltree *p = PG_GETARG_LTREE(1); + bool res = inner_isparent(c, p); + + PG_FREE_IF_COPY(c, 0); + PG_FREE_IF_COPY(p, 1); + PG_RETURN_BOOL(res); } -static ltree* -inner_subltree(ltree *t, int4 startpos, int4 endpos) { - char *start=NULL,*end=NULL; +static ltree * +inner_subltree(ltree * t, int4 startpos, int4 endpos) +{ + char *start = NULL, + *end = NULL; ltree_level *ptr = LTREE_FIRST(t); - ltree *res; - int i; + ltree *res; + int i; - if ( startpos <0 || endpos <0 || startpos>=t->numlevel || startpos >= endpos ) - elog(ERROR,"Wrong positions"); + if (startpos < 0 || endpos < 0 || startpos >= t->numlevel || startpos >= endpos) + elog(ERROR, "Wrong positions"); - if ( endpos > t->numlevel ) + if (endpos > t->numlevel) endpos = t->numlevel; - for(i=0;i<endpos ;i++) { - if ( i==startpos ) - start = (char*)ptr; - if ( i==endpos-1 ) { - end = (char*)LEVEL_NEXT(ptr); + for (i = 0; i < endpos; i++) + { + if (i == startpos) + start = (char *) ptr; + if (i == endpos - 1) + { + end = (char *) LEVEL_NEXT(ptr); break; } - ptr = LEVEL_NEXT(ptr); + ptr = LEVEL_NEXT(ptr); } - res=(ltree*)palloc( LTREE_HDRSIZE + (end-start) ); - res->len = LTREE_HDRSIZE + (end-start); - res->numlevel = endpos-startpos; + res = (ltree *) palloc(LTREE_HDRSIZE + (end - start)); + res->len = LTREE_HDRSIZE + (end - start); + res->numlevel = endpos - startpos; + + memcpy(LTREE_FIRST(res), start, end - start); - memcpy( LTREE_FIRST(res), start, end-start); - return res; } Datum -subltree(PG_FUNCTION_ARGS) { - ltree *t = PG_GETARG_LTREE(0); - ltree *res = inner_subltree(t,PG_GETARG_INT32(1),PG_GETARG_INT32(2)); +subltree(PG_FUNCTION_ARGS) +{ + ltree *t = PG_GETARG_LTREE(0); + ltree *res = inner_subltree(t, PG_GETARG_INT32(1), PG_GETARG_INT32(2)); - PG_FREE_IF_COPY(t,0); + PG_FREE_IF_COPY(t, 0); PG_RETURN_POINTER(res); } -Datum -subpath(PG_FUNCTION_ARGS) { - ltree *t = PG_GETARG_LTREE(0); - int4 start = PG_GETARG_INT32(1); - int4 len = ( fcinfo->nargs==3 ) ? PG_GETARG_INT32(2) : 0; - int4 end; - ltree *res; - - end = start+len; - - if ( start < 0 ) { +Datum +subpath(PG_FUNCTION_ARGS) +{ + ltree *t = PG_GETARG_LTREE(0); + int4 start = PG_GETARG_INT32(1); + int4 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0; + int4 end; + ltree *res; + + end = start + len; + + if (start < 0) + { start = t->numlevel + start; - end = start+len; + end = start + len; } - if ( start < 0 ) { /* start > t->numlevel */ + if (start < 0) + { /* start > t->numlevel */ start = t->numlevel + start; - end = start+len; + end = start + len; } - if ( len < 0 ) + if (len < 0) end = t->numlevel + len; - else if ( len == 0 ) + else if (len == 0) end = 0xffff; - res = inner_subltree(t,start,end); + res = inner_subltree(t, start, end); - PG_FREE_IF_COPY(t,0); + PG_FREE_IF_COPY(t, 0); PG_RETURN_POINTER(res); -} - -static ltree* -ltree_concat( ltree *a, ltree *b) { - ltree *r; - r=(ltree*)palloc( a->len + b->len - LTREE_HDRSIZE); - r->len = a->len + b->len - LTREE_HDRSIZE; - r->numlevel = a->numlevel + b->numlevel; - - memcpy( LTREE_FIRST(r), LTREE_FIRST(a), a->len - LTREE_HDRSIZE); - memcpy( ((char*)LTREE_FIRST(r))+ a->len - LTREE_HDRSIZE, LTREE_FIRST(b), b->len - - LTREE_HDRSIZE); - return r; } -Datum -ltree_addltree(PG_FUNCTION_ARGS) { - ltree *a = PG_GETARG_LTREE(0); - ltree *b = PG_GETARG_LTREE(1); - ltree *r; +static ltree * +ltree_concat(ltree * a, ltree * b) +{ + ltree *r; + + r = (ltree *) palloc(a->len + b->len - LTREE_HDRSIZE); + r->len = a->len + b->len - LTREE_HDRSIZE; + r->numlevel = a->numlevel + b->numlevel; + + memcpy(LTREE_FIRST(r), LTREE_FIRST(a), a->len - LTREE_HDRSIZE); + memcpy(((char *) LTREE_FIRST(r)) + a->len - LTREE_HDRSIZE, LTREE_FIRST(b), b->len - + LTREE_HDRSIZE); + return r; +} + +Datum +ltree_addltree(PG_FUNCTION_ARGS) +{ + ltree *a = PG_GETARG_LTREE(0); + ltree *b = PG_GETARG_LTREE(1); + ltree *r; r = ltree_concat(a, b); - PG_FREE_IF_COPY(a,0); - PG_FREE_IF_COPY(b,1); + PG_FREE_IF_COPY(a, 0); + PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(r); } Datum -ltree_addtext(PG_FUNCTION_ARGS) { - ltree *a = PG_GETARG_LTREE(0); - text *b = PG_GETARG_TEXT_P(1); - char *s; - ltree *r,*tmp; - - s = (char*)palloc( VARSIZE(b) - VARHDRSZ+1 ); - memcpy(s, VARDATA(b), VARSIZE(b) - VARHDRSZ ); +ltree_addtext(PG_FUNCTION_ARGS) +{ + ltree *a = PG_GETARG_LTREE(0); + text *b = PG_GETARG_TEXT_P(1); + char *s; + ltree *r, + *tmp; + + s = (char *) palloc(VARSIZE(b) - VARHDRSZ + 1); + memcpy(s, VARDATA(b), VARSIZE(b) - VARHDRSZ); s[VARSIZE(b) - VARHDRSZ] = '\0'; - tmp = (ltree*)DatumGetPointer( DirectFunctionCall1( - ltree_in, - PointerGetDatum(s) - ) ); + tmp = (ltree *) DatumGetPointer(DirectFunctionCall1( + ltree_in, + PointerGetDatum(s) + )); pfree(s); - r = ltree_concat(a,tmp); + r = ltree_concat(a, tmp); - pfree( tmp ); - - PG_FREE_IF_COPY(a,0); - PG_FREE_IF_COPY(b,1); + pfree(tmp); + + PG_FREE_IF_COPY(a, 0); + PG_FREE_IF_COPY(b, 1); PG_RETURN_POINTER(r); } Datum -ltree_textadd(PG_FUNCTION_ARGS) { - ltree *a = PG_GETARG_LTREE(1); - text *b = PG_GETARG_TEXT_P(0); - char *s; - ltree *r,*tmp; - - s = (char*)palloc( VARSIZE(b) - VARHDRSZ + 1 ); - memcpy(s, VARDATA(b), VARSIZE(b) - VARHDRSZ ); - s[VARSIZE(b) - VARHDRSZ] = '\0'; - - tmp = (ltree*)DatumGetPointer( DirectFunctionCall1( - ltree_in, - PointerGetDatum(s) - ) ); - - pfree(s); - - r = ltree_concat(tmp,a); - - pfree( tmp ); - - PG_FREE_IF_COPY(a,1); - PG_FREE_IF_COPY(b,0); - PG_RETURN_POINTER(r); +ltree_textadd(PG_FUNCTION_ARGS) +{ + ltree *a = PG_GETARG_LTREE(1); + text *b = PG_GETARG_TEXT_P(0); + char *s; + ltree *r, + *tmp; + + s = (char *) palloc(VARSIZE(b) - VARHDRSZ + 1); + memcpy(s, VARDATA(b), VARSIZE(b) - VARHDRSZ); + s[VARSIZE(b) - VARHDRSZ] = '\0'; + + tmp = (ltree *) DatumGetPointer(DirectFunctionCall1( + ltree_in, + PointerGetDatum(s) + )); + + pfree(s); + + r = ltree_concat(tmp, a); + + pfree(tmp); + + PG_FREE_IF_COPY(a, 1); + PG_FREE_IF_COPY(b, 0); + PG_RETURN_POINTER(r); } -ltree* -lca_inner(ltree** a, int len) { - int tmp,num=( (*a)->numlevel ) ? (*a)->numlevel-1 : 0; - ltree **ptr=a+1; - int i,reslen=LTREE_HDRSIZE; - ltree_level *l1, *l2; - ltree *res; - +ltree * +lca_inner(ltree ** a, int len) +{ + int tmp, + num = ((*a)->numlevel) ? (*a)->numlevel - 1 : 0; + ltree **ptr = a + 1; + int i, + reslen = LTREE_HDRSIZE; + ltree_level *l1, + *l2; + ltree *res; + - if ( (*a)->numlevel == 0 ) + if ((*a)->numlevel == 0) return NULL; - while( ptr-a < len ) { - if ( (*ptr)->numlevel == 0 ) + while (ptr - a < len) + { + if ((*ptr)->numlevel == 0) return NULL; - else if ( (*ptr)->numlevel == 1 ) - num=0; - else { + else if ((*ptr)->numlevel == 1) + num = 0; + else + { l1 = LTREE_FIRST(*a); l2 = LTREE_FIRST(*ptr); - tmp=num; num=0; - for(i=0;i<min(tmp, (*ptr)->numlevel-1); i++) { - if ( l1->len == l2->len && strncmp(l1->name,l2->name,l1->len) == 0 ) - num=i+1; + tmp = num; + num = 0; + for (i = 0; i < min(tmp, (*ptr)->numlevel - 1); i++) + { + if (l1->len == l2->len && strncmp(l1->name, l2->name, l1->len) == 0) + num = i + 1; else break; - l1=LEVEL_NEXT(l1); - l2=LEVEL_NEXT(l2); + l1 = LEVEL_NEXT(l1); + l2 = LEVEL_NEXT(l2); } } ptr++; } l1 = LTREE_FIRST(*a); - for(i=0;i<num;i++) { + for (i = 0; i < num; i++) + { reslen += MAXALIGN(l1->len + LEVEL_HDRSIZE); - l1=LEVEL_NEXT(l1); + l1 = LEVEL_NEXT(l1); } - res=(ltree*)palloc( reslen ); + res = (ltree *) palloc(reslen); res->len = reslen; res->numlevel = num; l1 = LTREE_FIRST(*a); l2 = LTREE_FIRST(res); - for(i=0;i<num;i++) { - memcpy(l2,l1, MAXALIGN(l1->len + LEVEL_HDRSIZE)); - l1=LEVEL_NEXT(l1); - l2=LEVEL_NEXT(l2); - } + for (i = 0; i < num; i++) + { + memcpy(l2, l1, MAXALIGN(l1->len + LEVEL_HDRSIZE)); + l1 = LEVEL_NEXT(l1); + l2 = LEVEL_NEXT(l2); + } return res; } Datum -lca(PG_FUNCTION_ARGS) { - int i; - ltree **a,*res; - - a=(ltree**)palloc( sizeof(ltree*) * fcinfo->nargs ); - for(i=0;i<fcinfo->nargs;i++) +lca(PG_FUNCTION_ARGS) +{ + int i; + ltree **a, + *res; + + a = (ltree **) palloc(sizeof(ltree *) * fcinfo->nargs); + for (i = 0; i < fcinfo->nargs; i++) a[i] = PG_GETARG_LTREE(i); - res = lca_inner(a, (int) fcinfo->nargs); - for(i=0;i<fcinfo->nargs;i++) - PG_FREE_IF_COPY(a[i],i); + res = lca_inner(a, (int) fcinfo->nargs); + for (i = 0; i < fcinfo->nargs; i++) + PG_FREE_IF_COPY(a[i], i); pfree(a); - - if ( res ) + + if (res) PG_RETURN_POINTER(res); else PG_RETURN_NULL(); } - - diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c index 59bf0776ee..e9be1621d6 100644 --- a/contrib/ltree/ltxtquery_io.c +++ b/contrib/ltree/ltxtquery_io.c @@ -1,5 +1,5 @@ /* - * txtquery io + * txtquery io * Teodor Sigaev <[email protected]> */ @@ -8,44 +8,47 @@ #include "crc32.h" PG_FUNCTION_INFO_V1(ltxtq_in); -Datum ltxtq_in(PG_FUNCTION_ARGS); +Datum ltxtq_in(PG_FUNCTION_ARGS); + PG_FUNCTION_INFO_V1(ltxtq_out); -Datum ltxtq_out(PG_FUNCTION_ARGS); +Datum ltxtq_out(PG_FUNCTION_ARGS); /* parser's states */ #define WAITOPERAND 1 #define INOPERAND 2 -#define WAITOPERATOR 3 +#define WAITOPERATOR 3 /* * node of query tree, also used * for storing polish notation in parser */ -typedef struct NODE { - int4 type; - int4 val; - int2 distance; - int2 length; - uint16 flag; +typedef struct NODE +{ + int4 type; + int4 val; + int2 distance; + int2 length; + uint16 flag; struct NODE *next; -} NODE; +} NODE; -typedef struct { - char *buf; - int4 state; - int4 count; +typedef struct +{ + char *buf; + int4 state; + int4 count; /* reverse polish notation in list (for temprorary usage) */ - NODE *str; + NODE *str; /* number in str */ - int4 num; + int4 num; /* user-friendly operand */ - int4 lenop; - int4 sumlen; - char *op; - char *curop; -} QPRS_STATE; + int4 lenop; + int4 sumlen; + char *op; + char *curop; +} QPRS_STATE; /* * get token from query string @@ -70,27 +73,31 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint1 (state->buf)++; return OPEN; } - else if ( ISALNUM(*(state->buf)) ) + else if (ISALNUM(*(state->buf))) { state->state = INOPERAND; *strval = state->buf; *lenval = 1; *flag = 0; - } else if ( !isspace((unsigned int)*(state->buf)) ) - elog(ERROR,"Operand syntax error"); + } + else if (!isspace((unsigned int) *(state->buf))) + elog(ERROR, "Operand syntax error"); break; case INOPERAND: - if ( ISALNUM(*(state->buf)) ) { - if ( *flag ) - elog(ERROR,"Modificators syntax error"); + if (ISALNUM(*(state->buf))) + { + if (*flag) + elog(ERROR, "Modificators syntax error"); (*lenval)++; - } else if ( *(state->buf) == '%' ) { + } + else if (*(state->buf) == '%') *flag |= LVAR_SUBLEXEM; - } else if ( *(state->buf) == '@' ) { + else if (*(state->buf) == '@') *flag |= LVAR_INCASE; - } else if ( *(state->buf) == '*' ) { + else if (*(state->buf) == '*') *flag |= LVAR_ANYEND; - } else { + else + { state->state = WAITOPERATOR; return VAL; } @@ -129,7 +136,7 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, uint1 static void pushquery(QPRS_STATE * state, int4 type, int4 val, int4 distance, int4 lenval, uint16 flag) { - NODE *tmp = (NODE *) palloc(sizeof(NODE)); + NODE *tmp = (NODE *) palloc(sizeof(NODE)); tmp->type = type; tmp->val = val; @@ -159,7 +166,7 @@ pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval, uint16 flag while (state->curop - state->op + lenval + 1 >= state->lenop) { - int4 tmp = state->curop - state->op; + int4 tmp = state->curop - state->op; state->lenop *= 2; state->op = (char *) repalloc((void *) state->op, state->lenop); @@ -173,26 +180,27 @@ pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval, uint16 flag return; } -#define STACKDEPTH 32 +#define STACKDEPTH 32 /* * make polish notaion of query */ static int4 makepol(QPRS_STATE * state) { - int4 val, + int4 val, type; - int4 lenval; - char *strval; - int4 stack[STACKDEPTH]; - int4 lenstack = 0; - uint16 flag; + int4 lenval; + char *strval; + int4 stack[STACKDEPTH]; + int4 lenstack = 0; + uint16 flag; - while ((type = gettoken_query(state, &val, &lenval, &strval,&flag)) != END) { + while ((type = gettoken_query(state, &val, &lenval, &strval, &flag)) != END) + { switch (type) { case VAL: - pushval_asis(state, VAL, strval, lenval,flag); + pushval_asis(state, VAL, strval, lenval, flag); while (lenstack && (stack[lenstack - 1] == (int4) '&' || stack[lenstack - 1] == (int4) '!')) { @@ -236,7 +244,8 @@ makepol(QPRS_STATE * state) } } - while (lenstack) { + while (lenstack) + { lenstack--; pushquery(state, OPR, stack[lenstack], 0, 0, 0); }; @@ -259,8 +268,8 @@ findoprnd(ITEM * ptr, int4 *pos) } else { - ITEM *curitem = &ptr[*pos]; - int4 tmp = *pos; + ITEM *curitem = &ptr[*pos]; + int4 tmp = *pos; (*pos)++; findoprnd(ptr, pos); @@ -276,16 +285,16 @@ findoprnd(ITEM * ptr, int4 *pos) static ltxtquery * queryin(char *buf) { - QPRS_STATE state; - int4 i; + QPRS_STATE state; + int4 i; ltxtquery *query; - int4 commonlen; - ITEM *ptr; - NODE *tmp; - int4 pos = 0; + int4 commonlen; + ITEM *ptr; + NODE *tmp; + int4 pos = 0; #ifdef BS_DEBUG - char pbuf[16384], + char pbuf[16384], *cur; #endif @@ -351,12 +360,12 @@ ltxtq_in(PG_FUNCTION_ARGS) */ typedef struct { - ITEM *curpol; - char *buf; - char *cur; - char *op; - int4 buflen; -} INFIX; + ITEM *curpol; + char *buf; + char *cur; + char *op; + int4 buflen; +} INFIX; #define RESIZEBUF(inf,addsize) \ while( ( inf->cur - inf->buf ) + addsize + 1 >= inf->buflen ) \ @@ -376,23 +385,27 @@ infix(INFIX * in, bool first) { if (in->curpol->type == VAL) { - char *op = in->op + in->curpol->distance; + char *op = in->op + in->curpol->distance; RESIZEBUF(in, in->curpol->length * 2 + 5); - while (*op) { + while (*op) + { *(in->cur) = *op; op++; in->cur++; } - if ( in->curpol->flag & LVAR_SUBLEXEM ) { + if (in->curpol->flag & LVAR_SUBLEXEM) + { *(in->cur) = '%'; in->cur++; } - if ( in->curpol->flag & LVAR_INCASE ) { + if (in->curpol->flag & LVAR_INCASE) + { *(in->cur) = '@'; in->cur++; } - if ( in->curpol->flag & LVAR_ANYEND ) { + if (in->curpol->flag & LVAR_ANYEND) + { *(in->cur) = '*'; in->cur++; } @@ -401,7 +414,7 @@ infix(INFIX * in, bool first) } else if (in->curpol->val == (int4) '!') { - bool isopr = false; + bool isopr = false; RESIZEBUF(in, 1); *(in->cur) = '!'; @@ -425,8 +438,8 @@ infix(INFIX * in, bool first) } else { - int4 op = in->curpol->val; - INFIX nrm; + int4 op = in->curpol->val; + INFIX nrm; in->curpol++; if (op == (int4) '|' && !first) @@ -467,7 +480,7 @@ Datum ltxtq_out(PG_FUNCTION_ARGS) { ltxtquery *query = PG_GETARG_LTXTQUERY(0); - INFIX nrm; + INFIX nrm; if (query->size == 0) elog(ERROR, "Empty"); @@ -481,4 +494,3 @@ ltxtq_out(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(query, 0); PG_RETURN_POINTER(nrm.buf); } - diff --git a/contrib/ltree/ltxtquery_op.c b/contrib/ltree/ltxtquery_op.c index 925385f7e3..263f39b5e4 100644 --- a/contrib/ltree/ltxtquery_op.c +++ b/contrib/ltree/ltxtquery_op.c @@ -1,5 +1,5 @@ /* - * txtquery operations with ltree + * txtquery operations with ltree * Teodor Sigaev <[email protected]> */ @@ -12,20 +12,26 @@ PG_FUNCTION_INFO_V1(ltxtq_rexec); /* * check for boolean condition */ -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)) +{ if (curitem->type == VAL) return (*chkcond) (checkval, curitem); - else if (curitem->val == (int4) '!') { + else if (curitem->val == (int4) '!') + { return (calcnot) ? ((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true) : true; - } else if (curitem->val == (int4) '&') { - if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond)) + } + else if (curitem->val == (int4) '&') + { + if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond)) return ltree_execute(curitem + 1, checkval, calcnot, chkcond); else return false; - } else { /* |-operator */ + } + else + { /* |-operator */ if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond)) return true; else @@ -34,54 +40,60 @@ ltree_execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (voi return false; } -typedef struct { - ltree *node; - char *operand; -} CHKVAL; +typedef struct +{ + ltree *node; + char *operand; +} CHKVAL; static bool -checkcondition_str(void* checkval, ITEM * val) { - ltree_level *level = LTREE_FIRST( ((CHKVAL*)checkval)->node ); - int tlen = ((CHKVAL*)checkval)->node->numlevel; - char *op = ((CHKVAL*)checkval)->operand + val->distance; - int (*cmpptr)(const char *,const char *,size_t); +checkcondition_str(void *checkval, ITEM * val) +{ + ltree_level *level = LTREE_FIRST(((CHKVAL *) checkval)->node); + int tlen = ((CHKVAL *) checkval)->node->numlevel; + char *op = ((CHKVAL *) checkval)->operand + val->distance; + int (*cmpptr) (const char *, const char *, size_t); - cmpptr = ( val->flag & LVAR_INCASE ) ? strncasecmp : strncmp; - while( tlen > 0 ) { - if ( val->flag & LVAR_SUBLEXEM ) { - if ( compare_subnode(level, op, val->length, cmpptr, (val->flag & LVAR_ANYEND) ) ) + cmpptr = (val->flag & LVAR_INCASE) ? strncasecmp : strncmp; + while (tlen > 0) + { + if (val->flag & LVAR_SUBLEXEM) + { + if (compare_subnode(level, op, val->length, cmpptr, (val->flag & LVAR_ANYEND))) return true; - } else if ( - ( - val->length == level->len || - ( level->len > val->length && (val->flag & LVAR_ANYEND) ) - ) && - (*cmpptr)( op, level->name, val->length) == 0 ) + } + else if ( + ( + val->length == level->len || + (level->len > val->length && (val->flag & LVAR_ANYEND)) + ) && + (*cmpptr) (op, level->name, val->length) == 0) return true; tlen--; - level = LEVEL_NEXT(level); + level = LEVEL_NEXT(level); } return false; } Datum -ltxtq_exec(PG_FUNCTION_ARGS) { - ltree *val = PG_GETARG_LTREE(0); +ltxtq_exec(PG_FUNCTION_ARGS) +{ + ltree *val = PG_GETARG_LTREE(0); ltxtquery *query = PG_GETARG_LTXTQUERY(1); - CHKVAL chkval; - bool result; + CHKVAL chkval; + bool result; chkval.node = val; chkval.operand = GETOPERAND(query); result = ltree_execute( - GETQUERY(query), - &chkval, - true, - checkcondition_str - ); + GETQUERY(query), + &chkval, + true, + checkcondition_str + ); PG_FREE_IF_COPY(val, 0); PG_FREE_IF_COPY(query, 1); @@ -89,11 +101,10 @@ ltxtq_exec(PG_FUNCTION_ARGS) { } Datum -ltxtq_rexec(PG_FUNCTION_ARGS) { - PG_RETURN_DATUM( DirectFunctionCall2( ltxtq_exec, - PG_GETARG_DATUM(1), - PG_GETARG_DATUM(0) - ) ); +ltxtq_rexec(PG_FUNCTION_ARGS) +{ + PG_RETURN_DATUM(DirectFunctionCall2(ltxtq_exec, + PG_GETARG_DATUM(1), + PG_GETARG_DATUM(0) + )); } - - diff --git a/contrib/mSQL-interface/mpgsql.c b/contrib/mSQL-interface/mpgsql.c index 27639ad1d4..3957c11dd2 100644 --- a/contrib/mSQL-interface/mpgsql.c +++ b/contrib/mSQL-interface/mpgsql.c @@ -263,7 +263,7 @@ msqlListTables(int a) char tbuf[BUFSIZ]; snprintf(tbuf, BUFSIZ, - "select relname from pg_class where relkind='r' and relowner=%d", + "select relname from pg_class where relkind='r' and relowner=%d", getuid()); if (msqlQuery(a, tbuf) > 0) { @@ -287,7 +287,7 @@ msqlListIndex(int a, char *b, char *c) char tbuf[BUFSIZ]; snprintf(tbuf, BUFSIZ, - "select relname from pg_class where relkind='i' and relowner=%d", + "select relname from pg_class where relkind='i' and relowner=%d", getuid()); if (msqlQuery(a, tbuf) > 0) { diff --git a/contrib/pg_dumplo/lo_export.c b/contrib/pg_dumplo/lo_export.c index 3e38b56409..702a8a2789 100644 --- a/contrib/pg_dumplo/lo_export.c +++ b/contrib/pg_dumplo/lo_export.c @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.9 2002/08/15 02:58:29 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.10 2002/09/04 20:31:06 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- @@ -142,7 +142,7 @@ pglo_export(LODumpMaster * pgLO) { snprintf(path, BUFSIZ, "%s/%s/%s", pgLO->space, pgLO->db, - ll->lo_table); + ll->lo_table); if (mkdir(path, DIR_UMASK) == -1) { @@ -154,7 +154,7 @@ pglo_export(LODumpMaster * pgLO) } snprintf(path, BUFSIZ, "%s/%s/%s/%s", pgLO->space, pgLO->db, - ll->lo_table, ll->lo_attr); + ll->lo_table, ll->lo_attr); if (mkdir(path, DIR_UMASK) == -1) { @@ -187,7 +187,7 @@ pglo_export(LODumpMaster * pgLO) } snprintf(path, BUFSIZ, "%s/%s/%s/%s/%s", pgLO->space, - pgLO->db, ll->lo_table, ll->lo_attr, val); + pgLO->db, ll->lo_table, ll->lo_attr, val); if (lo_export(pgLO->conn, lo, path) < 0) fprintf(stderr, "%s: lo_export failed:\n%s", progname, diff --git a/contrib/pg_dumplo/lo_import.c b/contrib/pg_dumplo/lo_import.c index b880e18b24..953dc10eb5 100644 --- a/contrib/pg_dumplo/lo_import.c +++ b/contrib/pg_dumplo/lo_import.c @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.7 2002/08/15 02:58:29 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.8 2002/09/04 20:31:06 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- @@ -82,7 +82,7 @@ pglo_import(LODumpMaster * pgLO) * UPDATE oid in tab */ snprintf(Qbuff, QUERY_BUFSIZ, - "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u", + "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u", loa.lo_table, loa.lo_attr, new_oid, loa.lo_attr, loa.lo_oid); /* fprintf(stderr, Qbuff); */ diff --git a/contrib/pg_dumplo/main.c b/contrib/pg_dumplo/main.c index 78456e1234..41c191a679 100644 --- a/contrib/pg_dumplo/main.c +++ b/contrib/pg_dumplo/main.c @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------- * pg_dumplo * - * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.10 2001/11/12 17:44:14 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.11 2002/09/04 20:31:07 momjian Exp $ * * Karel Zak 1999-2000 * ------------------------------------------------------------------------- @@ -284,7 +284,7 @@ usage() "-p --password=<password> password for connection to server\n" "-d --db=<database> database name\n" "-t --host=<hostname> server hostname\n" - "-o --port=<port> database server port (default: 5432)\n" + "-o --port=<port> database server port (default: 5432)\n" "-s --space=<dir> directory with dump tree (for export/import)\n" "-i --import import large obj dump tree to DB\n" "-e --export export (dump) large obj to dump tree\n" @@ -301,7 +301,7 @@ usage() "-p <password> password for connection to server\n" "-d <database> database name\n" "-t <hostname> server hostname\n" - "-o <port> database server port (default: 5432)\n" + "-o <port> database server port (default: 5432)\n" "-s <dir> directory with dump tree (for export/import)\n" "-i import large obj dump tree to DB\n" "-e export (dump) large obj to dump tree\n" diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c index 6e1813704c..4eb81ec544 100644 --- a/contrib/pgbench/pgbench.c +++ b/contrib/pgbench/pgbench.c @@ -1,10 +1,10 @@ /* - * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.18 2002/08/15 02:58:29 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.19 2002/09/04 20:31:08 momjian Exp $ * * pgbench: a simple TPC-B like benchmark program for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2000-2002 Tatsuo Ishii + * Copyright (c) 2000-2002 Tatsuo Ishii * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -88,8 +88,8 @@ typedef struct int state; /* state No. */ int cnt; /* xacts count */ int ecnt; /* error count */ - int listen; /* 0 indicates that an async query - * has been sent */ + int listen; /* 0 indicates that an async query has + * been sent */ int aid; /* account id for this transaction */ int bid; /* branch id for this transaction */ int tid; /* teller id for this transaction */ @@ -241,15 +241,19 @@ doOne(CState * state, int n, int debug, int ttype) discard_response(st); break; case 6: /* response to "end" */ - /* transaction finished: record the time it took in the log */ + + /* + * transaction finished: record the time it took in the + * log + */ if (use_log) { - long long diff; + long long diff; struct timeval now; gettimeofday(&now, 0); diff = (now.tv_sec - st->txn_begin.tv_sec) * 1000000 + - (now.tv_usec - st->txn_begin.tv_usec); + (now.tv_usec - st->txn_begin.tv_usec); fprintf(LOGFILE, "%d %d %lld\n", st->id, st->cnt, diff); } @@ -318,19 +322,19 @@ doOne(CState * state, int n, int debug, int ttype) case 3: if (ttype == 0) { - snprintf(sql, 256, "update tellers set tbalance = tbalance + %d where tid = %d\n", - st->delta, st->tid); - break; + snprintf(sql, 256, "update tellers set tbalance = tbalance + %d where tid = %d\n", + st->delta, st->tid); + break; } case 4: if (ttype == 0) { - snprintf(sql, 256, "update branches set bbalance = bbalance + %d where bid = %d", st->delta, st->bid); - break; + snprintf(sql, 256, "update branches set bbalance = bbalance + %d where bid = %d", st->delta, st->bid); + break; } case 5: snprintf(sql, 256, "insert into history(tid,bid,aid,delta,mtime) values(%d,%d,%d,%d,'now')", - st->tid, st->bid, st->aid, st->delta); + st->tid, st->bid, st->aid, st->delta); break; case 6: strcpy(sql, "end"); @@ -513,7 +517,7 @@ init(void) for (i = 0; i < ntellers * tps; i++) { snprintf(sql, 256, "insert into tellers(tid,bid,tbalance) values (%d,%d,0)" - ,i + 1, i / ntellers + 1); + ,i + 1, i / ntellers + 1); res = PQexec(con, sql); if (PQresultStatus(res) != PGRES_COMMAND_OK) { @@ -577,6 +581,7 @@ init(void) } #ifdef NOT_USED + /* * do a checkpoint to purge the old WAL logs */ @@ -586,7 +591,7 @@ init(void) fprintf(stderr, "%s", PQerrorMessage(con)); exit(1); } -#endif /* NOT_USED */ +#endif /* NOT_USED */ } } @@ -614,7 +619,7 @@ printResults( t2; int i; int normal_xacts = 0; - char *s; + char *s; for (i = 0; i < nclients; i++) normal_xacts += state[i].cnt; @@ -626,11 +631,11 @@ printResults( t2 = normal_xacts * 1000000.0 / t2; if (ttype == 0) - s = "TPC-B (sort of)"; + s = "TPC-B (sort of)"; else if (ttype == 2) - s = "Update only accounts"; + s = "Update only accounts"; else - s = "SELECT only"; + s = "SELECT only"; printf("transaction type: %s\n", s); printf("scaling factor: %d\n", tps); @@ -655,8 +660,9 @@ main(int argc, char **argv) * testing? */ int is_full_vacuum = 0; /* do full vacuum before testing? */ int debug = 0; /* debug flag */ - int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT only, - * 2: skip update of branches and tellers */ + int ttype = 0; /* transaction type. 0: TPC-B, 1: SELECT + * only, 2: skip update of branches and + * tellers */ static CState *state; /* status of clients */ @@ -789,7 +795,7 @@ main(int argc, char **argv) if (use_log) { - char logpath[64]; + char logpath[64]; snprintf(logpath, 64, "pgbench_log.%d", getpid()); LOGFILE = fopen(logpath, "w"); diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c index 4fbc60bcf2..51cab46a1e 100644 --- a/contrib/pgstattuple/pgstattuple.c +++ b/contrib/pgstattuple/pgstattuple.c @@ -1,7 +1,7 @@ /* - * $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.8 2002/08/29 17:14:31 tgl Exp $ + * $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.9 2002/09/04 20:31:08 momjian Exp $ * - * Copyright (c) 2001,2002 Tatsuo Ishii + * Copyright (c) 2001,2002 Tatsuo Ishii * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose, without fee, and without a @@ -71,12 +71,12 @@ pgstattuple(PG_FUNCTION_ARGS) double dead_tuple_percent; uint64 free_space = 0; /* free/reusable space in bytes */ double free_percent; /* free/reusable space in % */ - TupleDesc tupdesc; - TupleTableSlot *slot; - AttInMetadata *attinmeta; - char **values; - int i; - Datum result; + TupleDesc tupdesc; + TupleTableSlot *slot; + AttInMetadata *attinmeta; + char **values; + int i; + Datum result; /* * Build a tuple description for a pgstattupe_type tuple @@ -94,7 +94,7 @@ pgstattuple(PG_FUNCTION_ARGS) /* open relation */ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname, - "pgstattuple")); + "pgstattuple")); rel = heap_openrv(relrv, AccessShareLock); nblocks = RelationGetNumberOfBlocks(rel); @@ -116,7 +116,7 @@ pgstattuple(PG_FUNCTION_ARGS) /* * To avoid physically reading the table twice, try to do the - * free-space scan in parallel with the heap scan. However, + * free-space scan in parallel with the heap scan. However, * heap_getnext may find no tuples on a given page, so we cannot * simply examine the pages returned by the heap scan. */ @@ -142,7 +142,7 @@ pgstattuple(PG_FUNCTION_ARGS) heap_close(rel, AccessShareLock); - table_len = (uint64)nblocks *BLCKSZ; + table_len = (uint64) nblocks *BLCKSZ; if (nblocks == 0) { @@ -158,15 +158,13 @@ pgstattuple(PG_FUNCTION_ARGS) } /* - * Prepare a values array for storage in our slot. - * This should be an array of C strings which will - * be processed later by the appropriate "in" functions. + * Prepare a values array for storage in our slot. This should be an + * array of C strings which will be processed later by the appropriate + * "in" functions. */ values = (char **) palloc(NCOLUMNS * sizeof(char *)); - for (i=0;i<NCOLUMNS;i++) - { + for (i = 0; i < NCOLUMNS; i++) values[i] = (char *) palloc(NCHARS * sizeof(char)); - } i = 0; snprintf(values[i++], NCHARS, "%lld", table_len); snprintf(values[i++], NCHARS, "%lld", tuple_count); @@ -177,19 +175,17 @@ pgstattuple(PG_FUNCTION_ARGS) snprintf(values[i++], NCHARS, "%.2f", dead_tuple_percent); snprintf(values[i++], NCHARS, "%lld", free_space); snprintf(values[i++], NCHARS, "%.2f", free_percent); - + /* build a tuple */ tuple = BuildTupleFromCStrings(attinmeta, values); - + /* make the tuple into a datum */ result = TupleGetDatum(slot, tuple); - + /* Clean up */ - for (i=0;i<NCOLUMNS;i++) - { + for (i = 0; i < NCOLUMNS; i++) pfree(values[i]); - } pfree(values); - + PG_RETURN_DATUM(result); } diff --git a/contrib/rserv/rserv.c b/contrib/rserv/rserv.c index dc5f1268c9..be957a3454 100644 --- a/contrib/rserv/rserv.c +++ b/contrib/rserv/rserv.c @@ -128,8 +128,8 @@ _rserv_log_() okey = key; snprintf(sql, 8192, "update _RSERV_LOG_ set logid = %d, logtime = now(), " - "deleted = %d where reloid = %u and key = '%s'", - GetCurrentTransactionId(), deleted, rel->rd_id, okey); + "deleted = %d where reloid = %u and key = '%s'", + GetCurrentTransactionId(), deleted, rel->rd_id, okey); if (debug) elog(DEBUG3, sql); @@ -147,10 +147,10 @@ _rserv_log_() else if (SPI_processed == 0) { snprintf(sql, 8192, "insert into _RSERV_LOG_ " - "(reloid, logid, logtime, deleted, key) " - "values (%u, %d, now(), %d, '%s')", - rel->rd_id, GetCurrentTransactionId(), - deleted, okey); + "(reloid, logid, logtime, deleted, key) " + "values (%u, %d, now(), %d, '%s')", + rel->rd_id, GetCurrentTransactionId(), + deleted, okey); if (debug) elog(DEBUG3, sql); @@ -172,9 +172,9 @@ _rserv_log_() okey = newkey; snprintf(sql, 8192, "insert into _RSERV_LOG_ " - "(reloid, logid, logtime, deleted, key) " - "values (%u, %d, now(), 0, '%s')", - rel->rd_id, GetCurrentTransactionId(), okey); + "(reloid, logid, logtime, deleted, key) " + "values (%u, %d, now(), 0, '%s')", + rel->rd_id, GetCurrentTransactionId(), okey); if (debug) elog(DEBUG3, sql); @@ -221,17 +221,17 @@ _rserv_sync_(int32 server) for (xcnt = 0; xcnt < SerializableSnapshot->xcnt; xcnt++) { snprintf(buf + strlen(buf), 8192 - strlen(buf), - "%s%u", (xcnt) ? ", " : "", - SerializableSnapshot->xip[xcnt]); + "%s%u", (xcnt) ? ", " : "", + SerializableSnapshot->xip[xcnt]); } if ((ret = SPI_connect()) < 0) elog(ERROR, "_rserv_sync_: SPI_connect returned %d", ret); snprintf(sql, 8192, "insert into _RSERV_SYNC_ " - "(server, syncid, synctime, status, minid, maxid, active) " + "(server, syncid, synctime, status, minid, maxid, active) " "values (%u, currval('_rserv_sync_seq_'), now(), 0, %d, %d, '%s')", - server, SerializableSnapshot->xmin, SerializableSnapshot->xmax, active); + server, SerializableSnapshot->xmin, SerializableSnapshot->xmax, active); ret = SPI_exec(sql, 0); diff --git a/contrib/rtree_gist/rtree_gist.c b/contrib/rtree_gist/rtree_gist.c index 580ca6427f..5034b9d586 100644 --- a/contrib/rtree_gist/rtree_gist.c +++ b/contrib/rtree_gist/rtree_gist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/contrib/rtree_gist/Attic/rtree_gist.c,v 1.5 2002/05/28 15:24:53 tgl Exp $ + * $Header: /cvsroot/pgsql/contrib/rtree_gist/Attic/rtree_gist.c,v 1.6 2002/09/04 20:31:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -161,20 +161,23 @@ gbox_penalty(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } -typedef struct { - BOX *key; - int pos; -} KBsort; +typedef struct +{ + BOX *key; + int pos; +} KBsort; static int -compare_KB(const void* a, const void* b) { - BOX *abox = ((KBsort*)a)->key; - BOX *bbox = ((KBsort*)b)->key; - float sa = (abox->high.x - abox->low.x) * (abox->high.y - abox->low.y); - float sb = (bbox->high.x - bbox->low.x) * (bbox->high.y - bbox->low.y); - - if ( sa==sb ) return 0; - return ( sa>sb ) ? 1 : -1; +compare_KB(const void *a, const void *b) +{ + BOX *abox = ((KBsort *) a)->key; + BOX *bbox = ((KBsort *) b)->key; + float sa = (abox->high.x - abox->low.x) * (abox->high.y - abox->low.y); + float sb = (bbox->high.x - bbox->low.x) * (bbox->high.y - bbox->low.y); + + if (sa == sb) + return 0; + return (sa > sb) ? 1 : -1; } /* @@ -217,14 +220,14 @@ gbox_picksplit(PG_FUNCTION_ARGS) for (i = OffsetNumberNext(FirstOffsetNumber); i <= maxoff; i = OffsetNumberNext(i)) { cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key); - if ( allisequal == true && ( - pageunion.high.x != cur->high.x || - pageunion.high.y != cur->high.y || - pageunion.low.x != cur->low.x || - pageunion.low.y != cur->low.y - ) ) + if (allisequal == true && ( + pageunion.high.x != cur->high.x || + pageunion.high.y != cur->high.y || + pageunion.low.x != cur->low.x || + pageunion.low.y != cur->low.y + )) allisequal = false; - + if (pageunion.high.x < cur->high.x) pageunion.high.x = cur->high.x; if (pageunion.low.x > cur->low.x) @@ -293,45 +296,53 @@ gbox_picksplit(PG_FUNCTION_ARGS) { cur = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key); if (cur->low.x - pageunion.low.x < pageunion.high.x - cur->high.x) - ADDLIST(listL, unionL, posL,i); + ADDLIST(listL, unionL, posL, i); else - ADDLIST(listR, unionR, posR,i); + ADDLIST(listR, unionR, posR, i); if (cur->low.y - pageunion.low.y < pageunion.high.y - cur->high.y) - ADDLIST(listB, unionB, posB,i); + ADDLIST(listB, unionB, posB, i); else - ADDLIST(listT, unionT, posT,i); + ADDLIST(listT, unionT, posT, i); } /* bad disposition, sort by ascending and resplit */ - if ( (posR==0 || posL==0) && (posT==0 || posB==0) ) { - KBsort *arr = (KBsort*)palloc( sizeof(KBsort) * maxoff ); + if ((posR == 0 || posL == 0) && (posT == 0 || posB == 0)) + { + KBsort *arr = (KBsort *) palloc(sizeof(KBsort) * maxoff); + posL = posR = posB = posT = 0; - for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { - arr[i-1].key = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key); - arr[i-1].pos = i; + for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) + { + arr[i - 1].key = DatumGetBoxP(((GISTENTRY *) VARDATA(entryvec))[i].key); + arr[i - 1].pos = i; } - qsort( arr, maxoff, sizeof(KBsort), compare_KB ); - for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) { - cur = arr[i-1].key; + qsort(arr, maxoff, sizeof(KBsort), compare_KB); + for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) + { + cur = arr[i - 1].key; if (cur->low.x - pageunion.low.x < pageunion.high.x - cur->high.x) - ADDLIST(listL, unionL, posL,arr[i-1].pos); - else if ( cur->low.x - pageunion.low.x == pageunion.high.x - cur->high.x ) { - if ( posL>posR ) - ADDLIST(listR, unionR, posR,arr[i-1].pos); + ADDLIST(listL, unionL, posL, arr[i - 1].pos); + else if (cur->low.x - pageunion.low.x == pageunion.high.x - cur->high.x) + { + if (posL > posR) + ADDLIST(listR, unionR, posR, arr[i - 1].pos); else - ADDLIST(listL, unionL, posL,arr[i-1].pos); - } else - ADDLIST(listR, unionR, posR,arr[i-1].pos); + ADDLIST(listL, unionL, posL, arr[i - 1].pos); + } + else + ADDLIST(listR, unionR, posR, arr[i - 1].pos); if (cur->low.y - pageunion.low.y < pageunion.high.y - cur->high.y) - ADDLIST(listB, unionB, posB,arr[i-1].pos); - else if ( cur->low.y - pageunion.low.y == pageunion.high.y - cur->high.y ) { - if ( posB>posT ) - ADDLIST(listT, unionT, posT,arr[i-1].pos); + ADDLIST(listB, unionB, posB, arr[i - 1].pos); + else if (cur->low.y - pageunion.low.y == pageunion.high.y - cur->high.y) + { + if (posB > posT) + ADDLIST(listT, unionT, posT, arr[i - 1].pos); else - ADDLIST(listB, unionB, posB,arr[i-1].pos); - } else - ADDLIST(listT, unionT, posT,arr[i-1].pos); + ADDLIST(listB, unionB, posB, arr[i - 1].pos); + } + else + ADDLIST(listT, unionT, posT, arr[i - 1].pos); } pfree(arr); } diff --git a/contrib/spi/refint.c b/contrib/spi/refint.c index e1688c98a1..61c9e71fea 100644 --- a/contrib/spi/refint.c +++ b/contrib/spi/refint.c @@ -462,9 +462,9 @@ check_foreign_key(PG_FUNCTION_ARGS) * value */ snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), - " %s = %s%s%s %s ", - args2[k], (is_char_type > 0) ? "'" : "", - nv, (is_char_type > 0) ? "'" : "", (k < nkeys) ? ", " : ""); + " %s = %s%s%s %s ", + args2[k], (is_char_type > 0) ? "'" : "", + nv, (is_char_type > 0) ? "'" : "", (k < nkeys) ? ", " : ""); is_char_type = 0; } strcat(sql, " where "); @@ -488,8 +488,8 @@ check_foreign_key(PG_FUNCTION_ARGS) for (i = 1; i <= nkeys; i++) { snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), - "%s = null%s", - args2[i], (i < nkeys) ? ", " : ""); + "%s = null%s", + args2[i], (i < nkeys) ? ", " : ""); } strcat(sql, " where "); } @@ -498,7 +498,7 @@ check_foreign_key(PG_FUNCTION_ARGS) for (i = 1; i <= nkeys; i++) { snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), "%s = $%d %s", - args2[i], i, (i < nkeys) ? "and " : ""); + args2[i], i, (i < nkeys) ? "and " : ""); } /* Prepare plan for query */ diff --git a/contrib/spi/timetravel.c b/contrib/spi/timetravel.c index 771e9248b8..e992cbe475 100644 --- a/contrib/spi/timetravel.c +++ b/contrib/spi/timetravel.c @@ -270,7 +270,7 @@ timetravel(PG_FUNCTION_ARGS) for (i = 1; i <= natts; i++) { snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), "$%d%s", - i, (i < natts) ? ", " : ")"); + i, (i < natts) ? ", " : ")"); ctypes[i - 1] = SPI_gettypeid(tupdesc, i); } diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c index a87627a3e0..f620e61d5d 100644 --- a/contrib/tablefunc/tablefunc.c +++ b/contrib/tablefunc/tablefunc.c @@ -11,13 +11,13 @@ * documentation for any purpose, without fee, and without a written agreement * is hereby granted, provided that the above copyright notice and this * paragraph and the following two paragraphs appear in all copies. - * + * * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * + * * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS @@ -45,42 +45,42 @@ static bool compatCrosstabTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2); static bool compatConnectbyTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2); static void get_normal_pair(float8 *x1, float8 *x2); static TupleDesc make_crosstab_tupledesc(TupleDesc spi_tupdesc, - int num_catagories); + int num_catagories); static Tuplestorestate *connectby(char *relname, - char *key_fld, - char *parent_key_fld, - char *branch_delim, - char *start_with, - int max_depth, - bool show_branch, - MemoryContext per_query_ctx, - AttInMetadata *attinmeta); + char *key_fld, + char *parent_key_fld, + char *branch_delim, + char *start_with, + int max_depth, + bool show_branch, + MemoryContext per_query_ctx, + AttInMetadata *attinmeta); static Tuplestorestate *build_tuplestore_recursively(char *key_fld, - char *parent_key_fld, - char *relname, - char *branch_delim, - char *start_with, - char *branch, - int level, - int max_depth, - bool show_branch, - MemoryContext per_query_ctx, - AttInMetadata *attinmeta, - Tuplestorestate *tupstore); + char *parent_key_fld, + char *relname, + char *branch_delim, + char *start_with, + char *branch, + int level, + int max_depth, + bool show_branch, + MemoryContext per_query_ctx, + AttInMetadata *attinmeta, + Tuplestorestate *tupstore); static char *quote_ident_cstr(char *rawstr); typedef struct { - float8 mean; /* mean of the distribution */ - float8 stddev; /* stddev of the distribution */ - float8 carry_val; /* hold second generated value */ - bool use_carry; /* use second generated value */ + float8 mean; /* mean of the distribution */ + float8 stddev; /* stddev of the distribution */ + float8 carry_val; /* hold second generated value */ + bool use_carry; /* use second generated value */ } normal_rand_fctx; typedef struct { - SPITupleTable *spi_tuptable; /* sql results from user query */ - char *lastrowid; /* rowid of the last tuple sent */ + SPITupleTable *spi_tuptable; /* sql results from user query */ + char *lastrowid; /* rowid of the last tuple sent */ } crosstab_fctx; #define GET_TEXT(cstrp) DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstrp))) @@ -108,23 +108,26 @@ PG_FUNCTION_INFO_V1(normal_rand); Datum normal_rand(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - int call_cntr; - int max_calls; - normal_rand_fctx *fctx; - float8 mean; - float8 stddev; - float8 carry_val; - bool use_carry; - MemoryContext oldcontext; + FuncCallContext *funcctx; + int call_cntr; + int max_calls; + normal_rand_fctx *fctx; + float8 mean; + float8 stddev; + float8 carry_val; + bool use_carry; + MemoryContext oldcontext; /* stuff done only on the first call of the function */ - if(SRF_IS_FIRSTCALL()) - { + if (SRF_IS_FIRSTCALL()) + { /* create a function context for cross-call persistence */ - funcctx = SRF_FIRSTCALL_INIT(); + funcctx = SRF_FIRSTCALL_INIT(); - /* switch to memory context appropriate for multiple function calls */ + /* + * switch to memory context appropriate for multiple function + * calls + */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); /* total number of tuples to be returned */ @@ -134,11 +137,10 @@ normal_rand(PG_FUNCTION_ARGS) fctx = (normal_rand_fctx *) palloc(sizeof(normal_rand_fctx)); /* - * Use fctx to keep track of upper and lower bounds - * from call to call. It will also be used to carry over - * the spare value we get from the Box-Muller algorithm - * so that we only actually calculate a new value every - * other call. + * Use fctx to keep track of upper and lower bounds from call to + * call. It will also be used to carry over the spare value we get + * from the Box-Muller algorithm so that we only actually + * calculate a new value every other call. */ fctx->mean = PG_GETARG_FLOAT8(1); fctx->stddev = PG_GETARG_FLOAT8(2); @@ -154,10 +156,10 @@ normal_rand(PG_FUNCTION_ARGS) srandom(PG_GETARG_UINT32(3)); MemoryContextSwitchTo(oldcontext); - } + } /* stuff done on every call of the function */ - funcctx = SRF_PERCALL_SETUP(); + funcctx = SRF_PERCALL_SETUP(); call_cntr = funcctx->call_cntr; max_calls = funcctx->max_calls; @@ -166,12 +168,12 @@ normal_rand(PG_FUNCTION_ARGS) stddev = fctx->stddev; carry_val = fctx->carry_val; use_carry = fctx->use_carry; - - if (call_cntr < max_calls) /* do when there is more left to send */ - { + + if (call_cntr < max_calls) /* do when there is more left to send */ + { float8 result; - if(use_carry) + if (use_carry) { /* * reset use_carry and use second value obtained on last pass @@ -196,12 +198,11 @@ normal_rand(PG_FUNCTION_ARGS) } /* send the result */ - SRF_RETURN_NEXT(funcctx, Float8GetDatum(result)); - } - else /* do when there is no more left */ - { - SRF_RETURN_DONE(funcctx); - } + SRF_RETURN_NEXT(funcctx, Float8GetDatum(result)); + } + else +/* do when there is no more left */ + SRF_RETURN_DONE(funcctx); } /* @@ -218,9 +219,13 @@ normal_rand(PG_FUNCTION_ARGS) static void get_normal_pair(float8 *x1, float8 *x2) { - float8 u1, u2, v1, v2, s; + float8 u1, + u2, + v1, + v2, + s; - for(;;) + for (;;) { u1 = (float8) random() / (float8) RAND_MAX; u2 = (float8) random() / (float8) RAND_MAX; @@ -257,65 +262,68 @@ get_normal_pair(float8 *x1, float8 *x2) * * rowid cat value * ------+-------+------- - * row1 cat1 val1 - * row1 cat2 val2 - * row1 cat3 val3 - * row1 cat4 val4 - * row2 cat1 val5 - * row2 cat2 val6 - * row2 cat3 val7 - * row2 cat4 val8 + * row1 cat1 val1 + * row1 cat2 val2 + * row1 cat3 val3 + * row1 cat4 val4 + * row2 cat1 val5 + * row2 cat2 val6 + * row2 cat3 val7 + * row2 cat4 val8 * * crosstab returns: * <===== values columns =====> * rowid cat1 cat2 cat3 cat4 * ------+-------+-------+-------+------- - * row1 val1 val2 val3 val4 - * row2 val5 val6 val7 val8 + * row1 val1 val2 val3 val4 + * row2 val5 val6 val7 val8 * * NOTES: * 1. SQL result must be ordered by 1,2. * 2. The number of values columns depends on the tuple description - * of the function's declared return type. + * of the function's declared return type. * 2. Missing values (i.e. not enough adjacent rows of same rowid to - * fill the number of result values columns) are filled in with nulls. + * fill the number of result values columns) are filled in with nulls. * 3. Extra values (i.e. too many adjacent rows of same rowid to fill - * the number of result values columns) are skipped. + * the number of result values columns) are skipped. * 4. Rows with all nulls in the values columns are skipped. */ PG_FUNCTION_INFO_V1(crosstab); Datum crosstab(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TupleDesc ret_tupdesc; - int call_cntr; - int max_calls; - TupleTableSlot *slot; - AttInMetadata *attinmeta; - SPITupleTable *spi_tuptable = NULL; - TupleDesc spi_tupdesc; - char *lastrowid = NULL; - crosstab_fctx *fctx; - int i; - int num_categories; - MemoryContext oldcontext; + FuncCallContext *funcctx; + TupleDesc ret_tupdesc; + int call_cntr; + int max_calls; + TupleTableSlot *slot; + AttInMetadata *attinmeta; + SPITupleTable *spi_tuptable = NULL; + TupleDesc spi_tupdesc; + char *lastrowid = NULL; + crosstab_fctx *fctx; + int i; + int num_categories; + MemoryContext oldcontext; /* stuff done only on the first call of the function */ - if(SRF_IS_FIRSTCALL()) - { - char *sql = GET_STR(PG_GETARG_TEXT_P(0)); - Oid funcid = fcinfo->flinfo->fn_oid; - Oid functypeid; - char functyptype; - TupleDesc tupdesc = NULL; - int ret; - int proc; + if (SRF_IS_FIRSTCALL()) + { + char *sql = GET_STR(PG_GETARG_TEXT_P(0)); + Oid funcid = fcinfo->flinfo->fn_oid; + Oid functypeid; + char functyptype; + TupleDesc tupdesc = NULL; + int ret; + int proc; /* create a function context for cross-call persistence */ - funcctx = SRF_FIRSTCALL_INIT(); + funcctx = SRF_FIRSTCALL_INIT(); - /* switch to memory context appropriate for multiple function calls */ + /* + * switch to memory context appropriate for multiple function + * calls + */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); /* Connect to SPI manager */ @@ -336,20 +344,19 @@ crosstab(PG_FUNCTION_ARGS) * The provided SQL query must always return three columns. * * 1. rowname the label or identifier for each row in the final - * result - * 2. category the label or identifier for each column in the - * final result - * 3. values the value for each column in the final result + * result 2. category the label or identifier for each column + * in the final result 3. values the value for each column + * in the final result */ if (spi_tupdesc->natts != 3) elog(ERROR, "crosstab: provided SQL must return 3 columns;" - " a rowid, a category, and a values column"); + " a rowid, a category, and a values column"); } else { /* no qualifying tuples */ SPI_finish(); - SRF_RETURN_DONE(funcctx); + SRF_RETURN_DONE(funcctx); } /* SPI switches context on us, so reset it */ @@ -360,7 +367,7 @@ crosstab(PG_FUNCTION_ARGS) /* check typtype to see if we have a predetermined return type */ functyptype = get_typtype(functypeid); - + if (functyptype == 'c') { /* Build a tuple description for a functypeid tuple */ @@ -372,7 +379,7 @@ crosstab(PG_FUNCTION_ARGS) elog(ERROR, "Wrong number of arguments specified for function"); else { - int num_catagories = PG_GETARG_INT32(1); + int num_catagories = PG_GETARG_INT32(1); tupdesc = make_crosstab_tupledesc(spi_tupdesc, num_catagories); } @@ -389,7 +396,7 @@ crosstab(PG_FUNCTION_ARGS) */ if (!compatCrosstabTupleDescs(tupdesc, spi_tupdesc)) elog(ERROR, "crosstab: return and sql tuple descriptions are" - " incompatible"); + " incompatible"); /* allocate a slot for a tuple with this tupdesc */ slot = TupleDescGetSlot(tupdesc); @@ -398,8 +405,8 @@ crosstab(PG_FUNCTION_ARGS) funcctx->slot = slot; /* - * Generate attribute metadata needed later to produce tuples from raw - * C strings + * Generate attribute metadata needed later to produce tuples from + * raw C strings */ attinmeta = TupleDescGetAttInMetadata(tupdesc); funcctx->attinmeta = attinmeta; @@ -418,10 +425,10 @@ crosstab(PG_FUNCTION_ARGS) funcctx->max_calls = proc; MemoryContextSwitchTo(oldcontext); - } + } /* stuff done on every call of the function */ - funcctx = SRF_PERCALL_SETUP(); + funcctx = SRF_PERCALL_SETUP(); /* * initialize per-call variables @@ -446,9 +453,9 @@ crosstab(PG_FUNCTION_ARGS) /* the return tuple always must have 1 rowid + num_categories columns */ num_categories = ret_tupdesc->natts - 1; - + if (call_cntr < max_calls) /* do when there is more left to send */ - { + { HeapTuple tuple; Datum result; char **values; @@ -463,8 +470,8 @@ crosstab(PG_FUNCTION_ARGS) memset(values, '\0', (1 + num_categories) * sizeof(char *)); /* - * now loop through the sql results and assign each value - * in sequence to the next category + * now loop through the sql results and assign each value in + * sequence to the next category */ for (i = 0; i < num_categories; i++) { @@ -481,11 +488,12 @@ crosstab(PG_FUNCTION_ARGS) /* get the rowid from the current sql result tuple */ rowid = SPI_getvalue(spi_tuple, spi_tupdesc, 1); - /* - * If this is the first pass through the values for this rowid - * set it, otherwise make sure it hasn't changed on us. Also - * check to see if the rowid is the same as that of the last - * tuple sent -- if so, skip this tuple entirely + /* + * If this is the first pass through the values for this + * rowid set it, otherwise make sure it hasn't changed on + * us. Also check to see if the rowid is the same as that + * of the last tuple sent -- if so, skip this tuple + * entirely */ if (i == 0) values[0] = pstrdup(rowid); @@ -498,18 +506,19 @@ crosstab(PG_FUNCTION_ARGS) allnulls = false; /* - * Get the next category item value, which is alway attribute - * number three. + * Get the next category item value, which is alway + * attribute number three. * - * Be careful to sssign the value to the array index based - * on which category we are presently processing. + * Be careful to sssign the value to the array index + * based on which category we are presently + * processing. */ values[1 + i] = SPI_getvalue(spi_tuple, spi_tupdesc, 3); /* - * increment the counter since we consume a row - * for each category, but not for last pass - * because the API will do that for us + * increment the counter since we consume a row for + * each category, but not for last pass because the + * API will do that for us */ if (i < (num_categories - 1)) call_cntr = ++funcctx->call_cntr; @@ -517,10 +526,9 @@ crosstab(PG_FUNCTION_ARGS) else { /* - * We'll fill in NULLs for the missing values, - * but we need to decrement the counter since - * this sql result row doesn't belong to the current - * output tuple. + * We'll fill in NULLs for the missing values, but we + * need to decrement the counter since this sql result + * row doesn't belong to the current output tuple. */ call_cntr = --funcctx->call_cntr; break; @@ -534,7 +542,10 @@ crosstab(PG_FUNCTION_ARGS) if (values[0] != NULL) { - /* switch to memory context appropriate for multiple function calls */ + /* + * switch to memory context appropriate for multiple + * function calls + */ oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); lastrowid = fctx->lastrowid = pstrdup(values[0]); @@ -555,14 +566,13 @@ crosstab(PG_FUNCTION_ARGS) xpfree(values[i]); xpfree(values); - SRF_RETURN_NEXT(funcctx, result); + SRF_RETURN_NEXT(funcctx, result); } else { /* * Skipping this tuple entirely, but we need to advance - * the counter like the API would if we had returned - * one. + * the counter like the API would if we had returned one. */ call_cntr = ++funcctx->call_cntr; @@ -574,17 +584,18 @@ crosstab(PG_FUNCTION_ARGS) { /* release SPI related resources */ SPI_finish(); - SRF_RETURN_DONE(funcctx); + SRF_RETURN_DONE(funcctx); } } } } - else /* do when there is no more left */ - { + else +/* do when there is no more left */ + { /* release SPI related resources */ SPI_finish(); - SRF_RETURN_DONE(funcctx); - } + SRF_RETURN_DONE(funcctx); + } } /* @@ -595,29 +606,29 @@ crosstab(PG_FUNCTION_ARGS) * * keyid parent_keyid * ------+-------------- - * row1 NULL - * row2 row1 - * row3 row1 - * row4 row2 - * row5 row2 - * row6 row4 - * row7 row3 - * row8 row6 - * row9 row5 + * row1 NULL + * row2 row1 + * row3 row1 + * row4 row2 + * row5 row2 + * row6 row4 + * row7 row3 + * row8 row6 + * row9 row5 * * * connectby(text relname, text keyid_fld, text parent_keyid_fld, - * text start_with, int max_depth [, text branch_delim]) + * text start_with, int max_depth [, text branch_delim]) * connectby('foo', 'keyid', 'parent_keyid', 'row2', 0, '~') returns: * * keyid parent_id level branch * ------+-----------+--------+----------------------- - * row2 NULL 0 row2 - * row4 row2 1 row2~row4 - * row6 row4 2 row2~row4~row6 - * row8 row6 3 row2~row4~row6~row8 - * row5 row2 1 row2~row5 - * row9 row5 2 row2~row5~row9 + * row2 NULL 0 row2 + * row4 row2 1 row2~row4 + * row6 row4 2 row2~row4~row6 + * row8 row6 3 row2~row4~row6~row8 + * row5 row2 1 row2~row5 + * row9 row5 2 row2~row5~row9 * */ PG_FUNCTION_INFO_V1(connectby_text); @@ -628,18 +639,18 @@ PG_FUNCTION_INFO_V1(connectby_text); Datum connectby_text(PG_FUNCTION_ARGS) { - char *relname = GET_STR(PG_GETARG_TEXT_P(0)); - char *key_fld = GET_STR(PG_GETARG_TEXT_P(1)); - char *parent_key_fld = GET_STR(PG_GETARG_TEXT_P(2)); - char *start_with = GET_STR(PG_GETARG_TEXT_P(3)); - int max_depth = PG_GETARG_INT32(4); - char *branch_delim = NULL; - bool show_branch = false; - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - TupleDesc tupdesc; - AttInMetadata *attinmeta; - MemoryContext per_query_ctx; - MemoryContext oldcontext; + char *relname = GET_STR(PG_GETARG_TEXT_P(0)); + char *key_fld = GET_STR(PG_GETARG_TEXT_P(1)); + char *parent_key_fld = GET_STR(PG_GETARG_TEXT_P(2)); + char *start_with = GET_STR(PG_GETARG_TEXT_P(3)); + int max_depth = PG_GETARG_INT32(4); + char *branch_delim = NULL; + bool show_branch = false; + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + TupleDesc tupdesc; + AttInMetadata *attinmeta; + MemoryContext per_query_ctx; + MemoryContext oldcontext; if (fcinfo->nargs == 6) { @@ -662,7 +673,7 @@ connectby_text(PG_FUNCTION_ARGS) /* check to see if caller supports us returning a tuplestore */ if (!rsinfo->allowedModes & SFRM_Materialize) elog(ERROR, "connectby requires Materialize mode, but it is not " - "allowed in this context"); + "allowed in this context"); /* OK, go to work */ rsinfo->returnMode = SFRM_Materialize; @@ -680,8 +691,8 @@ connectby_text(PG_FUNCTION_ARGS) MemoryContextSwitchTo(oldcontext); /* - * SFRM_Materialize mode expects us to return a NULL Datum. - * The actual tuples are in our tuplestore and passed back through + * SFRM_Materialize mode expects us to return a NULL Datum. The actual + * tuples are in our tuplestore and passed back through * rsinfo->setResult. rsinfo->setDesc is set to the tuple description * that we actually used to build our tuples with, so the caller can * verify we did what it was expecting. @@ -703,9 +714,9 @@ connectby(char *relname, MemoryContext per_query_ctx, AttInMetadata *attinmeta) { - Tuplestorestate *tupstore = NULL; - int ret; - MemoryContext oldcontext; + Tuplestorestate *tupstore = NULL; + int ret; + MemoryContext oldcontext; /* Connect to SPI manager */ if ((ret = SPI_connect()) < 0) @@ -721,17 +732,17 @@ connectby(char *relname, /* now go get the whole tree */ tupstore = build_tuplestore_recursively(key_fld, - parent_key_fld, - relname, - branch_delim, - start_with, - start_with, /* current_branch */ - 0, /* initial level is 0 */ - max_depth, - show_branch, - per_query_ctx, - attinmeta, - tupstore); + parent_key_fld, + relname, + branch_delim, + start_with, + start_with, /* current_branch */ + 0, /* initial level is 0 */ + max_depth, + show_branch, + per_query_ctx, + attinmeta, + tupstore); SPI_finish(); @@ -756,23 +767,23 @@ build_tuplestore_recursively(char *key_fld, AttInMetadata *attinmeta, Tuplestorestate *tupstore) { - TupleDesc tupdesc = attinmeta->tupdesc; - MemoryContext oldcontext; - StringInfo sql = makeStringInfo(); - int ret; - int proc; + TupleDesc tupdesc = attinmeta->tupdesc; + MemoryContext oldcontext; + StringInfo sql = makeStringInfo(); + int ret; + int proc; - if(max_depth > 0 && level > max_depth) + if (max_depth > 0 && level > max_depth) return tupstore; /* Build initial sql statement */ appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = '%s' AND %s IS NOT NULL", - quote_ident_cstr(key_fld), - quote_ident_cstr(parent_key_fld), - quote_ident_cstr(relname), - quote_ident_cstr(parent_key_fld), - start_with, - quote_ident_cstr(key_fld)); + quote_ident_cstr(key_fld), + quote_ident_cstr(parent_key_fld), + quote_ident_cstr(relname), + quote_ident_cstr(parent_key_fld), + start_with, + quote_ident_cstr(key_fld)); /* Retrieve the desired rows */ ret = SPI_exec(sql->data, 0); @@ -781,16 +792,16 @@ build_tuplestore_recursively(char *key_fld, /* Check for qualifying tuples */ if ((ret == SPI_OK_SELECT) && (proc > 0)) { - HeapTuple tuple; - HeapTuple spi_tuple; - SPITupleTable *tuptable = SPI_tuptable; - TupleDesc spi_tupdesc = tuptable->tupdesc; - int i; - char *current_key; - char *current_key_parent; - char current_level[INT32_STRLEN]; - char *current_branch; - char **values; + HeapTuple tuple; + HeapTuple spi_tuple; + SPITupleTable *tuptable = SPI_tuptable; + TupleDesc spi_tupdesc = tuptable->tupdesc; + int i; + char *current_key; + char *current_key_parent; + char current_level[INT32_STRLEN]; + char *current_branch; + char **values; if (show_branch) values = (char **) palloc(CONNECTBY_NCOLS * sizeof(char *)); @@ -802,13 +813,13 @@ build_tuplestore_recursively(char *key_fld, { /* * Check that return tupdesc is compatible with the one we got - * from the query, but only at level 0 -- no need to check more - * than once + * from the query, but only at level 0 -- no need to check + * more than once */ if (!compatConnectbyTupleDescs(tupdesc, spi_tupdesc)) elog(ERROR, "connectby: return and sql tuple descriptions are " - "incompatible"); + "incompatible"); /* root value is the one we initially start with */ values[0] = start_with; @@ -842,7 +853,7 @@ build_tuplestore_recursively(char *key_fld, for (i = 0; i < proc; i++) { - StringInfo branchstr = NULL; + StringInfo branchstr = NULL; /* start a new branch */ if (show_branch) @@ -895,17 +906,17 @@ build_tuplestore_recursively(char *key_fld, /* recurse using current_key_parent as the new start_with */ tupstore = build_tuplestore_recursively(key_fld, - parent_key_fld, - relname, - branch_delim, - values[0], - current_branch, - level + 1, - max_depth, - show_branch, - per_query_ctx, - attinmeta, - tupstore); + parent_key_fld, + relname, + branch_delim, + values[0], + current_branch, + level + 1, + max_depth, + show_branch, + per_query_ctx, + attinmeta, + tupstore); } } @@ -923,29 +934,29 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch) { if (tupdesc->natts != CONNECTBY_NCOLS) elog(ERROR, "Query-specified return tuple not valid for Connectby: " - "wrong number of columns"); + "wrong number of columns"); } else { if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH) elog(ERROR, "Query-specified return tuple not valid for Connectby: " - "wrong number of columns"); + "wrong number of columns"); } /* check that the types of the first two columns match */ if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid) elog(ERROR, "Query-specified return tuple not valid for Connectby: " - "first two columns must be the same type"); + "first two columns must be the same type"); /* check that the type of the third column is INT4 */ if (tupdesc->attrs[2]->atttypid != INT4OID) elog(ERROR, "Query-specified return tuple not valid for Connectby: " - "third column must be type %s", format_type_be(INT4OID)); + "third column must be type %s", format_type_be(INT4OID)); /* check that the type of the forth column is TEXT if applicable */ if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID) elog(ERROR, "Query-specified return tuple not valid for Connectby: " - "third column must be type %s", format_type_be(TEXTOID)); + "third column must be type %s", format_type_be(TEXTOID)); /* OK, the tupdesc is valid for our purposes */ } @@ -956,22 +967,22 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch) static bool compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) { - Oid ret_atttypid; - Oid sql_atttypid; + Oid ret_atttypid; + Oid sql_atttypid; /* check the key_fld types match */ ret_atttypid = ret_tupdesc->attrs[0]->atttypid; sql_atttypid = sql_tupdesc->attrs[0]->atttypid; if (ret_atttypid != sql_atttypid) elog(ERROR, "compatConnectbyTupleDescs: SQL key field datatype does " - "not match return key field datatype"); + "not match return key field datatype"); /* check the parent_key_fld types match */ ret_atttypid = ret_tupdesc->attrs[1]->atttypid; sql_atttypid = sql_tupdesc->attrs[1]->atttypid; if (ret_atttypid != sql_atttypid) elog(ERROR, "compatConnectbyTupleDescs: SQL parent key field datatype " - "does not match return parent key field datatype"); + "does not match return parent key field datatype"); /* OK, the two tupdescs are compatible for our purposes */ return true; @@ -984,23 +995,22 @@ static bool compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) { int i; - Form_pg_attribute ret_attr; - Oid ret_atttypid; - Form_pg_attribute sql_attr; - Oid sql_atttypid; + Form_pg_attribute ret_attr; + Oid ret_atttypid; + Form_pg_attribute sql_attr; + Oid sql_atttypid; /* check the rowid types match */ ret_atttypid = ret_tupdesc->attrs[0]->atttypid; sql_atttypid = sql_tupdesc->attrs[0]->atttypid; if (ret_atttypid != sql_atttypid) elog(ERROR, "compatCrosstabTupleDescs: SQL rowid datatype does not match" - " return rowid datatype"); + " return rowid datatype"); /* - * - attribute [1] of the sql tuple is the category; - * no need to check it - * - attribute [2] of the sql tuple should match - * attributes [1] to [natts] of the return tuple + * - attribute [1] of the sql tuple is the category; no need to check + * it - attribute [2] of the sql tuple should match attributes [1] to + * [natts] of the return tuple */ sql_attr = sql_tupdesc->attrs[2]; for (i = 1; i < ret_tupdesc->natts; i++) @@ -1018,19 +1028,18 @@ compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc) static TupleDesc make_crosstab_tupledesc(TupleDesc spi_tupdesc, int num_catagories) { - Form_pg_attribute sql_attr; - Oid sql_atttypid; - TupleDesc tupdesc; - int natts; - AttrNumber attnum; - char attname[NAMEDATALEN]; - int i; + Form_pg_attribute sql_attr; + Oid sql_atttypid; + TupleDesc tupdesc; + int natts; + AttrNumber attnum; + char attname[NAMEDATALEN]; + int i; /* - * We need to build a tuple description with one column - * for the rowname, and num_catagories columns for the values. - * Each must be of the same type as the corresponding - * spi result input column. + * We need to build a tuple description with one column for the + * rowname, and num_catagories columns for the values. Each must be of + * the same type as the corresponding spi result input column. */ natts = num_catagories + 1; tupdesc = CreateTemplateTupleDesc(natts, false); @@ -1069,9 +1078,9 @@ make_crosstab_tupledesc(TupleDesc spi_tupdesc, int num_catagories) static char * quote_ident_cstr(char *rawstr) { - text *rawstr_text; - text *result_text; - char *result; + text *rawstr_text; + text *result_text; + char *result; rawstr_text = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(rawstr))); result_text = DatumGetTextP(DirectFunctionCall1(quote_ident, PointerGetDatum(rawstr_text))); diff --git a/contrib/tablefunc/tablefunc.h b/contrib/tablefunc/tablefunc.h index 3002d32f99..c8ea8ffcd5 100644 --- a/contrib/tablefunc/tablefunc.h +++ b/contrib/tablefunc/tablefunc.h @@ -11,13 +11,13 @@ * documentation for any purpose, without fee, and without a written agreement * is hereby granted, provided that the above copyright notice and this * paragraph and the following two paragraphs appear in all copies. - * + * * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * + * * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS diff --git a/contrib/tsearch/deflex.h b/contrib/tsearch/deflex.h index 17c4fdf1ec..9603f9810a 100644 --- a/contrib/tsearch/deflex.h +++ b/contrib/tsearch/deflex.h @@ -12,12 +12,12 @@ #define HOST 6 #define SCIENTIFIC 7 #define VERSIONNUMBER 8 -#define PARTHYPHENWORD 9 -#define CYRPARTHYPHENWORD 10 -#define LATPARTHYPHENWORD 11 -#define SPACE 12 -#define TAG 13 -#define HTTP 14 +#define PARTHYPHENWORD 9 +#define CYRPARTHYPHENWORD 10 +#define LATPARTHYPHENWORD 11 +#define SPACE 12 +#define TAG 13 +#define HTTP 14 #define HYPHENWORD 15 #define LATHYPHENWORD 16 #define CYRHYPHENWORD 17 @@ -25,10 +25,9 @@ #define FILEPATH 19 #define DECIMAL 20 #define SIGNEDINT 21 -#define UNSIGNEDINT 22 +#define UNSIGNEDINT 22 #define HTMLENTITY 23 extern const char *descr[]; #endif - diff --git a/contrib/tsearch/gistidx.c b/contrib/tsearch/gistidx.c index 61ab1bd8f0..1222c36a1e 100644 --- a/contrib/tsearch/gistidx.c +++ b/contrib/tsearch/gistidx.c @@ -17,28 +17,35 @@ #include "gistidx.h" #include "crc32.h" -PG_FUNCTION_INFO_V1( gtxtidx_in ); -Datum gtxtidx_in(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_out ); -Datum gtxtidx_out(PG_FUNCTION_ARGS); - -PG_FUNCTION_INFO_V1( gtxtidx_compress ); -Datum gtxtidx_compress(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_decompress ); -Datum gtxtidx_decompress(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_consistent ); -Datum gtxtidx_consistent(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_union ); -Datum gtxtidx_union(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_same ); -Datum gtxtidx_same(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_penalty ); -Datum gtxtidx_penalty(PG_FUNCTION_ARGS); -PG_FUNCTION_INFO_V1( gtxtidx_picksplit ); -Datum gtxtidx_picksplit(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(gtxtidx_in); +Datum gtxtidx_in(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_out); +Datum gtxtidx_out(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_compress); +Datum gtxtidx_compress(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_decompress); +Datum gtxtidx_decompress(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_consistent); +Datum gtxtidx_consistent(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_union); +Datum gtxtidx_union(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_same); +Datum gtxtidx_same(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_penalty); +Datum gtxtidx_penalty(PG_FUNCTION_ARGS); + +PG_FUNCTION_INFO_V1(gtxtidx_picksplit); +Datum gtxtidx_picksplit(PG_FUNCTION_ARGS); #define GETENTRY(vec,pos) ((GISTTYPE *) DatumGetPointer(((GISTENTRY *) VARDATA(vec))[(pos)].key)) -#define SUMBIT(val) ( \ +#define SUMBIT(val) ( \ GETBITBYTE(val,0) + \ GETBITBYTE(val,1) + \ GETBITBYTE(val,2) + \ @@ -46,38 +53,44 @@ Datum gtxtidx_picksplit(PG_FUNCTION_ARGS); GETBITBYTE(val,4) + \ GETBITBYTE(val,5) + \ GETBITBYTE(val,6) + \ - GETBITBYTE(val,7) \ -) + GETBITBYTE(val,7) \ +) Datum -gtxtidx_in(PG_FUNCTION_ARGS) { - elog(ERROR,"Not implemented"); +gtxtidx_in(PG_FUNCTION_ARGS) +{ + elog(ERROR, "Not implemented"); PG_RETURN_DATUM(0); } Datum -gtxtidx_out(PG_FUNCTION_ARGS) { - elog(ERROR,"Not implemented"); +gtxtidx_out(PG_FUNCTION_ARGS) +{ + elog(ERROR, "Not implemented"); PG_RETURN_DATUM(0); } static int -compareint( const void * a, const void * b ) { - if ( *((int4*)a) == *((int4*)b) ) return 0; - return ( *((int4*)a) > *((int4*)b) ) ? 1 : -1; +compareint(const void *a, const void *b) +{ + if (*((int4 *) a) == *((int4 *) b)) + return 0; + return (*((int4 *) a) > *((int4 *) b)) ? 1 : -1; } static int -uniqueint( int4* a, int4 l ) { - int4 *ptr, *res; +uniqueint(int4 *a, int4 l) +{ + int4 *ptr, + *res; - if ( l == 1 ) + if (l == 1) return l; ptr = res = a; - qsort((void*)a, l, sizeof(int4), compareint ); + qsort((void *) a, l, sizeof(int4), compareint); while (ptr - a < l) if (*ptr != *res) @@ -88,129 +101,149 @@ uniqueint( int4* a, int4 l ) { } static void -makesign( BITVECP sign, GISTTYPE *a) { - int4 k,len = ARRNELEM( a ); - int4 *ptr = GETARR( a ); - MemSet( (void*)sign, 0, sizeof(BITVEC) ); - for(k=0;k<len;k++) - HASH( sign, ptr[k] ); +makesign(BITVECP sign, GISTTYPE * a) +{ + int4 k, + len = ARRNELEM(a); + int4 *ptr = GETARR(a); + + MemSet((void *) sign, 0, sizeof(BITVEC)); + for (k = 0; k < len; k++) + HASH(sign, ptr[k]); } Datum -gtxtidx_compress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); +gtxtidx_compress(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); GISTENTRY *retval = entry; - if ( entry->leafkey ) { /* txtidx */ - GISTTYPE *res; - txtidx *toastedval = (txtidx*)DatumGetPointer( entry->key ); - txtidx *val = (txtidx*)DatumGetPointer( PG_DETOAST_DATUM(entry->key) ); - int4 len; - int4 *arr; - WordEntry *ptr = ARRPTR(val); - char *words = STRPTR(val); - - len = CALCGTSIZE( ARRKEY, val->size ); - res = (GISTTYPE*)palloc( len ); + if (entry->leafkey) + { /* txtidx */ + GISTTYPE *res; + txtidx *toastedval = (txtidx *) DatumGetPointer(entry->key); + txtidx *val = (txtidx *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); + int4 len; + int4 *arr; + WordEntry *ptr = ARRPTR(val); + char *words = STRPTR(val); + + len = CALCGTSIZE(ARRKEY, val->size); + res = (GISTTYPE *) palloc(len); res->len = len; res->flag = ARRKEY; arr = GETARR(res); len = val->size; - while( len-- ) { - *arr = crc32_sz( (uint8*)&words[ ptr->pos ], ptr->len ); - arr++; ptr++; + while (len--) + { + *arr = crc32_sz((uint8 *) &words[ptr->pos], ptr->len); + arr++; + ptr++; } - len = uniqueint( GETARR(res), val->size ); - if ( len != val->size ) { - /* there is a collision of hash-function; - len is always less than val->size */ - len = CALCGTSIZE( ARRKEY, len ); - res = (GISTTYPE*)repalloc( (void*)res, len ); + len = uniqueint(GETARR(res), val->size); + if (len != val->size) + { + /* + * there is a collision of hash-function; len is always less + * than val->size + */ + len = CALCGTSIZE(ARRKEY, len); + res = (GISTTYPE *) repalloc((void *) res, len); res->len = len; } - if ( val != toastedval ) + if (val != toastedval) pfree(val); /* make signature, if array is too long */ - if ( res->len > TOAST_INDEX_TARGET ) { - GISTTYPE *ressign; + if (res->len > TOAST_INDEX_TARGET) + { + GISTTYPE *ressign; - len = CALCGTSIZE( SIGNKEY, 0 ); - ressign = (GISTTYPE*)palloc( len ); + len = CALCGTSIZE(SIGNKEY, 0); + ressign = (GISTTYPE *) palloc(len); ressign->len = len; ressign->flag = SIGNKEY; - makesign( GETSIGN(ressign), res ); + makesign(GETSIGN(ressign), res); pfree(res); res = ressign; } - - retval = (GISTENTRY*)palloc(sizeof(GISTENTRY)); - gistentryinit(*retval, PointerGetDatum(res), - entry->rel, entry->page, - entry->offset, res->len, FALSE); - } else if ( ISSIGNKEY(DatumGetPointer( entry->key )) && - ! ISALLTRUE(DatumGetPointer( entry->key )) ){ - int4 i,len; - GISTTYPE *res; - BITVECP sign = GETSIGN( DatumGetPointer( entry->key ) ); + + retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); + gistentryinit(*retval, PointerGetDatum(res), + entry->rel, entry->page, + entry->offset, res->len, FALSE); + } + else if (ISSIGNKEY(DatumGetPointer(entry->key)) && + !ISALLTRUE(DatumGetPointer(entry->key))) + { + int4 i, + len; + GISTTYPE *res; + BITVECP sign = GETSIGN(DatumGetPointer(entry->key)); LOOPBYTE( - if ( (sign[i] & 0xff) != 0xff ) - PG_RETURN_POINTER(retval); + if ((sign[i] & 0xff) != 0xff) + PG_RETURN_POINTER(retval); ); - len = CALCGTSIZE( SIGNKEY|ALLISTRUE, 0 ); - res = (GISTTYPE*)palloc( len ); + len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0); + res = (GISTTYPE *) palloc(len); res->len = len; - res->flag = SIGNKEY | ALLISTRUE; - - retval = (GISTENTRY*)palloc(sizeof(GISTENTRY)); - gistentryinit(*retval, PointerGetDatum(res), - entry->rel, entry->page, - entry->offset, res->len, FALSE); + res->flag = SIGNKEY | ALLISTRUE; + + retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); + gistentryinit(*retval, PointerGetDatum(res), + entry->rel, entry->page, + entry->offset, res->len, FALSE); } PG_RETURN_POINTER(retval); } Datum -gtxtidx_decompress(PG_FUNCTION_ARGS) { - GISTENTRY *entry = (GISTENTRY *)PG_GETARG_POINTER(0); - GISTTYPE *key = (GISTTYPE*)DatumGetPointer( PG_DETOAST_DATUM(entry->key) ); +gtxtidx_decompress(PG_FUNCTION_ARGS) +{ + GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); + GISTTYPE *key = (GISTTYPE *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); - if ( key != (GISTTYPE*)DatumGetPointer(entry->key) ) { - GISTENTRY *retval = (GISTENTRY*)palloc(sizeof(GISTENTRY)); - gistentryinit(*retval, PointerGetDatum(key), - entry->rel, entry->page, - entry->offset, key->len, FALSE); + if (key != (GISTTYPE *) DatumGetPointer(entry->key)) + { + GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); + + gistentryinit(*retval, PointerGetDatum(key), + entry->rel, entry->page, + entry->offset, key->len, FALSE); PG_RETURN_POINTER(retval); } - PG_RETURN_POINTER(entry); + PG_RETURN_POINTER(entry); } -typedef struct { - int4 *arrb; - int4 *arre; -} CHKVAL; - +typedef struct +{ + int4 *arrb; + int4 *arre; +} CHKVAL; + /* * is there value 'val' in array or not ? */ static bool -checkcondition_arr( void *checkval, ITEM* val ) { - int4 *StopLow = ((CHKVAL*)checkval)->arrb; - int4 *StopHigh = ((CHKVAL*)checkval)->arre; - int4 *StopMiddle; +checkcondition_arr(void *checkval, ITEM * val) +{ + int4 *StopLow = ((CHKVAL *) checkval)->arrb; + int4 *StopHigh = ((CHKVAL *) checkval)->arre; + int4 *StopMiddle; /* Loop invariant: StopLow <= val < StopHigh */ - - while (StopLow < StopHigh) { + + while (StopLow < StopHigh) + { StopMiddle = StopLow + (StopHigh - StopLow) / 2; if (*StopMiddle == val->val) return (true); - else if (*StopMiddle < val->val ) + else if (*StopMiddle < val->val) StopLow = StopMiddle + 1; else StopHigh = StopMiddle; @@ -220,264 +253,321 @@ checkcondition_arr( void *checkval, ITEM* val ) { } static bool -checkcondition_bit( void *checkval, ITEM* val ) { - return GETBIT( checkval, HASHVAL( val->val ) ); +checkcondition_bit(void *checkval, ITEM * val) +{ + return GETBIT(checkval, HASHVAL(val->val)); } -Datum -gtxtidx_consistent(PG_FUNCTION_ARGS) { - QUERYTYPE *query = (QUERYTYPE *)PG_GETARG_POINTER(1); - GISTTYPE *key = (GISTTYPE *)DatumGetPointer( - ((GISTENTRY *)PG_GETARG_POINTER(0))->key +Datum +gtxtidx_consistent(PG_FUNCTION_ARGS) +{ + QUERYTYPE *query = (QUERYTYPE *) PG_GETARG_POINTER(1); + GISTTYPE *key = (GISTTYPE *) DatumGetPointer( + ((GISTENTRY *) PG_GETARG_POINTER(0))->key ); - if ( !query->size ) + if (!query->size) PG_RETURN_BOOL(false); - if ( ISSIGNKEY(key) ) { - if ( ISALLTRUE(key) ) + if (ISSIGNKEY(key)) + { + if (ISALLTRUE(key)) PG_RETURN_BOOL(true); - PG_RETURN_BOOL( execute( - GETQUERY(query), - (void*)GETSIGN(key), false, - checkcondition_bit - )); - } else { /* only leaf pages */ - CHKVAL chkval; + PG_RETURN_BOOL(execute( + GETQUERY(query), + (void *) GETSIGN(key), false, + checkcondition_bit + )); + } + else + { /* only leaf pages */ + CHKVAL chkval; chkval.arrb = GETARR(key); - chkval.arre = chkval.arrb + ARRNELEM(key); - PG_RETURN_BOOL( execute( - GETQUERY(query), - (void*)&chkval, true, - checkcondition_arr - ) ); + chkval.arre = chkval.arrb + ARRNELEM(key); + PG_RETURN_BOOL(execute( + GETQUERY(query), + (void *) &chkval, true, + checkcondition_arr + )); } } static int4 -unionkey( BITVECP sbase, GISTTYPE *add ) { - int4 i; +unionkey(BITVECP sbase, GISTTYPE * add) +{ + int4 i; + + if (ISSIGNKEY(add)) + { + BITVECP sadd = GETSIGN(add); - if ( ISSIGNKEY(add) ) { - BITVECP sadd = GETSIGN( add ); - - if ( ISALLTRUE(add) ) + if (ISALLTRUE(add)) return 1; LOOPBYTE( - sbase[i] |= sadd[i]; + sbase[i] |= sadd[i]; ); - } else { - int4 *ptr = GETARR( add ); - for(i=0;i<ARRNELEM(add);i++) - HASH( sbase, ptr[i] ); + } + else + { + int4 *ptr = GETARR(add); + + for (i = 0; i < ARRNELEM(add); i++) + HASH(sbase, ptr[i]); } return 0; } Datum -gtxtidx_union(PG_FUNCTION_ARGS) { - bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); - int *size = (int *) PG_GETARG_POINTER(1); - BITVEC base; - int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY); - int4 i; - int4 flag = 0; - GISTTYPE *result; - - MemSet( (void*)base, 0, sizeof(BITVEC) ); - for(i=0;i<len;i++) { - if ( unionkey( base, GETENTRY(entryvec, i) ) ) { +gtxtidx_union(PG_FUNCTION_ARGS) +{ + bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); + int *size = (int *) PG_GETARG_POINTER(1); + BITVEC base; + int4 len = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY); + int4 i; + int4 flag = 0; + GISTTYPE *result; + + MemSet((void *) base, 0, sizeof(BITVEC)); + for (i = 0; i < len; i++) + { + if (unionkey(base, GETENTRY(entryvec, i))) + { flag = ALLISTRUE; break; } } flag |= SIGNKEY; - len = CALCGTSIZE( flag, 0 ); - result = (GISTTYPE*)palloc( len ); + len = CALCGTSIZE(flag, 0); + result = (GISTTYPE *) palloc(len); *size = result->len = len; result->flag = flag; - if ( ! ISALLTRUE(result) ) - memcpy((void*)GETSIGN(result), (void*)base, sizeof( BITVEC ) ); + if (!ISALLTRUE(result)) + memcpy((void *) GETSIGN(result), (void *) base, sizeof(BITVEC)); - PG_RETURN_POINTER( result ); + PG_RETURN_POINTER(result); } Datum -gtxtidx_same(PG_FUNCTION_ARGS) { - GISTTYPE *a = (GISTTYPE*)PG_GETARG_POINTER(0); - GISTTYPE *b = (GISTTYPE*)PG_GETARG_POINTER(1); - bool *result = (bool *)PG_GETARG_POINTER(2); - - if ( ISSIGNKEY(a) ) { /* then b also ISSIGNKEY */ - if ( ISALLTRUE(a) && ISALLTRUE(b) ) { +gtxtidx_same(PG_FUNCTION_ARGS) +{ + GISTTYPE *a = (GISTTYPE *) PG_GETARG_POINTER(0); + GISTTYPE *b = (GISTTYPE *) PG_GETARG_POINTER(1); + bool *result = (bool *) PG_GETARG_POINTER(2); + + if (ISSIGNKEY(a)) + { /* then b also ISSIGNKEY */ + if (ISALLTRUE(a) && ISALLTRUE(b)) *result = true; - } else if ( ISALLTRUE(a) ) { + else if (ISALLTRUE(a)) *result = false; - } else if ( ISALLTRUE(b) ) { + else if (ISALLTRUE(b)) *result = false; - } else { - int4 i; - BITVECP sa=GETSIGN(a), sb=GETSIGN(b); - + else + { + int4 i; + BITVECP sa = GETSIGN(a), + sb = GETSIGN(b); + *result = true; LOOPBYTE( - if ( sa[i] != sb[i] ) { - *result = false; - break; - } + if (sa[i] != sb[i]) + { + *result = false; + break; + } ); - } - } else { /* a and b ISARRKEY */ - int4 lena = ARRNELEM(a), lenb = ARRNELEM(b); + } + } + else + { /* a and b ISARRKEY */ + int4 lena = ARRNELEM(a), + lenb = ARRNELEM(b); - if ( lena != lenb ) { + if (lena != lenb) *result = false; - } else { - int4 *ptra = GETARR(a), *ptrb = GETARR(b); - int4 i; + else + { + int4 *ptra = GETARR(a), + *ptrb = GETARR(b); + int4 i; *result = true; - for(i=0;i<lena;i++) - if ( ptra[i] != ptrb[i] ) { + for (i = 0; i < lena; i++) + if (ptra[i] != ptrb[i]) + { *result = false; break; } } } - + PG_RETURN_POINTER(result); } static int4 -sizebitvec( BITVECP sign ) { - int4 size=0, i; +sizebitvec(BITVECP sign) +{ + int4 size = 0, + i; + LOOPBYTE( - size += SUMBIT(*(char*)sign); - sign = (BITVECP) ( ((char*)sign) + 1 ); + size += SUMBIT(*(char *) sign); + sign = (BITVECP) (((char *) sign) + 1); ); - return size; + return size; } Datum -gtxtidx_penalty(PG_FUNCTION_ARGS) { - GISTENTRY *origentry = (GISTENTRY *)PG_GETARG_POINTER(0); /*always ISSIGNKEY*/ - GISTENTRY *newentry = (GISTENTRY *)PG_GETARG_POINTER(1); - float *penalty = (float *) PG_GETARG_POINTER(2); - GISTTYPE *origval = (GISTTYPE*)DatumGetPointer( origentry->key ); - GISTTYPE *newval = (GISTTYPE*)DatumGetPointer( newentry->key ); - int4 unionsize = 0; - BITVECP orig = GETSIGN(origval); - - if ( ISALLTRUE(origval) ) { +gtxtidx_penalty(PG_FUNCTION_ARGS) +{ + GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */ + GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1); + float *penalty = (float *) PG_GETARG_POINTER(2); + GISTTYPE *origval = (GISTTYPE *) DatumGetPointer(origentry->key); + GISTTYPE *newval = (GISTTYPE *) DatumGetPointer(newentry->key); + int4 unionsize = 0; + BITVECP orig = GETSIGN(origval); + + if (ISALLTRUE(origval)) + { *penalty = 0.0; - PG_RETURN_POINTER( penalty ); + PG_RETURN_POINTER(penalty); } - if ( ISARRKEY(newval) ) { - int4 *ptr=GETARR(newval), n=ARRNELEM(newval); - while( n-- ) { - if ( GETBIT(orig, HASHVAL( *ptr ) ) == 0 ) + if (ISARRKEY(newval)) + { + int4 *ptr = GETARR(newval), + n = ARRNELEM(newval); + + while (n--) + { + if (GETBIT(orig, HASHVAL(*ptr)) == 0) unionsize++; ptr++; } - *penalty = (float)unionsize; - } else { - if ( ISALLTRUE(newval) ) { - *penalty = (float) (SIGLENBIT - sizebitvec( orig ) ); - } else { - char valtmp; - BITVECP nval = GETSIGN(newval); - int4 i; + *penalty = (float) unionsize; + } + else + { + if (ISALLTRUE(newval)) + *penalty = (float) (SIGLENBIT - sizebitvec(orig)); + else + { + char valtmp; + BITVECP nval = GETSIGN(newval); + int4 i; LOOPBYTE( - valtmp = nval[i] | orig[i]; - unionsize += SUMBIT(valtmp) - SUMBIT(orig[i]); + valtmp = nval[i] | orig[i]; + unionsize += SUMBIT(valtmp) - SUMBIT(orig[i]); ); - *penalty = (float)unionsize; - } + *penalty = (float) unionsize; + } } - PG_RETURN_POINTER( penalty ); + PG_RETURN_POINTER(penalty); } -typedef struct { - bool allistrue; - BITVEC sign; -} CACHESIGN; +typedef struct +{ + bool allistrue; + BITVEC sign; +} CACHESIGN; static void -fillcache( CACHESIGN *item, GISTTYPE *key ) { +fillcache(CACHESIGN * item, GISTTYPE * key) +{ item->allistrue = false; - if ( ISARRKEY( key ) ) { + if (ISARRKEY(key)) makesign(item->sign, key); - } else if ( ISALLTRUE(key) ) { + else if (ISALLTRUE(key)) item->allistrue = true; - } else { - memcpy( (void*)item->sign, (void*)GETSIGN(key), sizeof(BITVEC)); - } -} + else + memcpy((void *) item->sign, (void *) GETSIGN(key), sizeof(BITVEC)); +} #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) ) -typedef struct { - OffsetNumber pos; - int4 cost; +typedef struct +{ + OffsetNumber pos; + int4 cost; } SPLITCOST; static int -comparecost( const void *a, const void *b ) { - if ( ((SPLITCOST*)a)->cost == ((SPLITCOST*)b)->cost ) +comparecost(const void *a, const void *b) +{ + if (((SPLITCOST *) a)->cost == ((SPLITCOST *) b)->cost) return 0; else - return ( ((SPLITCOST*)a)->cost > ((SPLITCOST*)b)->cost ) ? 1 : -1; + return (((SPLITCOST *) a)->cost > ((SPLITCOST *) b)->cost) ? 1 : -1; } Datum -gtxtidx_picksplit(PG_FUNCTION_ARGS) { - bytea *entryvec = (bytea *)PG_GETARG_POINTER(0); - GIST_SPLITVEC *v = (GIST_SPLITVEC *)PG_GETARG_POINTER(1); - OffsetNumber k,j; - GISTTYPE *datum_l, *datum_r; - BITVEC union_l, union_r; - bool firsttime = true; - int4 size_alpha,size_beta,sizeu,sizei; - int4 size_waste, waste = 0.0; - int4 size_l, size_r; - int4 nbytes; - OffsetNumber seed_1=0, seed_2=0; - OffsetNumber *left, *right; +gtxtidx_picksplit(PG_FUNCTION_ARGS) +{ + bytea *entryvec = (bytea *) PG_GETARG_POINTER(0); + GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1); + OffsetNumber k, + j; + GISTTYPE *datum_l, + *datum_r; + BITVEC union_l, + union_r; + bool firsttime = true; + int4 size_alpha, + size_beta, + sizeu, + sizei; + int4 size_waste, + waste = 0.0; + int4 size_l, + size_r; + int4 nbytes; + OffsetNumber seed_1 = 0, + seed_2 = 0; + OffsetNumber *left, + *right; OffsetNumber maxoff; - BITVECP ptra, ptrb, ptrc; - int i; + BITVECP ptra, + ptrb, + ptrc; + int i; CACHESIGN *cache; - char valtmp; - SPLITCOST *costvector; + char valtmp; + SPLITCOST *costvector; maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2; nbytes = (maxoff + 2) * sizeof(OffsetNumber); v->spl_left = (OffsetNumber *) palloc(nbytes); v->spl_right = (OffsetNumber *) palloc(nbytes); - cache = (CACHESIGN*)palloc(sizeof(CACHESIGN)*(maxoff+2)); - fillcache( &cache[FirstOffsetNumber], GETENTRY(entryvec,FirstOffsetNumber) ); + cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 2)); + fillcache(&cache[FirstOffsetNumber], GETENTRY(entryvec, FirstOffsetNumber)); - for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) { - for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) { - if ( k==FirstOffsetNumber ) - fillcache( &cache[j], GETENTRY(entryvec,j) ); - - if ( cache[k].allistrue || cache[j].allistrue ) { + for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) + { + for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) + { + if (k == FirstOffsetNumber) + fillcache(&cache[j], GETENTRY(entryvec, j)); + + if (cache[k].allistrue || cache[j].allistrue) + { sizeu = SIGLENBIT; - if ( cache[k].allistrue && cache[j].allistrue ) + if (cache[k].allistrue && cache[j].allistrue) sizei = SIGLENBIT; else - sizei = ( cache[k].allistrue ) ? - sizebitvec( cache[j].sign ) : sizebitvec( cache[k].sign ); - } else { + sizei = (cache[k].allistrue) ? + sizebitvec(cache[j].sign) : sizebitvec(cache[k].sign); + } + else + { sizeu = sizei = 0; ptra = cache[j].sign; ptrb = cache[k].sign; @@ -492,21 +582,22 @@ gtxtidx_picksplit(PG_FUNCTION_ARGS) { sizeu++; \ } while(0) LOOPBYTE( - COUNT(0); - COUNT(1); - COUNT(2); - COUNT(3); - COUNT(4); - COUNT(5); - COUNT(6); - COUNT(7); - ptra = (BITVECP) ( ((char*)ptra) + 1 ); - ptrb = (BITVECP) ( ((char*)ptrb) + 1 ); + COUNT(0); + COUNT(1); + COUNT(2); + COUNT(3); + COUNT(4); + COUNT(5); + COUNT(6); + COUNT(7); + ptra = (BITVECP) (((char *) ptra) + 1); + ptrb = (BITVECP) (((char *) ptrb) + 1); ); } size_waste = sizeu - sizei; - if (size_waste > waste || firsttime) { + if (size_waste > waste || firsttime) + { waste = size_waste; seed_1 = k; seed_2 = j; @@ -520,142 +611,177 @@ gtxtidx_picksplit(PG_FUNCTION_ARGS) { right = v->spl_right; v->spl_nright = 0; - if ( seed_1 == 0 || seed_2 == 0 ) { + if (seed_1 == 0 || seed_2 == 0) + { seed_1 = 1; seed_2 = 2; } - /* form initial .. */ - if ( cache[seed_1].allistrue ) { - datum_l = (GISTTYPE*)palloc( CALCGTSIZE( SIGNKEY|ALLISTRUE, 0 ) ); - datum_l->len = CALCGTSIZE( SIGNKEY|ALLISTRUE, 0 ); datum_l->flag = SIGNKEY|ALLISTRUE; + /* form initial .. */ + if (cache[seed_1].allistrue) + { + datum_l = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0)); + datum_l->len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0); + datum_l->flag = SIGNKEY | ALLISTRUE; size_l = SIGLENBIT; - } else { - datum_l = (GISTTYPE*)palloc( CALCGTSIZE( SIGNKEY, 0 ) ); - datum_l->len = CALCGTSIZE( SIGNKEY, 0 ); datum_l->flag = SIGNKEY; - memcpy((void*)GETSIGN(datum_l), (void*)cache[seed_1].sign, sizeof(BITVEC)); - size_l = sizebitvec( GETSIGN(datum_l) ); } - if ( cache[seed_2].allistrue ) { - datum_r = (GISTTYPE*)palloc( CALCGTSIZE( SIGNKEY|ALLISTRUE, 0 ) ); - datum_r->len = CALCGTSIZE( SIGNKEY|ALLISTRUE, 0 ); datum_r->flag = SIGNKEY|ALLISTRUE; + else + { + datum_l = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY, 0)); + datum_l->len = CALCGTSIZE(SIGNKEY, 0); + datum_l->flag = SIGNKEY; + memcpy((void *) GETSIGN(datum_l), (void *) cache[seed_1].sign, sizeof(BITVEC)); + size_l = sizebitvec(GETSIGN(datum_l)); + } + if (cache[seed_2].allistrue) + { + datum_r = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0)); + datum_r->len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0); + datum_r->flag = SIGNKEY | ALLISTRUE; size_r = SIGLENBIT; - } else { - datum_r = (GISTTYPE*)palloc( CALCGTSIZE( SIGNKEY, 0 ) ); - datum_r->len = CALCGTSIZE( SIGNKEY, 0 ); datum_r->flag = SIGNKEY; - memcpy((void*)GETSIGN(datum_r), (void*)cache[seed_2].sign, sizeof(BITVEC)); - size_r = sizebitvec( GETSIGN(datum_r) ); } - + else + { + datum_r = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY, 0)); + datum_r->len = CALCGTSIZE(SIGNKEY, 0); + datum_r->flag = SIGNKEY; + memcpy((void *) GETSIGN(datum_r), (void *) cache[seed_2].sign, sizeof(BITVEC)); + size_r = sizebitvec(GETSIGN(datum_r)); + } + maxoff = OffsetNumberNext(maxoff); - fillcache( &cache[maxoff], GETENTRY(entryvec,maxoff) ); + fillcache(&cache[maxoff], GETENTRY(entryvec, maxoff)); /* sort before ... */ - costvector=(SPLITCOST*)palloc( sizeof(SPLITCOST)*maxoff ); - for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) { - costvector[j-1].pos = j; - if ( cache[j].allistrue ) { + costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff); + for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j)) + { + costvector[j - 1].pos = j; + if (cache[j].allistrue) + { size_alpha = SIGLENBIT - size_l; - size_beta = SIGLENBIT - size_r; - } else { + size_beta = SIGLENBIT - size_r; + } + else + { ptra = cache[seed_1].sign; ptrb = cache[seed_2].sign; ptrc = cache[j].sign; size_beta = size_alpha = 0; - if ( cache[seed_1].allistrue ) { - if ( ! cache[seed_2].allistrue ) { + if (cache[seed_1].allistrue) + { + if (!cache[seed_2].allistrue) + { LOOPBIT( - if ( GETBIT(ptrc,i) && ! GETBIT(ptrb,i) ) + if (GETBIT(ptrc, i) && !GETBIT(ptrb, i)) size_beta++; - ); + ); } - } else if ( cache[seed_2].allistrue ) { - if ( ! cache[seed_1].allistrue ) { + } + else if (cache[seed_2].allistrue) + { + if (!cache[seed_1].allistrue) + { LOOPBIT( - if ( GETBIT(ptrc,i) && ! GETBIT(ptra,i) ) + if (GETBIT(ptrc, i) && !GETBIT(ptra, i)) size_alpha++; - ); + ); } - } else { + } + else + { LOOPBIT( - if ( GETBIT(ptrc,i) && ! GETBIT(ptra,i) ) - size_alpha++; - if ( GETBIT(ptrc,i) && ! GETBIT(ptrb,i) ) - size_beta++; + if (GETBIT(ptrc, i) && !GETBIT(ptra, i)) + size_alpha++; + if (GETBIT(ptrc, i) && !GETBIT(ptrb, i)) + size_beta++; ); } } - costvector[j-1].cost = abs( size_alpha - size_beta ); + costvector[j - 1].cost = abs(size_alpha - size_beta); } - qsort( (void*)costvector, maxoff, sizeof(SPLITCOST), comparecost ); - - for (k = 0; k < maxoff; k++) { + qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost); + + for (k = 0; k < maxoff; k++) + { j = costvector[k].pos; - if ( j == seed_1 ) { + if (j == seed_1) + { *left++ = j; v->spl_nleft++; continue; - } else if ( j == seed_2 ) { + } + else if (j == seed_2) + { *right++ = j; v->spl_nright++; continue; } - if ( ISALLTRUE( datum_l ) || cache[j].allistrue ) { + if (ISALLTRUE(datum_l) || cache[j].allistrue) size_alpha = SIGLENBIT; - } else { + else + { ptra = cache[j].sign; ptrb = GETSIGN(datum_l); size_alpha = 0; LOOPBYTE( - valtmp = union_l[i] = ptra[i] | ptrb[i]; - size_alpha += SUMBIT( valtmp ); + valtmp = union_l[i] = ptra[i] | ptrb[i]; + size_alpha += SUMBIT(valtmp); ); } - if ( ISALLTRUE( datum_r ) || cache[j].allistrue ) { + if (ISALLTRUE(datum_r) || cache[j].allistrue) size_beta = SIGLENBIT; - } else { + else + { ptra = cache[j].sign; ptrb = GETSIGN(datum_r); size_beta = 0; LOOPBYTE( - valtmp = union_r[i] = ptra[i] | ptrb[i]; - size_beta += SUMBIT( valtmp ); + valtmp = union_r[i] = ptra[i] | ptrb[i]; + size_beta += SUMBIT(valtmp); ); } - if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.1)) { - if ( ! ISALLTRUE( datum_l ) ) { - if ( size_alpha == SIGLENBIT ) { - if ( size_alpha != size_l ) - MemSet( (void*)GETSIGN(datum_l),0xff, sizeof(BITVEC)); - } else - memcpy( (void*)GETSIGN(datum_l), (void*)union_l, sizeof(BITVEC) ); + if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.1)) + { + if (!ISALLTRUE(datum_l)) + { + if (size_alpha == SIGLENBIT) + { + if (size_alpha != size_l) + MemSet((void *) GETSIGN(datum_l), 0xff, sizeof(BITVEC)); + } + else + memcpy((void *) GETSIGN(datum_l), (void *) union_l, sizeof(BITVEC)); } size_l = size_alpha; *left++ = j; v->spl_nleft++; - } else { - if ( ! ISALLTRUE( datum_r ) ) { - if ( size_beta == SIGLENBIT ) { - if ( size_beta != size_r ) - MemSet( (void*)GETSIGN(datum_r),0xff, sizeof(BITVEC)); - } else - memcpy( (void*)GETSIGN(datum_r), (void*)union_r, sizeof(BITVEC) ); + } + else + { + if (!ISALLTRUE(datum_r)) + { + if (size_beta == SIGLENBIT) + { + if (size_beta != size_r) + MemSet((void *) GETSIGN(datum_r), 0xff, sizeof(BITVEC)); + } + else + memcpy((void *) GETSIGN(datum_r), (void *) union_r, sizeof(BITVEC)); } size_r = size_beta; *right++ = j; v->spl_nright++; } } - + *right = *left = FirstOffsetNumber; pfree(costvector); pfree(cache); v->spl_ldatum = PointerGetDatum(datum_l); v->spl_rdatum = PointerGetDatum(datum_r); - PG_RETURN_POINTER( v ); + PG_RETURN_POINTER(v); } - - diff --git a/contrib/tsearch/morph.c b/contrib/tsearch/morph.c index e8fedc77b8..477c3bf069 100644 --- a/contrib/tsearch/morph.c +++ b/contrib/tsearch/morph.c @@ -114,7 +114,7 @@ initmorph(void) needinit[i] = false; PGLC_current(&lc); - if ( lc.lc_ctype ) + if (lc.lc_ctype) for (i = 1; i < lengthof(dicts); i++) if (strcmp(dicts[i].localename, lc.lc_ctype) == 0) { diff --git a/contrib/tsearch/query.c b/contrib/tsearch/query.c index c3917f204f..b69151c879 100644 --- a/contrib/tsearch/query.c +++ b/contrib/tsearch/query.c @@ -593,8 +593,8 @@ mqtxt_in(PG_FUNCTION_ARGS) res = clean_fakeval(GETQUERY(query), &len); if (!res) { - query->len=HDRSIZEQT; - query->size=0; + query->len = HDRSIZEQT; + query->size = 0; PG_RETURN_POINTER(query); } memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(ITEM)); @@ -739,11 +739,13 @@ qtxt_out(PG_FUNCTION_ARGS) QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0))); INFIX nrm; - if (query->size == 0) { - char *b=palloc(1); - *b='\0'; + if (query->size == 0) + { + char *b = palloc(1); + + *b = '\0'; PG_RETURN_POINTER(b); - } + } nrm.curpol = GETQUERY(query); nrm.buflen = 32; nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen); @@ -769,11 +771,12 @@ querytree(PG_FUNCTION_ARGS) int4 len; - if (query->size == 0) { + if (query->size == 0) + { res = (text *) palloc(VARHDRSZ); VARATT_SIZEP(res) = VARHDRSZ; PG_RETURN_POINTER(res); - } + } q = clean_NOT(GETQUERY(query), &len); diff --git a/contrib/tsearch/txtidx.c b/contrib/tsearch/txtidx.c index 14f69913b7..7be9f79270 100644 --- a/contrib/tsearch/txtidx.c +++ b/contrib/tsearch/txtidx.c @@ -327,7 +327,7 @@ typedef struct { uint16 len; char *word; -} WORD; +} WORD; typedef struct { @@ -402,7 +402,7 @@ compareWORD(const void *a, const void *b) } static int -uniqueWORD(WORD *a, int4 l) +uniqueWORD(WORD * a, int4 l) { WORD *ptr, *res; diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c index ac80ea361a..83b53a9696 100644 --- a/contrib/vacuumlo/vacuumlo.c +++ b/contrib/vacuumlo/vacuumlo.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.13 2002/08/15 02:58:29 momjian Exp $ + * $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.14 2002/09/04 20:31:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -35,20 +35,23 @@ #define BUFSIZE 1024 extern char *optarg; -extern int optind, opterr, optopt; - -struct _param { - char *pg_user; - int pg_prompt; - char *pg_port; - char *pg_host; - int verbose; - int dry_run; +extern int optind, + opterr, + optopt; + +struct _param +{ + char *pg_user; + int pg_prompt; + char *pg_port; + char *pg_host; + int verbose; + int dry_run; }; -int vacuumlo(char *, struct _param *); -char *simple_prompt(const char *prompt, int , int); -void usage(void); +int vacuumlo(char *, struct _param *); +char *simple_prompt(const char *prompt, int, int); +void usage(void); /* @@ -63,7 +66,7 @@ void usage(void); * * Returns a malloc()'ed string with the input (w/o trailing newline). */ -static int prompt_state = 0; +static int prompt_state = 0; char * simple_prompt(const char *prompt, int maxlen, int echo) @@ -82,7 +85,7 @@ simple_prompt(const char *prompt, int maxlen, int echo) if (!destination) return NULL; - prompt_state = 1; /* disable SIGINT */ + prompt_state = 1; /* disable SIGINT */ /* * Do not try to collapse these into one "w+" mode file. Doesn't work @@ -153,7 +156,7 @@ simple_prompt(const char *prompt, int maxlen, int echo) fclose(termout); } - prompt_state = 0; /* SIGINT okay again */ + prompt_state = 0; /* SIGINT okay again */ return destination; } @@ -164,33 +167,35 @@ simple_prompt(const char *prompt, int maxlen, int echo) * This vacuums LOs of one database. It returns 0 on success, -1 on failure. */ int -vacuumlo(char *database, struct _param *param) +vacuumlo(char *database, struct _param * param) { PGconn *conn; PGresult *res, - *res2; + *res2; char buf[BUFSIZE]; - int matched; - int deleted; - int i; - char *password = NULL; - - if(param->pg_prompt) { - password = simple_prompt("Password: ", 32, 0); - if(!password) { - fprintf(stderr, "failed to get password\n"); - exit(1); + int matched; + int deleted; + int i; + char *password = NULL; + + if (param->pg_prompt) + { + password = simple_prompt("Password: ", 32, 0); + if (!password) + { + fprintf(stderr, "failed to get password\n"); + exit(1); } } - conn = PQsetdbLogin( param->pg_host, - param->pg_port, - NULL, - NULL, - database, - param->pg_user, - password - ); + conn = PQsetdbLogin(param->pg_host, + param->pg_port, + NULL, + NULL, + database, + param->pg_user, + password + ); /* check to see that the backend connection was successfully made */ if (PQstatus(conn) == CONNECTION_BAD) @@ -201,10 +206,11 @@ vacuumlo(char *database, struct _param *param) return -1; } - if (param->verbose) { + if (param->verbose) + { fprintf(stdout, "Connected to %s\n", database); - if(param->dry_run) - fprintf(stdout, "Test run: no large objects will be removed!\n"); + if (param->dry_run) + fprintf(stdout, "Test run: no large objects will be removed!\n"); } /* @@ -289,7 +295,7 @@ vacuumlo(char *database, struct _param *param) * whole program is a Postgres-ism. */ snprintf(buf, BUFSIZE, "DELETE FROM vacuum_l WHERE lo = \"%s\".\"%s\" ", - table, field); + table, field); res2 = PQexec(conn, buf); if (PQresultStatus(res2) != PGRES_COMMAND_OK) { @@ -342,16 +348,18 @@ vacuumlo(char *database, struct _param *param) fflush(stdout); } - if(param->dry_run == 0) { - if (lo_unlink(conn, lo) < 0) - { - fprintf(stderr, "\nFailed to remove lo %u: ", lo); - fprintf(stderr, "%s", PQerrorMessage(conn)); - } - else - deleted++; - } else - deleted++; + if (param->dry_run == 0) + { + if (lo_unlink(conn, lo) < 0) + { + fprintf(stderr, "\nFailed to remove lo %u: ", lo); + fprintf(stderr, "%s", PQerrorMessage(conn)); + } + else + deleted++; + } + else + deleted++; } PQclear(res); @@ -365,23 +373,24 @@ vacuumlo(char *database, struct _param *param) if (param->verbose) fprintf(stdout, "\r%s %d large objects from %s.\n", - (param->dry_run?"Would remove":"Removed"), deleted, database); + (param->dry_run ? "Would remove" : "Removed"), deleted, database); return 0; } void -usage(void) { - fprintf(stdout, "vacuumlo removes unreferenced large objects from databases\n\n"); - fprintf(stdout, "Usage:\n vacuumlo [options] dbname [dbnames...]\n\n"); - fprintf(stdout, "Options:\n"); +usage(void) +{ + fprintf(stdout, "vacuumlo removes unreferenced large objects from databases\n\n"); + fprintf(stdout, "Usage:\n vacuumlo [options] dbname [dbnames...]\n\n"); + fprintf(stdout, "Options:\n"); fprintf(stdout, " -v\t\tWrite a lot of output\n"); fprintf(stdout, " -n\t\tDon't remove any large object, just show what would be done\n"); - fprintf(stdout, " -U username\tUsername to connect as\n"); - fprintf(stdout, " -W\t\tPrompt for password\n"); - fprintf(stdout, " -h hostname\tDatabase server host\n"); + fprintf(stdout, " -U username\tUsername to connect as\n"); + fprintf(stdout, " -W\t\tPrompt for password\n"); + fprintf(stdout, " -h hostname\tDatabase server host\n"); fprintf(stdout, " -p port\tDatabase server port\n"); - fprintf(stdout, " -p port\tDatabase server port\n\n"); + fprintf(stdout, " -p port\tDatabase server port\n\n"); } @@ -389,69 +398,75 @@ int main(int argc, char **argv) { int rc = 0; - struct _param param; - int c; - int port; + struct _param param; + int c; + int port; /* Parameter handling */ - param.pg_user = NULL; + param.pg_user = NULL; param.pg_prompt = 0; param.pg_host = NULL; param.pg_port = 0; - param.verbose = 0; + param.verbose = 0; param.dry_run = 0; - while( 1 ) { - c = getopt(argc, argv, "?h:U:p:vnW"); - if(c == -1) - break; - - switch(c) { - case '?': - if(optopt == '?') { - usage(); - exit(0); - } - exit(1); - case ':': - exit(1); - case 'v': - param.verbose = 1; - break; - case 'n': - param.dry_run = 1; - param.verbose = 1; - break; - case 'U': - param.pg_user = strdup(optarg); - break; - case 'W': - param.pg_prompt = 1; - break; - case 'p': - port = strtol(optarg, NULL, 10); - if( (port < 1) || (port > 65535)) { - fprintf(stderr, "[%s]: invalid port number '%s'\n", argv[0], optarg); - exit(1); - } - param.pg_port = strdup(optarg); - break; - case 'h': - param.pg_host = strdup(optarg); - break; - } + while (1) + { + c = getopt(argc, argv, "?h:U:p:vnW"); + if (c == -1) + break; + + switch (c) + { + case '?': + if (optopt == '?') + { + usage(); + exit(0); + } + exit(1); + case ':': + exit(1); + case 'v': + param.verbose = 1; + break; + case 'n': + param.dry_run = 1; + param.verbose = 1; + break; + case 'U': + param.pg_user = strdup(optarg); + break; + case 'W': + param.pg_prompt = 1; + break; + case 'p': + port = strtol(optarg, NULL, 10); + if ((port < 1) || (port > 65535)) + { + fprintf(stderr, "[%s]: invalid port number '%s'\n", argv[0], optarg); + exit(1); + } + param.pg_port = strdup(optarg); + break; + case 'h': + param.pg_host = strdup(optarg); + break; + } } - + /* No database given? Show usage */ - if(optind >= argc-1) { - fprintf(stderr, "vacuumlo: missing required argument: database name\n"); - fprintf(stderr, "Try 'vacuumlo -?' for help.\n"); - exit(1); + if (optind >= argc - 1) + { + fprintf(stderr, "vacuumlo: missing required argument: database name\n"); + fprintf(stderr, "Try 'vacuumlo -?' for help.\n"); + exit(1); } - for(c = optind; c < argc; c++) { - /* Work on selected database */ - rc += (vacuumlo(argv[c], ¶m) != 0); + for (c = optind; c < argc; c++) + { + /* Work on selected database */ + rc += (vacuumlo(argv[c], ¶m) != 0); } return rc; diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 884db0ad21..9901965a48 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.81 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.82 2002/09/04 20:31:08 momjian Exp $ * * NOTES * The old interface functions have been converted to macros @@ -326,9 +326,9 @@ nocachegetattr(HeapTuple tuple, /* * If slow is false, and we got here, we know that we have a tuple - * with no nulls or var-widths before the target attribute. If possible, - * we also want to initialize the remainder of the attribute cached - * offset values. + * with no nulls or var-widths before the target attribute. If + * possible, we also want to initialize the remainder of the attribute + * cached offset values. */ if (!slow) { @@ -702,8 +702,8 @@ heap_modifytuple(HeapTuple tuple, nulls); /* - * copy the identification info of the old tuple: t_ctid, t_self, - * and OID (if any) + * copy the identification info of the old tuple: t_ctid, t_self, and + * OID (if any) */ newTuple->t_data->t_ctid = tuple->t_data->t_ctid; newTuple->t_self = tuple->t_self; diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c index 2fbc5dd0b1..30bbc4e354 100644 --- a/src/backend/access/common/indextuple.c +++ b/src/backend/access/common/indextuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.59 2002/08/25 17:20:00 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.60 2002/09/04 20:31:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -319,9 +319,9 @@ nocache_index_getattr(IndexTuple tup, /* * If slow is false, and we got here, we know that we have a tuple - * with no nulls or var-widths before the target attribute. If possible, - * we also want to initialize the remainder of the attribute cached - * offset values. + * with no nulls or var-widths before the target attribute. If + * possible, we also want to initialize the remainder of the attribute + * cached offset values. */ if (!slow) { diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c index db4187dba4..f1f96f1886 100644 --- a/src/backend/access/common/printtup.c +++ b/src/backend/access/common/printtup.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.64 2002/08/24 15:00:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.65 2002/09/04 20:31:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -23,7 +23,7 @@ static void printtup_setup(DestReceiver *self, int operation, - const char *portalName, TupleDesc typeinfo); + const char *portalName, TupleDesc typeinfo); static void printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self); static void printtup_internal(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self); static void printtup_cleanup(DestReceiver *self); @@ -88,8 +88,8 @@ printtup_setup(DestReceiver *self, int operation, pq_puttextmessage('P', portalName); /* - * if this is a retrieve, then we send back the tuple - * descriptor of the tuples. + * if this is a retrieve, then we send back the tuple descriptor of + * the tuples. */ if (operation == CMD_SELECT) { @@ -100,7 +100,7 @@ printtup_setup(DestReceiver *self, int operation, pq_beginmessage(&buf); pq_sendbyte(&buf, 'T'); /* tuple descriptor message type */ - pq_sendint(&buf, natts, 2); /* # of attrs in tuples */ + pq_sendint(&buf, natts, 2); /* # of attrs in tuples */ for (i = 0; i < natts; ++i) { diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index 6d6cdf38ce..ce4452eec5 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.88 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.89 2002/09/04 20:31:09 momjian Exp $ * * NOTES * some of the executor utility code such as "ExecTypeFromTL" should be @@ -114,8 +114,8 @@ CreateTupleDescCopy(TupleDesc tupdesc) { desc->attrs[i] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE); memcpy(desc->attrs[i], - tupdesc->attrs[i], - ATTRIBUTE_TUPLE_SIZE); + tupdesc->attrs[i], + ATTRIBUTE_TUPLE_SIZE); desc->attrs[i]->attnotnull = false; desc->attrs[i]->atthasdef = false; } @@ -148,8 +148,8 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc) { desc->attrs[i] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE); memcpy(desc->attrs[i], - tupdesc->attrs[i], - ATTRIBUTE_TUPLE_SIZE); + tupdesc->attrs[i], + ATTRIBUTE_TUPLE_SIZE); } if (constr) { @@ -425,9 +425,8 @@ TupleDescInitEntry(TupleDesc desc, * * (Why not just make the atttypid point to the OID type, instead of the * type the query returns? Because the executor uses the atttypid to - * tell the front end what type will be returned, - * and in the end the type returned will be the result of the query, - * not an OID.) + * tell the front end what type will be returned, and in the end the + * type returned will be the result of the query, not an OID.) * * (Why not wait until the return type of the set is known (i.e., the * recursive call to the executor to execute the set has returned) diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c index 2849ca31ec..c238ea273e 100644 --- a/src/backend/access/gist/gist.c +++ b/src/backend/access/gist/gist.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.95 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.96 2002/09/04 20:31:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -294,6 +294,7 @@ gistinsert(PG_FUNCTION_ARGS) Datum *datum = (Datum *) PG_GETARG_POINTER(1); char *nulls = (char *) PG_GETARG_POINTER(2); ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3); + #ifdef NOT_USED Relation heapRel = (Relation) PG_GETARG_POINTER(4); bool checkUnique = PG_GETARG_BOOL(5); @@ -494,13 +495,13 @@ gistlayerinsert(Relation r, BlockNumber blkno, /* key is modified, so old version must be deleted */ ItemPointerSet(&oldtid, blkno, child); gistdelete(r, &oldtid); - + /* - * if child was splitted, new key for child will be inserted - * in the end list of child, so we must say to any scans - * that page is changed beginning from 'child' offset + * if child was splitted, new key for child will be inserted in + * the end list of child, so we must say to any scans that page is + * changed beginning from 'child' offset */ - if ( ret & SPLITED ) + if (ret & SPLITED) gistadjscans(r, GISTOP_SPLIT, blkno, child); } @@ -615,7 +616,7 @@ gistwritebuffer(Relation r, Page page, IndexTuple *itup, static int gistnospace(Page page, IndexTuple *itvec, int len) { - unsigned int size = 0; + unsigned int size = 0; int i; for (i = 0; i < len; i++) @@ -679,7 +680,7 @@ gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate) needfree = (bool *) palloc(((len == 1) ? 2 : len) * sizeof(bool)); /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */ - storage = (char*)palloc( ((len == 1) ? 2 : len) * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); + storage = (char *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ); for (j = 0; j < r->rd_att->natts; j++) @@ -786,7 +787,7 @@ gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *gis int j; /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */ - storage = (char*) palloc( 2 * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); + storage = (char *) palloc(2 * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ); VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ; ev0p = &((GISTENTRY *) VARDATA(evec))[0]; @@ -911,7 +912,7 @@ gistunionsubkey(Relation r, GISTSTATE *giststate, IndexTuple *itvec, GIST_SPLITV needfree = (bool *) palloc(((len == 1) ? 2 : len) * sizeof(bool)); /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */ - storage = (char*)palloc( ((len == 1) ? 2 : len) * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); + storage = (char *) palloc(((len == 1) ? 2 : len) * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ); for (j = 1; j < r->rd_att->natts; j++) @@ -1098,7 +1099,7 @@ gistadjsubkey(Relation r, v->spl_nright = curlen; /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */ - storage = (char*)palloc( 2 * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); + storage = (char *) palloc(2 * sizeof(GISTENTRY) + MAXALIGN(VARHDRSZ)); evec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ); VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ; ev0p = &((GISTENTRY *) VARDATA(evec))[0]; @@ -1276,7 +1277,7 @@ gistSplit(Relation r, /* workaround for 64-bit: ensure GISTENTRY array is maxaligned */ storage = palloc(MAXALIGN(VARHDRSZ) + (*len + 1) * sizeof(GISTENTRY)); entryvec = (bytea *) (storage + MAXALIGN(VARHDRSZ) - VARHDRSZ); - decompvec = (bool *) palloc( (*len + 1) * sizeof(bool)); + decompvec = (bool *) palloc((*len + 1) * sizeof(bool)); VARATT_SIZEP(entryvec) = (*len + 1) * sizeof(GISTENTRY) + VARHDRSZ; for (i = 1; i <= *len; i++) { diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c index aaa26b41d2..2f5801fe78 100644 --- a/src/backend/access/gist/gistget.c +++ b/src/backend/access/gist/gistget.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.34 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/gist/gistget.c,v 1.35 2002/09/04 20:31:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,7 +33,7 @@ gistgettuple(PG_FUNCTION_ARGS) { IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0); ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1); - bool res; + bool res; /* if we have it cached in the scan desc, just return the value */ if (gistscancache(s, dir)) diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c index 9a6ca258bc..3a75265f01 100644 --- a/src/backend/access/hash/hash.c +++ b/src/backend/access/hash/hash.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.59 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.60 2002/09/04 20:31:09 momjian Exp $ * * NOTES * This file contains only the public interface routines. @@ -164,6 +164,7 @@ hashinsert(PG_FUNCTION_ARGS) Datum *datum = (Datum *) PG_GETARG_POINTER(1); char *nulls = (char *) PG_GETARG_POINTER(2); ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3); + #ifdef NOT_USED Relation heapRel = (Relation) PG_GETARG_POINTER(4); bool checkUnique = PG_GETARG_BOOL(5); @@ -213,7 +214,7 @@ hashgettuple(PG_FUNCTION_ARGS) HashScanOpaque so = (HashScanOpaque) scan->opaque; Page page; OffsetNumber offnum; - bool res; + bool res; /* * If we've already initialized this scan, we can just advance it in @@ -228,18 +229,21 @@ hashgettuple(PG_FUNCTION_ARGS) if (scan->kill_prior_tuple) { /* - * Yes, so mark it by setting the LP_DELETE bit in the item flags. + * Yes, so mark it by setting the LP_DELETE bit in the item + * flags. */ offnum = ItemPointerGetOffsetNumber(&(scan->currentItemData)); page = BufferGetPage(so->hashso_curbuf); PageGetItemId(page, offnum)->lp_flags |= LP_DELETE; + /* * Since this can be redone later if needed, it's treated the - * same as a commit-hint-bit status update for heap tuples: - * we mark the buffer dirty but don't make a WAL log entry. + * same as a commit-hint-bit status update for heap tuples: we + * mark the buffer dirty but don't make a WAL log entry. */ SetBufferCommitInfoNeedsSave(so->hashso_curbuf); } + /* * Now continue the scan. */ diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c index fb58bccf00..e6595de072 100644 --- a/src/backend/access/hash/hashfunc.c +++ b/src/backend/access/hash/hashfunc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.34 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.35 2002/09/04 20:31:09 momjian Exp $ * * NOTES * These functions are stored in pg_amproc. For each operator class @@ -96,7 +96,8 @@ hashname(PG_FUNCTION_ARGS) char *key = NameStr(*PG_GETARG_NAME(0)); int keylen = strlen(key); - Assert(keylen < NAMEDATALEN); /* else it's not truncated correctly */ + Assert(keylen < NAMEDATALEN); /* else it's not truncated + * correctly */ return hash_any((unsigned char *) key, keylen); } @@ -134,9 +135,9 @@ hashvarlena(PG_FUNCTION_ARGS) * high bits or all three low bits, whether the original value of a,b,c * is almost all zero or is uniformly distributed, * - If mix() is run forward or backward, at least 32 bits in a,b,c - * have at least 1/4 probability of changing. + * have at least 1/4 probability of changing. * - If mix() is run forward, every bit of c will change between 1/3 and - * 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.) + * 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.) *---------- */ #define mix(a,b,c) \ @@ -147,17 +148,17 @@ hashvarlena(PG_FUNCTION_ARGS) a -= b; a -= c; a ^= (c>>12); \ b -= c; b -= a; b ^= (a<<16); \ c -= a; c -= b; c ^= (b>>5); \ - a -= b; a -= c; a ^= (c>>3); \ + a -= b; a -= c; a ^= (c>>3); \ b -= c; b -= a; b ^= (a<<10); \ c -= a; c -= b; c ^= (b>>15); \ } /* * hash_any() -- hash a variable-length key into a 32-bit value - * k : the key (the unaligned variable-length array of bytes) - * len : the length of the key, counting by bytes + * k : the key (the unaligned variable-length array of bytes) + * len : the length of the key, counting by bytes * - * Returns a uint32 value. Every bit of the key affects every bit of + * Returns a uint32 value. Every bit of the key affects every bit of * the return value. Every 1-bit and 2-bit delta achieves avalanche. * About 6*len+35 instructions. The best hash table sizes are powers * of 2. There is no need to do mod a prime (mod is sooo slow!). @@ -166,7 +167,10 @@ hashvarlena(PG_FUNCTION_ARGS) Datum hash_any(register const unsigned char *k, register int keylen) { - register uint32 a,b,c,len; + register uint32 a, + b, + c, + len; /* Set up the internal state */ len = keylen; @@ -176,32 +180,44 @@ hash_any(register const unsigned char *k, register int keylen) /* handle most of the key */ while (len >= 12) { - a += (k[0] +((uint32)k[1]<<8) +((uint32)k[2]<<16) +((uint32)k[3]<<24)); - b += (k[4] +((uint32)k[5]<<8) +((uint32)k[6]<<16) +((uint32)k[7]<<24)); - c += (k[8] +((uint32)k[9]<<8) +((uint32)k[10]<<16)+((uint32)k[11]<<24)); - mix(a,b,c); - k += 12; len -= 12; + a += (k[0] + ((uint32) k[1] << 8) + ((uint32) k[2] << 16) + ((uint32) k[3] << 24)); + b += (k[4] + ((uint32) k[5] << 8) + ((uint32) k[6] << 16) + ((uint32) k[7] << 24)); + c += (k[8] + ((uint32) k[9] << 8) + ((uint32) k[10] << 16) + ((uint32) k[11] << 24)); + mix(a, b, c); + k += 12; + len -= 12; } /* handle the last 11 bytes */ c += keylen; switch (len) /* all the case statements fall through */ { - case 11: c+=((uint32)k[10]<<24); - case 10: c+=((uint32)k[9]<<16); - case 9 : c+=((uint32)k[8]<<8); + case 11: + c += ((uint32) k[10] << 24); + case 10: + c += ((uint32) k[9] << 16); + case 9: + c += ((uint32) k[8] << 8); /* the first byte of c is reserved for the length */ - case 8 : b+=((uint32)k[7]<<24); - case 7 : b+=((uint32)k[6]<<16); - case 6 : b+=((uint32)k[5]<<8); - case 5 : b+=k[4]; - case 4 : a+=((uint32)k[3]<<24); - case 3 : a+=((uint32)k[2]<<16); - case 2 : a+=((uint32)k[1]<<8); - case 1 : a+=k[0]; + case 8: + b += ((uint32) k[7] << 24); + case 7: + b += ((uint32) k[6] << 16); + case 6: + b += ((uint32) k[5] << 8); + case 5: + b += k[4]; + case 4: + a += ((uint32) k[3] << 24); + case 3: + a += ((uint32) k[2] << 16); + case 2: + a += ((uint32) k[1] << 8); + case 1: + a += k[0]; /* case 0: nothing left to add */ } - mix(a,b,c); + mix(a, b, c); /* report the result */ return UInt32GetDatum(c); } diff --git a/src/backend/access/hash/hashscan.c b/src/backend/access/hash/hashscan.c index b597fc196a..272e182b6e 100644 --- a/src/backend/access/hash/hashscan.c +++ b/src/backend/access/hash/hashscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/hash/hashscan.c,v 1.28 2002/06/20 20:29:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/hash/hashscan.c,v 1.29 2002/09/04 20:31:09 momjian Exp $ * * NOTES * Because we can be doing an index scan on a relation while we @@ -45,7 +45,7 @@ static HashScanList HashScans = (HashScanList) NULL; static void _hash_scandel(IndexScanDesc scan, - BlockNumber blkno, OffsetNumber offno); + BlockNumber blkno, OffsetNumber offno); /* @@ -158,7 +158,7 @@ _hash_scandel(IndexScanDesc scan, BlockNumber blkno, OffsetNumber offno) * then step backwards (affecting current), then exchange again. */ ItemPointerData tmpitem; - Buffer tmpbuf; + Buffer tmpbuf; tmpitem = *mark; *mark = *current; diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 9acd6b3385..d7df449a63 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,12 +8,12 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.147 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.148 2002/09/04 20:31:09 momjian Exp $ * * * INTERFACE ROUTINES * relation_open - open any relation by relation OID - * relation_openrv - open any relation specified by a RangeVar + * relation_openrv - open any relation specified by a RangeVar * relation_openr - open a system relation by name * relation_close - close any relation * heap_open - open a heap relation by relation OID @@ -306,7 +306,7 @@ heapgettup(Relation relation, { if (ItemIdIsUsed(lpp)) { - bool valid; + bool valid; tuple->t_datamcxt = NULL; tuple->t_data = (HeapTupleHeader) PageGetItem((Page) dp, lpp); @@ -985,8 +985,8 @@ heap_fetch(Relation relation, *userbuf = buffer; /* - * Count the successful fetch in *pgstat_info if given, - * otherwise in the relation's default statistics area. + * Count the successful fetch in *pgstat_info if given, otherwise + * in the relation's default statistics area. */ if (pgstat_info != NULL) pgstat_count_heap_fetch(pgstat_info); @@ -1120,6 +1120,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid) /* this is redundant with an Assert in HeapTupleSetOid */ Assert(tup->t_data->t_infomask & HEAP_HASOID); #endif + /* * If the object id of this tuple has already been assigned, trust * the caller. There are a couple of ways this can happen. At @@ -1224,10 +1225,10 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid) WriteBuffer(buffer); /* - * If tuple is cachable, mark it for invalidation from the caches in case - * we abort. Note it is OK to do this after WriteBuffer releases the - * buffer, because the "tup" data structure is all in local memory, - * not in the shared buffer. + * If tuple is cachable, mark it for invalidation from the caches in + * case we abort. Note it is OK to do this after WriteBuffer releases + * the buffer, because the "tup" data structure is all in local + * memory, not in the shared buffer. */ CacheInvalidateHeapTuple(relation, tup); @@ -1379,6 +1380,7 @@ l1: LockBuffer(buffer, BUFFER_LOCK_UNLOCK); #ifdef TUPLE_TOASTER_ACTIVE + /* * If the relation has toastable attributes, we need to delete no * longer needed items there too. We have to do this before @@ -1728,10 +1730,10 @@ l2: WriteBuffer(buffer); /* - * If new tuple is cachable, mark it for invalidation from the caches in - * case we abort. Note it is OK to do this after WriteBuffer releases - * the buffer, because the "newtup" data structure is all in local - * memory, not in the shared buffer. + * If new tuple is cachable, mark it for invalidation from the caches + * in case we abort. Note it is OK to do this after WriteBuffer + * releases the buffer, because the "newtup" data structure is all in + * local memory, not in the shared buffer. */ CacheInvalidateHeapTuple(relation, newtup); @@ -2045,16 +2047,16 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from, xlhdr.hdr.mask = newtup->t_data->t_infomask; if (move) /* remember xmin & xmax */ { - TransactionId xid[2]; /* xmax, xmin */ + TransactionId xid[2]; /* xmax, xmin */ if (newtup->t_data->t_infomask & (HEAP_XMAX_INVALID | - HEAP_MARKED_FOR_UPDATE)) + HEAP_MARKED_FOR_UPDATE)) xid[0] = InvalidTransactionId; else xid[0] = HeapTupleHeaderGetXmax(newtup->t_data); xid[1] = HeapTupleHeaderGetXmin(newtup->t_data); memcpy((char *) &xlhdr + hsize, - (char *) xid, + (char *) xid, 2 * sizeof(TransactionId)); hsize += 2 * sizeof(TransactionId); } @@ -2143,7 +2145,7 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record) PageRepairFragmentation(page, NULL); PageSetLSN(page, lsn); - PageSetSUI(page, ThisStartUpID); /* prev sui */ + PageSetSUI(page, ThisStartUpID); /* prev sui */ UnlockAndWriteBuffer(buffer); } @@ -2463,11 +2465,11 @@ newsame:; if (move) { - TransactionId xid[2]; /* xmax, xmin */ - + TransactionId xid[2]; /* xmax, xmin */ + hsize = SizeOfHeapUpdate + SizeOfHeapHeader; memcpy((char *) xid, - (char *) xlrec + hsize, 2 * sizeof(TransactionId)); + (char *) xlrec + hsize, 2 * sizeof(TransactionId)); htup->t_infomask = xlhdr.mask; htup->t_infomask &= ~(HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID | diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c index ab6eff8262..f8a883b150 100644 --- a/src/backend/access/heap/tuptoaster.c +++ b/src/backend/access/heap/tuptoaster.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.35 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.36 2002/09/04 20:31:09 momjian Exp $ * * * INTERFACE ROUTINES @@ -46,7 +46,7 @@ static void toast_insert_or_update(Relation rel, HeapTuple newtup, static Datum toast_save_datum(Relation rel, Datum value); static varattrib *toast_fetch_datum(varattrib *attr); static varattrib *toast_fetch_datum_slice(varattrib *attr, - int32 sliceoffset, int32 length); + int32 sliceoffset, int32 length); /* ---------- @@ -165,73 +165,68 @@ heap_tuple_untoast_attr(varattrib *attr) /* ---------- * heap_tuple_untoast_attr_slice - * - * Public entry point to get back part of a toasted value - * from compression or external storage. + * Public entry point to get back part of a toasted value + * from compression or external storage. * ---------- */ -varattrib * +varattrib * heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelength) { varattrib *preslice; varattrib *result; - int32 attrsize; - + int32 attrsize; + if (VARATT_IS_COMPRESSED(attr)) { - varattrib *tmp; - + varattrib *tmp; + if (VARATT_IS_EXTERNAL(attr)) - { tmp = toast_fetch_datum(attr); - } else { - tmp = attr; /* compressed in main tuple */ + tmp = attr; /* compressed in main tuple */ } - + preslice = (varattrib *) palloc(attr->va_content.va_external.va_rawsize + VARHDRSZ); VARATT_SIZEP(preslice) = attr->va_content.va_external.va_rawsize + VARHDRSZ; pglz_decompress((PGLZ_Header *) tmp, VARATT_DATA(preslice)); - - if (tmp != attr) + + if (tmp != attr) pfree(tmp); } - else + else { /* Plain value */ if (VARATT_IS_EXTERNAL(attr)) - { + { /* fast path */ return (toast_fetch_datum_slice(attr, sliceoffset, slicelength)); } else - { preslice = attr; - } } - + /* slicing of datum for compressed cases and plain value */ - + attrsize = VARSIZE(preslice) - VARHDRSZ; - if (sliceoffset >= attrsize) + if (sliceoffset >= attrsize) { sliceoffset = 0; slicelength = 0; } - + if (((sliceoffset + slicelength) > attrsize) || slicelength < 0) - { slicelength = attrsize - sliceoffset; - } - + result = (varattrib *) palloc(slicelength + VARHDRSZ); VARATT_SIZEP(result) = slicelength + VARHDRSZ; - + memcpy(VARDATA(result), VARDATA(preslice) + sliceoffset, slicelength); - - if (preslice != attr) pfree(preslice); - + + if (preslice != attr) + pfree(preslice); + return result; } @@ -1053,9 +1048,9 @@ toast_fetch_datum(varattrib *attr) /* * Read the chunks by index * - * Note that because the index is actually on (valueid, chunkidx) - * we will see the chunks in chunkidx order, even though we didn't - * explicitly ask for it. + * Note that because the index is actually on (valueid, chunkidx) we will + * see the chunks in chunkidx order, even though we didn't explicitly + * ask for it. */ nextidx = 0; @@ -1146,45 +1141,44 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length) varattrib *result; int32 attrsize; int32 residx; - int32 nextidx; - int numchunks; - int startchunk; - int endchunk; + int32 nextidx; + int numchunks; + int startchunk; + int endchunk; int32 startoffset; int32 endoffset; - int totalchunks; + int totalchunks; Pointer chunk; bool isnull; int32 chunksize; - int32 chcpystrt; - int32 chcpyend; + int32 chcpystrt; + int32 chcpyend; attrsize = attr->va_content.va_external.va_extsize; totalchunks = ((attrsize - 1) / TOAST_MAX_CHUNK_SIZE) + 1; - if (sliceoffset >= attrsize) + if (sliceoffset >= attrsize) { - sliceoffset = 0; - length = 0; + sliceoffset = 0; + length = 0; } if (((sliceoffset + length) > attrsize) || length < 0) - { - length = attrsize - sliceoffset; - } + length = attrsize - sliceoffset; result = (varattrib *) palloc(length + VARHDRSZ); VARATT_SIZEP(result) = length + VARHDRSZ; if (VARATT_IS_COMPRESSED(attr)) VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED; - - if (length == 0) return (result); /* Can save a lot of work at this point! */ + + if (length == 0) + return (result); /* Can save a lot of work at this point! */ startchunk = sliceoffset / TOAST_MAX_CHUNK_SIZE; endchunk = (sliceoffset + length - 1) / TOAST_MAX_CHUNK_SIZE; - numchunks = (endchunk - startchunk ) + 1; - + numchunks = (endchunk - startchunk) + 1; + startoffset = sliceoffset % TOAST_MAX_CHUNK_SIZE; endoffset = (sliceoffset + length - 1) % TOAST_MAX_CHUNK_SIZE; @@ -1204,33 +1198,34 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length) (bits16) 0, (AttrNumber) 1, (RegProcedure) F_OIDEQ, - ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); + ObjectIdGetDatum(attr->va_content.va_external.va_valueid)); + /* * Now dependent on number of chunks: */ - - if (numchunks == 1) + + if (numchunks == 1) { - ScanKeyEntryInitialize(&toastkey[1], + ScanKeyEntryInitialize(&toastkey[1], (bits16) 0, (AttrNumber) 2, (RegProcedure) F_INT4EQ, Int32GetDatum(startchunk)); - nscankeys = 2; + nscankeys = 2; } else { - ScanKeyEntryInitialize(&toastkey[1], + ScanKeyEntryInitialize(&toastkey[1], (bits16) 0, (AttrNumber) 2, (RegProcedure) F_INT4GE, Int32GetDatum(startchunk)); - ScanKeyEntryInitialize(&toastkey[2], + ScanKeyEntryInitialize(&toastkey[2], (bits16) 0, (AttrNumber) 2, (RegProcedure) F_INT4LE, Int32GetDatum(endchunk)); - nscankeys = 3; + nscankeys = 3; } /* @@ -1279,21 +1274,23 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length) */ chcpystrt = 0; chcpyend = chunksize - 1; - if (residx == startchunk) chcpystrt = startoffset; - if (residx == endchunk) chcpyend = endoffset; - - memcpy(((char *) VARATT_DATA(result)) + - (residx * TOAST_MAX_CHUNK_SIZE - sliceoffset) +chcpystrt, + if (residx == startchunk) + chcpystrt = startoffset; + if (residx == endchunk) + chcpyend = endoffset; + + memcpy(((char *) VARATT_DATA(result)) + + (residx * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt, VARATT_DATA(chunk) + chcpystrt, (chcpyend - chcpystrt) + 1); - + nextidx++; } /* * Final checks that we successfully fetched the datum */ - if ( nextidx != (endchunk + 1)) + if (nextidx != (endchunk + 1)) elog(ERROR, "missing chunk number %d for toast value %u", nextidx, attr->va_content.va_external.va_valueid); diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c index 9bf88a795a..2a21e2962e 100644 --- a/src/backend/access/index/genam.c +++ b/src/backend/access/index/genam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.35 2002/06/20 20:29:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/index/genam.c,v 1.36 2002/09/04 20:31:09 momjian Exp $ * * NOTES * many of the old access method routines have been turned into @@ -77,7 +77,7 @@ RelationGetIndexScan(Relation indexRelation, scan->heapRelation = NULL; /* may be set later */ scan->indexRelation = indexRelation; - scan->xs_snapshot = SnapshotNow; /* may be set later */ + scan->xs_snapshot = SnapshotNow; /* may be set later */ scan->numberOfKeys = nkeys; /* @@ -90,8 +90,8 @@ RelationGetIndexScan(Relation indexRelation, scan->keyData = NULL; scan->kill_prior_tuple = false; - scan->ignore_killed_tuples = true; /* default setting */ - scan->keys_are_unique = false; /* may be set by amrescan */ + scan->ignore_killed_tuples = true; /* default setting */ + scan->keys_are_unique = false; /* may be set by amrescan */ scan->got_tuple = false; scan->opaque = NULL; @@ -201,6 +201,7 @@ systable_beginscan(Relation heapRelation, /* We assume it's a system index, so index_openr is OK */ sysscan->irel = irel = index_openr(indexRelname); + /* * Change attribute numbers to be index column numbers. * @@ -210,7 +211,7 @@ systable_beginscan(Relation heapRelation, for (i = 0; i < nkeys; i++) { Assert(key[i].sk_attno == irel->rd_index->indkey[i]); - key[i].sk_attno = i+1; + key[i].sk_attno = i + 1; } sysscan->iscan = index_beginscan(heapRelation, irel, snapshot, nkeys, key); diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c index fc53aeffb4..d2e11d2a8d 100644 --- a/src/backend/access/index/indexam.c +++ b/src/backend/access/index/indexam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.61 2002/06/20 20:29:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/index/indexam.c,v 1.62 2002/09/04 20:31:09 momjian Exp $ * * INTERFACE ROUTINES * index_open - open an index relation by relation OID @@ -272,8 +272,8 @@ index_beginscan(Relation heapRelation, PointerGetDatum(key))); /* - * Save additional parameters into the scandesc. Everything else - * was set up by RelationGetIndexScan. + * Save additional parameters into the scandesc. Everything else was + * set up by RelationGetIndexScan. */ scan->heapRelation = heapRelation; scan->xs_snapshot = snapshot; @@ -293,7 +293,7 @@ index_beginscan(Relation heapRelation, * index_rescan - (re)start a scan of an index * * The caller may specify a new set of scankeys (but the number of keys - * cannot change). Note that this is also called when first starting + * cannot change). Note that this is also called when first starting * an indexscan; see RelationGetIndexScan. * ---------------- */ @@ -305,8 +305,8 @@ index_rescan(IndexScanDesc scan, ScanKey key) SCAN_CHECKS; GET_SCAN_PROCEDURE(rescan, amrescan); - scan->kill_prior_tuple = false; /* for safety */ - scan->keys_are_unique = false; /* may be set by amrescan */ + scan->kill_prior_tuple = false; /* for safety */ + scan->keys_are_unique = false; /* may be set by amrescan */ scan->got_tuple = false; OidFunctionCall2(procedure, @@ -375,7 +375,7 @@ index_restrpos(IndexScanDesc scan) SCAN_CHECKS; GET_SCAN_PROCEDURE(restrpos, amrestrpos); - scan->kill_prior_tuple = false; /* for safety */ + scan->kill_prior_tuple = false; /* for safety */ scan->got_tuple = false; OidFunctionCall1(procedure, PointerGetDatum(scan)); @@ -385,7 +385,7 @@ index_restrpos(IndexScanDesc scan) * index_getnext - get the next heap tuple from a scan * * The result is the next heap tuple satisfying the scan keys and the - * snapshot, or NULL if no more matching tuples exist. On success, + * snapshot, or NULL if no more matching tuples exist. On success, * the buffer containing the heap tuple is pinned (the pin will be dropped * at the next index_getnext or index_endscan). The index TID corresponding * to the heap tuple can be obtained if needed from scan->currentItemData. @@ -409,8 +409,8 @@ index_getnext(IndexScanDesc scan, ScanDirection direction) scan->kill_prior_tuple = false; /* - * Can skip entering the index AM if we already got a tuple - * and it must be unique. + * Can skip entering the index AM if we already got a tuple and it + * must be unique. */ if (scan->keys_are_unique && scan->got_tuple) return NULL; @@ -454,9 +454,9 @@ index_getnext(IndexScanDesc scan, ScanDirection direction) * index AM to not return it on future indexscans. * * We told heap_fetch to keep a pin on the buffer, so we can - * re-access the tuple here. But we must re-lock the buffer first. - * Also, it's just barely possible for an update of hint bits to - * occur here. + * re-access the tuple here. But we must re-lock the buffer + * first. Also, it's just barely possible for an update of hint + * bits to occur here. */ LockBuffer(scan->xs_cbuf, BUFFER_LOCK_SHARE); sv_infomask = heapTuple->t_data->t_infomask; @@ -497,7 +497,7 @@ bool index_getnext_indexitem(IndexScanDesc scan, ScanDirection direction) { - bool found; + bool found; SCAN_CHECKS; @@ -642,10 +642,11 @@ index_getprocinfo(Relation irel, procId = loc[procindex]; /* - * Complain if function was not found during IndexSupportInitialize. - * This should not happen unless the system tables contain bogus - * entries for the index opclass. (If an AM wants to allow a - * support function to be optional, it can use index_getprocid.) + * Complain if function was not found during + * IndexSupportInitialize. This should not happen unless the + * system tables contain bogus entries for the index opclass. (If + * an AM wants to allow a support function to be optional, it can + * use index_getprocid.) */ if (!RegProcedureIsValid(procId)) elog(ERROR, "Missing support function %d for attribute %d of index %s", diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index 16d63e03c9..99011a5c95 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.95 2002/08/06 02:36:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.96 2002/09/04 20:31:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -119,14 +119,14 @@ top: * * NOTE: obviously, _bt_check_unique can only detect keys that are * already in the index; so it cannot defend against concurrent - * insertions of the same key. We protect against that by means - * of holding a write lock on the target page. Any other would-be + * insertions of the same key. We protect against that by means of + * holding a write lock on the target page. Any other would-be * inserter of the same key must acquire a write lock on the same * target page, so only one would-be inserter can be making the check - * at one time. Furthermore, once we are past the check we hold - * write locks continuously until we have performed our insertion, - * so no later inserter can fail to see our insertion. (This - * requires some care in _bt_insertonpg.) + * at one time. Furthermore, once we are past the check we hold write + * locks continuously until we have performed our insertion, so no + * later inserter can fail to see our insertion. (This requires some + * care in _bt_insertonpg.) * * If we must wait for another xact, we release the lock while waiting, * and then must start over completely. @@ -205,15 +205,16 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel, if (offset <= maxoff) { /* - * _bt_compare returns 0 for (1,NULL) and (1,NULL) - this's how we - * handling NULLs - and so we must not use _bt_compare in real - * comparison, but only for ordering/finding items on pages. - - * vadim 03/24/97 + * _bt_compare returns 0 for (1,NULL) and (1,NULL) - this's + * how we handling NULLs - and so we must not use _bt_compare + * in real comparison, but only for ordering/finding items on + * pages. - vadim 03/24/97 */ if (!_bt_isequal(itupdesc, page, offset, natts, itup_scankey)) break; /* we're past all the equal tuples */ curitemid = PageGetItemId(page, offset); + /* * We can skip the heap fetch if the item is marked killed. */ @@ -226,10 +227,11 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel, { /* it is a duplicate */ TransactionId xwait = - (TransactionIdIsValid(SnapshotDirty->xmin)) ? - SnapshotDirty->xmin : SnapshotDirty->xmax; + (TransactionIdIsValid(SnapshotDirty->xmin)) ? + SnapshotDirty->xmin : SnapshotDirty->xmax; ReleaseBuffer(hbuffer); + /* * If this tuple is being updated by other transaction * then we have to wait for its commit/abort. @@ -252,8 +254,8 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel, { /* * Hmm, if we can't see the tuple, maybe it can be - * marked killed. This logic should match index_getnext - * and btgettuple. + * marked killed. This logic should match + * index_getnext and btgettuple. */ uint16 sv_infomask; @@ -421,7 +423,7 @@ _bt_insertonpg(Relation rel, { /* step right one page */ BlockNumber rblkno = lpageop->btpo_next; - Buffer rbuf; + Buffer rbuf; /* * must write-lock next page before releasing write lock on diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 46787e577a..ac46681c61 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -12,7 +12,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.91 2002/06/20 20:29:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.92 2002/09/04 20:31:10 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -315,24 +315,28 @@ btgettuple(PG_FUNCTION_ARGS) * buffer, too. */ _bt_restscan(scan); + /* * Check to see if we should kill the previously-fetched tuple. */ if (scan->kill_prior_tuple) { /* - * Yes, so mark it by setting the LP_DELETE bit in the item flags. + * Yes, so mark it by setting the LP_DELETE bit in the item + * flags. */ offnum = ItemPointerGetOffsetNumber(&(scan->currentItemData)); page = BufferGetPage(so->btso_curbuf); PageGetItemId(page, offnum)->lp_flags |= LP_DELETE; + /* * Since this can be redone later if needed, it's treated the - * same as a commit-hint-bit status update for heap tuples: - * we mark the buffer dirty but don't make a WAL log entry. + * same as a commit-hint-bit status update for heap tuples: we + * mark the buffer dirty but don't make a WAL log entry. */ SetBufferCommitInfoNeedsSave(so->btso_curbuf); } + /* * Now continue the scan. */ @@ -645,15 +649,15 @@ btbulkdelete(PG_FUNCTION_ARGS) /* * If this is first deletion on this page, trade in read * lock for a really-exclusive write lock. Then, step - * back one and re-examine the item, because other backends - * might have inserted item(s) while we weren't holding - * the lock! + * back one and re-examine the item, because other + * backends might have inserted item(s) while we weren't + * holding the lock! * * We assume that only concurrent insertions, not deletions, - * can occur while we're not holding the page lock (the caller - * should hold a suitable relation lock to ensure this). - * Therefore, the item we want to delete is either in the - * same slot as before, or some slot to its right. + * can occur while we're not holding the page lock (the + * caller should hold a suitable relation lock to ensure + * this). Therefore, the item we want to delete is either + * in the same slot as before, or some slot to its right. * Rechecking the same slot is necessary and sufficient to * get back in sync after any insertions. */ @@ -675,19 +679,19 @@ btbulkdelete(PG_FUNCTION_ARGS) } /* - * In either case, we now need to back up the scan one item, - * so that the next cycle will re-examine the same offnum on - * this page. + * In either case, we now need to back up the scan one + * item, so that the next cycle will re-examine the same + * offnum on this page. * * For now, just hack the current-item index. Will need to * be smarter when deletion includes removal of empty * index pages. * * We must decrement ip_posid in all cases but one: if the - * page was formerly rightmost but was split while we didn't - * hold the lock, and ip_posid is pointing to item 1, then - * ip_posid now points at the high key not a valid data item. - * In this case we do want to step forward. + * page was formerly rightmost but was split while we + * didn't hold the lock, and ip_posid is pointing to item + * 1, then ip_posid now points at the high key not a valid + * data item. In this case we do want to step forward. */ opaque = (BTPageOpaque) PageGetSpecialPointer(page); if (current->ip_posid >= P_FIRSTDATAKEY(opaque)) diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c index 999c3ba462..50fe3312cc 100644 --- a/src/backend/access/nbtree/nbtutils.c +++ b/src/backend/access/nbtree/nbtutils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.50 2002/06/20 20:29:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.51 2002/09/04 20:31:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -22,7 +22,7 @@ #include "executor/execdebug.h" -static int _bt_getstrategynumber(RegProcedure sk_procedure, StrategyMap map); +static int _bt_getstrategynumber(RegProcedure sk_procedure, StrategyMap map); /* @@ -178,7 +178,7 @@ _bt_formitem(IndexTuple itup) * example. * * Furthermore, we detect the case where the index is unique and we have - * equality quals for all columns. In this case there can be at most one + * equality quals for all columns. In this case there can be at most one * (visible) matching tuple. index_getnext uses this to avoid uselessly * continuing the scan after finding one match. * @@ -439,8 +439,8 @@ _bt_orderkeys(IndexScanDesc scan) so->numberOfKeys = new_numberOfKeys; /* - * If unique index and we have equality keys for all columns, - * set keys_are_unique flag for higher levels. + * If unique index and we have equality keys for all columns, set + * keys_are_unique flag for higher levels. */ if (allEqualSoFar && relation->rd_index->indisunique && relation->rd_rel->relnatts == new_numberOfKeys) diff --git a/src/backend/access/rtree/rtget.c b/src/backend/access/rtree/rtget.c index 87ebb60559..9a21954c17 100644 --- a/src/backend/access/rtree/rtget.c +++ b/src/backend/access/rtree/rtget.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.27 2002/06/20 20:29:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.28 2002/09/04 20:31:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,7 @@ rtgettuple(PG_FUNCTION_ARGS) { IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0); ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1); - bool res; + bool res; /* if we have it cached in the scan desc, just return the value */ if (rtscancache(s, dir)) diff --git a/src/backend/access/rtree/rtree.c b/src/backend/access/rtree/rtree.c index 957b9865c5..650820085c 100644 --- a/src/backend/access/rtree/rtree.c +++ b/src/backend/access/rtree/rtree.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.74 2002/06/25 17:26:11 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.75 2002/09/04 20:31:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -223,6 +223,7 @@ rtinsert(PG_FUNCTION_ARGS) Datum *datum = (Datum *) PG_GETARG_POINTER(1); char *nulls = (char *) PG_GETARG_POINTER(2); ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3); + #ifdef NOT_USED Relation heapRel = (Relation) PG_GETARG_POINTER(4); bool checkUnique = PG_GETARG_BOOL(5); diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c index c4ca0c7071..3d3816430a 100644 --- a/src/backend/access/transam/transam.c +++ b/src/backend/access/transam/transam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.53 2002/06/20 20:29:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.54 2002/09/04 20:31:13 momjian Exp $ * * NOTES * This file contains the high level access-method interface to the @@ -27,7 +27,7 @@ * Flag indicating that we are bootstrapping. * * Transaction ID generation is disabled during bootstrap; we just use - * BootstrapTransactionId. Also, the transaction ID status-check routines + * BootstrapTransactionId. Also, the transaction ID status-check routines * are short-circuited; they claim that BootstrapTransactionId has already * committed, allowing tuples already inserted to be seen immediately. * ---------------- diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 4b8e76085b..6453bad761 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -6,7 +6,7 @@ * Copyright (c) 2000, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.50 2002/06/11 13:40:50 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.51 2002/09/04 20:31:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -68,12 +68,12 @@ GetNewTransactionId(void) * might see a partially-set xid here. But holding both locks at once * would be a nasty concurrency hit (and in fact could cause a * deadlock against GetSnapshotData). So for now, assume atomicity. - * Note that readers of PGPROC xid field should be careful to fetch the - * value only once, rather than assume they can read it multiple times - * and get the same answer each time. + * Note that readers of PGPROC xid field should be careful to fetch + * the value only once, rather than assume they can read it multiple + * times and get the same answer each time. * - * A solution to the atomic-store problem would be to give each PGPROC its - * own spinlock used only for fetching/storing that PGPROC's xid. + * A solution to the atomic-store problem would be to give each PGPROC + * its own spinlock used only for fetching/storing that PGPROC's xid. * (SInvalLock would then mean primarily that PROCs couldn't be added/ * removed while holding the lock.) */ diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 1c1121e3e1..fd401e963e 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.131 2002/08/30 22:18:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.132 2002/09/04 20:31:13 momjian Exp $ * * NOTES * Transaction aborts can now occur two ways: @@ -265,7 +265,6 @@ SetTransactionFlushEnabled(bool state) { TransactionFlushState = (state == true); } - #endif @@ -421,7 +420,7 @@ CommandCounterIncrement(void) TransactionState s = CurrentTransactionState; s->commandId += 1; - if (s->commandId == FirstCommandId) /* check for overflow */ + if (s->commandId == FirstCommandId) /* check for overflow */ elog(ERROR, "You may only have 2^32-1 commands per transaction"); /* Propagate new command ID into query snapshots, if set */ @@ -517,8 +516,8 @@ void RecordTransactionCommit(void) { /* - * If we made neither any XLOG entries nor any temp-rel updates, - * we can omit recording the transaction commit at all. + * If we made neither any XLOG entries nor any temp-rel updates, we + * can omit recording the transaction commit at all. */ if (MyXactMadeXLogEntry || MyXactMadeTempRelUpdate) { @@ -531,10 +530,10 @@ RecordTransactionCommit(void) START_CRIT_SECTION(); /* - * We only need to log the commit in xlog if the transaction made any - * transaction-controlled XLOG entries. (Otherwise, its XID appears - * nowhere in permanent storage, so no one else will ever care if it - * committed.) + * We only need to log the commit in xlog if the transaction made + * any transaction-controlled XLOG entries. (Otherwise, its XID + * appears nowhere in permanent storage, so no one else will ever + * care if it committed.) */ if (MyLastRecPtr.xrecoff != 0) { @@ -560,20 +559,20 @@ RecordTransactionCommit(void) } /* - * We must flush our XLOG entries to disk if we made any XLOG entries, - * whether in or out of transaction control. For example, if we - * reported a nextval() result to the client, this ensures that any - * XLOG record generated by nextval will hit the disk before we report - * the transaction committed. + * We must flush our XLOG entries to disk if we made any XLOG + * entries, whether in or out of transaction control. For + * example, if we reported a nextval() result to the client, this + * ensures that any XLOG record generated by nextval will hit the + * disk before we report the transaction committed. */ if (MyXactMadeXLogEntry) { /* * Sleep before flush! So we can flush more than one commit - * records per single fsync. (The idea is some other backend may - * do the XLogFlush while we're sleeping. This needs work still, - * because on most Unixen, the minimum select() delay is 10msec or - * more, which is way too long.) + * records per single fsync. (The idea is some other backend + * may do the XLogFlush while we're sleeping. This needs work + * still, because on most Unixen, the minimum select() delay + * is 10msec or more, which is way too long.) * * We do not sleep if enableFsync is not turned on, nor if there * are fewer than CommitSiblings other backends with active @@ -593,13 +592,14 @@ RecordTransactionCommit(void) } /* - * We must mark the transaction committed in clog if its XID appears - * either in permanent rels or in local temporary rels. We test - * this by seeing if we made transaction-controlled entries *OR* - * local-rel tuple updates. Note that if we made only the latter, - * we have not emitted an XLOG record for our commit, and so in the - * event of a crash the clog update might be lost. This is okay - * because no one else will ever care whether we committed. + * We must mark the transaction committed in clog if its XID + * appears either in permanent rels or in local temporary rels. + * We test this by seeing if we made transaction-controlled + * entries *OR* local-rel tuple updates. Note that if we made + * only the latter, we have not emitted an XLOG record for our + * commit, and so in the event of a crash the clog update might be + * lost. This is okay because no one else will ever care whether + * we committed. */ if (MyLastRecPtr.xrecoff != 0 || MyXactMadeTempRelUpdate) TransactionIdCommit(xid); @@ -628,6 +628,7 @@ AtCommit_Cache(void) * Clean up the relation cache. */ AtEOXact_RelationCache(true); + /* * Make catalog changes visible to all backends. */ @@ -698,8 +699,8 @@ RecordTransactionAbort(void) { /* * If we made neither any transaction-controlled XLOG entries nor any - * temp-rel updates, we can omit recording the transaction abort at all. - * No one will ever care that it aborted. + * temp-rel updates, we can omit recording the transaction abort at + * all. No one will ever care that it aborted. */ if (MyLastRecPtr.xrecoff != 0 || MyXactMadeTempRelUpdate) { @@ -716,11 +717,12 @@ RecordTransactionAbort(void) START_CRIT_SECTION(); /* - * We only need to log the abort in XLOG if the transaction made any - * transaction-controlled XLOG entries. (Otherwise, its XID appears - * nowhere in permanent storage, so no one else will ever care if it - * committed.) We do not flush XLOG to disk in any case, since the - * default assumption after a crash would be that we aborted, anyway. + * We only need to log the abort in XLOG if the transaction made + * any transaction-controlled XLOG entries. (Otherwise, its XID + * appears nowhere in permanent storage, so no one else will ever + * care if it committed.) We do not flush XLOG to disk in any + * case, since the default assumption after a crash would be that + * we aborted, anyway. */ if (MyLastRecPtr.xrecoff != 0) { @@ -1165,8 +1167,8 @@ StartTransactionCommand(bool preventChain) TransactionState s = CurrentTransactionState; /* - * Remember if caller wants to prevent autocommit-off chaining. - * This is only allowed if not already in a transaction block. + * Remember if caller wants to prevent autocommit-off chaining. This + * is only allowed if not already in a transaction block. */ suppressChain = preventChain; if (preventChain && s->blockState != TBLOCK_DEFAULT) @@ -1260,16 +1262,18 @@ CommitTransactionCommand(bool forceCommit) { /* * If we aren't in a transaction block, and we are doing - * autocommit, just do our usual transaction commit. But - * if we aren't doing autocommit, start a transaction block - * automatically by switching to INPROGRESS state. (We handle - * this choice here, and not earlier, so that an explicit BEGIN - * issued in autocommit-off mode won't issue strange warnings.) + * autocommit, just do our usual transaction commit. But if + * we aren't doing autocommit, start a transaction block + * automatically by switching to INPROGRESS state. (We handle + * this choice here, and not earlier, so that an explicit + * BEGIN issued in autocommit-off mode won't issue strange + * warnings.) * - * Autocommit mode is forced by either a true forceCommit parameter - * to me, or a true preventChain parameter to the preceding - * StartTransactionCommand call. This is needed so that commands - * like VACUUM can ensure that the right things happen. + * Autocommit mode is forced by either a true forceCommit + * parameter to me, or a true preventChain parameter to the + * preceding StartTransactionCommand call. This is needed so + * that commands like VACUUM can ensure that the right things + * happen. */ case TBLOCK_DEFAULT: if (autocommit || forceCommit || suppressChain) @@ -1442,9 +1446,9 @@ BeginTransactionBlock(void) s->blockState = TBLOCK_BEGIN; /* - * do begin processing. NOTE: if you put anything here, check that - * it behaves properly in both autocommit-on and autocommit-off modes. - * In the latter case we will already have done some work in the new + * do begin processing. NOTE: if you put anything here, check that it + * behaves properly in both autocommit-on and autocommit-off modes. In + * the latter case we will already have done some work in the new * transaction. */ diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d2955d4058..0ff60292e6 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.105 2002/09/02 02:47:01 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.106 2002/09/04 20:31:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -131,13 +131,13 @@ bool InRecovery = false; * * Note that XLOG records inserted outside transaction control are not * reflected into MyLastRecPtr. They do, however, cause MyXactMadeXLogEntry - * to be set true. The latter can be used to test whether the current xact + * to be set true. The latter can be used to test whether the current xact * made any loggable changes (including out-of-xact changes, such as * sequence updates). * * When we insert/update/delete a tuple in a temporary relation, we do not * make any XLOG record, since we don't care about recovering the state of - * the temp rel after a crash. However, we will still need to remember + * the temp rel after a crash. However, we will still need to remember * whether our transaction committed or aborted in that case. So, we must * set MyXactMadeTempRelUpdate true to indicate that the XID will be of * interest later. @@ -151,7 +151,7 @@ bool MyXactMadeTempRelUpdate = false; /* * ProcLastRecPtr points to the start of the last XLOG record inserted by the * current backend. It is updated for all inserts, transaction-controlled - * or not. ProcLastRecEnd is similar but points to end+1 of last record. + * or not. ProcLastRecEnd is similar but points to end+1 of last record. */ static XLogRecPtr ProcLastRecPtr = {0, 0}; @@ -162,7 +162,7 @@ XLogRecPtr ProcLastRecEnd = {0, 0}; * (which is almost but not quite the same as a pointer to the most recent * CHECKPOINT record). We update this from the shared-memory copy, * XLogCtl->Insert.RedoRecPtr, whenever we can safely do so (ie, when we - * hold the Insert lock). See XLogInsert for details. We are also allowed + * hold the Insert lock). See XLogInsert for details. We are also allowed * to update from XLogCtl->Insert.RedoRecPtr if we hold the info_lck; * see GetRedoRecPtr. */ @@ -766,7 +766,7 @@ begin:; /* * We do not acquire SInvalLock here because of possible deadlock. * Anyone who wants to inspect other procs' logRec must acquire - * WALInsertLock, instead. A better solution would be a per-PROC + * WALInsertLock, instead. A better solution would be a per-PROC * spinlock, but no time for that before 7.2 --- tgl 12/19/01. */ MyProc->logRec = RecPtr; @@ -1283,26 +1283,27 @@ XLogFlush(XLogRecPtr record) /* * If we still haven't flushed to the request point then we have a - * problem; most likely, the requested flush point is past end of XLOG. - * This has been seen to occur when a disk page has a corrupted LSN. + * problem; most likely, the requested flush point is past end of + * XLOG. This has been seen to occur when a disk page has a corrupted + * LSN. * * Formerly we treated this as a PANIC condition, but that hurts the * system's robustness rather than helping it: we do not want to take * down the whole system due to corruption on one data page. In - * particular, if the bad page is encountered again during recovery then - * we would be unable to restart the database at all! (This scenario - * has actually happened in the field several times with 7.1 releases. - * Note that we cannot get here while InRedo is true, but if the bad - * page is brought in and marked dirty during recovery then + * particular, if the bad page is encountered again during recovery + * then we would be unable to restart the database at all! (This + * scenario has actually happened in the field several times with 7.1 + * releases. Note that we cannot get here while InRedo is true, but if + * the bad page is brought in and marked dirty during recovery then * CreateCheckpoint will try to flush it at the end of recovery.) * * The current approach is to ERROR under normal conditions, but only - * WARNING during recovery, so that the system can be brought up even if - * there's a corrupt LSN. Note that for calls from xact.c, the ERROR - * will be promoted to PANIC since xact.c calls this routine inside a - * critical section. However, calls from bufmgr.c are not within - * critical sections and so we will not force a restart for a bad LSN - * on a data page. + * WARNING during recovery, so that the system can be brought up even + * if there's a corrupt LSN. Note that for calls from xact.c, the + * ERROR will be promoted to PANIC since xact.c calls this routine + * inside a critical section. However, calls from bufmgr.c are not + * within critical sections and so we will not force a restart for a + * bad LSN on a data page. */ if (XLByteLT(LogwrtResult.Flush, record)) elog(InRecovery ? WARNING : ERROR, @@ -1565,7 +1566,7 @@ PreallocXlogFiles(XLogRecPtr endptr) XLByteToPrevSeg(endptr, _logId, _logSeg); if ((endptr.xrecoff - 1) % XLogSegSize >= - (uint32) (0.75 * XLogSegSize)) + (uint32) (0.75 * XLogSegSize)) { NextLogSeg(_logId, _logSeg); use_existent = true; @@ -1618,8 +1619,8 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr) /* * Before deleting the file, see if it can be recycled as * a future log segment. We allow recycling segments up - * to XLOGfileslop segments beyond the current - * XLOG location. + * to XLOGfileslop segments beyond the current XLOG + * location. */ if (InstallXLogFileSegment(endlogId, endlogSeg, path, true, XLOGfileslop, @@ -2196,7 +2197,7 @@ ReadControlFile(void) if (ControlFile->catalog_version_no != CATALOG_VERSION_NO) elog(PANIC, "The database cluster was initialized with CATALOG_VERSION_NO %d,\n" - "\tbut the backend was compiled with CATALOG_VERSION_NO %d.\n" + "\tbut the backend was compiled with CATALOG_VERSION_NO %d.\n" "\tIt looks like you need to initdb.", ControlFile->catalog_version_no, CATALOG_VERSION_NO); if (ControlFile->blcksz != BLCKSZ) @@ -2221,7 +2222,7 @@ ReadControlFile(void) if (ControlFile->funcMaxArgs != FUNC_MAX_ARGS) elog(PANIC, - "The database cluster was initialized with FUNC_MAX_ARGS %d,\n" + "The database cluster was initialized with FUNC_MAX_ARGS %d,\n" "\tbut the backend was compiled with FUNC_MAX_ARGS %d.\n" "\tIt looks like you need to recompile or initdb.", ControlFile->funcMaxArgs, FUNC_MAX_ARGS); @@ -2235,21 +2236,21 @@ ReadControlFile(void) #else if (ControlFile->enableIntTimes != FALSE) elog(PANIC, - "The database cluster was initialized with HAVE_INT64_TIMESTAMP\n" - "\tbut the backend was compiled without HAVE_INT64_TIMESTAMP.\n" + "The database cluster was initialized with HAVE_INT64_TIMESTAMP\n" + "\tbut the backend was compiled without HAVE_INT64_TIMESTAMP.\n" "\tIt looks like you need to recompile or initdb."); #endif if (ControlFile->localeBuflen != LOCALE_NAME_BUFLEN) elog(PANIC, "The database cluster was initialized with LOCALE_NAME_BUFLEN %d,\n" - "\tbut the backend was compiled with LOCALE_NAME_BUFLEN %d.\n" + "\tbut the backend was compiled with LOCALE_NAME_BUFLEN %d.\n" "\tIt looks like you need to initdb.", ControlFile->localeBuflen, LOCALE_NAME_BUFLEN); if (setlocale(LC_COLLATE, ControlFile->lc_collate) == NULL) elog(PANIC, - "The database cluster was initialized with LC_COLLATE '%s',\n" + "The database cluster was initialized with LC_COLLATE '%s',\n" "\twhich is not recognized by setlocale().\n" "\tIt looks like you need to initdb.", ControlFile->lc_collate); @@ -3019,19 +3020,19 @@ CreateCheckPoint(bool shutdown) } /* - * Get UNDO record ptr - this is oldest of PGPROC->logRec values. We do - * this while holding insert lock to ensure that we won't miss any + * Get UNDO record ptr - this is oldest of PGPROC->logRec values. We + * do this while holding insert lock to ensure that we won't miss any * about-to-commit transactions (UNDO must include all xacts that have * commits after REDO point). * * XXX temporarily ifdef'd out to avoid three-way deadlock condition: * GetUndoRecPtr needs to grab SInvalLock to ensure that it is looking - * at a stable set of proc records, but grabbing SInvalLock while holding - * WALInsertLock is no good. GetNewTransactionId may cause a WAL record - * to be written while holding XidGenLock, and GetSnapshotData needs to - * get XidGenLock while holding SInvalLock, so there's a risk of deadlock. - * Need to find a better solution. See pgsql-hackers discussion of - * 17-Dec-01. + * at a stable set of proc records, but grabbing SInvalLock while + * holding WALInsertLock is no good. GetNewTransactionId may cause a + * WAL record to be written while holding XidGenLock, and + * GetSnapshotData needs to get XidGenLock while holding SInvalLock, + * so there's a risk of deadlock. Need to find a better solution. See + * pgsql-hackers discussion of 17-Dec-01. */ #ifdef NOT_USED checkPoint.undo = GetUndoRecPtr(); @@ -3298,9 +3299,7 @@ assign_xlog_sync_method(const char *method, bool doit, bool interactive) } #endif else - { return NULL; - } if (!doit) return method; diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 28faa61b29..26e522f6cf 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.140 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.141 2002/09/04 20:31:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -191,7 +191,7 @@ usage(void) { fprintf(stderr, gettext("Usage:\n" - " postgres -boot [-d level] [-D datadir] [-F] [-o file] [-x num] dbname\n" + " postgres -boot [-d level] [-D datadir] [-F] [-o file] [-x num] dbname\n" " -d 1-5 debug mode\n" " -D datadir data directory\n" " -F turn off fsync\n" @@ -235,9 +235,7 @@ BootstrapMain(int argc, char *argv[]) * If we are running under the postmaster, this is done already. */ if (!IsUnderPostmaster) - { MemoryContextInit(); - } /* * process command arguments @@ -260,18 +258,19 @@ BootstrapMain(int argc, char *argv[]) potential_DataDir = optarg; break; case 'd': - { - /* Turn on debugging for the bootstrap process. */ - char *debugstr = palloc(strlen("debug") + strlen(optarg) + 1); - sprintf(debugstr, "debug%s", optarg); - SetConfigOption("server_min_messages", debugstr, - PGC_POSTMASTER, PGC_S_ARGV); - SetConfigOption("client_min_messages", debugstr, - PGC_POSTMASTER, PGC_S_ARGV); - pfree(debugstr); + { + /* Turn on debugging for the bootstrap process. */ + char *debugstr = palloc(strlen("debug") + strlen(optarg) + 1); + + sprintf(debugstr, "debug%s", optarg); + SetConfigOption("server_min_messages", debugstr, + PGC_POSTMASTER, PGC_S_ARGV); + SetConfigOption("client_min_messages", debugstr, + PGC_POSTMASTER, PGC_S_ARGV); + pfree(debugstr); + break; + } break; - } - break; case 'F': SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV); break; @@ -391,7 +390,8 @@ BootstrapMain(int argc, char *argv[]) InitDummyProcess(); /* needed to get LWLocks */ CreateDummyCaches(); CreateCheckPoint(false); - SetSavedRedoRecPtr(); /* pass redo ptr back to postmaster */ + SetSavedRedoRecPtr(); /* pass redo ptr back to + * postmaster */ proc_exit(0); /* done */ case BS_XLOG_STARTUP: @@ -587,7 +587,7 @@ DefineAttr(char *name, char *type, int attnum) namestrcpy(&attrtypes[attnum]->attname, name); elog(DEBUG3, "column %s %s", NameStr(attrtypes[attnum]->attname), type); - attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */ + attrtypes[attnum]->attnum = 1 + attnum; /* fillatt */ typeoid = gettype(type); @@ -640,14 +640,15 @@ DefineAttr(char *name, char *type, int attnum) } attrtypes[attnum]->attcacheoff = -1; attrtypes[attnum]->atttypmod = -1; + /* - * Mark as "not null" if type is fixed-width and prior columns are too. - * This corresponds to case where column can be accessed directly via - * C struct declaration. + * Mark as "not null" if type is fixed-width and prior columns are + * too. This corresponds to case where column can be accessed directly + * via C struct declaration. */ if (attlen > 0) { - int i; + int i; for (i = 0; i < attnum; i++) { @@ -829,7 +830,7 @@ cleanup() * and not an OID at all, until the first reference to a type not known in * Procid[]. At that point it will read and cache pg_type in the Typ array, * and subsequently return a real OID (and set the global pointer Ap to - * point at the found row in Typ). So caller must check whether Typ is + * point at the found row in Typ). So caller must check whether Typ is * still NULL to determine what the return value is! * ---------------- */ diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index ea3131b3fc..56c9a4fe65 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.76 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.77 2002/09/04 20:31:13 momjian Exp $ * * NOTES * See acl.h. @@ -91,22 +91,25 @@ merge_acl_with_grant(Acl *old_acl, bool is_grant, foreach(j, grantees) { PrivGrantee *grantee = (PrivGrantee *) lfirst(j); - AclItem aclitem; + AclItem aclitem; uint32 idtype; if (grantee->username) { - aclitem.ai_id = get_usesysid(grantee->username); + aclitem. ai_id = get_usesysid(grantee->username); + idtype = ACL_IDTYPE_UID; } else if (grantee->groupname) { - aclitem.ai_id = get_grosysid(grantee->groupname); + aclitem. ai_id = get_grosysid(grantee->groupname); + idtype = ACL_IDTYPE_GID; } else { - aclitem.ai_id = ACL_ID_WORLD; + aclitem. ai_id = ACL_ID_WORLD; + idtype = ACL_IDTYPE_WORLD; } @@ -376,7 +379,7 @@ ExecuteGrantStmt_Function(GrantStmt *stmt) char replaces[Natts_pg_proc]; oid = LookupFuncNameTypeNames(func->funcname, func->funcargs, - stmt->is_grant ? "GRANT" : "REVOKE"); + stmt->is_grant ? "GRANT" : "REVOKE"); relation = heap_openr(ProcedureRelationName, RowExclusiveLock); tuple = SearchSysCache(PROCOID, @@ -569,8 +572,8 @@ ExecuteGrantStmt_Namespace(GrantStmt *stmt) aclcheck_error(ACLCHECK_NOT_OWNER, nspname); /* - * If there's no ACL, create a default using the pg_namespace.nspowner - * field. + * If there's no ACL, create a default using the + * pg_namespace.nspowner field. */ aclDatum = SysCacheGetAttr(NAMESPACENAME, tuple, Anum_pg_namespace_nspacl, @@ -1163,8 +1166,8 @@ pg_namespace_aclcheck(Oid nsp_oid, Oid userid, AclMode mode) Acl *acl; /* - * If we have been assigned this namespace as a temp namespace, - * assume we have all grantable privileges on it. + * If we have been assigned this namespace as a temp namespace, assume + * we have all grantable privileges on it. */ if (isTempNamespace(nsp_oid)) return ACLCHECK_OK; diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c index 4c4578719c..2792d27220 100644 --- a/src/backend/catalog/catalog.c +++ b/src/backend/catalog/catalog.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.47 2002/06/20 20:29:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.48 2002/09/04 20:31:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -91,8 +91,8 @@ GetDatabasePath(Oid tblNode) bool IsSystemRelation(Relation relation) { - return IsSystemNamespace(RelationGetNamespace(relation)) || - IsToastNamespace(RelationGetNamespace(relation)); + return IsSystemNamespace(RelationGetNamespace(relation)) || + IsToastNamespace(RelationGetNamespace(relation)); } /* @@ -104,10 +104,10 @@ IsSystemRelation(Relation relation) bool IsSystemClass(Form_pg_class reltuple) { - Oid relnamespace = reltuple->relnamespace; + Oid relnamespace = reltuple->relnamespace; - return IsSystemNamespace(relnamespace) || - IsToastNamespace(relnamespace); + return IsSystemNamespace(relnamespace) || + IsToastNamespace(relnamespace); } /* @@ -129,9 +129,9 @@ IsToastRelation(Relation relation) bool IsToastClass(Form_pg_class reltuple) { - Oid relnamespace = reltuple->relnamespace; + Oid relnamespace = reltuple->relnamespace; - return IsToastNamespace(relnamespace); + return IsToastNamespace(relnamespace); } /* diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index d51c8d589a..8fb977e725 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.8 2002/08/02 18:15:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.9 2002/09/04 20:31:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -69,46 +69,46 @@ typedef enum ObjectClasses /* expansible list of ObjectAddresses */ typedef struct ObjectAddresses { - ObjectAddress *refs; /* => palloc'd array */ - int numrefs; /* current number of references */ - int maxrefs; /* current size of palloc'd array */ - struct ObjectAddresses *link; /* list link for use in recursion */ + ObjectAddress *refs; /* => palloc'd array */ + int numrefs; /* current number of references */ + int maxrefs; /* current size of palloc'd array */ + struct ObjectAddresses *link; /* list link for use in recursion */ } ObjectAddresses; /* for find_expr_references_walker */ typedef struct { - ObjectAddresses addrs; /* addresses being accumulated */ - List *rtables; /* list of rangetables to resolve Vars */ + ObjectAddresses addrs; /* addresses being accumulated */ + List *rtables; /* list of rangetables to resolve Vars */ } find_expr_references_context; /* * Because not all system catalogs have predetermined OIDs, we build a table - * mapping between ObjectClasses and OIDs. This is done at most once per + * mapping between ObjectClasses and OIDs. This is done at most once per * backend run, to minimize lookup overhead. */ -static bool object_classes_initialized = false; +static bool object_classes_initialized = false; static Oid object_classes[MAX_OCLASS]; static bool recursiveDeletion(const ObjectAddress *object, - DropBehavior behavior, - const ObjectAddress *callingObject, - ObjectAddresses *pending, - Relation depRel); + DropBehavior behavior, + const ObjectAddress *callingObject, + ObjectAddresses *pending, + Relation depRel); static void doDeletion(const ObjectAddress *object); static bool find_expr_references_walker(Node *node, - find_expr_references_context *context); + find_expr_references_context *context); static void eliminate_duplicate_dependencies(ObjectAddresses *addrs); static int object_address_comparator(const void *a, const void *b); static void init_object_addresses(ObjectAddresses *addrs); static void add_object_address(ObjectClasses oclass, Oid objectId, int32 subId, - ObjectAddresses *addrs); + ObjectAddresses *addrs); static void add_exact_object_address(const ObjectAddress *object, - ObjectAddresses *addrs); + ObjectAddresses *addrs); static void del_object_address(const ObjectAddress *object, - ObjectAddresses *addrs); + ObjectAddresses *addrs); static void del_object_address_by_index(int index, ObjectAddresses *addrs); static void term_object_addresses(ObjectAddresses *addrs); static void init_object_classes(void); @@ -131,12 +131,12 @@ void performDeletion(const ObjectAddress *object, DropBehavior behavior) { - char *objDescription; - Relation depRel; + char *objDescription; + Relation depRel; /* - * Get object description for possible use in failure message. - * Must do this before deleting it ... + * Get object description for possible use in failure message. Must do + * this before deleting it ... */ objDescription = getObjectDescription(object); @@ -165,7 +165,7 @@ performDeletion(const ObjectAddress *object, * callingObject is NULL at the outer level, else identifies the object that * we recursed from (the reference object that someone else needs to delete). * pending is a linked list of objects that outer recursion levels want to - * delete. We remove the target object from any outer-level list it may + * delete. We remove the target object from any outer-level list it may * appear in. * depRel is the already-open pg_depend relation. * @@ -178,7 +178,7 @@ performDeletion(const ObjectAddress *object, * This is even more complex than one could wish, because it is possible for * the same pair of objects to be related by both NORMAL and AUTO (or IMPLICIT) * dependencies. (Since one or both paths might be indirect, it's very hard - * to prevent this; we must cope instead.) If there is an AUTO/IMPLICIT + * to prevent this; we must cope instead.) If there is an AUTO/IMPLICIT * deletion path then we should perform the deletion, and not fail because * of the NORMAL dependency. So, when we hit a NORMAL dependency we don't * immediately decide we've failed; instead we stick the NORMAL dependent @@ -191,7 +191,7 @@ performDeletion(const ObjectAddress *object, * * Note: in the case where the AUTO path is traversed first, we will never * see the NORMAL dependency path because of the pg_depend removals done in - * recursive executions of step 1. The pending list is necessary essentially + * recursive executions of step 1. The pending list is necessary essentially * just to make the behavior independent of the order in which pg_depend * entries are visited. */ @@ -202,16 +202,16 @@ recursiveDeletion(const ObjectAddress *object, ObjectAddresses *pending, Relation depRel) { - bool ok = true; - char *objDescription; - ObjectAddresses mypending; - ScanKeyData key[3]; - int nkeys; - SysScanDesc scan; - HeapTuple tup; - ObjectAddress otherObject; - ObjectAddress owningObject; - bool amOwned = false; + bool ok = true; + char *objDescription; + ObjectAddresses mypending; + ScanKeyData key[3]; + int nkeys; + SysScanDesc scan; + HeapTuple tup; + ObjectAddress otherObject; + ObjectAddress owningObject; + bool amOwned = false; /* * Get object description for possible use in messages. Must do this @@ -231,8 +231,8 @@ recursiveDeletion(const ObjectAddress *object, * ensures that we avoid infinite recursion in the case of cycles. * Also, some dependency types require extra processing here. * - * When dropping a whole object (subId = 0), remove all pg_depend - * records for its sub-objects too. + * When dropping a whole object (subId = 0), remove all pg_depend records + * for its sub-objects too. */ ScanKeyEntryInitialize(&key[0], 0x0, Anum_pg_depend_classid, F_OIDEQ, @@ -255,7 +255,7 @@ recursiveDeletion(const ObjectAddress *object, while (HeapTupleIsValid(tup = systable_getnext(scan))) { - Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup); + Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup); otherObject.classId = foundDep->refclassid; otherObject.objectId = foundDep->refobjid; @@ -268,9 +268,10 @@ recursiveDeletion(const ObjectAddress *object, /* no problem */ break; case DEPENDENCY_INTERNAL: + /* - * This object is part of the internal implementation - * of another object. We have three cases: + * This object is part of the internal implementation of + * another object. We have three cases: * * 1. At the outermost recursion level, disallow the DROP. * (We just elog here, rather than considering this drop @@ -279,30 +280,32 @@ recursiveDeletion(const ObjectAddress *object, */ if (callingObject == NULL) { - char *otherObjDesc = getObjectDescription(&otherObject); + char *otherObjDesc = getObjectDescription(&otherObject); elog(ERROR, "Cannot drop %s because %s requires it" "\n\tYou may drop %s instead", objDescription, otherObjDesc, otherObjDesc); } + /* - * 2. When recursing from the other end of this dependency, - * it's okay to continue with the deletion. This holds when - * recursing from a whole object that includes the nominal - * other end as a component, too. + * 2. When recursing from the other end of this + * dependency, it's okay to continue with the deletion. + * This holds when recursing from a whole object that + * includes the nominal other end as a component, too. */ if (callingObject->classId == otherObject.classId && callingObject->objectId == otherObject.objectId && - (callingObject->objectSubId == otherObject.objectSubId || - callingObject->objectSubId == 0)) + (callingObject->objectSubId == otherObject.objectSubId || + callingObject->objectSubId == 0)) break; + /* * 3. When recursing from anyplace else, transform this * deletion request into a delete of the other object. - * (This will be an error condition iff RESTRICT mode.) - * In this case we finish deleting my dependencies except - * for the INTERNAL link, which will be needed to cause - * the owning object to recurse back to me. + * (This will be an error condition iff RESTRICT mode.) In + * this case we finish deleting my dependencies except for + * the INTERNAL link, which will be needed to cause the + * owning object to recurse back to me. */ if (amOwned) /* shouldn't happen */ elog(ERROR, "recursiveDeletion: multiple INTERNAL dependencies for %s", @@ -312,6 +315,7 @@ recursiveDeletion(const ObjectAddress *object, /* "continue" bypasses the simple_heap_delete call below */ continue; case DEPENDENCY_PIN: + /* * Should not happen; PIN dependencies should have zeroes * in the depender fields... @@ -331,10 +335,10 @@ recursiveDeletion(const ObjectAddress *object, systable_endscan(scan); /* - * CommandCounterIncrement here to ensure that preceding changes - * are all visible; in particular, that the above deletions of pg_depend - * entries are visible. That prevents infinite recursion in case of - * a dependency loop (which is perfectly legal). + * CommandCounterIncrement here to ensure that preceding changes are + * all visible; in particular, that the above deletions of pg_depend + * entries are visible. That prevents infinite recursion in case of a + * dependency loop (which is perfectly legal). */ CommandCounterIncrement(); @@ -368,21 +372,21 @@ recursiveDeletion(const ObjectAddress *object, /* * Step 2: scan pg_depend records that link to this object, showing - * the things that depend on it. Recursively delete those things. - * (We don't delete the pg_depend records here, as the recursive call - * will do that.) Note it's important to delete the dependent objects + * the things that depend on it. Recursively delete those things. (We + * don't delete the pg_depend records here, as the recursive call will + * do that.) Note it's important to delete the dependent objects * before the referenced one, since the deletion routines might do - * things like try to update the pg_class record when deleting a - * check constraint. + * things like try to update the pg_class record when deleting a check + * constraint. * * Again, when dropping a whole object (subId = 0), find pg_depend * records for its sub-objects too. * * NOTE: because we are using SnapshotNow, if a recursive call deletes - * any pg_depend tuples that our scan hasn't yet visited, we will not see - * them as good when we do visit them. This is essential for correct - * behavior if there are multiple dependency paths between two objects - * --- else we might try to delete an already-deleted object. + * any pg_depend tuples that our scan hasn't yet visited, we will not + * see them as good when we do visit them. This is essential for + * correct behavior if there are multiple dependency paths between two + * objects --- else we might try to delete an already-deleted object. */ ScanKeyEntryInitialize(&key[0], 0x0, Anum_pg_depend_refclassid, F_OIDEQ, @@ -405,7 +409,7 @@ recursiveDeletion(const ObjectAddress *object, while (HeapTupleIsValid(tup = systable_getnext(scan))) { - Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup); + Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup); otherObject.classId = foundDep->classid; otherObject.objectId = foundDep->objid; @@ -418,9 +422,9 @@ recursiveDeletion(const ObjectAddress *object, { /* * We've found a restricted object (or at least one - * that's not deletable along this path). Log for later - * processing. (Note it's okay if the same object gets - * into mypending multiple times.) + * that's not deletable along this path). Log for + * later processing. (Note it's okay if the same + * object gets into mypending multiple times.) */ add_exact_object_address(&otherObject, &mypending); } @@ -437,6 +441,7 @@ recursiveDeletion(const ObjectAddress *object, break; case DEPENDENCY_AUTO: case DEPENDENCY_INTERNAL: + /* * We propagate the DROP without complaint even in the * RESTRICT case. (However, normal dependencies on the @@ -451,6 +456,7 @@ recursiveDeletion(const ObjectAddress *object, ok = false; break; case DEPENDENCY_PIN: + /* * For a PIN dependency we just elog immediately; there * won't be any others to report. @@ -469,19 +475,19 @@ recursiveDeletion(const ObjectAddress *object, /* * If we found no restricted objects, or got rid of them all via other - * paths, we're in good shape. Otherwise continue step 2 by processing - * the remaining restricted objects. + * paths, we're in good shape. Otherwise continue step 2 by + * processing the remaining restricted objects. */ if (mypending.numrefs > 0) { /* - * Successively extract and delete each remaining object. - * Note that the right things will happen if some of these objects + * Successively extract and delete each remaining object. Note + * that the right things will happen if some of these objects * depend on others: we'll report/delete each one exactly once. */ while (mypending.numrefs > 0) { - ObjectAddress otherObject = mypending.refs[0]; + ObjectAddress otherObject = mypending.refs[0]; del_object_address_by_index(0, &mypending); @@ -508,19 +514,21 @@ recursiveDeletion(const ObjectAddress *object, doDeletion(object); /* - * Delete any comments associated with this object. (This is a convenient - * place to do it instead of having every object type know to do it.) + * Delete any comments associated with this object. (This is a + * convenient place to do it instead of having every object type know + * to do it.) */ DeleteComments(object->objectId, object->classId, object->objectSubId); /* - * If this object is mentioned in any caller's pending list, remove it. + * If this object is mentioned in any caller's pending list, remove + * it. */ del_object_address(object, pending); /* - * CommandCounterIncrement here to ensure that preceding changes - * are all visible. + * CommandCounterIncrement here to ensure that preceding changes are + * all visible. */ CommandCounterIncrement(); @@ -543,37 +551,37 @@ doDeletion(const ObjectAddress *object) switch (getObjectClass(object)) { case OCLASS_CLASS: - { - HeapTuple relTup; - char relKind; - - /* - * Need the relkind to figure out how to drop. - */ - relTup = SearchSysCache(RELOID, - ObjectIdGetDatum(object->objectId), - 0, 0, 0); - if (!HeapTupleIsValid(relTup)) - elog(ERROR, "doDeletion: Relation %u does not exist", - object->objectId); - relKind = ((Form_pg_class) GETSTRUCT(relTup))->relkind; - ReleaseSysCache(relTup); - - if (relKind == RELKIND_INDEX) - { - Assert(object->objectSubId == 0); - index_drop(object->objectId); - } - else { - if (object->objectSubId != 0) - RemoveAttributeById(object->objectId, - object->objectSubId); + HeapTuple relTup; + char relKind; + + /* + * Need the relkind to figure out how to drop. + */ + relTup = SearchSysCache(RELOID, + ObjectIdGetDatum(object->objectId), + 0, 0, 0); + if (!HeapTupleIsValid(relTup)) + elog(ERROR, "doDeletion: Relation %u does not exist", + object->objectId); + relKind = ((Form_pg_class) GETSTRUCT(relTup))->relkind; + ReleaseSysCache(relTup); + + if (relKind == RELKIND_INDEX) + { + Assert(object->objectSubId == 0); + index_drop(object->objectId); + } else - heap_drop_with_catalog(object->objectId); + { + if (object->objectSubId != 0) + RemoveAttributeById(object->objectId, + object->objectSubId); + else + heap_drop_with_catalog(object->objectId); + } + break; } - break; - } case OCLASS_PROC: RemoveFunctionById(object->objectId); @@ -644,7 +652,7 @@ doDeletion(const ObjectAddress *object) * It can be NIL if no such variables are expected. * * XXX is it important to create dependencies on the datatypes mentioned in - * the expression? In most cases this would be redundant (eg, a ref to an + * the expression? In most cases this would be redundant (eg, a ref to an * operator indirectly references its input and output datatypes), but I'm * not quite convinced there are no cases where we need it. */ @@ -653,7 +661,7 @@ recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior) { - find_expr_references_context context; + find_expr_references_context context; init_object_addresses(&context.addrs); @@ -755,8 +763,8 @@ find_expr_references_walker(Node *node, bool result; /* - * Add whole-relation refs for each plain relation mentioned in the - * subquery's rtable. (Note: query_tree_walker takes care of + * Add whole-relation refs for each plain relation mentioned in + * the subquery's rtable. (Note: query_tree_walker takes care of * recursing into RTE_FUNCTION and RTE_SUBQUERY RTEs, so no need * to do that here.) */ @@ -787,7 +795,7 @@ find_expr_references_walker(Node *node, static void eliminate_duplicate_dependencies(ObjectAddresses *addrs) { - ObjectAddress *priorobj; + ObjectAddress *priorobj; int oldref, newrefs; @@ -803,13 +811,14 @@ eliminate_duplicate_dependencies(ObjectAddresses *addrs) newrefs = 1; for (oldref = 1; oldref < addrs->numrefs; oldref++) { - ObjectAddress *thisobj = addrs->refs + oldref; + ObjectAddress *thisobj = addrs->refs + oldref; if (priorobj->classId == thisobj->classId && priorobj->objectId == thisobj->objectId) { if (priorobj->objectSubId == thisobj->objectSubId) continue; /* identical, so drop thisobj */ + /* * If we have a whole-object reference and a reference to a * part of the same object, we don't need the whole-object @@ -852,9 +861,10 @@ object_address_comparator(const void *a, const void *b) return -1; if (obja->objectId > objb->objectId) return 1; + /* - * We sort the subId as an unsigned int so that 0 will come first. - * See logic in eliminate_duplicate_dependencies. + * We sort the subId as an unsigned int so that 0 will come first. See + * logic in eliminate_duplicate_dependencies. */ if ((unsigned int) obja->objectSubId < (unsigned int) objb->objectSubId) return -1; @@ -894,7 +904,7 @@ static void add_object_address(ObjectClasses oclass, Oid objectId, int32 subId, ObjectAddresses *addrs) { - ObjectAddress *item; + ObjectAddress *item; /* enlarge array if needed */ if (addrs->numrefs >= addrs->maxrefs) @@ -920,7 +930,7 @@ static void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs) { - ObjectAddress *item; + ObjectAddress *item; /* enlarge array if needed */ if (addrs->numrefs >= addrs->maxrefs) @@ -937,7 +947,7 @@ add_exact_object_address(const ObjectAddress *object, /* * If an ObjectAddresses array contains any matches for the given object, - * remove it/them. Also, do the same in any linked ObjectAddresses arrays. + * remove it/them. Also, do the same in any linked ObjectAddresses arrays. */ static void del_object_address(const ObjectAddress *object, @@ -948,9 +958,9 @@ del_object_address(const ObjectAddress *object, int i; /* Scan backwards to simplify deletion logic. */ - for (i = addrs->numrefs-1; i >= 0; i--) + for (i = addrs->numrefs - 1; i >= 0; i--) { - ObjectAddress *thisobj = addrs->refs + i; + ObjectAddress *thisobj = addrs->refs + i; if (object->classId == thisobj->classId && object->objectId == thisobj->objectId) @@ -1134,150 +1144,150 @@ getObjectDescription(const ObjectAddress *object) break; case OCLASS_CAST: - { - Relation castDesc; - ScanKeyData skey[1]; - SysScanDesc rcscan; - HeapTuple tup; - Form_pg_cast castForm; + { + Relation castDesc; + ScanKeyData skey[1]; + SysScanDesc rcscan; + HeapTuple tup; + Form_pg_cast castForm; - castDesc = heap_openr(CastRelationName, AccessShareLock); + castDesc = heap_openr(CastRelationName, AccessShareLock); - ScanKeyEntryInitialize(&skey[0], 0x0, - ObjectIdAttributeNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); + ScanKeyEntryInitialize(&skey[0], 0x0, + ObjectIdAttributeNumber, F_OIDEQ, + ObjectIdGetDatum(object->objectId)); - rcscan = systable_beginscan(castDesc, CastOidIndex, true, - SnapshotNow, 1, skey); + rcscan = systable_beginscan(castDesc, CastOidIndex, true, + SnapshotNow, 1, skey); - tup = systable_getnext(rcscan); + tup = systable_getnext(rcscan); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "getObjectDescription: Cast %u does not exist", - object->objectId); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "getObjectDescription: Cast %u does not exist", + object->objectId); - castForm = (Form_pg_cast) GETSTRUCT(tup); + castForm = (Form_pg_cast) GETSTRUCT(tup); - appendStringInfo(&buffer, "cast from %s to %s", - format_type_be(castForm->castsource), - format_type_be(castForm->casttarget)); + appendStringInfo(&buffer, "cast from %s to %s", + format_type_be(castForm->castsource), + format_type_be(castForm->casttarget)); - systable_endscan(rcscan); - heap_close(castDesc, AccessShareLock); - break; - } + systable_endscan(rcscan); + heap_close(castDesc, AccessShareLock); + break; + } case OCLASS_CONSTRAINT: - { - Relation conDesc; - ScanKeyData skey[1]; - SysScanDesc rcscan; - HeapTuple tup; - Form_pg_constraint con; + { + Relation conDesc; + ScanKeyData skey[1]; + SysScanDesc rcscan; + HeapTuple tup; + Form_pg_constraint con; - conDesc = heap_openr(ConstraintRelationName, AccessShareLock); + conDesc = heap_openr(ConstraintRelationName, AccessShareLock); - ScanKeyEntryInitialize(&skey[0], 0x0, - ObjectIdAttributeNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); + ScanKeyEntryInitialize(&skey[0], 0x0, + ObjectIdAttributeNumber, F_OIDEQ, + ObjectIdGetDatum(object->objectId)); - rcscan = systable_beginscan(conDesc, ConstraintOidIndex, true, - SnapshotNow, 1, skey); + rcscan = systable_beginscan(conDesc, ConstraintOidIndex, true, + SnapshotNow, 1, skey); - tup = systable_getnext(rcscan); + tup = systable_getnext(rcscan); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "getObjectDescription: Constraint %u does not exist", - object->objectId); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "getObjectDescription: Constraint %u does not exist", + object->objectId); - con = (Form_pg_constraint) GETSTRUCT(tup); + con = (Form_pg_constraint) GETSTRUCT(tup); - if (OidIsValid(con->conrelid)) - { - appendStringInfo(&buffer, "constraint %s on ", - NameStr(con->conname)); - getRelationDescription(&buffer, con->conrelid); - } - else - { - appendStringInfo(&buffer, "constraint %s", - NameStr(con->conname)); - } + if (OidIsValid(con->conrelid)) + { + appendStringInfo(&buffer, "constraint %s on ", + NameStr(con->conname)); + getRelationDescription(&buffer, con->conrelid); + } + else + { + appendStringInfo(&buffer, "constraint %s", + NameStr(con->conname)); + } - systable_endscan(rcscan); - heap_close(conDesc, AccessShareLock); - break; - } + systable_endscan(rcscan); + heap_close(conDesc, AccessShareLock); + break; + } case OCLASS_CONVERSION: - { - HeapTuple conTup; - - conTup = SearchSysCache(CONOID, - ObjectIdGetDatum(object->objectId), - 0, 0, 0); - if (!HeapTupleIsValid(conTup)) - elog(ERROR, "getObjectDescription: Conversion %u does not exist", - object->objectId); - appendStringInfo(&buffer, "conversion %s", - NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname)); - ReleaseSysCache(conTup); - break; - } + { + HeapTuple conTup; + + conTup = SearchSysCache(CONOID, + ObjectIdGetDatum(object->objectId), + 0, 0, 0); + if (!HeapTupleIsValid(conTup)) + elog(ERROR, "getObjectDescription: Conversion %u does not exist", + object->objectId); + appendStringInfo(&buffer, "conversion %s", + NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname)); + ReleaseSysCache(conTup); + break; + } case OCLASS_DEFAULT: - { - Relation attrdefDesc; - ScanKeyData skey[1]; - SysScanDesc adscan; - HeapTuple tup; - Form_pg_attrdef attrdef; - ObjectAddress colobject; + { + Relation attrdefDesc; + ScanKeyData skey[1]; + SysScanDesc adscan; + HeapTuple tup; + Form_pg_attrdef attrdef; + ObjectAddress colobject; - attrdefDesc = heap_openr(AttrDefaultRelationName, AccessShareLock); + attrdefDesc = heap_openr(AttrDefaultRelationName, AccessShareLock); - ScanKeyEntryInitialize(&skey[0], 0x0, - ObjectIdAttributeNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); + ScanKeyEntryInitialize(&skey[0], 0x0, + ObjectIdAttributeNumber, F_OIDEQ, + ObjectIdGetDatum(object->objectId)); - adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndex, true, - SnapshotNow, 1, skey); + adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndex, true, + SnapshotNow, 1, skey); - tup = systable_getnext(adscan); + tup = systable_getnext(adscan); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "getObjectDescription: Default %u does not exist", - object->objectId); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "getObjectDescription: Default %u does not exist", + object->objectId); - attrdef = (Form_pg_attrdef) GETSTRUCT(tup); + attrdef = (Form_pg_attrdef) GETSTRUCT(tup); - colobject.classId = RelOid_pg_class; - colobject.objectId = attrdef->adrelid; - colobject.objectSubId = attrdef->adnum; + colobject.classId = RelOid_pg_class; + colobject.objectId = attrdef->adrelid; + colobject.objectSubId = attrdef->adnum; - appendStringInfo(&buffer, "default for %s", - getObjectDescription(&colobject)); + appendStringInfo(&buffer, "default for %s", + getObjectDescription(&colobject)); - systable_endscan(adscan); - heap_close(attrdefDesc, AccessShareLock); - break; - } + systable_endscan(adscan); + heap_close(attrdefDesc, AccessShareLock); + break; + } case OCLASS_LANGUAGE: - { - HeapTuple langTup; - - langTup = SearchSysCache(LANGOID, - ObjectIdGetDatum(object->objectId), - 0, 0, 0); - if (!HeapTupleIsValid(langTup)) - elog(ERROR, "getObjectDescription: Language %u does not exist", - object->objectId); - appendStringInfo(&buffer, "language %s", - NameStr(((Form_pg_language) GETSTRUCT(langTup))->lanname)); - ReleaseSysCache(langTup); - break; - } + { + HeapTuple langTup; + + langTup = SearchSysCache(LANGOID, + ObjectIdGetDatum(object->objectId), + 0, 0, 0); + if (!HeapTupleIsValid(langTup)) + elog(ERROR, "getObjectDescription: Language %u does not exist", + object->objectId); + appendStringInfo(&buffer, "language %s", + NameStr(((Form_pg_language) GETSTRUCT(langTup))->lanname)); + ReleaseSysCache(langTup); + break; + } case OCLASS_OPERATOR: appendStringInfo(&buffer, "operator %s", @@ -1285,126 +1295,126 @@ getObjectDescription(const ObjectAddress *object) break; case OCLASS_OPCLASS: - { - HeapTuple opcTup; - Form_pg_opclass opcForm; - HeapTuple amTup; - Form_pg_am amForm; - char *nspname; - - opcTup = SearchSysCache(CLAOID, - ObjectIdGetDatum(object->objectId), - 0, 0, 0); - if (!HeapTupleIsValid(opcTup)) - elog(ERROR, "cache lookup of opclass %u failed", - object->objectId); - opcForm = (Form_pg_opclass) GETSTRUCT(opcTup); - - /* Qualify the name if not visible in search path */ - if (OpclassIsVisible(object->objectId)) - nspname = NULL; - else - nspname = get_namespace_name(opcForm->opcnamespace); - - appendStringInfo(&buffer, "operator class %s", - quote_qualified_identifier(nspname, - NameStr(opcForm->opcname))); - - amTup = SearchSysCache(AMOID, - ObjectIdGetDatum(opcForm->opcamid), - 0, 0, 0); - if (!HeapTupleIsValid(amTup)) - elog(ERROR, "syscache lookup for AM %u failed", - opcForm->opcamid); - amForm = (Form_pg_am) GETSTRUCT(amTup); - - appendStringInfo(&buffer, " for %s", - NameStr(amForm->amname)); - - ReleaseSysCache(amTup); - ReleaseSysCache(opcTup); - break; - } + { + HeapTuple opcTup; + Form_pg_opclass opcForm; + HeapTuple amTup; + Form_pg_am amForm; + char *nspname; + + opcTup = SearchSysCache(CLAOID, + ObjectIdGetDatum(object->objectId), + 0, 0, 0); + if (!HeapTupleIsValid(opcTup)) + elog(ERROR, "cache lookup of opclass %u failed", + object->objectId); + opcForm = (Form_pg_opclass) GETSTRUCT(opcTup); + + /* Qualify the name if not visible in search path */ + if (OpclassIsVisible(object->objectId)) + nspname = NULL; + else + nspname = get_namespace_name(opcForm->opcnamespace); + + appendStringInfo(&buffer, "operator class %s", + quote_qualified_identifier(nspname, + NameStr(opcForm->opcname))); + + amTup = SearchSysCache(AMOID, + ObjectIdGetDatum(opcForm->opcamid), + 0, 0, 0); + if (!HeapTupleIsValid(amTup)) + elog(ERROR, "syscache lookup for AM %u failed", + opcForm->opcamid); + amForm = (Form_pg_am) GETSTRUCT(amTup); + + appendStringInfo(&buffer, " for %s", + NameStr(amForm->amname)); + + ReleaseSysCache(amTup); + ReleaseSysCache(opcTup); + break; + } case OCLASS_REWRITE: - { - Relation ruleDesc; - ScanKeyData skey[1]; - SysScanDesc rcscan; - HeapTuple tup; - Form_pg_rewrite rule; + { + Relation ruleDesc; + ScanKeyData skey[1]; + SysScanDesc rcscan; + HeapTuple tup; + Form_pg_rewrite rule; - ruleDesc = heap_openr(RewriteRelationName, AccessShareLock); + ruleDesc = heap_openr(RewriteRelationName, AccessShareLock); - ScanKeyEntryInitialize(&skey[0], 0x0, - ObjectIdAttributeNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); + ScanKeyEntryInitialize(&skey[0], 0x0, + ObjectIdAttributeNumber, F_OIDEQ, + ObjectIdGetDatum(object->objectId)); - rcscan = systable_beginscan(ruleDesc, RewriteOidIndex, true, - SnapshotNow, 1, skey); + rcscan = systable_beginscan(ruleDesc, RewriteOidIndex, true, + SnapshotNow, 1, skey); - tup = systable_getnext(rcscan); + tup = systable_getnext(rcscan); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "getObjectDescription: Rule %u does not exist", - object->objectId); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "getObjectDescription: Rule %u does not exist", + object->objectId); - rule = (Form_pg_rewrite) GETSTRUCT(tup); + rule = (Form_pg_rewrite) GETSTRUCT(tup); - appendStringInfo(&buffer, "rule %s on ", - NameStr(rule->rulename)); - getRelationDescription(&buffer, rule->ev_class); + appendStringInfo(&buffer, "rule %s on ", + NameStr(rule->rulename)); + getRelationDescription(&buffer, rule->ev_class); - systable_endscan(rcscan); - heap_close(ruleDesc, AccessShareLock); - break; - } + systable_endscan(rcscan); + heap_close(ruleDesc, AccessShareLock); + break; + } case OCLASS_TRIGGER: - { - Relation trigDesc; - ScanKeyData skey[1]; - SysScanDesc tgscan; - HeapTuple tup; - Form_pg_trigger trig; + { + Relation trigDesc; + ScanKeyData skey[1]; + SysScanDesc tgscan; + HeapTuple tup; + Form_pg_trigger trig; - trigDesc = heap_openr(TriggerRelationName, AccessShareLock); + trigDesc = heap_openr(TriggerRelationName, AccessShareLock); - ScanKeyEntryInitialize(&skey[0], 0x0, - ObjectIdAttributeNumber, F_OIDEQ, - ObjectIdGetDatum(object->objectId)); + ScanKeyEntryInitialize(&skey[0], 0x0, + ObjectIdAttributeNumber, F_OIDEQ, + ObjectIdGetDatum(object->objectId)); - tgscan = systable_beginscan(trigDesc, TriggerOidIndex, true, - SnapshotNow, 1, skey); + tgscan = systable_beginscan(trigDesc, TriggerOidIndex, true, + SnapshotNow, 1, skey); - tup = systable_getnext(tgscan); + tup = systable_getnext(tgscan); - if (!HeapTupleIsValid(tup)) - elog(ERROR, "getObjectDescription: Trigger %u does not exist", - object->objectId); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "getObjectDescription: Trigger %u does not exist", + object->objectId); - trig = (Form_pg_trigger) GETSTRUCT(tup); + trig = (Form_pg_trigger) GETSTRUCT(tup); - appendStringInfo(&buffer, "trigger %s on ", - NameStr(trig->tgname)); - getRelationDescription(&buffer, trig->tgrelid); + appendStringInfo(&buffer, "trigger %s on ", + NameStr(trig->tgname)); + getRelationDescription(&buffer, trig->tgrelid); - systable_endscan(tgscan); - heap_close(trigDesc, AccessShareLock); - break; - } + systable_endscan(tgscan); + heap_close(trigDesc, AccessShareLock); + break; + } case OCLASS_SCHEMA: - { - char *nspname; + { + char *nspname; - nspname = get_namespace_name(object->objectId); - if (!nspname) - elog(ERROR, "getObjectDescription: Schema %u does not exist", - object->objectId); - appendStringInfo(&buffer, "schema %s", nspname); - break; - } + nspname = get_namespace_name(object->objectId); + if (!nspname) + elog(ERROR, "getObjectDescription: Schema %u does not exist", + object->objectId); + appendStringInfo(&buffer, "schema %s", nspname); + break; + } default: appendStringInfo(&buffer, "unknown object %u %u %d", @@ -1424,7 +1434,7 @@ static void getRelationDescription(StringInfo buffer, Oid relid) { HeapTuple relTup; - Form_pg_class relForm; + Form_pg_class relForm; char *nspname; char *relname; diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 09afaf2df5..15f3e1e2d3 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.224 2002/09/02 01:05:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.225 2002/09/04 20:31:13 momjian Exp $ * * * INTERFACE ROUTINES @@ -67,10 +67,10 @@ static void AddNewRelationTuple(Relation pg_class_desc, Oid new_rel_oid, Oid new_type_oid, char relkind); static void AddNewRelationType(const char *typeName, - Oid typeNamespace, - Oid new_rel_oid, - char new_rel_kind, - Oid new_type_oid); + Oid typeNamespace, + Oid new_rel_oid, + char new_rel_kind, + Oid new_type_oid); static void RelationRemoveInheritance(Relation relation); static void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin); static void StoreRelCheck(Relation rel, char *ccname, char *ccbin); @@ -214,14 +214,14 @@ heap_create(const char *relname, Oid relid; Oid dbid = shared_relation ? InvalidOid : MyDatabaseId; bool nailme = false; - RelFileNode rnode; + RelFileNode rnode; Relation rel; /* * sanity checks */ if (!allow_system_table_mods && - (IsSystemNamespace(relnamespace) || IsToastNamespace(relnamespace)) && + (IsSystemNamespace(relnamespace) || IsToastNamespace(relnamespace)) && IsNormalProcessingMode()) elog(ERROR, "cannot create %s.%s: " "system catalog modifications are currently disallowed", @@ -256,21 +256,13 @@ heap_create(const char *relname, relid = RelOid_pg_class; } else if (strcmp(ShadowRelationName, relname) == 0) - { relid = RelOid_pg_shadow; - } else if (strcmp(GroupRelationName, relname) == 0) - { relid = RelOid_pg_group; - } else if (strcmp(DatabaseRelationName, relname) == 0) - { relid = RelOid_pg_database; - } else - { relid = newoid(); - } } else relid = newoid(); @@ -293,7 +285,8 @@ heap_create(const char *relname, nailme); /* - * have the storage manager create the relation's disk file, if wanted. + * have the storage manager create the relation's disk file, if + * wanted. */ if (storage_create) heap_storage_create(rel); @@ -396,7 +389,7 @@ CheckAttributeNames(TupleDesc tupdesc, char relkind) */ for (i = 0; i < natts; i++) { - Oid att_type = tupdesc->attrs[i]->atttypid; + Oid att_type = tupdesc->attrs[i]->atttypid; if (att_type == UNKNOWNOID) elog(WARNING, "Attribute \"%s\" has an unknown type" @@ -427,8 +420,8 @@ AddNewAttributeTuples(Oid new_rel_oid, Relation rel; CatalogIndexState indstate; int natts = tupdesc->natts; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* * open pg_attribute and its indexes. @@ -451,7 +444,7 @@ AddNewAttributeTuples(Oid new_rel_oid, (*dpp)->attcacheoff = -1; tup = heap_addheader(Natts_pg_attribute, - false, + false, ATTRIBUTE_TUPLE_SIZE, (void *) *dpp); @@ -463,7 +456,7 @@ AddNewAttributeTuples(Oid new_rel_oid, myself.classId = RelOid_pg_class; myself.objectId = new_rel_oid; - myself.objectSubId = i+1; + myself.objectSubId = i + 1; referenced.classId = RelOid_pg_type; referenced.objectId = (*dpp)->atttypid; referenced.objectSubId = 0; @@ -475,7 +468,8 @@ AddNewAttributeTuples(Oid new_rel_oid, /* * Next we add the system attributes. Skip OID if rel has no OIDs. * Skip all for a view or type relation. We don't bother with making - * datatype dependencies here, since presumably all these types are pinned. + * datatype dependencies here, since presumably all these types are + * pinned. */ if (relkind != RELKIND_VIEW && relkind != RELKIND_COMPOSITE_TYPE) { @@ -488,7 +482,7 @@ AddNewAttributeTuples(Oid new_rel_oid, Form_pg_attribute attStruct; tup = heap_addheader(Natts_pg_attribute, - false, + false, ATTRIBUTE_TUPLE_SIZE, (void *) *dpp); @@ -497,9 +491,9 @@ AddNewAttributeTuples(Oid new_rel_oid, attStruct->attrelid = new_rel_oid; /* - * Unneeded since they should be OK in the constant data - * anyway - */ + * Unneeded since they should be OK in the constant data + * anyway + */ /* attStruct->attstattarget = 0; */ /* attStruct->attcacheoff = -1; */ @@ -590,7 +584,7 @@ AddNewRelationTuple(Relation pg_class_desc, * ---------------- */ tup = heap_addheader(Natts_pg_class_fixed, - true, + true, CLASS_TUPLE_SIZE, (void *) new_rel_reltup); @@ -628,13 +622,13 @@ AddNewRelationType(const char *typeName, * * OLD and probably obsolete comments: * - * The sizes are set to oid size because it makes implementing sets - * MUCH easier, and no one (we hope) uses these fields to figure out - * how much space to allocate for the type. An oid is the type used - * for a set definition. When a user requests a set, what they - * actually get is the oid of a tuple in the pg_proc catalog, so the - * size of the "set" is the size of an oid. Similarly, byval being - * true makes sets much easier, and it isn't used by anything else. + * The sizes are set to oid size because it makes implementing sets MUCH + * easier, and no one (we hope) uses these fields to figure out how + * much space to allocate for the type. An oid is the type used for a + * set definition. When a user requests a set, what they actually get + * is the oid of a tuple in the pg_proc catalog, so the size of the + * "set" is the size of an oid. Similarly, byval being true makes sets + * much easier, and it isn't used by anything else. */ TypeCreate(typeName, /* type name */ typeNamespace, /* type namespace */ @@ -689,10 +683,10 @@ heap_create_with_catalog(const char *relname, if (get_relname_relid(relname, relnamespace)) elog(ERROR, "Relation '%s' already exists", relname); - + /* * Create the relcache entry (mostly dummy at this point) and the - * physical disk file. (If we fail further down, it's the smgr's + * physical disk file. (If we fail further down, it's the smgr's * responsibility to remove the disk file again.) * * NB: create a physical file only if it's not a view or type relation. @@ -702,7 +696,7 @@ heap_create_with_catalog(const char *relname, tupdesc, shared_relation, (relkind != RELKIND_VIEW && - relkind != RELKIND_COMPOSITE_TYPE), + relkind != RELKIND_COMPOSITE_TYPE), allow_system_table_mods); /* Fetch the relation OID assigned by heap_create */ @@ -746,14 +740,14 @@ heap_create_with_catalog(const char *relname, AddNewAttributeTuples(new_rel_oid, new_rel_desc->rd_att, relkind); /* - * make a dependency link to force the relation to be deleted if - * its namespace is. Skip this in bootstrap mode, since we don't - * make dependencies while bootstrapping. + * make a dependency link to force the relation to be deleted if its + * namespace is. Skip this in bootstrap mode, since we don't make + * dependencies while bootstrapping. */ if (!IsBootstrapProcessingMode()) { - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; myself.classId = RelOid_pg_class; myself.objectId = new_rel_oid; @@ -768,8 +762,9 @@ heap_create_with_catalog(const char *relname, * store constraints and defaults passed in the tupdesc, if any. * * NB: this may do a CommandCounterIncrement and rebuild the relcache - * entry, so the relation must be valid and self-consistent at this point. - * In particular, there are not yet constraints and defaults anywhere. + * entry, so the relation must be valid and self-consistent at this + * point. In particular, there are not yet constraints and defaults + * anywhere. */ StoreConstraints(new_rel_desc, tupdesc); @@ -788,8 +783,8 @@ heap_create_with_catalog(const char *relname, * RelationRemoveInheritance * * Formerly, this routine checked for child relations and aborted the - * deletion if any were found. Now we rely on the dependency mechanism - * to check for or delete child relations. By the time we get here, + * deletion if any were found. Now we rely on the dependency mechanism + * to check for or delete child relations. By the time we get here, * there are no children and we need only remove any pg_inherits rows * linking this relation to its parent(s). */ @@ -811,9 +806,7 @@ RelationRemoveInheritance(Relation relation) SnapshotNow, 1, &key); while (HeapTupleIsValid(tuple = systable_getnext(scan))) - { simple_heap_delete(catalogRelation, &tuple->t_self); - } systable_endscan(scan); heap_close(catalogRelation, RowExclusiveLock); @@ -863,7 +856,7 @@ void DeleteAttributeTuples(Oid relid) { Relation attrel; - SysScanDesc scan; + SysScanDesc scan; ScanKeyData key[1]; HeapTuple atttup; @@ -880,9 +873,7 @@ DeleteAttributeTuples(Oid relid) /* Delete all the matching tuples */ while ((atttup = systable_getnext(scan)) != NULL) - { simple_heap_delete(attrel, &atttup->t_self); - } /* Clean up after the scan */ systable_endscan(scan); @@ -907,10 +898,10 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) /* * Grab an exclusive lock on the target table, which we will NOT - * release until end of transaction. (In the simple case where - * we are directly dropping this column, AlterTableDropColumn already - * did this ... but when cascading from a drop of some other object, - * we may not have any lock.) + * release until end of transaction. (In the simple case where we are + * directly dropping this column, AlterTableDropColumn already did + * this ... but when cascading from a drop of some other object, we + * may not have any lock.) */ rel = relation_open(relid, AccessExclusiveLock); @@ -920,7 +911,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) ObjectIdGetDatum(relid), Int16GetDatum(attnum), 0, 0); - if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ + if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ elog(ERROR, "RemoveAttributeById: Failed to find attribute %d in relation %u", attnum, relid); attStruct = (Form_pg_attribute) GETSTRUCT(tuple); @@ -985,7 +976,7 @@ RemoveAttrDefault(Oid relid, AttrNumber attnum, /* There should be at most one matching tuple, but we loop anyway */ while (HeapTupleIsValid(tuple = systable_getnext(scan))) { - ObjectAddress object; + ObjectAddress object; object.classId = RelationGetRelid(attrdef_rel); object.objectId = HeapTupleGetOid(tuple); @@ -1007,7 +998,7 @@ RemoveAttrDefault(Oid relid, AttrNumber attnum, /* * RemoveAttrDefaultById * - * Remove a pg_attrdef entry specified by OID. This is the guts of + * Remove a pg_attrdef entry specified by OID. This is the guts of * attribute-default removal. Note it should be called via performDeletion, * not directly. */ @@ -1058,7 +1049,7 @@ RemoveAttrDefaultById(Oid attrdefId) ObjectIdGetDatum(myrelid), Int16GetDatum(myattnum), 0, 0); - if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ + if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ elog(ERROR, "RemoveAttrDefaultById: cache lookup failed for rel %u attr %d", myrelid, myattnum); @@ -1175,7 +1166,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin) HeapTuple atttup; Form_pg_attribute attStruct; Oid attrdefOid; - ObjectAddress colobject, + ObjectAddress colobject, defobject; /* @@ -1307,8 +1298,8 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin) attNos = (int16 *) palloc(keycount * sizeof(int16)); foreach(vl, varList) { - Var *var = (Var *) lfirst(vl); - int j; + Var *var = (Var *) lfirst(vl); + int j; for (j = 0; j < i; j++) if (attNos[j] == var->varattno) @@ -1324,24 +1315,24 @@ StoreRelCheck(Relation rel, char *ccname, char *ccbin) /* * Create the Check Constraint */ - CreateConstraintEntry(ccname, /* Constraint Name */ - RelationGetNamespace(rel), /* namespace */ - CONSTRAINT_CHECK, /* Constraint Type */ - false, /* Is Deferrable */ + CreateConstraintEntry(ccname, /* Constraint Name */ + RelationGetNamespace(rel), /* namespace */ + CONSTRAINT_CHECK, /* Constraint Type */ + false, /* Is Deferrable */ false, /* Is Deferred */ - RelationGetRelid(rel), /* relation */ - attNos, /* attrs in the constraint */ - keycount, /* # attrs in the constraint */ - InvalidOid, /* not a domain constraint */ - InvalidOid, /* Foreign key fields */ + RelationGetRelid(rel), /* relation */ + attNos, /* attrs in the constraint */ + keycount, /* # attrs in the constraint */ + InvalidOid, /* not a domain constraint */ + InvalidOid, /* Foreign key fields */ NULL, 0, ' ', ' ', ' ', - expr, /* Tree form check constraint */ + expr, /* Tree form check constraint */ ccbin, /* Binary form check constraint */ - ccsrc); /* Source form check constraint */ + ccsrc); /* Source form check constraint */ pfree(ccsrc); } @@ -1366,8 +1357,8 @@ StoreConstraints(Relation rel, TupleDesc tupdesc) /* * Deparsing of constraint expressions will fail unless the * just-created pg_attribute tuples for this relation are made - * visible. So, bump the command counter. CAUTION: this will - * cause a relcache entry rebuild. + * visible. So, bump the command counter. CAUTION: this will cause a + * relcache entry rebuild. */ CommandCounterIncrement(); @@ -1513,12 +1504,14 @@ AddRelationRawConstraints(Relation rel, List *listptr2; /* - * Generate a name that does not conflict with pre-existing - * constraints, nor with any auto-generated names so far. + * Generate a name that does not conflict with + * pre-existing constraints, nor with any auto-generated + * names so far. */ ccname = GenerateConstraintName(RelationGetRelid(rel), RelationGetNamespace(rel), &constr_name_ctr); + /* * Check against other new constraints, in case the user * has specified a name that looks like an auto-generated @@ -1668,7 +1661,7 @@ cookDefault(ParseState *pstate, int32 atttypmod, char *attname) { - Node *expr; + Node *expr; Assert(raw_default != NULL); @@ -1699,18 +1692,18 @@ cookDefault(ParseState *pstate, /* * Check that it will be possible to coerce the expression to the - * column's type. We store the expression without coercion, - * however, to avoid premature coercion in cases like + * column's type. We store the expression without coercion, however, + * to avoid premature coercion in cases like * * CREATE TABLE tbl (fld timestamp DEFAULT 'now'::text); * - * NB: this should match the code in optimizer/prep/preptlist.c that - * will actually do the coercion, to ensure we don't accept an - * unusable default expression. + * NB: this should match the code in optimizer/prep/preptlist.c that will + * actually do the coercion, to ensure we don't accept an unusable + * default expression. */ if (OidIsValid(atttypid)) { - Oid type_id = exprType(expr); + Oid type_id = exprType(expr); if (type_id != atttypid) { @@ -1718,7 +1711,7 @@ cookDefault(ParseState *pstate, atttypid, atttypmod, false) == NULL) elog(ERROR, "Column \"%s\" is of type %s" " but default expression is of type %s" - "\n\tYou will need to rewrite or cast the expression", + "\n\tYou will need to rewrite or cast the expression", attname, format_type_be(atttypid), format_type_be(type_id)); @@ -1735,7 +1728,7 @@ cookDefault(ParseState *pstate, */ fix_opids(expr); - return(expr); + return (expr); } @@ -1753,7 +1746,7 @@ RemoveRelConstraints(Relation rel, const char *constrName, { int ndeleted = 0; Relation conrel; - SysScanDesc conscan; + SysScanDesc conscan; ScanKeyData key[1]; HeapTuple contup; @@ -1773,11 +1766,11 @@ RemoveRelConstraints(Relation rel, const char *constrName, */ while ((contup = systable_getnext(conscan)) != NULL) { - Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(contup); + Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(contup); if (strcmp(NameStr(con->conname), constrName) == 0) { - ObjectAddress conobj; + ObjectAddress conobj; conobj.classId = RelationGetRelid(conrel); conobj.objectId = HeapTupleGetOid(contup); @@ -1815,9 +1808,7 @@ RemoveStatistics(Relation rel) SnapshotNow, 1, &key); while (HeapTupleIsValid(tuple = systable_getnext(scan))) - { simple_heap_delete(pgstatistic, &tuple->t_self); - } systable_endscan(scan); heap_close(pgstatistic, RowExclusiveLock); @@ -1836,7 +1827,7 @@ RelationTruncateIndexes(Oid heapId) { Relation indexRelation; ScanKeyData entry; - SysScanDesc scan; + SysScanDesc scan; HeapTuple indexTuple; /* Scan pg_index to find indexes on specified heap */ diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index f91600f94a..4909c2ea08 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.195 2002/09/03 16:00:02 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.196 2002/09/04 20:31:14 momjian Exp $ * * * INTERFACE ROUTINES @@ -320,13 +320,13 @@ UpdateRelationRelation(Relation indexRelation) /* XXX Natts_pg_class_fixed is a hack - see pg_class.h */ tuple = heap_addheader(Natts_pg_class_fixed, - true, + true, CLASS_TUPLE_SIZE, (void *) indexRelation->rd_rel); /* - * the new tuple must have the oid already chosen for the index. - * sure would be embarrassing to do this sort of thing in polite company. + * the new tuple must have the oid already chosen for the index. sure + * would be embarrassing to do this sort of thing in polite company. */ HeapTupleSetOid(tuple, RelationGetRelid(indexRelation)); simple_heap_insert(pg_class, tuple); @@ -391,7 +391,7 @@ AppendAttributeTuples(Relation indexRelation, int numatts) Assert(indexTupDesc->attrs[i]->attcacheoff == -1); new_tuple = heap_addheader(Natts_pg_attribute, - false, + false, ATTRIBUTE_TUPLE_SIZE, (void *) indexTupDesc->attrs[i]); @@ -478,7 +478,7 @@ UpdateIndexRelation(Oid indexoid, * form a tuple to insert into pg_index */ tuple = heap_addheader(Natts_pg_index, - false, + false, itupLen, (void *) indexForm); @@ -532,8 +532,8 @@ index_create(Oid heapRelationId, heapRelation = heap_open(heapRelationId, ShareLock); /* - * The index will be in the same namespace as its parent table, - * and is shared across databases if and only if the parent is. + * The index will be in the same namespace as its parent table, and is + * shared across databases if and only if the parent is. */ namespaceId = RelationGetNamespace(heapRelation); shared_relation = heapRelation->rd_rel->relisshared; @@ -554,7 +554,7 @@ index_create(Oid heapRelationId, * We cannot allow indexing a shared relation after initdb (because * there's no way to make the entry in other databases' pg_class). * Unfortunately we can't distinguish initdb from a manually started - * standalone backend. However, we can at least prevent this mistake + * standalone backend. However, we can at least prevent this mistake * under normal multi-user operation. */ if (shared_relation && IsUnderPostmaster) @@ -577,6 +577,7 @@ index_create(Oid heapRelationId, classObjectId); indexTupDesc->tdhasoid = false; + /* * create the index relation's relcache entry and physical disk file. * (If we fail further down, it's the smgr's responsibility to remove @@ -643,20 +644,20 @@ index_create(Oid heapRelationId, * Register constraint and dependencies for the index. * * If the index is from a CONSTRAINT clause, construct a pg_constraint - * entry. The index is then linked to the constraint, which in turn is - * linked to the table. If it's not a CONSTRAINT, make the dependency - * directly on the table. + * entry. The index is then linked to the constraint, which in turn + * is linked to the table. If it's not a CONSTRAINT, make the + * dependency directly on the table. * - * We don't need a dependency on the namespace, because there'll be - * an indirect dependency via our parent table. + * We don't need a dependency on the namespace, because there'll be an + * indirect dependency via our parent table. * - * During bootstrap we can't register any dependencies, and we don't - * try to make a constraint either. + * During bootstrap we can't register any dependencies, and we don't try + * to make a constraint either. */ if (!IsBootstrapProcessingMode()) { - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; myself.classId = RelOid_pg_class; myself.objectId = indexoid; @@ -674,25 +675,25 @@ index_create(Oid heapRelationId, else { elog(ERROR, "index_create: constraint must be PRIMARY or UNIQUE"); - constraintType = 0; /* keep compiler quiet */ + constraintType = 0; /* keep compiler quiet */ } conOid = CreateConstraintEntry(indexRelationName, namespaceId, constraintType, - false, /* isDeferrable */ - false, /* isDeferred */ + false, /* isDeferrable */ + false, /* isDeferred */ heapRelationId, indexInfo->ii_KeyAttrNumbers, indexInfo->ii_NumKeyAttrs, - InvalidOid, /* no domain */ - InvalidOid, /* no foreign key */ + InvalidOid, /* no domain */ + InvalidOid, /* no foreign key */ NULL, 0, ' ', ' ', ' ', - NULL, /* no check constraint */ + NULL, /* no check constraint */ NULL, NULL); @@ -807,6 +808,7 @@ index_drop(Oid indexId) * fix RELATION relation */ DeleteRelationTuple(indexId); + /* * fix ATTRIBUTE relation */ @@ -839,11 +841,12 @@ index_drop(Oid indexId) smgrunlink(DEFAULT_SMGR, userIndexRelation); /* - * We are presently too lazy to attempt to compute the new correct value - * of relhasindex (the next VACUUM will fix it if necessary). So there is - * no need to update the pg_class tuple for the owning relation. - * But we must send out a shared-cache-inval notice on the owning relation - * to ensure other backends update their relcache lists of indexes. + * We are presently too lazy to attempt to compute the new correct + * value of relhasindex (the next VACUUM will fix it if necessary). + * So there is no need to update the pg_class tuple for the owning + * relation. But we must send out a shared-cache-inval notice on the + * owning relation to ensure other backends update their relcache + * lists of indexes. */ CacheInvalidateRelcache(heapId); @@ -1640,7 +1643,7 @@ IndexBuildHeapScan(Relation heapRelation, * transaction.) */ if (!TransactionIdIsCurrentTransactionId( - HeapTupleHeaderGetXmin(heapTuple->t_data))) + HeapTupleHeaderGetXmin(heapTuple->t_data))) elog(ERROR, "IndexBuildHeapScan: concurrent insert in progress"); indexIt = true; tupleIsAlive = true; @@ -1655,7 +1658,7 @@ IndexBuildHeapScan(Relation heapRelation, * transaction.) */ if (!TransactionIdIsCurrentTransactionId( - HeapTupleHeaderGetXmax(heapTuple->t_data))) + HeapTupleHeaderGetXmax(heapTuple->t_data))) elog(ERROR, "IndexBuildHeapScan: concurrent delete in progress"); indexIt = true; tupleIsAlive = false; @@ -1798,12 +1801,12 @@ reindex_index(Oid indexId, bool force, bool inplace) /* * Open our index relation and get an exclusive lock on it. * - * Note: doing this before opening the parent heap relation means - * there's a possibility for deadlock failure against another xact - * that is doing normal accesses to the heap and index. However, - * it's not real clear why you'd be needing to do REINDEX on a table - * that's in active use, so I'd rather have the protection of making - * sure the index is locked down. + * Note: doing this before opening the parent heap relation means there's + * a possibility for deadlock failure against another xact that is + * doing normal accesses to the heap and index. However, it's not + * real clear why you'd be needing to do REINDEX on a table that's in + * active use, so I'd rather have the protection of making sure the + * index is locked down. */ iRel = index_open(indexId); if (iRel == NULL) diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c index 4206c33edb..27d66b4b2e 100644 --- a/src/backend/catalog/indexing.c +++ b/src/backend/catalog/indexing.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.101 2002/08/06 02:36:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.102 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,7 +44,7 @@ CatalogOpenIndexes(Relation heapRel) resultRelInfo = makeNode(ResultRelInfo); resultRelInfo->ri_RangeTableIndex = 1; /* dummy */ resultRelInfo->ri_RelationDesc = heapRel; - resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */ + resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */ ExecOpenIndices(resultRelInfo); @@ -132,14 +132,14 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple) * CatalogUpdateIndexes - do all the indexing work for a new catalog tuple * * This is a convenience routine for the common case where we only need - * to insert or update a single tuple in a system catalog. Avoid using it for + * to insert or update a single tuple in a system catalog. Avoid using it for * multiple tuples, since opening the indexes and building the index info * structures is moderately expensive. */ void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple) { - CatalogIndexState indstate; + CatalogIndexState indstate; indstate = CatalogOpenIndexes(heapRel); CatalogIndexInsert(indstate, heapTuple); diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 1b4f2aef8e..182d9016e9 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -13,7 +13,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.34 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.35 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,10 +60,10 @@ * 2. If a TEMP table namespace has been initialized in this session, it * is always searched just after any special namespace. * - * 3. The system catalog namespace is always searched. If the system + * 3. The system catalog namespace is always searched. If the system * namespace is present in the explicit path then it will be searched in * the specified order; otherwise it will be searched after TEMP tables and - * *before* the explicit list. (It might seem that the system namespace + * *before* the explicit list. (It might seem that the system namespace * should be implicitly last, but this behavior appears to be required by * SQL99. Also, this provides a way to search the system namespace first * without thereby making it the default creation target namespace.) @@ -76,7 +76,7 @@ * In bootstrap mode, the search path is set equal to 'pg_catalog', so that * the system namespace is the only one searched or inserted into. * The initdb script is also careful to set search_path to 'pg_catalog' for - * its post-bootstrap standalone backend runs. Otherwise the default search + * its post-bootstrap standalone backend runs. Otherwise the default search * path is determined by GUC. The factory default path contains the PUBLIC * namespace (if it exists), preceded by the user's personal namespace * (if one exists). @@ -109,7 +109,7 @@ static bool namespaceSearchPathValid = true; /* * myTempNamespace is InvalidOid until and unless a TEMP namespace is set up * in a particular backend session (this happens when a CREATE TEMP TABLE - * command is first executed). Thereafter it's the OID of the temp namespace. + * command is first executed). Thereafter it's the OID of the temp namespace. * firstTempTransaction flags whether we've committed creation of the TEMP * namespace or not. */ @@ -127,7 +127,7 @@ static Oid mySpecialNamespace = InvalidOid; * This is the text equivalent of the search path --- it's the value * of the GUC variable 'search_path'. */ -char *namespace_search_path = NULL; +char *namespace_search_path = NULL; /* Local functions */ @@ -138,11 +138,11 @@ static void RemoveTempRelationsCallback(void); static void NamespaceCallback(Datum arg, Oid relid); /* These don't really need to appear in any header file */ -Datum pg_table_is_visible(PG_FUNCTION_ARGS); -Datum pg_type_is_visible(PG_FUNCTION_ARGS); -Datum pg_function_is_visible(PG_FUNCTION_ARGS); -Datum pg_operator_is_visible(PG_FUNCTION_ARGS); -Datum pg_opclass_is_visible(PG_FUNCTION_ARGS); +Datum pg_table_is_visible(PG_FUNCTION_ARGS); +Datum pg_type_is_visible(PG_FUNCTION_ARGS); +Datum pg_function_is_visible(PG_FUNCTION_ARGS); +Datum pg_operator_is_visible(PG_FUNCTION_ARGS); +Datum pg_opclass_is_visible(PG_FUNCTION_ARGS); /* @@ -230,7 +230,7 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) { /* use exact schema given */ namespaceId = GetSysCacheOid(NAMESPACENAME, - CStringGetDatum(newRelation->schemaname), + CStringGetDatum(newRelation->schemaname), 0, 0, 0); if (!OidIsValid(namespaceId)) elog(ERROR, "Namespace \"%s\" does not exist", @@ -312,10 +312,10 @@ RelationIsVisible(Oid relid) else { /* - * If it is in the path, it might still not be visible; it could be - * hidden by another relation of the same name earlier in the path. - * So we must do a slow check to see if this rel would be found by - * RelnameGetRelid. + * If it is in the path, it might still not be visible; it could + * be hidden by another relation of the same name earlier in the + * path. So we must do a slow check to see if this rel would be + * found by RelnameGetRelid. */ char *relname = NameStr(relform->relname); @@ -394,10 +394,10 @@ TypeIsVisible(Oid typid) else { /* - * If it is in the path, it might still not be visible; it could be - * hidden by another type of the same name earlier in the path. - * So we must do a slow check to see if this type would be found by - * TypenameGetTypid. + * If it is in the path, it might still not be visible; it could + * be hidden by another type of the same name earlier in the path. + * So we must do a slow check to see if this type would be found + * by TypenameGetTypid. */ char *typname = NameStr(typform->typname); @@ -492,18 +492,18 @@ FuncnameGetCandidates(List *names, int nargs) /* * Okay, it's in the search path, but does it have the same - * arguments as something we already accepted? If so, keep + * arguments as something we already accepted? If so, keep * only the one that appears earlier in the search path. * - * If we have an ordered list from SearchSysCacheList (the - * normal case), then any conflicting proc must immediately - * adjoin this one in the list, so we only need to look at - * the newest result item. If we have an unordered list, - * we have to scan the whole result list. + * If we have an ordered list from SearchSysCacheList (the normal + * case), then any conflicting proc must immediately adjoin + * this one in the list, so we only need to look at the newest + * result item. If we have an unordered list, we have to scan + * the whole result list. */ if (resultList) { - FuncCandidateList prevResult; + FuncCandidateList prevResult; if (catlist->ordered) { @@ -521,8 +521,8 @@ FuncnameGetCandidates(List *names, int nargs) prevResult = prevResult->next) { if (nargs == prevResult->nargs && - memcmp(procform->proargtypes, prevResult->args, - nargs * sizeof(Oid)) == 0) + memcmp(procform->proargtypes, prevResult->args, + nargs * sizeof(Oid)) == 0) break; } } @@ -531,7 +531,7 @@ FuncnameGetCandidates(List *names, int nargs) /* We have a match with a previous result */ Assert(pathpos != prevResult->pathpos); if (pathpos > prevResult->pathpos) - continue; /* keep previous result */ + continue; /* keep previous result */ /* replace previous result */ prevResult->pathpos = pathpos; prevResult->oid = HeapTupleGetOid(proctup); @@ -595,10 +595,10 @@ FunctionIsVisible(Oid funcid) else { /* - * If it is in the path, it might still not be visible; it could be - * hidden by another proc of the same name and arguments earlier - * in the path. So we must do a slow check to see if this is the - * same proc that would be found by FuncnameGetCandidates. + * If it is in the path, it might still not be visible; it could + * be hidden by another proc of the same name and arguments + * earlier in the path. So we must do a slow check to see if this + * is the same proc that would be found by FuncnameGetCandidates. */ char *proname = NameStr(procform->proname); int nargs = procform->pronargs; @@ -641,7 +641,7 @@ FunctionIsVisible(Oid funcid) * identical entries in later namespaces. * * The returned items always have two args[] entries --- one or the other - * will be InvalidOid for a prefix or postfix oprkind. nargs is 2, too. + * will be InvalidOid for a prefix or postfix oprkind. nargs is 2, too. */ FuncCandidateList OpernameGetCandidates(List *names, char oprkind) @@ -707,18 +707,18 @@ OpernameGetCandidates(List *names, char oprkind) /* * Okay, it's in the search path, but does it have the same - * arguments as something we already accepted? If so, keep + * arguments as something we already accepted? If so, keep * only the one that appears earlier in the search path. * - * If we have an ordered list from SearchSysCacheList (the - * normal case), then any conflicting oper must immediately - * adjoin this one in the list, so we only need to look at - * the newest result item. If we have an unordered list, - * we have to scan the whole result list. + * If we have an ordered list from SearchSysCacheList (the normal + * case), then any conflicting oper must immediately adjoin + * this one in the list, so we only need to look at the newest + * result item. If we have an unordered list, we have to scan + * the whole result list. */ if (resultList) { - FuncCandidateList prevResult; + FuncCandidateList prevResult; if (catlist->ordered) { @@ -744,7 +744,7 @@ OpernameGetCandidates(List *names, char oprkind) /* We have a match with a previous result */ Assert(pathpos != prevResult->pathpos); if (pathpos > prevResult->pathpos) - continue; /* keep previous result */ + continue; /* keep previous result */ /* replace previous result */ prevResult->pathpos = pathpos; prevResult->oid = HeapTupleGetOid(opertup); @@ -807,10 +807,11 @@ OperatorIsVisible(Oid oprid) else { /* - * If it is in the path, it might still not be visible; it could be - * hidden by another operator of the same name and arguments earlier - * in the path. So we must do a slow check to see if this is the - * same operator that would be found by OpernameGetCandidates. + * If it is in the path, it might still not be visible; it could + * be hidden by another operator of the same name and arguments + * earlier in the path. So we must do a slow check to see if this + * is the same operator that would be found by + * OpernameGetCandidates. */ char *oprname = NameStr(oprform->oprname); FuncCandidateList clist; @@ -882,18 +883,18 @@ OpclassGetCandidates(Oid amid) /* * Okay, it's in the search path, but does it have the same name - * as something we already accepted? If so, keep - * only the one that appears earlier in the search path. + * as something we already accepted? If so, keep only the one + * that appears earlier in the search path. * - * If we have an ordered list from SearchSysCacheList (the - * normal case), then any conflicting opclass must immediately - * adjoin this one in the list, so we only need to look at - * the newest result item. If we have an unordered list, - * we have to scan the whole result list. + * If we have an ordered list from SearchSysCacheList (the normal + * case), then any conflicting opclass must immediately adjoin + * this one in the list, so we only need to look at the newest + * result item. If we have an unordered list, we have to scan the + * whole result list. */ if (resultList) { - OpclassCandidateList prevResult; + OpclassCandidateList prevResult; if (catlist->ordered) { @@ -919,7 +920,7 @@ OpclassGetCandidates(Oid amid) /* We have a match with a previous result */ Assert(pathpos != prevResult->pathpos); if (pathpos > prevResult->pathpos) - continue; /* keep previous result */ + continue; /* keep previous result */ /* replace previous result */ prevResult->opcname_tmp = NameStr(opcform->opcname); prevResult->pathpos = pathpos; @@ -1019,10 +1020,10 @@ OpclassIsVisible(Oid opcid) else { /* - * If it is in the path, it might still not be visible; it could be - * hidden by another opclass of the same name earlier in the path. - * So we must do a slow check to see if this opclass would be found by - * OpclassnameGetOpcid. + * If it is in the path, it might still not be visible; it could + * be hidden by another opclass of the same name earlier in the + * path. So we must do a slow check to see if this opclass would + * be found by OpclassnameGetOpcid. */ char *opcname = NameStr(opcform->opcname); @@ -1063,6 +1064,7 @@ DeconstructQualifiedName(List *names, catalogname = strVal(lfirst(names)); schemaname = strVal(lsecond(names)); objname = strVal(lfirst(lnext(lnext(names)))); + /* * We check the catalog name and then ignore it. */ @@ -1190,7 +1192,7 @@ char * NameListToString(List *names) { StringInfoData string; - List *l; + List *l; initStringInfo(&string); @@ -1248,11 +1250,12 @@ PopSpecialNamespace(Oid namespaceId) /* * FindConversionByName - find a conversion by possibly qualified name */ -Oid FindConversionByName(List *name) +Oid +FindConversionByName(List *name) { - char *conversion_name; - Oid namespaceId; - Oid conoid; + char *conversion_name; + Oid namespaceId; + Oid conoid; List *lptr; /* Convert list of names to a name and namespace */ @@ -1285,7 +1288,8 @@ Oid FindConversionByName(List *name) /* * FindDefaultConversionProc - find default encoding cnnversion proc */ -Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding) +Oid +FindDefaultConversionProc(int4 for_encoding, int4 to_encoding) { Oid proc; List *lptr; @@ -1341,13 +1345,13 @@ recomputeNamespacePath(void) * Convert the list of names to a list of OIDs. If any names are not * recognizable or we don't have read access, just leave them out of * the list. (We can't raise an error, since the search_path setting - * has already been accepted.) Don't make duplicate entries, either. + * has already been accepted.) Don't make duplicate entries, either. */ oidlist = NIL; foreach(l, namelist) { - char *curname = (char *) lfirst(l); - Oid namespaceId; + char *curname = (char *) lfirst(l); + Oid namespaceId; if (strcmp(curname, "$user") == 0) { @@ -1359,7 +1363,7 @@ recomputeNamespacePath(void) 0, 0, 0); if (HeapTupleIsValid(tuple)) { - char *uname; + char *uname; uname = NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename); namespaceId = GetSysCacheOid(NAMESPACENAME, @@ -1396,9 +1400,9 @@ recomputeNamespacePath(void) firstNS = (Oid) lfirsti(oidlist); /* - * Add any implicitly-searched namespaces to the list. Note these - * go on the front, not the back; also notice that we do not check - * USAGE permissions for these. + * Add any implicitly-searched namespaces to the list. Note these go + * on the front, not the back; also notice that we do not check USAGE + * permissions for these. */ if (!intMember(PG_CATALOG_NAMESPACE, oidlist)) oidlist = lconsi(PG_CATALOG_NAMESPACE, oidlist); @@ -1453,13 +1457,13 @@ InitTempTableNamespace(void) Oid namespaceId; /* - * First, do permission check to see if we are authorized to make - * temp tables. We use a nonstandard error message here since + * First, do permission check to see if we are authorized to make temp + * tables. We use a nonstandard error message here since * "databasename: permission denied" might be a tad cryptic. * - * Note we apply the check to the session user, not the currently - * active userid, since we are not going to change our minds about - * temp table availability during the session. + * Note we apply the check to the session user, not the currently active + * userid, since we are not going to change our minds about temp table + * availability during the session. */ if (pg_database_aclcheck(MyDatabaseId, GetSessionUserId(), ACL_CREATE_TEMP) != ACLCHECK_OK) @@ -1476,11 +1480,11 @@ InitTempTableNamespace(void) /* * First use of this temp namespace in this database; create it. * The temp namespaces are always owned by the superuser. We - * leave their permissions at default --- i.e., no access except to - * superuser --- to ensure that unprivileged users can't peek + * leave their permissions at default --- i.e., no access except + * to superuser --- to ensure that unprivileged users can't peek * at other backends' temp tables. This works because the places - * that access the temp namespace for my own backend skip permissions - * checks on it. + * that access the temp namespace for my own backend skip + * permissions checks on it. */ namespaceId = NamespaceCreate(namespaceName, BOOTSTRAP_USESYSID); /* Advance command counter to make namespace visible */ @@ -1504,7 +1508,7 @@ InitTempTableNamespace(void) firstTempTransaction = true; - namespaceSearchPathValid = false; /* need to rebuild list */ + namespaceSearchPathValid = false; /* need to rebuild list */ } /* @@ -1516,7 +1520,7 @@ AtEOXact_Namespace(bool isCommit) /* * If we abort the transaction in which a temp namespace was selected, * we'll have to do any creation or cleanout work over again. So, - * just forget the namespace entirely until next time. On the other + * just forget the namespace entirely until next time. On the other * hand, if we commit then register an exit callback to clean out the * temp tables at backend shutdown. (We only want to register the * callback once per session, so this is a good place to do it.) @@ -1528,17 +1532,18 @@ AtEOXact_Namespace(bool isCommit) else { myTempNamespace = InvalidOid; - namespaceSearchPathValid = false; /* need to rebuild list */ + namespaceSearchPathValid = false; /* need to rebuild list */ } firstTempTransaction = false; } + /* * Clean up if someone failed to do PopSpecialNamespace */ if (OidIsValid(mySpecialNamespace)) { mySpecialNamespace = InvalidOid; - namespaceSearchPathValid = false; /* need to rebuild list */ + namespaceSearchPathValid = false; /* need to rebuild list */ } } @@ -1561,14 +1566,14 @@ RemoveTempRelations(Oid tempNamespaceId) /* * Scan pg_class to find all the relations in the target namespace. - * Ignore indexes, though, on the assumption that they'll go away - * when their tables are deleted. + * Ignore indexes, though, on the assumption that they'll go away when + * their tables are deleted. * - * NOTE: if there are deletion constraints between temp relations, - * then our CASCADE delete call may cause as-yet-unvisited objects - * to go away. This is okay because we are using SnapshotNow; when - * the scan does reach those pg_class tuples, they'll be ignored as - * already deleted. + * NOTE: if there are deletion constraints between temp relations, then + * our CASCADE delete call may cause as-yet-unvisited objects to go + * away. This is okay because we are using SnapshotNow; when the scan + * does reach those pg_class tuples, they'll be ignored as already + * deleted. */ ScanKeyEntryInitialize(&key, 0x0, Anum_pg_class_relnamespace, @@ -1605,7 +1610,7 @@ RemoveTempRelations(Oid tempNamespaceId) static void RemoveTempRelationsCallback(void) { - if (OidIsValid(myTempNamespace)) /* should always be true */ + if (OidIsValid(myTempNamespace)) /* should always be true */ { /* Need to ensure we have a usable transaction. */ AbortOutOfAnyTransaction(); @@ -1644,18 +1649,19 @@ assign_search_path(const char *newval, bool doit, bool interactive) /* * If we aren't inside a transaction, we cannot do database access so - * cannot verify the individual names. Must accept the list on faith. + * cannot verify the individual names. Must accept the list on faith. */ if (interactive && IsTransactionState()) { /* * Verify that all the names are either valid namespace names or * "$user". We do not require $user to correspond to a valid - * namespace. We do not check for USAGE rights, either; should we? + * namespace. We do not check for USAGE rights, either; should + * we? */ foreach(l, namelist) { - char *curname = (char *) lfirst(l); + char *curname = (char *) lfirst(l); if (strcmp(curname, "$user") == 0) continue; @@ -1670,9 +1676,9 @@ assign_search_path(const char *newval, bool doit, bool interactive) freeList(namelist); /* - * We mark the path as needing recomputation, but don't do anything until - * it's needed. This avoids trying to do database access during GUC - * initialization. + * We mark the path as needing recomputation, but don't do anything + * until it's needed. This avoids trying to do database access during + * GUC initialization. */ if (doit) namespaceSearchPathValid = false; @@ -1692,7 +1698,8 @@ InitializeSearchPath(void) { /* * In bootstrap mode, the search path must be 'pg_catalog' so that - * tables are created in the proper namespace; ignore the GUC setting. + * tables are created in the proper namespace; ignore the GUC + * setting. */ MemoryContext oldcxt; @@ -1707,8 +1714,8 @@ InitializeSearchPath(void) else { /* - * In normal mode, arrange for a callback on any syscache invalidation - * of pg_namespace rows. + * In normal mode, arrange for a callback on any syscache + * invalidation of pg_namespace rows. */ CacheRegisterSyscacheCallback(NAMESPACEOID, NamespaceCallback, diff --git a/src/backend/catalog/pg_aggregate.c b/src/backend/catalog/pg_aggregate.c index 719d229b8d..7b83cf960d 100644 --- a/src/backend/catalog/pg_aggregate.c +++ b/src/backend/catalog/pg_aggregate.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.54 2002/08/22 00:01:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.55 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -54,8 +54,8 @@ AggregateCreate(const char *aggName, Oid procOid; TupleDesc tupDesc; int i; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* sanity checks */ if (!aggName) @@ -85,12 +85,12 @@ AggregateCreate(const char *aggName, proc = (Form_pg_proc) GETSTRUCT(tup); if (proc->prorettype != aggTransType) elog(ERROR, "return type of transition function %s is not %s", - NameListToString(aggtransfnName), format_type_be(aggTransType)); + NameListToString(aggtransfnName), format_type_be(aggTransType)); /* * If the transfn is strict and the initval is NULL, make sure input - * type and transtype are the same (or at least binary-compatible), - * so that it's OK to use the first input value as the initial + * type and transtype are the same (or at least binary-compatible), so + * that it's OK to use the first input value as the initial * transValue. */ if (proc->proisstrict && agginitval == NULL) @@ -128,26 +128,29 @@ AggregateCreate(const char *aggName, /* * Everything looks okay. Try to create the pg_proc entry for the - * aggregate. (This could fail if there's already a conflicting entry.) + * aggregate. (This could fail if there's already a conflicting + * entry.) */ MemSet(fnArgs, 0, FUNC_MAX_ARGS * sizeof(Oid)); fnArgs[0] = aggBaseType; procOid = ProcedureCreate(aggName, aggNamespace, - false, /* no replacement */ - false, /* doesn't return a set */ - finaltype, /* returnType */ - INTERNALlanguageId, /* languageObjectId */ + false, /* no replacement */ + false, /* doesn't return a set */ + finaltype, /* returnType */ + INTERNALlanguageId, /* languageObjectId */ 0, - "aggregate_dummy", /* placeholder proc */ - "-", /* probin */ - true, /* isAgg */ - false, /* security invoker (currently not definable for agg) */ - false, /* isStrict (not needed for agg) */ - PROVOLATILE_IMMUTABLE, /* volatility (not needed for agg) */ - 1, /* parameterCount */ - fnArgs); /* parameterTypes */ + "aggregate_dummy", /* placeholder proc */ + "-", /* probin */ + true, /* isAgg */ + false, /* security invoker (currently not + * definable for agg) */ + false, /* isStrict (not needed for agg) */ + PROVOLATILE_IMMUTABLE, /* volatility (not + * needed for agg) */ + 1, /* parameterCount */ + fnArgs); /* parameterTypes */ /* * Okay to create the pg_aggregate entry. diff --git a/src/backend/catalog/pg_constraint.c b/src/backend/catalog/pg_constraint.c index 85ca6eab64..92d455223b 100644 --- a/src/backend/catalog/pg_constraint.c +++ b/src/backend/catalog/pg_constraint.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.5 2002/08/26 17:53:57 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.6 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,7 +34,7 @@ * Create a constraint table entry. * * Subsidiary records (such as triggers or indexes to implement the - * constraint) are *not* created here. But we do make dependency links + * constraint) are *not* created here. But we do make dependency links * from the constraint to the things it depends on. */ Oid @@ -136,7 +136,7 @@ CreateConstraintEntry(const char *constraintName, */ if (conBin) values[Anum_pg_constraint_conbin - 1] = DirectFunctionCall1(textin, - CStringGetDatum(conBin)); + CStringGetDatum(conBin)); else nulls[Anum_pg_constraint_conbin - 1] = 'n'; @@ -145,7 +145,7 @@ CreateConstraintEntry(const char *constraintName, */ if (conSrc) values[Anum_pg_constraint_consrc - 1] = DirectFunctionCall1(textin, - CStringGetDatum(conSrc)); + CStringGetDatum(conSrc)); else nulls[Anum_pg_constraint_consrc - 1] = 'n'; @@ -165,10 +165,10 @@ CreateConstraintEntry(const char *constraintName, if (OidIsValid(relId)) { /* - * Register auto dependency from constraint to owning relation, - * or to specific column(s) if any are mentioned. + * Register auto dependency from constraint to owning relation, or + * to specific column(s) if any are mentioned. */ - ObjectAddress relobject; + ObjectAddress relobject; relobject.classId = RelOid_pg_class; relobject.objectId = relId; @@ -195,7 +195,7 @@ CreateConstraintEntry(const char *constraintName, * Register normal dependency from constraint to foreign relation, * or to specific column(s) if any are mentioned. */ - ObjectAddress relobject; + ObjectAddress relobject; relobject.classId = RelOid_pg_class; relobject.objectId = foreignRelId; @@ -219,11 +219,11 @@ CreateConstraintEntry(const char *constraintName, if (conExpr != NULL) { /* - * Register dependencies from constraint to objects mentioned - * in CHECK expression. We gin up a rather bogus rangetable - * list to handle any Vars in the constraint. + * Register dependencies from constraint to objects mentioned in + * CHECK expression. We gin up a rather bogus rangetable list to + * handle any Vars in the constraint. */ - RangeTblEntry rte; + RangeTblEntry rte; MemSet(&rte, 0, sizeof(rte)); rte.type = T_RangeTblEntry; @@ -271,7 +271,7 @@ ConstraintNameIsUsed(Oid relId, Oid relNamespace, const char *cname) while (HeapTupleIsValid(tup = systable_getnext(conscan))) { - Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup); + Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup); if (con->conrelid == relId) { @@ -338,7 +338,7 @@ GenerateConstraintName(Oid relId, Oid relNamespace, int *counter) while (HeapTupleIsValid(tup = systable_getnext(conscan))) { - Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup); + Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tup); if (con->conrelid == relId) { @@ -366,7 +366,7 @@ ConstraintNameIsGenerated(const char *cname) { if (cname[0] != '$') return false; - if (strspn(cname+1, "0123456789") != strlen(cname+1)) + if (strspn(cname + 1, "0123456789") != strlen(cname + 1)) return false; return true; } @@ -377,11 +377,11 @@ ConstraintNameIsGenerated(const char *cname) void RemoveConstraintById(Oid conId) { - Relation conDesc; - ScanKeyData skey[1]; - SysScanDesc conscan; - HeapTuple tup; - Form_pg_constraint con; + Relation conDesc; + ScanKeyData skey[1]; + SysScanDesc conscan; + HeapTuple tup; + Form_pg_constraint con; conDesc = heap_openr(ConstraintRelationName, RowExclusiveLock); @@ -399,8 +399,8 @@ RemoveConstraintById(Oid conId) con = (Form_pg_constraint) GETSTRUCT(tup); /* - * If the constraint is for a relation, open and exclusive-lock - * the relation it's for. + * If the constraint is for a relation, open and exclusive-lock the + * relation it's for. * * XXX not clear what we should lock, if anything, for other constraints. */ @@ -411,16 +411,16 @@ RemoveConstraintById(Oid conId) rel = heap_open(con->conrelid, AccessExclusiveLock); /* - * We need to update the relcheck count if it is a check constraint - * being dropped. This update will force backends to rebuild - * relcache entries when we commit. + * We need to update the relcheck count if it is a check + * constraint being dropped. This update will force backends to + * rebuild relcache entries when we commit. */ if (con->contype == CONSTRAINT_CHECK) { - Relation pgrel; - HeapTuple relTup; - Form_pg_class classForm; - + Relation pgrel; + HeapTuple relTup; + Form_pg_class classForm; + pgrel = heap_openr(RelationRelationName, RowExclusiveLock); relTup = SearchSysCacheCopy(RELOID, ObjectIdGetDatum(con->conrelid), diff --git a/src/backend/catalog/pg_conversion.c b/src/backend/catalog/pg_conversion.c index 7dfd0679a2..bd721507ed 100644 --- a/src/backend/catalog/pg_conversion.c +++ b/src/backend/catalog/pg_conversion.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.5 2002/08/06 05:40:45 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.6 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,12 +36,13 @@ * Add a new tuple to pg_coversion. * --------------- */ -Oid ConversionCreate(const char *conname, Oid connamespace, - int32 conowner, - int4 conforencoding, int4 contoencoding, - Oid conproc, bool def) +Oid +ConversionCreate(const char *conname, Oid connamespace, + int32 conowner, + int4 conforencoding, int4 contoencoding, + Oid conproc, bool def) { - int i; + int i; Relation rel; TupleDesc tupDesc; HeapTuple tup; @@ -49,8 +50,8 @@ Oid ConversionCreate(const char *conname, Oid connamespace, Datum values[Natts_pg_conversion]; NameData cname; Oid oid; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* sanity checks */ if (!conname) @@ -58,20 +59,22 @@ Oid ConversionCreate(const char *conname, Oid connamespace, /* make sure there is no existing conversion of same name */ if (SearchSysCacheExists(CONNAMESP, - PointerGetDatum(conname), - ObjectIdGetDatum(connamespace), - 0,0)) + PointerGetDatum(conname), + ObjectIdGetDatum(connamespace), + 0, 0)) elog(ERROR, "conversion name \"%s\" already exists", conname); if (def) { - /* make sure there is no existing default - <for encoding><to encoding> pair in this name space */ + /* + * make sure there is no existing default <for encoding><to + * encoding> pair in this name space + */ if (FindDefaultConversion(connamespace, conforencoding, contoencoding)) elog(ERROR, "default conversion for %s to %s already exists", - pg_encoding_to_char(conforencoding),pg_encoding_to_char(contoencoding)); + pg_encoding_to_char(conforencoding), pg_encoding_to_char(contoencoding)); } /* open pg_conversion */ @@ -129,8 +132,9 @@ Oid ConversionCreate(const char *conname, Oid connamespace, * Drop a conversion and do dependency check. * --------------- */ -void ConversionDrop(const char *conname, Oid connamespace, - int32 conowner, DropBehavior behavior) +void +ConversionDrop(const char *conname, Oid connamespace, + int32 conowner, DropBehavior behavior) { Relation rel; TupleDesc tupDesc; @@ -138,8 +142,8 @@ void ConversionDrop(const char *conname, Oid connamespace, HeapScanDesc scan; ScanKeyData scanKeyData; Form_pg_conversion body; - ObjectAddress object; - Oid myoid; + ObjectAddress object; + Oid myoid; /* sanity checks */ if (!conname) @@ -156,12 +160,12 @@ void ConversionDrop(const char *conname, Oid connamespace, tupDesc = rel->rd_att; scan = heap_beginscan(rel, SnapshotNow, - 1, &scanKeyData); + 1, &scanKeyData); /* search for the target tuple */ while (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection))) { - body = (Form_pg_conversion)GETSTRUCT(tuple); + body = (Form_pg_conversion) GETSTRUCT(tuple); if (!strncmp(NameStr(body->conname), conname, NAMEDATALEN)) break; } @@ -172,12 +176,12 @@ void ConversionDrop(const char *conname, Oid connamespace, return; } - if (!superuser() && ((Form_pg_conversion)GETSTRUCT(tuple))->conowner != GetUserId()) + if (!superuser() && ((Form_pg_conversion) GETSTRUCT(tuple))->conowner != GetUserId()) elog(ERROR, "permission denied"); myoid = HeapTupleGetOid(tuple); heap_endscan(scan); - heap_close(rel, AccessShareLock); + heap_close(rel, AccessShareLock); /* * Do the deletion @@ -215,7 +219,7 @@ RemoveConversionById(Oid conversionOid) tupDesc = rel->rd_att; scan = heap_beginscan(rel, SnapshotNow, - 1, &scanKeyData); + 1, &scanKeyData); /* search for the target tuple */ if (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection))) @@ -233,28 +237,29 @@ RemoveConversionById(Oid conversionOid) * If found, returns the procedure's oid, otherwise InvalidOid. * --------------- */ -Oid FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding) +Oid +FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding) { - CatCList *catlist; + CatCList *catlist; HeapTuple tuple; Form_pg_conversion body; - Oid proc = InvalidOid; - int i; + Oid proc = InvalidOid; + int i; /* Check we have usage rights in target namespace */ if (pg_namespace_aclcheck(name_space, GetUserId(), ACL_USAGE) != ACLCHECK_OK) return proc; catlist = SearchSysCacheList(CONDEFAULT, 3, - ObjectIdGetDatum(name_space), - Int32GetDatum(for_encoding), - Int32GetDatum(to_encoding), - 0); + ObjectIdGetDatum(name_space), + Int32GetDatum(for_encoding), + Int32GetDatum(to_encoding), + 0); for (i = 0; i < catlist->n_members; i++) { tuple = &catlist->members[i]->tuple; - body = (Form_pg_conversion)GETSTRUCT(tuple); + body = (Form_pg_conversion) GETSTRUCT(tuple); if (body->condefault == TRUE) { proc = body->conproc; @@ -272,22 +277,23 @@ Oid FindDefaultConversion(Oid name_space, int4 for_encoding, int4 to_encoding) * Returns conversion oid. * --------------- */ -Oid FindConversion(const char *conname, Oid connamespace) +Oid +FindConversion(const char *conname, Oid connamespace) { HeapTuple tuple; - Oid procoid; - Oid conoid; + Oid procoid; + Oid conoid; AclResult aclresult; /* search pg_conversion by connamespace and conversion name */ tuple = SearchSysCache(CONNAMESP, PointerGetDatum(conname), ObjectIdGetDatum(connamespace), - 0,0); + 0, 0); if (!HeapTupleIsValid(tuple)) return InvalidOid; - procoid = ((Form_pg_conversion)GETSTRUCT(tuple))->conproc; + procoid = ((Form_pg_conversion) GETSTRUCT(tuple))->conproc; conoid = HeapTupleGetOid(tuple); ReleaseSysCache(tuple); @@ -318,7 +324,7 @@ pg_convert3(PG_FUNCTION_ARGS) text *retval; unsigned char *str; unsigned char *result; - int len; + int len; if (!OidIsValid(convoid)) elog(ERROR, "Conversion does not exist"); @@ -331,13 +337,13 @@ pg_convert3(PG_FUNCTION_ARGS) tuple = SearchSysCache(CONOID, ObjectIdGetDatum(convoid), - 0,0,0); + 0, 0, 0); if (!HeapTupleIsValid(tuple)) elog(ERROR, "Conversion %u search from syscache failed", convoid); result = palloc(len * 4 + 1); - body = (Form_pg_conversion)GETSTRUCT(tuple); + body = (Form_pg_conversion) GETSTRUCT(tuple); OidFunctionCall5(body->conproc, Int32GetDatum(body->conforencoding), Int32GetDatum(body->contoencoding), @@ -347,9 +353,11 @@ pg_convert3(PG_FUNCTION_ARGS) ReleaseSysCache(tuple); - /* build text data type structre. we cannot use textin() here, - since textin assumes that input string encoding is same as - database encoding. */ + /* + * build text data type structre. we cannot use textin() here, since + * textin assumes that input string encoding is same as database + * encoding. + */ len = strlen(result) + VARHDRSZ; retval = palloc(len); VARATT_SIZEP(retval) = len; diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c index 0427b37bb9..cd058a1306 100644 --- a/src/backend/catalog/pg_depend.c +++ b/src/backend/catalog/pg_depend.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.5 2002/08/11 21:17:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.6 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,7 +44,7 @@ recordDependencyOn(const ObjectAddress *depender, /* * Record multiple dependencies (of the same kind) for a single dependent - * object. This has a little less overhead than recording each separately. + * object. This has a little less overhead than recording each separately. */ void recordMultipleDependencies(const ObjectAddress *depender, @@ -79,9 +79,9 @@ recordMultipleDependencies(const ObjectAddress *depender, for (i = 0; i < nreferenced; i++, referenced++) { /* - * If the referenced object is pinned by the system, there's no real - * need to record dependencies on it. This saves lots of space in - * pg_depend, so it's worth the time taken to check. + * If the referenced object is pinned by the system, there's no + * real need to record dependencies on it. This saves lots of + * space in pg_depend, so it's worth the time taken to check. */ if (!isObjectPinned(referenced, dependDesc)) { @@ -89,15 +89,15 @@ recordMultipleDependencies(const ObjectAddress *depender, * Record the Dependency. Note we don't bother to check for * duplicate dependencies; there's no harm in them. */ - values[Anum_pg_depend_classid - 1] = ObjectIdGetDatum(depender->classId); - values[Anum_pg_depend_objid - 1] = ObjectIdGetDatum(depender->objectId); - values[Anum_pg_depend_objsubid - 1] = Int32GetDatum(depender->objectSubId); + values[Anum_pg_depend_classid - 1] = ObjectIdGetDatum(depender->classId); + values[Anum_pg_depend_objid - 1] = ObjectIdGetDatum(depender->objectId); + values[Anum_pg_depend_objsubid - 1] = Int32GetDatum(depender->objectSubId); - values[Anum_pg_depend_refclassid - 1] = ObjectIdGetDatum(referenced->classId); - values[Anum_pg_depend_refobjid - 1] = ObjectIdGetDatum(referenced->objectId); - values[Anum_pg_depend_refobjsubid - 1] = Int32GetDatum(referenced->objectSubId); + values[Anum_pg_depend_refclassid - 1] = ObjectIdGetDatum(referenced->classId); + values[Anum_pg_depend_refobjid - 1] = ObjectIdGetDatum(referenced->objectId); + values[Anum_pg_depend_refobjsubid - 1] = Int32GetDatum(referenced->objectSubId); - values[Anum_pg_depend_deptype -1] = CharGetDatum((char) behavior); + values[Anum_pg_depend_deptype - 1] = CharGetDatum((char) behavior); tup = heap_formtuple(dependDesc->rd_att, values, nulls); @@ -130,11 +130,11 @@ recordMultipleDependencies(const ObjectAddress *depender, long deleteDependencyRecordsFor(Oid classId, Oid objectId) { - long count = 0; - Relation depRel; - ScanKeyData key[2]; - SysScanDesc scan; - HeapTuple tup; + long count = 0; + Relation depRel; + ScanKeyData key[2]; + SysScanDesc scan; + HeapTuple tup; depRel = heap_openr(DependRelationName, RowExclusiveLock); @@ -174,7 +174,7 @@ static bool isObjectPinned(const ObjectAddress *object, Relation rel) { bool ret = false; - SysScanDesc scan; + SysScanDesc scan; HeapTuple tup; ScanKeyData key[2]; @@ -192,13 +192,13 @@ isObjectPinned(const ObjectAddress *object, Relation rel) /* * Since we won't generate additional pg_depend entries for pinned * objects, there can be at most one entry referencing a pinned - * object. Hence, it's sufficient to look at the first returned + * object. Hence, it's sufficient to look at the first returned * tuple; we don't need to loop. */ tup = systable_getnext(scan); if (HeapTupleIsValid(tup)) { - Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup); + Form_pg_depend foundDep = (Form_pg_depend) GETSTRUCT(tup); if (foundDep->deptype == DEPENDENCY_PIN) ret = true; diff --git a/src/backend/catalog/pg_operator.c b/src/backend/catalog/pg_operator.c index 8c6174608f..941212a649 100644 --- a/src/backend/catalog/pg_operator.c +++ b/src/backend/catalog/pg_operator.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.76 2002/08/22 00:01:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.77 2002/09/04 20:31:14 momjian Exp $ * * NOTES * these routines moved here from commands/define.c and somewhat cleaned up. @@ -34,28 +34,28 @@ static Oid OperatorGet(const char *operatorName, - Oid operatorNamespace, - Oid leftObjectId, - Oid rightObjectId, - bool *defined); + Oid operatorNamespace, + Oid leftObjectId, + Oid rightObjectId, + bool *defined); static Oid OperatorLookup(List *operatorName, - Oid leftObjectId, - Oid rightObjectId, - bool *defined); + Oid leftObjectId, + Oid rightObjectId, + bool *defined); static Oid OperatorShellMake(const char *operatorName, - Oid operatorNamespace, - Oid leftTypeId, - Oid rightTypeId); + Oid operatorNamespace, + Oid leftTypeId, + Oid rightTypeId); static void OperatorUpd(Oid baseId, Oid commId, Oid negId); static Oid get_other_operator(List *otherOp, - Oid otherLeftTypeId, Oid otherRightTypeId, - const char *operatorName, Oid operatorNamespace, - Oid leftTypeId, Oid rightTypeId, - bool isCommutator); + Oid otherLeftTypeId, Oid otherRightTypeId, + const char *operatorName, Oid operatorNamespace, + Oid leftTypeId, Oid rightTypeId, + bool isCommutator); static void makeOperatorDependencies(HeapTuple tuple, Oid pg_operator_relid); @@ -229,23 +229,23 @@ OperatorShellMake(const char *operatorName, */ i = 0; namestrcpy(&oname, operatorName); - values[i++] = NameGetDatum(&oname); /* oprname */ + values[i++] = NameGetDatum(&oname); /* oprname */ values[i++] = ObjectIdGetDatum(operatorNamespace); /* oprnamespace */ - values[i++] = Int32GetDatum(GetUserId()); /* oprowner */ + values[i++] = Int32GetDatum(GetUserId()); /* oprowner */ values[i++] = CharGetDatum(leftTypeId ? (rightTypeId ? 'b' : 'r') : 'l'); /* oprkind */ - values[i++] = BoolGetDatum(false); /* oprcanhash */ - values[i++] = ObjectIdGetDatum(leftTypeId); /* oprleft */ - values[i++] = ObjectIdGetDatum(rightTypeId); /* oprright */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprresult */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprcom */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprnegate */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprlsortop */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprrsortop */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprltcmpop */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprgtcmpop */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprcode */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprrest */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* oprjoin */ + values[i++] = BoolGetDatum(false); /* oprcanhash */ + values[i++] = ObjectIdGetDatum(leftTypeId); /* oprleft */ + values[i++] = ObjectIdGetDatum(rightTypeId); /* oprright */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprresult */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprcom */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprnegate */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprlsortop */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprrsortop */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprltcmpop */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprgtcmpop */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprcode */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprrest */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* oprjoin */ /* * open pg_operator @@ -506,14 +506,14 @@ OperatorCreate(const char *operatorName, i = 0; namestrcpy(&oname, operatorName); - values[i++] = NameGetDatum(&oname); /* oprname */ + values[i++] = NameGetDatum(&oname); /* oprname */ values[i++] = ObjectIdGetDatum(operatorNamespace); /* oprnamespace */ - values[i++] = Int32GetDatum(GetUserId()); /* oprowner */ + values[i++] = Int32GetDatum(GetUserId()); /* oprowner */ values[i++] = CharGetDatum(leftTypeId ? (rightTypeId ? 'b' : 'r') : 'l'); /* oprkind */ - values[i++] = BoolGetDatum(canHash); /* oprcanhash */ - values[i++] = ObjectIdGetDatum(leftTypeId); /* oprleft */ - values[i++] = ObjectIdGetDatum(rightTypeId); /* oprright */ - values[i++] = ObjectIdGetDatum(operResultType); /* oprresult */ + values[i++] = BoolGetDatum(canHash); /* oprcanhash */ + values[i++] = ObjectIdGetDatum(leftTypeId); /* oprleft */ + values[i++] = ObjectIdGetDatum(rightTypeId); /* oprright */ + values[i++] = ObjectIdGetDatum(operResultType); /* oprresult */ /* * Set up the other operators. If they do not currently exist, create @@ -528,16 +528,17 @@ OperatorCreate(const char *operatorName, operatorName, operatorNamespace, leftTypeId, rightTypeId, true); + /* - * self-linkage to this operator; will fix below. Note - * that only self-linkage for commutation makes sense. + * self-linkage to this operator; will fix below. Note that only + * self-linkage for commutation makes sense. */ if (!OidIsValid(commutatorId)) selfCommutator = true; } else commutatorId = InvalidOid; - values[i++] = ObjectIdGetDatum(commutatorId); /* oprcom */ + values[i++] = ObjectIdGetDatum(commutatorId); /* oprcom */ if (negatorName) { @@ -550,20 +551,20 @@ OperatorCreate(const char *operatorName, } else negatorId = InvalidOid; - values[i++] = ObjectIdGetDatum(negatorId); /* oprnegate */ + values[i++] = ObjectIdGetDatum(negatorId); /* oprnegate */ if (leftSortName) { /* left sort op takes left-side data type */ leftSortId = get_other_operator(leftSortName, - leftTypeId, leftTypeId, - operatorName, operatorNamespace, - leftTypeId, rightTypeId, - false); + leftTypeId, leftTypeId, + operatorName, operatorNamespace, + leftTypeId, rightTypeId, + false); } else leftSortId = InvalidOid; - values[i++] = ObjectIdGetDatum(leftSortId); /* oprlsortop */ + values[i++] = ObjectIdGetDatum(leftSortId); /* oprlsortop */ if (rightSortName) { @@ -576,7 +577,7 @@ OperatorCreate(const char *operatorName, } else rightSortId = InvalidOid; - values[i++] = ObjectIdGetDatum(rightSortId); /* oprrsortop */ + values[i++] = ObjectIdGetDatum(rightSortId); /* oprrsortop */ if (ltCompareName) { @@ -589,7 +590,7 @@ OperatorCreate(const char *operatorName, } else ltCompareId = InvalidOid; - values[i++] = ObjectIdGetDatum(ltCompareId); /* oprltcmpop */ + values[i++] = ObjectIdGetDatum(ltCompareId); /* oprltcmpop */ if (gtCompareName) { @@ -602,11 +603,11 @@ OperatorCreate(const char *operatorName, } else gtCompareId = InvalidOid; - values[i++] = ObjectIdGetDatum(gtCompareId); /* oprgtcmpop */ + values[i++] = ObjectIdGetDatum(gtCompareId); /* oprgtcmpop */ - values[i++] = ObjectIdGetDatum(procOid); /* oprcode */ - values[i++] = ObjectIdGetDatum(restOid); /* oprrest */ - values[i++] = ObjectIdGetDatum(joinOid); /* oprjoin */ + values[i++] = ObjectIdGetDatum(procOid); /* oprcode */ + values[i++] = ObjectIdGetDatum(restOid); /* oprrest */ + values[i++] = ObjectIdGetDatum(joinOid); /* oprjoin */ pg_operator_desc = heap_openr(OperatorRelationName, RowExclusiveLock); @@ -703,8 +704,8 @@ get_other_operator(List *otherOp, Oid otherLeftTypeId, Oid otherRightTypeId, otherRightTypeId == rightTypeId) { /* - * self-linkage to this operator; caller will fix later. Note - * that only self-linkage for commutation makes sense. + * self-linkage to this operator; caller will fix later. Note that + * only self-linkage for commutation makes sense. */ if (!isCommutator) elog(ERROR, "operator cannot be its own negator or sort operator"); @@ -868,9 +869,9 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) static void makeOperatorDependencies(HeapTuple tuple, Oid pg_operator_relid) { - Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple); - ObjectAddress myself, - referenced; + Form_pg_operator oper = (Form_pg_operator) GETSTRUCT(tuple); + ObjectAddress myself, + referenced; myself.classId = pg_operator_relid; myself.objectId = HeapTupleGetOid(tuple); @@ -918,11 +919,11 @@ makeOperatorDependencies(HeapTuple tuple, Oid pg_operator_relid) /* * NOTE: we do not consider the operator to depend on the associated * operators oprcom, oprnegate, oprlsortop, oprrsortop, oprltcmpop, - * oprgtcmpop. We would not want to delete this operator if those - * go away, but only reset the link fields; which is not a function - * that the dependency code can presently handle. (Something could - * perhaps be done with objectSubId though.) For now, it's okay to - * let those links dangle if a referenced operator is removed. + * oprgtcmpop. We would not want to delete this operator if those go + * away, but only reset the link fields; which is not a function that + * the dependency code can presently handle. (Something could perhaps + * be done with objectSubId though.) For now, it's okay to let those + * links dangle if a referenced operator is removed. */ /* Dependency on implementation function */ diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c index 805ce61930..ba667a2654 100644 --- a/src/backend/catalog/pg_proc.c +++ b/src/backend/catalog/pg_proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.92 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.93 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,9 +34,9 @@ static void checkretval(Oid rettype, char fn_typtype, List *queryTreeList); -Datum fmgr_internal_validator(PG_FUNCTION_ARGS); -Datum fmgr_c_validator(PG_FUNCTION_ARGS); -Datum fmgr_sql_validator(PG_FUNCTION_ARGS); +Datum fmgr_internal_validator(PG_FUNCTION_ARGS); +Datum fmgr_c_validator(PG_FUNCTION_ARGS); +Datum fmgr_sql_validator(PG_FUNCTION_ARGS); /* ---------------------------------------------------------------- @@ -73,8 +73,8 @@ ProcedureCreate(const char *procedureName, TupleDesc tupDesc; Oid retval; bool is_update; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* * sanity checks @@ -153,16 +153,16 @@ ProcedureCreate(const char *procedureName, i = 0; namestrcpy(&procname, procedureName); values[i++] = NameGetDatum(&procname); /* proname */ - values[i++] = ObjectIdGetDatum(procNamespace); /* pronamespace */ + values[i++] = ObjectIdGetDatum(procNamespace); /* pronamespace */ values[i++] = Int32GetDatum(GetUserId()); /* proowner */ - values[i++] = ObjectIdGetDatum(languageObjectId); /* prolang */ - values[i++] = BoolGetDatum(isAgg); /* proisagg */ - values[i++] = BoolGetDatum(security_definer); /* prosecdef */ + values[i++] = ObjectIdGetDatum(languageObjectId); /* prolang */ + values[i++] = BoolGetDatum(isAgg); /* proisagg */ + values[i++] = BoolGetDatum(security_definer); /* prosecdef */ values[i++] = BoolGetDatum(isStrict); /* proisstrict */ values[i++] = BoolGetDatum(returnsSet); /* proretset */ values[i++] = CharGetDatum(volatility); /* provolatile */ - values[i++] = UInt16GetDatum(parameterCount); /* pronargs */ - values[i++] = ObjectIdGetDatum(returnType); /* prorettype */ + values[i++] = UInt16GetDatum(parameterCount); /* pronargs */ + values[i++] = ObjectIdGetDatum(returnType); /* prorettype */ values[i++] = PointerGetDatum(typev); /* proargtypes */ values[i++] = DirectFunctionCall1(textin, /* prosrc */ CStringGetDatum(prosrc)); @@ -213,8 +213,8 @@ ProcedureCreate(const char *procedureName, } /* do not change existing ownership or permissions, either */ - replaces[Anum_pg_proc_proowner-1] = ' '; - replaces[Anum_pg_proc_proacl-1] = ' '; + replaces[Anum_pg_proc_proowner - 1] = ' '; + replaces[Anum_pg_proc_proacl - 1] = ' '; /* Okay, do it... */ tup = heap_modifytuple(oldtup, rel, values, nulls, replaces); @@ -228,7 +228,7 @@ ProcedureCreate(const char *procedureName, /* Creating a new procedure */ /* start out with empty permissions */ - nulls[Anum_pg_proc_proacl-1] = 'n'; + nulls[Anum_pg_proc_proacl - 1] = 'n'; tup = heap_formtuple(tupDesc, values, nulls); simple_heap_insert(rel, tup); @@ -332,7 +332,8 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) tlist = parse->targetList; /* - * The last query must be a SELECT if and only if return type isn't VOID. + * The last query must be a SELECT if and only if return type isn't + * VOID. */ if (rettype == VOIDOID) { @@ -360,8 +361,8 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) /* * For base-type returns, the target list should have exactly one - * entry, and its type should agree with what the user declared. (As - * of Postgres 7.2, we accept binary-compatible types too.) + * entry, and its type should agree with what the user declared. + * (As of Postgres 7.2, we accept binary-compatible types too.) */ if (tlistlen != 1) elog(ERROR, "function declared to return %s returns multiple columns in final SELECT", @@ -378,11 +379,11 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) Assert(typerelid != InvalidOid); /* - * If the target list is of length 1, and the type of the varnode in - * the target list matches the declared return type, this is okay. - * This can happen, for example, where the body of the function is - * 'SELECT func2()', where func2 has the same return type as the - * function that's calling it. + * If the target list is of length 1, and the type of the varnode + * in the target list matches the declared return type, this is + * okay. This can happen, for example, where the body of the + * function is 'SELECT func2()', where func2 has the same return + * type as the function that's calling it. */ if (tlistlen == 1) { @@ -392,15 +393,15 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) } /* - * Otherwise verify that the targetlist matches the return tuple type. - * This part of the typechecking is a hack. We look up the relation - * that is the declared return type, and scan the non-deleted - * attributes to ensure that they match the datatypes of the - * non-resjunk columns. + * Otherwise verify that the targetlist matches the return tuple + * type. This part of the typechecking is a hack. We look up the + * relation that is the declared return type, and scan the + * non-deleted attributes to ensure that they match the datatypes + * of the non-resjunk columns. */ reln = relation_open(typerelid, AccessShareLock); relnatts = reln->rd_rel->relnatts; - rellogcols = 0; /* we'll count nondeleted cols as we go */ + rellogcols = 0; /* we'll count nondeleted cols as we go */ colindex = 0; foreach(tlistitem, tlist) @@ -413,7 +414,8 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) if (tle->resdom->resjunk) continue; - do { + do + { colindex++; if (colindex > relnatts) elog(ERROR, "function declared to return %s does not SELECT the right number of columns (%d)", @@ -453,8 +455,8 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList) Assert(typerelid == InvalidOid); /* - * For RECORD return type, defer this check until we get the - * first tuple. + * For RECORD return type, defer this check until we get the first + * tuple. */ } else @@ -532,7 +534,7 @@ fmgr_c_validator(PG_FUNCTION_ARGS) if (isnull) elog(ERROR, "null probin"); probin = DatumGetCString(DirectFunctionCall1(textout, tmp)); - + (void) load_external_function(probin, prosrc, true, &libraryhandle); (void) fetch_finfo_record(libraryhandle, prosrc); diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index e3eb6abe32..d43c1edeee 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.81 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.82 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -73,7 +73,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace) i = 0; namestrcpy(&name, typeName); values[i++] = NameGetDatum(&name); /* typname */ - values[i++] = ObjectIdGetDatum(typeNamespace); /* typnamespace */ + values[i++] = ObjectIdGetDatum(typeNamespace); /* typnamespace */ values[i++] = ObjectIdGetDatum(InvalidOid); /* typowner */ values[i++] = Int16GetDatum(0); /* typlen */ values[i++] = BoolGetDatum(false); /* typbyval */ @@ -84,12 +84,12 @@ TypeShellMake(const char *typeName, Oid typeNamespace) values[i++] = ObjectIdGetDatum(InvalidOid); /* typelem */ values[i++] = ObjectIdGetDatum(InvalidOid); /* typinput */ values[i++] = ObjectIdGetDatum(InvalidOid); /* typoutput */ - values[i++] = CharGetDatum('i'); /* typalign */ - values[i++] = CharGetDatum('p'); /* typstorage */ - values[i++] = BoolGetDatum(false); /* typnotnull */ - values[i++] = ObjectIdGetDatum(InvalidOid); /* typbasetype */ - values[i++] = Int32GetDatum(-1); /* typtypmod */ - values[i++] = Int32GetDatum(0); /* typndims */ + values[i++] = CharGetDatum('i'); /* typalign */ + values[i++] = CharGetDatum('p'); /* typstorage */ + values[i++] = BoolGetDatum(false); /* typnotnull */ + values[i++] = ObjectIdGetDatum(InvalidOid); /* typbasetype */ + values[i++] = Int32GetDatum(-1); /* typtypmod */ + values[i++] = Int32GetDatum(0); /* typndims */ nulls[i++] = 'n'; /* typdefaultbin */ nulls[i++] = 'n'; /* typdefault */ @@ -129,8 +129,8 @@ Oid TypeCreate(const char *typeName, Oid typeNamespace, Oid assignedTypeOid, - Oid relationOid, /* only for 'c'atalog typeType */ - char relationKind, /* ditto */ + Oid relationOid, /* only for 'c'atalog typeType */ + char relationKind, /* ditto */ int16 internalSize, char typeType, char typDelim, @@ -138,13 +138,13 @@ TypeCreate(const char *typeName, Oid outputProcedure, Oid elementType, Oid baseType, - const char *defaultTypeValue, /* human readable rep */ + const char *defaultTypeValue, /* human readable rep */ const char *defaultTypeBin, /* cooked rep */ bool passedByValue, char alignment, char storage, int32 typeMod, - int32 typNDims, /* Array dimensions for baseType */ + int32 typNDims, /* Array dimensions for baseType */ bool typeNotNull) { Relation pg_type_desc; @@ -158,8 +158,8 @@ TypeCreate(const char *typeName, int i; /* - * We assume that the caller validated the arguments individually, - * but did not check for bad combinations. + * We assume that the caller validated the arguments individually, but + * did not check for bad combinations. * * Validate size specifications: either positive (fixed-length) or -1 * (varlena) or -2 (cstring). Pass-by-value types must have a fixed @@ -195,27 +195,27 @@ TypeCreate(const char *typeName, i = 0; namestrcpy(&name, typeName); values[i++] = NameGetDatum(&name); /* typname */ - values[i++] = ObjectIdGetDatum(typeNamespace); /* typnamespace */ + values[i++] = ObjectIdGetDatum(typeNamespace); /* typnamespace */ values[i++] = Int32GetDatum(GetUserId()); /* typowner */ values[i++] = Int16GetDatum(internalSize); /* typlen */ values[i++] = BoolGetDatum(passedByValue); /* typbyval */ values[i++] = CharGetDatum(typeType); /* typtype */ - values[i++] = BoolGetDatum(true); /* typisdefined */ + values[i++] = BoolGetDatum(true); /* typisdefined */ values[i++] = CharGetDatum(typDelim); /* typdelim */ values[i++] = ObjectIdGetDatum(typeType == 'c' ? relationOid : InvalidOid); /* typrelid */ - values[i++] = ObjectIdGetDatum(elementType); /* typelem */ - values[i++] = ObjectIdGetDatum(inputProcedure); /* typinput */ - values[i++] = ObjectIdGetDatum(outputProcedure); /* typoutput */ + values[i++] = ObjectIdGetDatum(elementType); /* typelem */ + values[i++] = ObjectIdGetDatum(inputProcedure); /* typinput */ + values[i++] = ObjectIdGetDatum(outputProcedure); /* typoutput */ values[i++] = CharGetDatum(alignment); /* typalign */ values[i++] = CharGetDatum(storage); /* typstorage */ - values[i++] = BoolGetDatum(typeNotNull); /* typnotnull */ - values[i++] = ObjectIdGetDatum(baseType); /* typbasetype */ - values[i++] = Int32GetDatum(typeMod); /* typtypmod */ - values[i++] = Int32GetDatum(typNDims); /* typndims */ + values[i++] = BoolGetDatum(typeNotNull); /* typnotnull */ + values[i++] = ObjectIdGetDatum(baseType); /* typbasetype */ + values[i++] = Int32GetDatum(typeMod); /* typtypmod */ + values[i++] = Int32GetDatum(typNDims); /* typndims */ /* - * initialize the default binary value for this type. Check for - * nulls of course. + * initialize the default binary value for this type. Check for nulls + * of course. */ if (defaultTypeBin) values[i] = DirectFunctionCall1(textin, @@ -229,7 +229,7 @@ TypeCreate(const char *typeName, */ if (defaultTypeValue) values[i] = DirectFunctionCall1(textin, - CStringGetDatum(defaultTypeValue)); + CStringGetDatum(defaultTypeValue)); else nulls[i] = 'n'; i++; /* typdefault */ @@ -291,8 +291,8 @@ TypeCreate(const char *typeName, */ if (!IsBootstrapProcessingMode()) { - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; myself.classId = RelOid_pg_type; myself.objectId = typeObjectId; @@ -321,13 +321,13 @@ TypeCreate(const char *typeName, /* * If the type is a rowtype for a relation, mark it as internally - * dependent on the relation, *unless* it is a stand-alone composite - * type relation. For the latter case, we have to reverse the - * dependency. + * dependent on the relation, *unless* it is a stand-alone + * composite type relation. For the latter case, we have to + * reverse the dependency. * - * In the former case, this allows the type to be auto-dropped - * when the relation is, and not otherwise. And in the latter, - * of course we get the opposite effect. + * In the former case, this allows the type to be auto-dropped when + * the relation is, and not otherwise. And in the latter, of + * course we get the opposite effect. */ if (OidIsValid(relationOid)) { @@ -342,11 +342,11 @@ TypeCreate(const char *typeName, } /* - * If the type is an array type, mark it auto-dependent on the base - * type. (This is a compromise between the typical case where the - * array type is automatically generated and the case where it is - * manually created: we'd prefer INTERNAL for the former case and - * NORMAL for the latter.) + * If the type is an array type, mark it auto-dependent on the + * base type. (This is a compromise between the typical case + * where the array type is automatically generated and the case + * where it is manually created: we'd prefer INTERNAL for the + * former case and NORMAL for the latter.) */ if (OidIsValid(elementType)) { diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c index 85ee9e3f53..552573dc1a 100644 --- a/src/backend/commands/aggregatecmds.c +++ b/src/backend/commands/aggregatecmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v 1.4 2002/08/22 00:01:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v 1.5 2002/09/04 20:31:14 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -110,8 +110,8 @@ DefineAggregate(List *names, List *parameters) * We have historically allowed the command to look like basetype = 'ANY' * so we must do a case-insensitive comparison for the name ANY. Ugh. * - * basetype can be a pseudo-type, but transtype can't, since we need - * to be able to store values of the transtype. + * basetype can be a pseudo-type, but transtype can't, since we need to + * be able to store values of the transtype. */ if (strcasecmp(TypeNameToString(baseType), "ANY") == 0) baseTypeId = ANYOID; @@ -127,10 +127,10 @@ DefineAggregate(List *names, List *parameters) * Most of the argument-checking is done inside of AggregateCreate */ AggregateCreate(aggName, /* aggregate name */ - aggNamespace, /* namespace */ + aggNamespace, /* namespace */ transfuncName, /* step function name */ finalfuncName, /* final function name */ - baseTypeId, /* type of data being aggregated */ + baseTypeId, /* type of data being aggregated */ transTypeId, /* transition data type */ initval); /* initial condition */ } @@ -154,8 +154,8 @@ RemoveAggregate(RemoveAggrStmt *stmt) * if a basetype is passed in, then attempt to find an aggregate for * that specific type. * - * else attempt to find an aggregate with a basetype of ANYOID. - * This means that the aggregate is to apply to all basetypes (eg, COUNT). + * else attempt to find an aggregate with a basetype of ANYOID. This + * means that the aggregate is to apply to all basetypes (eg, COUNT). */ if (aggType) basetypeID = typenameTypeId(aggType); @@ -170,7 +170,7 @@ RemoveAggregate(RemoveAggrStmt *stmt) tup = SearchSysCache(PROCOID, ObjectIdGetDatum(procOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveAggregate: couldn't find pg_proc tuple for %s", NameListToString(aggName)); diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 2d9a2daa0c..5c20b05447 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.45 2002/08/26 18:45:57 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.46 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -110,10 +110,10 @@ typedef struct /* Default statistics target (GUC parameter) */ -int default_statistics_target = 10; +int default_statistics_target = 10; -static int elevel = -1; +static int elevel = -1; static MemoryContext anl_context = NULL; @@ -163,9 +163,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) elevel = DEBUG1; /* - * Use the current context for storing analysis info. vacuum.c ensures - * that this context will be cleared when I return, thus releasing the - * memory allocated here. + * Use the current context for storing analysis info. vacuum.c + * ensures that this context will be cleared when I return, thus + * releasing the memory allocated here. */ anl_context = CurrentMemoryContext; @@ -219,7 +219,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) * We can ANALYZE any table except pg_statistic. See update_attstats */ if (IsSystemNamespace(RelationGetNamespace(onerel)) && - strcmp(RelationGetRelationName(onerel), StatisticRelationName) == 0) + strcmp(RelationGetRelationName(onerel), StatisticRelationName) == 0) { relation_close(onerel, AccessShareLock); return; @@ -1042,11 +1042,15 @@ compute_minimal_stats(VacAttrStats *stats, */ int f1 = nonnull_cnt - summultiple; int d = f1 + nmultiple; - double numer, denom, stadistinct; + double numer, + denom, + stadistinct; + + numer = (double) numrows *(double) d; - numer = (double) numrows * (double) d; denom = (double) (numrows - f1) + - (double) f1 * (double) numrows / totalrows; + (double) f1 *(double) numrows / totalrows; + stadistinct = numer / denom; /* Clamp to sane range in case of roundoff error */ if (stadistinct < (double) d) @@ -1361,11 +1365,15 @@ compute_scalar_stats(VacAttrStats *stats, */ int f1 = ndistinct - nmultiple + toowide_cnt; int d = f1 + nmultiple; - double numer, denom, stadistinct; + double numer, + denom, + stadistinct; + + numer = (double) numrows *(double) d; - numer = (double) numrows * (double) d; denom = (double) (numrows - f1) + - (double) f1 * (double) numrows / totalrows; + (double) f1 *(double) numrows / totalrows; + stadistinct = numer / denom; /* Clamp to sane range in case of roundoff error */ if (stadistinct < (double) d) @@ -1666,7 +1674,7 @@ compare_mcvs(const void *a, const void *b) * relation for ANALYZE (ie, ShareUpdateExclusiveLock instead * of AccessShareLock); but that cure seems worse than the disease, * especially now that ANALYZE doesn't start a new transaction - * for each relation. The lock could be held for a long time... + * for each relation. The lock could be held for a long time... */ static void update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats) diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index d49aa0b678..55cee5b4a7 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.89 2002/09/03 01:04:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.90 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,7 +60,7 @@ static void swap_relfilenodes(Oid r1, Oid r2); * * This clusters the table by creating a new, clustered table and * swapping the relfilenodes of the new table and the old table, so - * the OID of the original table is preserved. Thus we do not lose + * the OID of the original table is preserved. Thus we do not lose * GRANT, inheritance nor references to this table (this was a bug * in releases thru 7.3). * @@ -111,11 +111,11 @@ cluster(RangeVar *oldrelation, char *oldindexname) RelationGetRelationName(OldHeap)); /* - * Disallow clustering system relations. This will definitely NOT work - * for shared relations (we have no way to update pg_class rows in other - * databases), nor for nailed-in-cache relations (the relfilenode values - * for those are hardwired, see relcache.c). It might work for other - * system relations, but I ain't gonna risk it. + * Disallow clustering system relations. This will definitely NOT + * work for shared relations (we have no way to update pg_class rows + * in other databases), nor for nailed-in-cache relations (the + * relfilenode values for those are hardwired, see relcache.c). It + * might work for other system relations, but I ain't gonna risk it. */ if (IsSystemRelation(OldHeap)) elog(ERROR, "CLUSTER: cannot cluster system relation \"%s\"", @@ -130,16 +130,20 @@ cluster(RangeVar *oldrelation, char *oldindexname) /* * Create the new heap, using a temporary name in the same namespace - * as the existing table. NOTE: there is some risk of collision with user - * relnames. Working around this seems more trouble than it's worth; in - * particular, we can't create the new heap in a different namespace from - * the old, or we will have problems with the TEMP status of temp tables. + * as the existing table. NOTE: there is some risk of collision with + * user relnames. Working around this seems more trouble than it's + * worth; in particular, we can't create the new heap in a different + * namespace from the old, or we will have problems with the TEMP + * status of temp tables. */ snprintf(NewHeapName, NAMEDATALEN, "pg_temp_%u", OIDOldHeap); OIDNewHeap = make_new_heap(OIDOldHeap, NewHeapName); - /* We don't need CommandCounterIncrement() because make_new_heap did it. */ + /* + * We don't need CommandCounterIncrement() because make_new_heap did + * it. + */ /* * Copy the heap data into the new table in the desired order. @@ -244,14 +248,14 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex) while ((tuple = index_getnext(scan, ForwardScanDirection)) != NULL) { /* - * We must copy the tuple because heap_insert() will overwrite - * the commit-status fields of the tuple it's handed, and the - * retrieved tuple will actually be in a disk buffer! Thus, - * the source relation would get trashed, which is bad news if - * we abort later on. (This was a bug in releases thru 7.0) + * We must copy the tuple because heap_insert() will overwrite the + * commit-status fields of the tuple it's handed, and the + * retrieved tuple will actually be in a disk buffer! Thus, the + * source relation would get trashed, which is bad news if we + * abort later on. (This was a bug in releases thru 7.0) * - * Note that the copied tuple will have the original OID, if any, - * so this does preserve OIDs. + * Note that the copied tuple will have the original OID, if any, so + * this does preserve OIDs. */ HeapTuple copiedTuple = heap_copytuple(tuple); @@ -276,15 +280,15 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex) static List * get_indexattr_list(Relation OldHeap, Oid OldIndex) { - List *indexes = NIL; + List *indexes = NIL; List *indlist; /* Ask the relcache to produce a list of the indexes of the old rel */ foreach(indlist, RelationGetIndexList(OldHeap)) { - Oid indexOID = (Oid) lfirsti(indlist); - HeapTuple indexTuple; - HeapTuple classTuple; + Oid indexOID = (Oid) lfirsti(indlist); + HeapTuple indexTuple; + HeapTuple classTuple; Form_pg_index indexForm; Form_pg_class classForm; IndexAttrs *attrs; @@ -320,7 +324,8 @@ get_indexattr_list(Relation OldHeap, Oid OldIndex) ReleaseSysCache(classTuple); ReleaseSysCache(indexTuple); - /* Cons the gathered data into the list. We do not care about + /* + * Cons the gathered data into the list. We do not care about * ordering, and this is more efficient than append. */ indexes = lcons(attrs, indexes); @@ -330,13 +335,13 @@ get_indexattr_list(Relation OldHeap, Oid OldIndex) } /* - * Create new indexes and swap the filenodes with old indexes. Then drop + * Create new indexes and swap the filenodes with old indexes. Then drop * the new index (carrying the old index filenode along). */ static void recreate_indexattr(Oid OIDOldHeap, List *indexes) { - List *elem; + List *elem; foreach(elem, indexes) { @@ -352,13 +357,13 @@ recreate_indexattr(Oid OIDOldHeap, List *indexes) snprintf(newIndexName, NAMEDATALEN, "pg_temp_%u", attrs->indexOID); /* - * The new index will have primary and constraint status set to false, - * but since we will only use its filenode it doesn't matter: - * after the filenode swap the index will keep the constraint - * status of the old index. + * The new index will have primary and constraint status set to + * false, but since we will only use its filenode it doesn't + * matter: after the filenode swap the index will keep the + * constraint status of the old index. */ newIndexOID = index_create(OIDOldHeap, newIndexName, - attrs->indexInfo, attrs->accessMethodOID, + attrs->indexInfo, attrs->accessMethodOID, attrs->classOID, false, false, allowSystemTableMods); CommandCounterIncrement(); @@ -369,8 +374,8 @@ recreate_indexattr(Oid OIDOldHeap, List *indexes) CommandCounterIncrement(); /* - * Make sure that indisclustered is correct: it should be set - * only for the index we just clustered on. + * Make sure that indisclustered is correct: it should be set only + * for the index we just clustered on. */ pg_index = heap_openr(IndexRelationName, RowExclusiveLock); tuple = SearchSysCacheCopy(INDEXRELID, @@ -392,13 +397,13 @@ recreate_indexattr(Oid OIDOldHeap, List *indexes) object.classId = RelOid_pg_class; object.objectId = newIndexOID; object.objectSubId = 0; - + /* - * The relation is local to our transaction and we know - * nothing depends on it, so DROP_RESTRICT should be OK. + * The relation is local to our transaction and we know nothing + * depends on it, so DROP_RESTRICT should be OK. */ performDeletion(&object, DROP_RESTRICT); - + /* performDeletion does CommandCounterIncrement() at its end */ } } @@ -473,7 +478,7 @@ swap_relfilenodes(Oid r1, Oid r2) /* Update the tuples in pg_class */ simple_heap_update(relRelation, &reltup1->t_self, reltup1); simple_heap_update(relRelation, &reltup2->t_self, reltup2); - + /* Keep system catalogs current */ indstate = CatalogOpenIndexes(relRelation); CatalogIndexInsert(indstate, reltup1); @@ -481,16 +486,17 @@ swap_relfilenodes(Oid r1, Oid r2) CatalogCloseIndexes(indstate); /* - * If we have toast tables associated with the relations being swapped, - * change their dependency links to re-associate them with their new - * owning relations. Otherwise the wrong one will get dropped ... + * If we have toast tables associated with the relations being + * swapped, change their dependency links to re-associate them with + * their new owning relations. Otherwise the wrong one will get + * dropped ... * - * NOTE: for now, we can assume the new table will have a TOAST table - * if and only if the old one does. This logic might need work if we - * get smarter about dropped columns. + * NOTE: for now, we can assume the new table will have a TOAST table if + * and only if the old one does. This logic might need work if we get + * smarter about dropped columns. * - * NOTE: at present, a TOAST table's only dependency is the one on - * its owning table. If more are ever created, we'd need to use something + * NOTE: at present, a TOAST table's only dependency is the one on its + * owning table. If more are ever created, we'd need to use something * more selective than deleteDependencyRecordsFor() to get rid of only * the link we want. */ @@ -532,12 +538,12 @@ swap_relfilenodes(Oid r1, Oid r2) } /* - * Blow away the old relcache entries now. We need this kluge because - * relcache.c indexes relcache entries by rd_node as well as OID. - * It will get confused if it is asked to (re)build an entry with a new + * Blow away the old relcache entries now. We need this kluge because + * relcache.c indexes relcache entries by rd_node as well as OID. It + * will get confused if it is asked to (re)build an entry with a new * rd_node value when there is still another entry laying about with - * that same rd_node value. (Fortunately, since one of the entries - * is local in our transaction, it's sufficient to clear out our own + * that same rd_node value. (Fortunately, since one of the entries is + * local in our transaction, it's sufficient to clear out our own * relcache this way; the problem cannot arise for other backends when * they see our update on the non-local relation.) */ diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index a692531485..fb8e641416 100644 --- a/src/backend/commands/comment.c +++ b/src/backend/commands/comment.c @@ -7,7 +7,7 @@ * Copyright (c) 1996-2001, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.59 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.60 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -231,7 +231,7 @@ DeleteComments(Oid oid, Oid classoid, int32 subid) Relation description; ScanKeyData skey[3]; int nkeys; - SysScanDesc sd; + SysScanDesc sd; HeapTuple oldtuple; /* Use the index to search for all matching old tuples */ @@ -260,9 +260,7 @@ DeleteComments(Oid oid, Oid classoid, int32 subid) SnapshotNow, nkeys, skey); while ((oldtuple = systable_getnext(sd)) != NULL) - { simple_heap_delete(description, &oldtuple->t_self); - } /* Done */ @@ -357,8 +355,8 @@ CommentAttribute(List *qualname, char *comment) nnames = length(qualname); if (nnames < 2) elog(ERROR, "CommentAttribute: must specify relation.attribute"); - relname = ltruncate(nnames-1, listCopy(qualname)); - attrname = strVal(nth(nnames-1, qualname)); + relname = ltruncate(nnames - 1, listCopy(qualname)); + attrname = strVal(nth(nnames - 1, qualname)); /* Open the containing relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -521,13 +519,13 @@ CommentRule(List *qualname, char *comment) else { elog(ERROR, "rule \"%s\" does not exist", rulename); - reloid = ruleoid = 0; /* keep compiler quiet */ + reloid = ruleoid = 0; /* keep compiler quiet */ } if (HeapTupleIsValid(tuple = heap_getnext(scanDesc, ForwardScanDirection))) elog(ERROR, "There are multiple rules \"%s\"" - "\n\tPlease specify a relation name as well as a rule name", + "\n\tPlease specify a relation name as well as a rule name", rulename); heap_endscan(scanDesc); @@ -540,8 +538,8 @@ CommentRule(List *qualname, char *comment) { /* New-style: rule and relname both provided */ Assert(nnames >= 2); - relname = ltruncate(nnames-1, listCopy(qualname)); - rulename = strVal(nth(nnames-1, qualname)); + relname = ltruncate(nnames - 1, listCopy(qualname)); + rulename = strVal(nth(nnames - 1, qualname)); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -724,7 +722,7 @@ CommentTrigger(List *qualname, char *comment) Relation pg_trigger, relation; HeapTuple triggertuple; - SysScanDesc scan; + SysScanDesc scan; ScanKeyData entry[2]; Oid oid; @@ -732,8 +730,8 @@ CommentTrigger(List *qualname, char *comment) nnames = length(qualname); if (nnames < 2) elog(ERROR, "CommentTrigger: must specify relation and trigger"); - relname = ltruncate(nnames-1, listCopy(qualname)); - trigname = strVal(nth(nnames-1, qualname)); + relname = ltruncate(nnames - 1, listCopy(qualname)); + trigname = strVal(nth(nnames - 1, qualname)); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -799,7 +797,7 @@ CommentConstraint(List *qualname, char *comment) Relation pg_constraint, relation; HeapTuple tuple; - SysScanDesc scan; + SysScanDesc scan; ScanKeyData skey[1]; Oid conOid = InvalidOid; @@ -807,8 +805,8 @@ CommentConstraint(List *qualname, char *comment) nnames = length(qualname); if (nnames < 2) elog(ERROR, "CommentConstraint: must specify relation and constraint"); - relName = ltruncate(nnames-1, listCopy(qualname)); - conName = strVal(nth(nnames-1, qualname)); + relName = ltruncate(nnames - 1, listCopy(qualname)); + conName = strVal(nth(nnames - 1, qualname)); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relName); @@ -820,9 +818,9 @@ CommentConstraint(List *qualname, char *comment) aclcheck_error(ACLCHECK_NOT_OWNER, RelationGetRelationName(relation)); /* - * Fetch the constraint tuple from pg_constraint. There may be more than - * one match, because constraints are not required to have unique names; - * if so, error out. + * Fetch the constraint tuple from pg_constraint. There may be more + * than one match, because constraints are not required to have unique + * names; if so, error out. */ pg_constraint = heap_openr(ConstraintRelationName, AccessShareLock); @@ -835,7 +833,7 @@ CommentConstraint(List *qualname, char *comment) while (HeapTupleIsValid(tuple = systable_getnext(scan))) { - Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple); + Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple); if (strcmp(NameStr(con->conname), conName) == 0) { diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c index 7d65a1a785..614d3676c2 100644 --- a/src/backend/commands/conversioncmds.c +++ b/src/backend/commands/conversioncmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v 1.3 2002/08/22 00:01:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v 1.4 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,19 +33,19 @@ void CreateConversionCommand(CreateConversionStmt *stmt) { Oid namespaceId; - char *conversion_name; + char *conversion_name; AclResult aclresult; int for_encoding; int to_encoding; Oid funcoid; Oid funcnamespace; - char *dummy; + char *dummy; const char *for_encoding_name = stmt->for_encoding_name; const char *to_encoding_name = stmt->to_encoding_name; - List *func_name = stmt->func_name; + List *func_name = stmt->func_name; - static Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, CSTRINGOID, INT4OID}; + static Oid funcargs[] = {INT4OID, INT4OID, CSTRINGOID, CSTRINGOID, INT4OID}; /* Convert list of names to a name and namespace */ namespaceId = QualifiedNameGetCreationNamespace(stmt->conversion_name, &conversion_name); @@ -64,10 +64,11 @@ CreateConversionCommand(CreateConversionStmt *stmt) if (to_encoding < 0) elog(ERROR, "Invalid to encoding name: %s", to_encoding_name); - /* Check the existence of the conversion function. - * Function name could be a qualified name. + /* + * Check the existence of the conversion function. Function name could + * be a qualified name. */ - funcoid = LookupFuncName(func_name, sizeof(funcargs)/sizeof(Oid), funcargs); + funcoid = LookupFuncName(func_name, sizeof(funcargs) / sizeof(Oid), funcargs); if (!OidIsValid(funcoid)) elog(ERROR, "Function %s does not exist", NameListToString(func_name)); @@ -80,8 +81,11 @@ CreateConversionCommand(CreateConversionStmt *stmt) aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE); if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_namespace_name(funcnamespace)); - - /* All seem ok, go ahead (possible failure would be a duplicate conversion name) */ + + /* + * All seem ok, go ahead (possible failure would be a duplicate + * conversion name) + */ ConversionCreate(conversion_name, namespaceId, GetUserId(), for_encoding, to_encoding, funcoid, stmt->def); } @@ -93,7 +97,7 @@ void DropConversionCommand(List *name, DropBehavior behavior) { Oid namespaceId; - char *conversion_name; + char *conversion_name; AclResult aclresult; /* Convert list of names to a name and namespace */ @@ -104,9 +108,9 @@ DropConversionCommand(List *name, DropBehavior behavior) if (aclresult != ACLCHECK_OK) aclcheck_error(aclresult, get_namespace_name(namespaceId)); - /* Go ahead (possible failure would be: - * none existing conversion - * not ower of this conversion + /* + * Go ahead (possible failure would be: none existing conversion not + * ower of this conversion */ ConversionDrop(conversion_name, namespaceId, GetUserId(), behavior); } diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index c8463ac8f8..d9da44c465 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.170 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.171 2002/09/04 20:31:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,9 +53,9 @@ typedef enum CopyReadResult /* non-export function prototypes */ static void CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, - FILE *fp, char *delim, char *null_print); + FILE *fp, char *delim, char *null_print); static void CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, - FILE *fp, char *delim, char *null_print); + FILE *fp, char *delim, char *null_print); static Oid GetInputFunction(Oid type); static Oid GetTypeElement(Oid type); static char *CopyReadAttribute(FILE *fp, const char *delim, CopyReadResult *result); @@ -268,17 +268,17 @@ CopyDonePeek(FILE *fp, int c, bool pickup) void DoCopy(const CopyStmt *stmt) { - RangeVar *relation = stmt->relation; - char *filename = stmt->filename; - bool is_from = stmt->is_from; - bool pipe = (stmt->filename == NULL); - List *option; - List *attnamelist = stmt->attlist; - List *attnumlist; - bool binary = false; - bool oids = false; - char *delim = NULL; - char *null_print = NULL; + RangeVar *relation = stmt->relation; + char *filename = stmt->filename; + bool is_from = stmt->is_from; + bool pipe = (stmt->filename == NULL); + List *option; + List *attnamelist = stmt->attlist; + List *attnumlist; + bool binary = false; + bool oids = false; + char *delim = NULL; + char *null_print = NULL; FILE *fp; Relation rel; AclMode required_access = (is_from ? ACL_INSERT : ACL_SELECT); @@ -336,7 +336,7 @@ DoCopy(const CopyStmt *stmt) if (!null_print) null_print = "\\N"; - + /* * Open and lock the relation, using the appropriate lock type. */ @@ -512,8 +512,8 @@ DoCopy(const CopyStmt *stmt) * Copy from relation TO file. */ static void -CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, - FILE *fp, char *delim, char *null_print) +CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, + FILE *fp, char *delim, char *null_print) { HeapTuple tuple; TupleDesc tupDesc; @@ -537,24 +537,23 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, /* * Get info about the columns we need to process. * - * For binary copy we really only need isvarlena, but compute it - * all... + * For binary copy we really only need isvarlena, but compute it all... */ out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo)); elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid)); isvarlena = (bool *) palloc(num_phys_attrs * sizeof(bool)); foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirsti(cur); Oid out_func_oid; - if (!getTypeOutputInfo(attr[attnum-1]->atttypid, - &out_func_oid, &elements[attnum-1], - &isvarlena[attnum-1])) + if (!getTypeOutputInfo(attr[attnum - 1]->atttypid, + &out_func_oid, &elements[attnum - 1], + &isvarlena[attnum - 1])) elog(ERROR, "COPY: couldn't lookup info for type %u", - attr[attnum-1]->atttypid); - fmgr_info(out_func_oid, &out_functions[attnum-1]); - if (binary && attr[attnum-1]->attlen == -2) + attr[attnum - 1]->atttypid); + fmgr_info(out_func_oid, &out_functions[attnum - 1]); + if (binary && attr[attnum - 1]->attlen == -2) elog(ERROR, "COPY BINARY: cstring not supported"); } @@ -597,7 +596,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, /* Send OID if wanted --- note fld_count doesn't include it */ if (oids) { - Oid oid = HeapTupleGetOid(tuple); + Oid oid = HeapTupleGetOid(tuple); fld_size = sizeof(Oid); CopySendData(&fld_size, sizeof(int16), fp); @@ -610,7 +609,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, if (oids) { string = DatumGetCString(DirectFunctionCall1(oidout, - ObjectIdGetDatum(HeapTupleGetOid(tuple)))); + ObjectIdGetDatum(HeapTupleGetOid(tuple)))); CopySendString(string, fp); pfree(string); need_delim = true; @@ -619,7 +618,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirsti(cur); Datum origvalue, value; bool isnull; @@ -653,25 +652,25 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, * (or for binary case, becase we must output untoasted * value). */ - if (isvarlena[attnum-1]) + if (isvarlena[attnum - 1]) value = PointerGetDatum(PG_DETOAST_DATUM(origvalue)); else value = origvalue; if (!binary) { - string = DatumGetCString(FunctionCall3(&out_functions[attnum-1], + string = DatumGetCString(FunctionCall3(&out_functions[attnum - 1], value, - ObjectIdGetDatum(elements[attnum-1]), - Int32GetDatum(attr[attnum-1]->atttypmod))); + ObjectIdGetDatum(elements[attnum - 1]), + Int32GetDatum(attr[attnum - 1]->atttypmod))); CopyAttributeOut(fp, string, delim); pfree(string); } else { - fld_size = attr[attnum-1]->attlen; + fld_size = attr[attnum - 1]->attlen; CopySendData(&fld_size, sizeof(int16), fp); - if (isvarlena[attnum-1]) + if (isvarlena[attnum - 1]) { /* varlena */ Assert(fld_size == -1); @@ -679,7 +678,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, VARSIZE(value), fp); } - else if (!attr[attnum-1]->attbyval) + else if (!attr[attnum - 1]->attbyval) { /* fixed-length pass-by-reference */ Assert(fld_size > 0); @@ -734,13 +733,15 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, * Copy FROM file to relation. */ static void -CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, +CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, FILE *fp, char *delim, char *null_print) { HeapTuple tuple; TupleDesc tupDesc; Form_pg_attribute *attr; - AttrNumber num_phys_attrs, attr_count, num_defaults; + AttrNumber num_phys_attrs, + attr_count, + num_defaults; FmgrInfo *in_functions; Oid *elements; int i; @@ -755,8 +756,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, TupleTableSlot *slot; bool file_has_oids; int *defmap; - Node **defexprs; /* array of default att expressions */ - ExprContext *econtext; /* used for ExecEvalExpr for default atts */ + Node **defexprs; /* array of default att expressions */ + ExprContext *econtext; /* used for ExecEvalExpr for default atts */ MemoryContext oldcontext = CurrentMemoryContext; tupDesc = RelationGetDescr(rel); @@ -787,9 +788,9 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, ExecSetSlotDescriptor(slot, tupDesc, false); /* - * pick up the input function and default expression (if any) for - * each attribute in the relation. (We don't actually use the - * input function if it's a binary copy.) + * pick up the input function and default expression (if any) for each + * attribute in the relation. (We don't actually use the input + * function if it's a binary copy.) */ defmap = (int *) palloc(sizeof(int) * num_phys_attrs); defexprs = (Node **) palloc(sizeof(Node *) * num_phys_attrs); @@ -874,13 +875,13 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, while (!done) { - bool skip_tuple; - Oid loaded_oid = InvalidOid; + bool skip_tuple; + Oid loaded_oid = InvalidOid; CHECK_FOR_INTERRUPTS(); copy_lineno++; - + /* Reset the per-tuple exprcontext */ ResetPerTupleExprContext(estate); @@ -894,8 +895,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, if (!binary) { - CopyReadResult result = NORMAL_ATTR; - char *string; + CopyReadResult result = NORMAL_ATTR; + char *string; if (file_has_oids) { @@ -918,14 +919,14 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, elog(ERROR, "Invalid Oid"); } } - + /* * Loop to read the user attributes on the line. */ foreach(cur, attnumlist) { - int attnum = lfirsti(cur); - int m = attnum - 1; + int attnum = lfirsti(cur); + int m = attnum - 1; /* * If prior attr on this line was ended by newline or EOF, @@ -953,8 +954,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, { values[m] = FunctionCall3(&in_functions[m], CStringGetDatum(string), - ObjectIdGetDatum(elements[m]), - Int32GetDatum(attr[m]->atttypmod)); + ObjectIdGetDatum(elements[m]), + Int32GetDatum(attr[m]->atttypmod)); nulls[m] = ' '; } } @@ -1009,7 +1010,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, i = 0; foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirsti(cur); i++; @@ -1018,9 +1019,9 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, elog(ERROR, "COPY BINARY: unexpected EOF"); if (fld_size == 0) continue; /* it's NULL; nulls[attnum-1] already set */ - if (fld_size != attr[attnum-1]->attlen) + if (fld_size != attr[attnum - 1]->attlen) elog(ERROR, "COPY BINARY: sizeof(field %d) is %d, expected %d", - i, (int) fld_size, (int) attr[attnum-1]->attlen); + i, (int) fld_size, (int) attr[attnum - 1]->attlen); if (fld_size == -1) { /* varlena field */ @@ -1039,9 +1040,9 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, fp); if (CopyGetEof(fp)) elog(ERROR, "COPY BINARY: unexpected EOF"); - values[attnum-1] = PointerGetDatum(varlena_ptr); + values[attnum - 1] = PointerGetDatum(varlena_ptr); } - else if (!attr[attnum-1]->attbyval) + else if (!attr[attnum - 1]->attbyval) { /* fixed-length pass-by-reference */ Pointer refval_ptr; @@ -1051,7 +1052,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, CopyGetData(refval_ptr, fld_size, fp); if (CopyGetEof(fp)) elog(ERROR, "COPY BINARY: unexpected EOF"); - values[attnum-1] = PointerGetDatum(refval_ptr); + values[attnum - 1] = PointerGetDatum(refval_ptr); } else { @@ -1059,29 +1060,28 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, Datum datumBuf; /* - * We need this horsing around because we don't - * know how shorter data values are aligned within - * a Datum. + * We need this horsing around because we don't know + * how shorter data values are aligned within a Datum. */ Assert(fld_size > 0 && fld_size <= sizeof(Datum)); CopyGetData(&datumBuf, fld_size, fp); if (CopyGetEof(fp)) elog(ERROR, "COPY BINARY: unexpected EOF"); - values[attnum-1] = fetch_att(&datumBuf, true, fld_size); + values[attnum - 1] = fetch_att(&datumBuf, true, fld_size); } - nulls[attnum-1] = ' '; + nulls[attnum - 1] = ' '; } } /* - * Now compute and insert any defaults available for the - * columns not provided by the input data. Anything not - * processed here or above will remain NULL. + * Now compute and insert any defaults available for the columns + * not provided by the input data. Anything not processed here or + * above will remain NULL. */ for (i = 0; i < num_defaults; i++) { - bool isnull; + bool isnull; values[defmap[i]] = ExecEvalExpr(defexprs[i], econtext, &isnull, NULL); @@ -1093,7 +1093,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, * And now we can form the input tuple. */ tuple = heap_formtuple(tupDesc, values, nulls); - + if (oids && file_has_oids) HeapTupleSetOid(tuple, loaded_oid); @@ -1464,14 +1464,14 @@ CopyAttributeOut(FILE *fp, char *server_string, char *delim) static List * CopyGetAttnums(Relation rel, List *attnamelist) { - List *attnums = NIL; + List *attnums = NIL; if (attnamelist == NIL) { /* Generate default column list */ - TupleDesc tupDesc = RelationGetDescr(rel); + TupleDesc tupDesc = RelationGetDescr(rel); Form_pg_attribute *attr = tupDesc->attrs; - int attr_count = tupDesc->natts; + int attr_count = tupDesc->natts; int i; for (i = 0; i < attr_count; i++) diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index f5bacf6b3c..addb6dcae4 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.104 2002/09/03 22:17:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.105 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -79,14 +79,14 @@ createdb(const CreatedbStmt *stmt) int32 datdba; List *option; DefElem *downer = NULL; - DefElem *dpath = NULL; - DefElem *dtemplate = NULL; - DefElem *dencoding = NULL; + DefElem *dpath = NULL; + DefElem *dtemplate = NULL; + DefElem *dencoding = NULL; char *dbname = stmt->dbname; char *dbowner = NULL; char *dbpath = NULL; char *dbtemplate = NULL; - int encoding = -1; + int encoding = -1; /* Extract options from the statement node tree */ foreach(option, stmt->options) @@ -133,7 +133,7 @@ createdb(const CreatedbStmt *stmt) /* obtain sysid of proposed owner */ if (dbowner) - datdba = get_usesysid(dbowner); /* will elog if no such user */ + datdba = get_usesysid(dbowner); /* will elog if no such user */ else datdba = GetUserId(); @@ -185,7 +185,7 @@ createdb(const CreatedbStmt *stmt) */ if (!src_istemplate) { - if (!superuser() && GetUserId() != src_owner ) + if (!superuser() && GetUserId() != src_owner) elog(ERROR, "CREATE DATABASE: permission to copy \"%s\" denied", dbtemplate); } @@ -226,10 +226,10 @@ createdb(const CreatedbStmt *stmt) * database), and resolve alternate physical location if one is * specified. * - * If an alternate location is specified but is the same as the - * normal path, just drop the alternate-location spec (this seems - * friendlier than erroring out). We must test this case to avoid - * creating a circular symlink below. + * If an alternate location is specified but is the same as the normal + * path, just drop the alternate-location spec (this seems friendlier + * than erroring out). We must test this case to avoid creating a + * circular symlink below. */ nominal_loc = GetDatabasePath(dboid); alt_loc = resolve_alt_dbpath(dbpath, dboid); @@ -328,11 +328,12 @@ createdb(const CreatedbStmt *stmt) /* do not set datpath to null, GetRawDatabaseInfo won't cope */ new_record[Anum_pg_database_datpath - 1] = DirectFunctionCall1(textin, CStringGetDatum(dbpath ? dbpath : "")); + /* * We deliberately set datconfig and datacl to defaults (NULL), rather * than copying them from the template database. Copying datacl would - * be a bad idea when the owner is not the same as the template's owner. - * It's more debatable whether datconfig should be copied. + * be a bad idea when the owner is not the same as the template's + * owner. It's more debatable whether datconfig should be copied. */ new_record_nulls[Anum_pg_database_datconfig - 1] = 'n'; new_record_nulls[Anum_pg_database_datacl - 1] = 'n'; @@ -495,7 +496,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt) HeapTuple tuple, newtuple; Relation rel; - ScanKeyData scankey; + ScanKeyData scankey; HeapScanDesc scan; Datum repl_val[Natts_pg_database]; char repl_null[Natts_pg_database]; @@ -512,25 +513,25 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt) elog(ERROR, "database \"%s\" does not exist", stmt->dbname); if (!(superuser() - || ((Form_pg_database) GETSTRUCT(tuple))->datdba == GetUserId())) + || ((Form_pg_database) GETSTRUCT(tuple))->datdba == GetUserId())) elog(ERROR, "permission denied"); MemSet(repl_repl, ' ', sizeof(repl_repl)); - repl_repl[Anum_pg_database_datconfig-1] = 'r'; + repl_repl[Anum_pg_database_datconfig - 1] = 'r'; - if (strcmp(stmt->variable, "all")==0 && valuestr == NULL) + if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL) { /* RESET ALL */ - repl_null[Anum_pg_database_datconfig-1] = 'n'; - repl_val[Anum_pg_database_datconfig-1] = (Datum) 0; + repl_null[Anum_pg_database_datconfig - 1] = 'n'; + repl_val[Anum_pg_database_datconfig - 1] = (Datum) 0; } else { - Datum datum; - bool isnull; - ArrayType *a; + Datum datum; + bool isnull; + ArrayType *a; - repl_null[Anum_pg_database_datconfig-1] = ' '; + repl_null[Anum_pg_database_datconfig - 1] = ' '; datum = heap_getattr(tuple, Anum_pg_database_datconfig, RelationGetDescr(rel), &isnull); @@ -542,7 +543,7 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt) else a = GUCArrayDelete(a, stmt->variable); - repl_val[Anum_pg_database_datconfig-1] = PointerGetDatum(a); + repl_val[Anum_pg_database_datconfig - 1] = PointerGetDatum(a); } newtuple = heap_modifytuple(tuple, rel, repl_val, repl_null, repl_repl); diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c index 02b730944b..09687818d8 100644 --- a/src/backend/commands/define.c +++ b/src/backend/commands/define.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.79 2002/08/10 19:01:53 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.80 2002/09/04 20:31:15 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -132,10 +132,11 @@ defGetInt64(DefElem *def) case T_Integer: return (int64) intVal(def->arg); case T_Float: + /* * Values too large for int4 will be represented as Float - * constants by the lexer. Accept these if they are valid int8 - * strings. + * constants by the lexer. Accept these if they are valid + * int8 strings. */ return DatumGetInt64(DirectFunctionCall1(int8in, CStringGetDatum(strVal(def->arg)))); @@ -188,14 +189,14 @@ defGetTypeName(DefElem *def) case T_TypeName: return (TypeName *) def->arg; case T_String: - { - /* Allow quoted typename for backwards compatibility */ - TypeName *n = makeNode(TypeName); - - n->names = makeList1(def->arg); - n->typmod = -1; - return n; - } + { + /* Allow quoted typename for backwards compatibility */ + TypeName *n = makeNode(TypeName); + + n->names = makeList1(def->arg); + n->typmod = -1; + return n; + } default: elog(ERROR, "Define: argument of \"%s\" must be a type name", def->defname); diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index bf8b6fb27b..4edc718421 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994-5, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.86 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.87 2002/09/04 20:31:15 momjian Exp $ * */ @@ -41,18 +41,18 @@ typedef struct ExplainState static StringInfo Explain_PlanToString(Plan *plan, ExplainState *es); static void ExplainOneQuery(Query *query, ExplainStmt *stmt, - TupOutputState *tstate); + TupOutputState *tstate); static void explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, - int indent, ExplainState *es); + int indent, ExplainState *es); static void show_scan_qual(List *qual, bool is_or_qual, const char *qlabel, - int scanrelid, Plan *outer_plan, - StringInfo str, int indent, ExplainState *es); + int scanrelid, Plan *outer_plan, + StringInfo str, int indent, ExplainState *es); static void show_upper_qual(List *qual, const char *qlabel, - const char *outer_name, int outer_varno, Plan *outer_plan, - const char *inner_name, int inner_varno, Plan *inner_plan, - StringInfo str, int indent, ExplainState *es); + const char *outer_name, int outer_varno, Plan *outer_plan, + const char *inner_name, int inner_varno, Plan *inner_plan, + StringInfo str, int indent, ExplainState *es); static void show_sort_keys(List *tlist, int nkeys, const char *qlabel, - StringInfo str, int indent, ExplainState *es); + StringInfo str, int indent, ExplainState *es); static Node *make_ors_ands_explicit(List *orclauses); /* @@ -189,7 +189,7 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate) do_text_output_multiline(tstate, f); pfree(f); if (es->printCost) - do_text_output_oneline(tstate, ""); /* separator line */ + do_text_output_oneline(tstate, ""); /* separator line */ } } @@ -325,7 +325,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, relation = index_open(lfirsti(l)); appendStringInfo(str, "%s%s", (++i > 1) ? ", " : "", - quote_identifier(RelationGetRelationName(relation))); + quote_identifier(RelationGetRelationName(relation))); index_close(relation); } /* FALL THRU */ @@ -335,7 +335,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, { RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid, es->rtable); - char *relname; + char *relname; /* Assume it's on a real relation */ Assert(rte->rtekind == RTE_RELATION); @@ -347,7 +347,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, quote_identifier(relname)); if (strcmp(rte->eref->aliasname, relname) != 0) appendStringInfo(str, " %s", - quote_identifier(rte->eref->aliasname)); + quote_identifier(rte->eref->aliasname)); } break; case T_SubqueryScan: @@ -365,10 +365,10 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, { RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid, es->rtable); - Expr *expr; - Func *funcnode; - Oid funcid; - char *proname; + Expr *expr; + Func *funcnode; + Oid funcid; + char *proname; /* Assert it's on a RangeFunction */ Assert(rte->rtekind == RTE_FUNCTION); @@ -384,7 +384,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, quote_identifier(proname)); if (strcmp(rte->eref->aliasname, proname) != 0) appendStringInfo(str, " %s", - quote_identifier(rte->eref->aliasname)); + quote_identifier(rte->eref->aliasname)); } break; default: @@ -482,7 +482,7 @@ explain_outNode(StringInfo str, Plan *plan, Plan *outer_plan, case T_SubqueryScan: show_upper_qual(plan->qual, "Filter", - "subplan", 1, ((SubqueryScan *) plan)->subplan, + "subplan", 1, ((SubqueryScan *) plan)->subplan, "", 0, NULL, str, indent, es); break; @@ -662,14 +662,14 @@ show_scan_qual(List *qual, bool is_or_qual, const char *qlabel, /* * If we have an outer plan that is referenced by the qual, add it to - * the deparse context. If not, don't (so that we don't force prefixes - * unnecessarily). + * the deparse context. If not, don't (so that we don't force + * prefixes unnecessarily). */ if (outer_plan) { if (intMember(OUTER, pull_varnos(node))) outercontext = deparse_context_for_subplan("outer", - outer_plan->targetlist, + outer_plan->targetlist, es->rtable); else outercontext = NULL; @@ -760,10 +760,11 @@ show_sort_keys(List *tlist, int nkeys, const char *qlabel, /* * In this routine we expect that the plan node's tlist has not been - * processed by set_plan_references(). Normally, any Vars will contain - * valid varnos referencing the actual rtable. But we might instead be - * looking at a dummy tlist generated by prepunion.c; if there are - * Vars with zero varno, use the tlist itself to determine their names. + * processed by set_plan_references(). Normally, any Vars will + * contain valid varnos referencing the actual rtable. But we might + * instead be looking at a dummy tlist generated by prepunion.c; if + * there are Vars with zero varno, use the tlist itself to determine + * their names. */ if (intMember(0, pull_varnos((Node *) tlist))) { @@ -811,7 +812,7 @@ show_sort_keys(List *tlist, int nkeys, const char *qlabel, } /* - * Indexscan qual lists have an implicit OR-of-ANDs structure. Make it + * Indexscan qual lists have an implicit OR-of-ANDs structure. Make it * explicit so deparsing works properly. */ static Node * @@ -823,13 +824,11 @@ make_ors_ands_explicit(List *orclauses) return (Node *) make_ands_explicit(lfirst(orclauses)); else { - List *args = NIL; - List *orptr; + List *args = NIL; + List *orptr; foreach(orptr, orclauses) - { args = lappend(args, make_ands_explicit(lfirst(orptr))); - } return (Node *) make_orclause(args); } diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 6d6ad94a4e..47ebe0d761 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.18 2002/08/22 00:01:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.19 2002/09/04 20:31:15 momjian Exp $ * * DESCRIPTION * These routines take the parse tree and pick out the @@ -61,7 +61,7 @@ * allow a shell type to be used, or even created if the specified return type * doesn't exist yet. (Without this, there's no way to define the I/O procs * for a new type.) But SQL function creation won't cope, so error out if - * the target language is SQL. (We do this here, not in the SQL-function + * the target language is SQL. (We do this here, not in the SQL-function * validator, so as not to produce a WARNING and then an ERROR for the same * condition.) */ @@ -69,7 +69,7 @@ static void compute_return_type(TypeName *returnType, Oid languageOid, Oid *prorettype_p, bool *returnsSet_p) { - Oid rettype; + Oid rettype; rettype = LookupTypeName(returnType); @@ -87,7 +87,7 @@ compute_return_type(TypeName *returnType, Oid languageOid, } else { - char *typnam = TypeNameToString(returnType); + char *typnam = TypeNameToString(returnType); Oid namespaceId; AclResult aclresult; char *typname; @@ -184,41 +184,41 @@ compute_attributes_sql_style(const List *options, bool *security_definer) { const List *option; - DefElem *as_item = NULL; - DefElem *language_item = NULL; - DefElem *volatility_item = NULL; - DefElem *strict_item = NULL; - DefElem *security_item = NULL; + DefElem *as_item = NULL; + DefElem *language_item = NULL; + DefElem *volatility_item = NULL; + DefElem *strict_item = NULL; + DefElem *security_item = NULL; foreach(option, options) { DefElem *defel = (DefElem *) lfirst(option); - if (strcmp(defel->defname, "as")==0) + if (strcmp(defel->defname, "as") == 0) { if (as_item) elog(ERROR, "conflicting or redundant options"); as_item = defel; } - else if (strcmp(defel->defname, "language")==0) + else if (strcmp(defel->defname, "language") == 0) { if (language_item) elog(ERROR, "conflicting or redundant options"); language_item = defel; } - else if (strcmp(defel->defname, "volatility")==0) + else if (strcmp(defel->defname, "volatility") == 0) { if (volatility_item) elog(ERROR, "conflicting or redundant options"); volatility_item = defel; } - else if (strcmp(defel->defname, "strict")==0) + else if (strcmp(defel->defname, "strict") == 0) { if (strict_item) elog(ERROR, "conflicting or redundant options"); strict_item = defel; } - else if (strcmp(defel->defname, "security")==0) + else if (strcmp(defel->defname, "security") == 0) { if (security_item) elog(ERROR, "conflicting or redundant options"); @@ -229,7 +229,7 @@ compute_attributes_sql_style(const List *options, } if (as_item) - *as = (List *)as_item->arg; + *as = (List *) as_item->arg; else elog(ERROR, "no function body specified"); @@ -240,11 +240,11 @@ compute_attributes_sql_style(const List *options, if (volatility_item) { - if (strcmp(strVal(volatility_item->arg), "immutable")==0) + if (strcmp(strVal(volatility_item->arg), "immutable") == 0) *volatility_p = PROVOLATILE_IMMUTABLE; - else if (strcmp(strVal(volatility_item->arg), "stable")==0) + else if (strcmp(strVal(volatility_item->arg), "stable") == 0) *volatility_p = PROVOLATILE_STABLE; - else if (strcmp(strVal(volatility_item->arg), "volatile")==0) + else if (strcmp(strVal(volatility_item->arg), "volatile") == 0) *volatility_p = PROVOLATILE_VOLATILE; else elog(ERROR, "invalid volatility"); @@ -386,7 +386,7 @@ CreateFunction(CreateFunctionStmt *stmt) /* override attributes from explicit list */ compute_attributes_sql_style(stmt->options, - &as_clause, &language, &volatility, &isStrict, &security); + &as_clause, &language, &volatility, &isStrict, &security); /* Convert language name to canonical case */ case_translate_language_name(language, languageName); @@ -439,13 +439,12 @@ CreateFunction(CreateFunctionStmt *stmt) if (languageOid == INTERNALlanguageId) { /* - * In PostgreSQL versions before 6.5, the SQL name of the - * created function could not be different from the internal - * name, and "prosrc" wasn't used. So there is code out there - * that does CREATE FUNCTION xyz AS '' LANGUAGE 'internal'. - * To preserve some modicum of backwards compatibility, accept - * an empty "prosrc" value as meaning the supplied SQL - * function name. + * In PostgreSQL versions before 6.5, the SQL name of the created + * function could not be different from the internal name, and + * "prosrc" wasn't used. So there is code out there that does + * CREATE FUNCTION xyz AS '' LANGUAGE 'internal'. To preserve some + * modicum of backwards compatibility, accept an empty "prosrc" + * value as meaning the supplied SQL function name. */ if (strlen(prosrc_str) == 0) prosrc_str = funcname; @@ -488,7 +487,7 @@ void RemoveFunction(RemoveFuncStmt *stmt) { List *functionName = stmt->funcname; - List *argTypes = stmt->args; /* list of TypeName nodes */ + List *argTypes = stmt->args; /* list of TypeName nodes */ Oid funcOid; HeapTuple tup; ObjectAddress object; @@ -496,13 +495,13 @@ RemoveFunction(RemoveFuncStmt *stmt) /* * Find the function, do permissions and validity checks */ - funcOid = LookupFuncNameTypeNames(functionName, argTypes, + funcOid = LookupFuncNameTypeNames(functionName, argTypes, "RemoveFunction"); tup = SearchSysCache(PROCOID, ObjectIdGetDatum(funcOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveFunction: couldn't find tuple for function %s", NameListToString(functionName)); @@ -557,7 +556,7 @@ RemoveFunctionById(Oid funcOid) tup = SearchSysCache(PROCOID, ObjectIdGetDatum(funcOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveFunctionById: couldn't find tuple for function %u", funcOid); @@ -579,7 +578,7 @@ RemoveFunctionById(Oid funcOid) tup = SearchSysCache(AGGFNOID, ObjectIdGetDatum(funcOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveFunctionById: couldn't find pg_aggregate tuple for %u", funcOid); @@ -611,7 +610,7 @@ CreateCast(CreateCastStmt *stmt) int i; ObjectAddress myself, - referenced; + referenced; sourcetypeid = LookupTypeName(stmt->sourcetype); if (!OidIsValid(sourcetypeid)) @@ -693,10 +692,10 @@ CreateCast(CreateCastStmt *stmt) } /* ready to go */ - values[Anum_pg_cast_castsource-1] = ObjectIdGetDatum(sourcetypeid); - values[Anum_pg_cast_casttarget-1] = ObjectIdGetDatum(targettypeid); - values[Anum_pg_cast_castfunc-1] = ObjectIdGetDatum(funcid); - values[Anum_pg_cast_castimplicit-1] = BoolGetDatum(stmt->implicit); + values[Anum_pg_cast_castsource - 1] = ObjectIdGetDatum(sourcetypeid); + values[Anum_pg_cast_casttarget - 1] = ObjectIdGetDatum(targettypeid); + values[Anum_pg_cast_castfunc - 1] = ObjectIdGetDatum(funcid); + values[Anum_pg_cast_castimplicit - 1] = BoolGetDatum(stmt->implicit); for (i = 0; i < Natts_pg_cast; ++i) nulls[i] = ' '; @@ -760,9 +759,9 @@ DropCast(DropCastStmt *stmt) TypeNameToString(stmt->targettype)); tuple = SearchSysCache(CASTSOURCETARGET, - ObjectIdGetDatum(sourcetypeid), - ObjectIdGetDatum(targettypeid), - 0, 0); + ObjectIdGetDatum(sourcetypeid), + ObjectIdGetDatum(targettypeid), + 0, 0); if (!HeapTupleIsValid(tuple)) elog(ERROR, "cast from type %s to type %s does not exist", TypeNameToString(stmt->sourcetype), diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index b951fccb98..6f0c8438a8 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.86 2002/08/30 22:18:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.87 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -117,9 +117,9 @@ DefineIndex(RangeVar *heapRelation, /* * Verify we (still) have CREATE rights in the rel's namespace. - * (Presumably we did when the rel was created, but maybe not anymore.) - * Skip check if bootstrapping, since permissions machinery may not - * be working yet. + * (Presumably we did when the rel was created, but maybe not + * anymore.) Skip check if bootstrapping, since permissions machinery + * may not be working yet. */ if (!IsBootstrapProcessingMode()) { @@ -254,8 +254,8 @@ CheckPredicate(List *predList, List *rangeTable, Oid baseRelOid) elog(ERROR, "Cannot use aggregate in index predicate"); /* - * A predicate using mutable functions is probably wrong, for the - * same reasons that we don't allow a functional index to use one. + * A predicate using mutable functions is probably wrong, for the same + * reasons that we don't allow a functional index to use one. */ if (contain_mutable_functions((Node *) predList)) elog(ERROR, "Functions in index predicate must be marked isImmutable"); @@ -432,7 +432,7 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType, if (schemaname) { /* Look in specific schema only */ - Oid namespaceId; + Oid namespaceId; namespaceId = LookupExplicitNamespace(schemaname); tuple = SearchSysCache(CLAAMNAMENSP, @@ -458,15 +458,15 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType, NameListToString(attribute->opclass), accessMethodName); /* - * Verify that the index operator class accepts this - * datatype. Note we will accept binary compatibility. + * Verify that the index operator class accepts this datatype. Note + * we will accept binary compatibility. */ opClassId = HeapTupleGetOid(tuple); opInputType = ((Form_pg_opclass) GETSTRUCT(tuple))->opcintype; if (!IsBinaryCompatible(attrType, opInputType)) elog(ERROR, "operator class \"%s\" does not accept data type %s", - NameListToString(attribute->opclass), format_type_be(attrType)); + NameListToString(attribute->opclass), format_type_be(attrType)); ReleaseSysCache(tuple); @@ -547,7 +547,7 @@ RemoveIndex(RangeVar *relation, DropBehavior behavior) if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_INDEX) elog(ERROR, "relation \"%s\" is of type \"%c\"", - relation->relname, ((Form_pg_class) GETSTRUCT(tuple))->relkind); + relation->relname, ((Form_pg_class) GETSTRUCT(tuple))->relkind); ReleaseSysCache(tuple); @@ -704,7 +704,7 @@ ReindexDatabase(const char *dbname, bool force, bool all) relcnt = relalc = 0; while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { - char relkind; + char relkind; if (!all) { diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c index fe2295cef0..c2bb202c9c 100644 --- a/src/backend/commands/lockcmds.c +++ b/src/backend/commands/lockcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/lockcmds.c,v 1.3 2002/06/20 20:29:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/lockcmds.c,v 1.4 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,8 +43,8 @@ LockTableCommand(LockStmt *lockstmt) Relation rel; /* - * We don't want to open the relation until we've checked privilege. - * So, manually get the relation OID. + * We don't want to open the relation until we've checked + * privilege. So, manually get the relation OID. */ reloid = RangeVarGetRelid(relation, false); diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index a0430a8786..277394626a 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.4 2002/08/22 00:01:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.5 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -38,7 +38,7 @@ static void storeOperators(Oid opclassoid, int numOperators, - Oid *operators, bool *recheck); + Oid *operators, bool *recheck); static void storeProcedures(Oid opclassoid, int numProcs, Oid *procedures); @@ -68,8 +68,8 @@ DefineOpClass(CreateOpClassStmt *stmt) AclResult aclresult; NameData opcName; int i; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* Convert list of names to a name and namespace */ namespaceoid = QualifiedNameGetCreationNamespace(stmt->opclassname, @@ -107,9 +107,9 @@ DefineOpClass(CreateOpClassStmt *stmt) storageoid = InvalidOid; /* - * Create work arrays to hold info about operators and procedures. - * We do this mainly so that we can detect duplicate strategy - * numbers and support-proc numbers. + * Create work arrays to hold info about operators and procedures. We + * do this mainly so that we can detect duplicate strategy numbers and + * support-proc numbers. */ operators = (Oid *) palloc(sizeof(Oid) * numOperators); MemSet(operators, 0, sizeof(Oid) * numOperators); @@ -141,11 +141,11 @@ DefineOpClass(CreateOpClassStmt *stmt) item->number); if (item->args != NIL) { - TypeName *typeName1 = (TypeName *) lfirst(item->args); - TypeName *typeName2 = (TypeName *) lsecond(item->args); + TypeName *typeName1 = (TypeName *) lfirst(item->args); + TypeName *typeName2 = (TypeName *) lsecond(item->args); operOid = LookupOperNameTypeNames(item->name, - typeName1, typeName2, + typeName1, typeName2, "DefineOpClass"); /* No need to check for error */ } @@ -221,8 +221,8 @@ DefineOpClass(CreateOpClassStmt *stmt) rel = heap_openr(OperatorClassRelationName, RowExclusiveLock); /* - * Make sure there is no existing opclass of this name (this is - * just to give a more friendly error message than "duplicate key"). + * Make sure there is no existing opclass of this name (this is just + * to give a more friendly error message than "duplicate key"). */ if (SearchSysCacheExists(CLAAMNAMENSP, ObjectIdGetDatum(amoid), @@ -233,12 +233,12 @@ DefineOpClass(CreateOpClassStmt *stmt) opcname, stmt->amname); /* - * If we are creating a default opclass, check there isn't one already. - * (XXX should we restrict this test to visible opclasses?) + * If we are creating a default opclass, check there isn't one + * already. (XXX should we restrict this test to visible opclasses?) */ if (stmt->isDefault) { - ScanKeyData skey[1]; + ScanKeyData skey[1]; SysScanDesc scan; ScanKeyEntryInitialize(&skey[0], 0x0, @@ -276,11 +276,11 @@ DefineOpClass(CreateOpClassStmt *stmt) values[i++] = ObjectIdGetDatum(amoid); /* opcamid */ namestrcpy(&opcName, opcname); values[i++] = NameGetDatum(&opcName); /* opcname */ - values[i++] = ObjectIdGetDatum(namespaceoid); /* opcnamespace */ + values[i++] = ObjectIdGetDatum(namespaceoid); /* opcnamespace */ values[i++] = Int32GetDatum(GetUserId()); /* opcowner */ values[i++] = ObjectIdGetDatum(typeoid); /* opcintype */ - values[i++] = BoolGetDatum(stmt->isDefault); /* opcdefault */ - values[i++] = ObjectIdGetDatum(storageoid); /* opckeytype */ + values[i++] = BoolGetDatum(stmt->isDefault); /* opcdefault */ + values[i++] = ObjectIdGetDatum(storageoid); /* opckeytype */ tup = heap_formtuple(rel->rd_att, values, nulls); @@ -291,8 +291,8 @@ DefineOpClass(CreateOpClassStmt *stmt) heap_freetuple(tup); /* - * Now add tuples to pg_amop and pg_amproc tying in the - * operators and functions. + * Now add tuples to pg_amop and pg_amproc tying in the operators and + * functions. */ storeOperators(opclassoid, numOperators, operators, recheck); storeProcedures(opclassoid, numProcs, procedures); @@ -358,11 +358,12 @@ static void storeOperators(Oid opclassoid, int numOperators, Oid *operators, bool *recheck) { - Relation rel; - Datum values[Natts_pg_amop]; - char nulls[Natts_pg_amop]; - HeapTuple tup; - int i, j; + Relation rel; + Datum values[Natts_pg_amop]; + char nulls[Natts_pg_amop]; + HeapTuple tup; + int i, + j; rel = heap_openr(AccessMethodOperatorRelationName, RowExclusiveLock); @@ -378,9 +379,9 @@ storeOperators(Oid opclassoid, int numOperators, } i = 0; - values[i++] = ObjectIdGetDatum(opclassoid); /* amopclaid */ - values[i++] = Int16GetDatum(j + 1); /* amopstrategy */ - values[i++] = BoolGetDatum(recheck[j]); /* amopreqcheck */ + values[i++] = ObjectIdGetDatum(opclassoid); /* amopclaid */ + values[i++] = Int16GetDatum(j + 1); /* amopstrategy */ + values[i++] = BoolGetDatum(recheck[j]); /* amopreqcheck */ values[i++] = ObjectIdGetDatum(operators[j]); /* amopopr */ tup = heap_formtuple(rel->rd_att, values, nulls); @@ -401,11 +402,12 @@ storeOperators(Oid opclassoid, int numOperators, static void storeProcedures(Oid opclassoid, int numProcs, Oid *procedures) { - Relation rel; - Datum values[Natts_pg_amproc]; - char nulls[Natts_pg_amproc]; - HeapTuple tup; - int i, j; + Relation rel; + Datum values[Natts_pg_amproc]; + char nulls[Natts_pg_amproc]; + HeapTuple tup; + int i, + j; rel = heap_openr(AccessMethodProcedureRelationName, RowExclusiveLock); @@ -421,9 +423,9 @@ storeProcedures(Oid opclassoid, int numProcs, Oid *procedures) } i = 0; - values[i++] = ObjectIdGetDatum(opclassoid); /* amopclaid */ - values[i++] = Int16GetDatum(j + 1); /* amprocnum */ - values[i++] = ObjectIdGetDatum(procedures[j]); /* amproc */ + values[i++] = ObjectIdGetDatum(opclassoid); /* amopclaid */ + values[i++] = Int16GetDatum(j + 1); /* amprocnum */ + values[i++] = ObjectIdGetDatum(procedures[j]); /* amproc */ tup = heap_formtuple(rel->rd_att, values, nulls); @@ -445,14 +447,15 @@ storeProcedures(Oid opclassoid, int numProcs, Oid *procedures) void RemoveOpClass(RemoveOpClassStmt *stmt) { - Oid amID, opcID; + Oid amID, + opcID; char *schemaname; char *opcname; HeapTuple tuple; ObjectAddress object; /* - * Get the access method's OID. + * Get the access method's OID. */ amID = GetSysCacheOid(AMNAME, CStringGetDatum(stmt->amname), @@ -471,7 +474,7 @@ RemoveOpClass(RemoveOpClassStmt *stmt) if (schemaname) { /* Look in specific schema only */ - Oid namespaceId; + Oid namespaceId; namespaceId = LookupExplicitNamespace(schemaname); tuple = SearchSysCache(CLAAMNAMENSP, @@ -523,10 +526,10 @@ RemoveOpClass(RemoveOpClassStmt *stmt) void RemoveOpClassById(Oid opclassOid) { - Relation rel; - HeapTuple tup; - ScanKeyData skey[1]; - SysScanDesc scan; + Relation rel; + HeapTuple tup; + ScanKeyData skey[1]; + SysScanDesc scan; /* * First remove the pg_opclass entry itself. @@ -536,7 +539,7 @@ RemoveOpClassById(Oid opclassOid) tup = SearchSysCache(CLAOID, ObjectIdGetDatum(opclassOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveOpClassById: couldn't find pg_class entry %u", opclassOid); @@ -559,9 +562,7 @@ RemoveOpClassById(Oid opclassOid) SnapshotNow, 1, skey); while (HeapTupleIsValid(tup = systable_getnext(scan))) - { simple_heap_delete(rel, &tup->t_self); - } systable_endscan(scan); heap_close(rel, RowExclusiveLock); @@ -579,9 +580,7 @@ RemoveOpClassById(Oid opclassOid) SnapshotNow, 1, skey); while (HeapTupleIsValid(tup = systable_getnext(scan))) - { simple_heap_delete(rel, &tup->t_self); - } systable_endscan(scan); heap_close(rel, RowExclusiveLock); diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c index 4d91ce48bf..bb82e0df56 100644 --- a/src/backend/commands/operatorcmds.c +++ b/src/backend/commands/operatorcmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/operatorcmds.c,v 1.6 2002/07/24 19:11:09 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/operatorcmds.c,v 1.7 2002/09/04 20:31:15 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -62,7 +62,7 @@ DefineOperator(List *names, List *parameters) char *oprName; Oid oprNamespace; AclResult aclresult; - bool canHash = false; /* operator hashes */ + bool canHash = false; /* operator hashes */ bool canMerge = false; /* operator merges */ List *functionName = NIL; /* function for operator */ TypeName *typeName1 = NULL; /* first type name */ @@ -74,7 +74,7 @@ DefineOperator(List *names, List *parameters) List *negatorName = NIL; /* optional negator operator name */ List *restrictionName = NIL; /* optional restrict. sel. * procedure */ - List *joinName = NIL; /* optional join sel. procedure */ + List *joinName = NIL; /* optional join sel. procedure */ List *leftSortName = NIL; /* optional left sort operator */ List *rightSortName = NIL; /* optional right sort operator */ List *ltCompareName = NIL; /* optional < compare operator */ @@ -173,7 +173,7 @@ DefineOperator(List *names, List *parameters) * now have OperatorCreate do all the work.. */ OperatorCreate(oprName, /* operator name */ - oprNamespace, /* namespace */ + oprNamespace, /* namespace */ typeId1, /* left type id */ typeId2, /* right type id */ functionName, /* function for operator */ @@ -185,9 +185,9 @@ DefineOperator(List *names, List *parameters) joinName, /* optional join sel. procedure name */ canHash, /* operator hashes */ leftSortName, /* optional left sort operator */ - rightSortName, /* optional right sort operator */ - ltCompareName, /* optional < comparison op */ - gtCompareName); /* optional < comparison op */ + rightSortName, /* optional right sort operator */ + ltCompareName, /* optional < comparison op */ + gtCompareName); /* optional < comparison op */ } @@ -198,9 +198,9 @@ DefineOperator(List *names, List *parameters) void RemoveOperator(RemoveOperStmt *stmt) { - List *operatorName = stmt->opname; - TypeName *typeName1 = (TypeName *) lfirst(stmt->args); - TypeName *typeName2 = (TypeName *) lsecond(stmt->args); + List *operatorName = stmt->opname; + TypeName *typeName1 = (TypeName *) lfirst(stmt->args); + TypeName *typeName2 = (TypeName *) lsecond(stmt->args); Oid operOid; HeapTuple tup; ObjectAddress object; @@ -211,7 +211,7 @@ RemoveOperator(RemoveOperStmt *stmt) tup = SearchSysCache(OPEROID, ObjectIdGetDatum(operOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveOperator: failed to find tuple for operator '%s'", NameListToString(operatorName)); @@ -247,7 +247,7 @@ RemoveOperatorById(Oid operOid) tup = SearchSysCache(OPEROID, ObjectIdGetDatum(operOid), 0, 0, 0); - if (!HeapTupleIsValid(tup)) /* should not happen */ + if (!HeapTupleIsValid(tup)) /* should not happen */ elog(ERROR, "RemoveOperatorById: failed to find tuple for operator %u", operOid); diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 754ea46246..0454b21b11 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.2 2002/05/21 22:05:54 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.3 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -134,12 +134,12 @@ PerformPortalFetch(char *name, * Determine which direction to go in, and check to see if we're * already at the end of the available tuples in that direction. If * so, set the direction to NoMovement to avoid trying to fetch any - * tuples. (This check exists because not all plan node types - * are robust about being called again if they've already returned - * NULL once.) Then call the executor (we must not skip this, because - * the destination needs to see a setup and shutdown even if no tuples - * are available). Finally, update the atStart/atEnd state depending - * on the number of tuples that were retrieved. + * tuples. (This check exists because not all plan node types are + * robust about being called again if they've already returned NULL + * once.) Then call the executor (we must not skip this, because the + * destination needs to see a setup and shutdown even if no tuples are + * available). Finally, update the atStart/atEnd state depending on + * the number of tuples that were retrieved. */ if (forward) { @@ -151,9 +151,9 @@ PerformPortalFetch(char *name, ExecutorRun(queryDesc, estate, direction, (long) count); if (estate->es_processed > 0) - portal->atStart = false; /* OK to back up now */ + portal->atStart = false; /* OK to back up now */ if (count <= 0 || (int) estate->es_processed < count) - portal->atEnd = true; /* we retrieved 'em all */ + portal->atEnd = true; /* we retrieved 'em all */ } else { @@ -165,9 +165,9 @@ PerformPortalFetch(char *name, ExecutorRun(queryDesc, estate, direction, (long) count); if (estate->es_processed > 0) - portal->atEnd = false; /* OK to go forward now */ + portal->atEnd = false; /* OK to go forward now */ if (count <= 0 || (int) estate->es_processed < count) - portal->atStart = true; /* we retrieved 'em all */ + portal->atStart = true; /* we retrieved 'em all */ } /* Return command status if wanted */ diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index 9dbe214616..cf869ed75e 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -6,7 +6,7 @@ * Copyright (c) 2002, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.1 2002/08/27 04:55:07 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.2 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,7 +34,7 @@ typedef struct List *query_list; /* list of queries */ List *plan_list; /* list of plans */ List *argtype_list; /* list of parameter type OIDs */ - MemoryContext context; /* context containing this query */ + MemoryContext context; /* context containing this query */ } QueryHashEntry; /* @@ -47,7 +47,7 @@ static HTAB *prepared_queries = NULL; static void InitQueryHashTable(void); static void StoreQuery(const char *stmt_name, List *query_list, - List *plan_list, List *argtype_list); + List *plan_list, List *argtype_list); static QueryHashEntry *FetchQuery(const char *plan_name); static void RunQuery(QueryDesc *qdesc, EState *state); @@ -58,9 +58,9 @@ static void RunQuery(QueryDesc *qdesc, EState *state); void PrepareQuery(PrepareStmt *stmt) { - List *plan_list = NIL; - List *query_list, - *query_list_item; + List *plan_list = NIL; + List *query_list, + *query_list_item; if (!stmt->name) elog(ERROR, "No statement name given"); @@ -73,8 +73,8 @@ PrepareQuery(PrepareStmt *stmt) foreach(query_list_item, query_list) { - Query *query = (Query *) lfirst(query_list_item); - Plan *plan; + Query *query = (Query *) lfirst(query_list_item); + Plan *plan; /* We can't generate plans for utility statements. */ if (query->commandType == CMD_UTILITY) @@ -97,10 +97,10 @@ PrepareQuery(PrepareStmt *stmt) void ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) { - QueryHashEntry *entry; - List *l, - *query_list, - *plan_list; + QueryHashEntry *entry; + List *l, + *query_list, + *plan_list; ParamListInfo paramLI = NULL; /* Look it up in the hash table */ @@ -115,8 +115,8 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) /* Evaluate parameters, if any */ if (entry->argtype_list != NIL) { - int nargs = length(entry->argtype_list); - int i = 0; + int nargs = length(entry->argtype_list); + int i = 0; ExprContext *econtext = MakeExprContext(NULL, CurrentMemoryContext); /* Parser should have caught this error, but check */ @@ -126,10 +126,10 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) paramLI = (ParamListInfo) palloc((nargs + 1) * sizeof(ParamListInfoData)); MemSet(paramLI, 0, (nargs + 1) * sizeof(ParamListInfoData)); - foreach (l, stmt->params) + foreach(l, stmt->params) { - Node *n = lfirst(l); - bool isNull; + Node *n = lfirst(l); + bool isNull; paramLI[i].value = ExecEvalExprSwitchContext(n, econtext, @@ -147,9 +147,9 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) /* Execute each query */ foreach(l, query_list) { - Query *query = lfirst(l); - Plan *plan = lfirst(plan_list); - bool is_last_query; + Query *query = lfirst(l); + Plan *plan = lfirst(plan_list); + bool is_last_query; plan_list = lnext(plan_list); is_last_query = (plan_list == NIL); @@ -158,8 +158,8 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) ProcessUtility(query->utilityStmt, outputDest, NULL); else { - QueryDesc *qdesc; - EState *state; + QueryDesc *qdesc; + EState *state; if (Show_executor_stats) ResetUsage(); @@ -185,11 +185,11 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) } /* - * If we're processing multiple queries, we need to increment - * the command counter between them. For the last query, - * there's no need to do this, it's done automatically. + * If we're processing multiple queries, we need to increment the + * command counter between them. For the last query, there's no + * need to do this, it's done automatically. */ - if (! is_last_query) + if (!is_last_query) CommandCounterIncrement(); } @@ -202,7 +202,7 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest) static void InitQueryHashTable(void) { - HASHCTL hash_ctl; + HASHCTL hash_ctl; MemSet(&hash_ctl, 0, sizeof(hash_ctl)); @@ -229,9 +229,9 @@ StoreQuery(const char *stmt_name, List *query_list, List *plan_list, { QueryHashEntry *entry; MemoryContext oldcxt, - entrycxt; - char key[HASH_KEY_LEN]; - bool found; + entrycxt; + char key[HASH_KEY_LEN]; + bool found; /* Initialize the hash table, if necessary */ if (!prepared_queries) @@ -258,10 +258,10 @@ StoreQuery(const char *stmt_name, List *query_list, List *plan_list, oldcxt = MemoryContextSwitchTo(entrycxt); /* - * We need to copy the data so that it is stored in the correct - * memory context. Do this before making hashtable entry, so that - * an out-of-memory failure only wastes memory and doesn't leave us - * with an incomplete (ie corrupt) hashtable entry. + * We need to copy the data so that it is stored in the correct memory + * context. Do this before making hashtable entry, so that an + * out-of-memory failure only wastes memory and doesn't leave us with + * an incomplete (ie corrupt) hashtable entry. */ query_list = (List *) copyObject(query_list); plan_list = (List *) copyObject(plan_list); @@ -293,7 +293,7 @@ StoreQuery(const char *stmt_name, List *query_list, List *plan_list, static QueryHashEntry * FetchQuery(const char *plan_name) { - char key[HASH_KEY_LEN]; + char key[HASH_KEY_LEN]; QueryHashEntry *entry; /* @@ -306,8 +306,8 @@ FetchQuery(const char *plan_name) /* * We can't just use the statement name as supplied by the user: the - * hash package is picky enough that it needs to be NULL-padded out - * to the appropriate length to work correctly. + * hash package is picky enough that it needs to be NULL-padded out to + * the appropriate length to work correctly. */ MemSet(key, 0, sizeof(key)); strncpy(key, plan_name, sizeof(key)); @@ -344,7 +344,7 @@ FetchQueryParams(const char *plan_name) static void RunQuery(QueryDesc *qdesc, EState *state) { - TupleDesc tupdesc; + TupleDesc tupdesc; tupdesc = ExecutorStart(qdesc, state); @@ -363,7 +363,7 @@ RunQuery(QueryDesc *qdesc, EState *state) void DeallocateQuery(DeallocateStmt *stmt) { - char key[HASH_KEY_LEN]; + char key[HASH_KEY_LEN]; QueryHashEntry *entry; /* @@ -376,18 +376,18 @@ DeallocateQuery(DeallocateStmt *stmt) /* * We can't just use the statement name as supplied by the user: the - * hash package is picky enough that it needs to be NULL-padded out - * to the appropriate length to work correctly. + * hash package is picky enough that it needs to be NULL-padded out to + * the appropriate length to work correctly. */ MemSet(key, 0, sizeof(key)); strncpy(key, stmt->name, sizeof(key)); /* * First lookup the entry, so we can release all the subsidiary memory - * it has allocated (when it's removed, hash_search() will return - * a dangling pointer, so it needs to be done prior to HASH_REMOVE). - * This requires an extra hash-table lookup, but DEALLOCATE - * isn't exactly a performance bottleneck. + * it has allocated (when it's removed, hash_search() will return a + * dangling pointer, so it needs to be done prior to HASH_REMOVE). + * This requires an extra hash-table lookup, but DEALLOCATE isn't + * exactly a performance bottleneck. */ entry = (QueryHashEntry *) hash_search(prepared_queries, key, diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c index 8aa2addc51..0d282e8f85 100644 --- a/src/backend/commands/proclang.c +++ b/src/backend/commands/proclang.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.41 2002/08/22 00:01:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.42 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,8 @@ void CreateProceduralLanguage(CreatePLangStmt *stmt) { char languageName[NAMEDATALEN]; - Oid procOid, valProcOid; + Oid procOid, + valProcOid; Oid typev[FUNC_MAX_ARGS]; char nulls[Natts_pg_language]; Datum values[Natts_pg_language]; @@ -49,8 +50,8 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) HeapTuple tup; TupleDesc tupDesc; int i; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* * Check permission diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index 621006758c..09165d47bd 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.5 2002/07/18 16:47:24 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.6 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -61,15 +61,17 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) owner_name = authId; /* The following will error out if user does not exist */ owner_userid = get_usesysid(owner_name); + /* - * Set the current user to the requested authorization so - * that objects created in the statement have the requested - * owner. (This will revert to session user on error or at - * the end of this routine.) + * Set the current user to the requested authorization so that + * objects created in the statement have the requested owner. + * (This will revert to session user on error or at the end of + * this routine.) */ SetUserId(owner_userid); } - else /* not superuser */ + else +/* not superuser */ { owner_userid = saved_userid; owner_name = GetUserNameFromId(owner_userid); @@ -98,17 +100,17 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) /* * Temporarily make the new namespace be the front of the search path, - * as well as the default creation target namespace. This will be undone - * at the end of this routine, or upon error. + * as well as the default creation target namespace. This will be + * undone at the end of this routine, or upon error. */ PushSpecialNamespace(namespaceId); /* * Examine the list of commands embedded in the CREATE SCHEMA command, * and reorganize them into a sequentially executable order with no - * forward references. Note that the result is still a list of raw - * parsetrees in need of parse analysis --- we cannot, in general, - * run analyze.c on one statement until we have actually executed the + * forward references. Note that the result is still a list of raw + * parsetrees in need of parse analysis --- we cannot, in general, run + * analyze.c on one statement until we have actually executed the * prior ones. */ parsetree_list = analyzeCreateSchemaStmt(stmt); @@ -171,12 +173,12 @@ RemoveSchema(List *names, DropBehavior behavior) aclcheck_error(ACLCHECK_NOT_OWNER, namespaceName); /* - * Do the deletion. Objects contained in the schema are removed - * by means of their dependency links to the schema. + * Do the deletion. Objects contained in the schema are removed by + * means of their dependency links to the schema. * - * XXX currently, index opclasses don't have creation/deletion - * commands, so they will not get removed when the containing - * schema is removed. This is annoying but not fatal. + * XXX currently, index opclasses don't have creation/deletion commands, + * so they will not get removed when the containing schema is removed. + * This is annoying but not fatal. */ object.classId = get_system_catalog_relid(NamespaceRelationName); object.objectId = namespaceId; diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index fd62e41f71..5906788247 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.86 2002/09/03 18:50:54 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.87 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,7 +60,7 @@ typedef struct sequence_magic * rely on the relcache, since it's only, well, a cache, and may decide to * discard entries.) * - * XXX We use linear search to find pre-existing SeqTable entries. This is + * XXX We use linear search to find pre-existing SeqTable entries. This is * good when only a small number of sequences are touched in a session, but * would suck with many different sequences. Perhaps use a hashtable someday. */ @@ -81,9 +81,9 @@ static SeqTable seqtab = NULL; /* Head of list of SeqTable items */ static void init_sequence(const char *caller, RangeVar *relation, - SeqTable *p_elm, Relation *p_rel); + SeqTable *p_elm, Relation *p_rel); static Form_pg_sequence read_info(const char *caller, SeqTable elm, - Relation rel, Buffer *buf); + Relation rel, Buffer *buf); static void init_params(CreateSeqStmt *seq, Form_pg_sequence new); static void do_setval(RangeVar *sequence, int64 next, bool iscalled); @@ -226,15 +226,15 @@ DefineSequence(CreateSeqStmt *seq) * Two special hacks here: * * 1. Since VACUUM does not process sequences, we have to force the tuple - * to have xmin = FrozenTransactionId now. Otherwise it would become - * invisible to SELECTs after 2G transactions. It is okay to do this + * to have xmin = FrozenTransactionId now. Otherwise it would become + * invisible to SELECTs after 2G transactions. It is okay to do this * because if the current transaction aborts, no other xact will ever * examine the sequence tuple anyway. * * 2. Even though heap_insert emitted a WAL log record, we have to emit * an XLOG_SEQ_LOG record too, since (a) the heap_insert record will * not have the right xmin, and (b) REDO of the heap_insert record - * would re-init page and sequence magic number would be lost. This + * would re-init page and sequence magic number would be lost. This * means two log records instead of one :-( */ LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); @@ -243,11 +243,12 @@ DefineSequence(CreateSeqStmt *seq) { /* - * Note that the "tuple" structure is still just a local tuple record - * created by heap_formtuple; its t_data pointer doesn't point at the - * disk buffer. To scribble on the disk buffer we need to fetch the - * item pointer. But do the same to the local tuple, since that will - * be the source for the WAL log record, below. + * Note that the "tuple" structure is still just a local tuple + * record created by heap_formtuple; its t_data pointer doesn't + * point at the disk buffer. To scribble on the disk buffer we + * need to fetch the item pointer. But do the same to the local + * tuple, since that will be the source for the WAL log record, + * below. */ ItemId itemId; Item item; @@ -323,7 +324,7 @@ nextval(PG_FUNCTION_ARGS) bool logit = false; sequence = makeRangeVarFromNameList(textToQualifiedNameList(seqin, - "nextval")); + "nextval")); /* open and AccessShareLock sequence */ init_sequence("nextval", sequence, &elm, &seqrel); @@ -358,14 +359,14 @@ nextval(PG_FUNCTION_ARGS) } /* - * Decide whether we should emit a WAL log record. If so, force up + * Decide whether we should emit a WAL log record. If so, force up * the fetch count to grab SEQ_LOG_VALS more values than we actually * need to cache. (These will then be usable without logging.) * - * If this is the first nextval after a checkpoint, we must force - * a new WAL record to be written anyway, else replay starting from the + * If this is the first nextval after a checkpoint, we must force a new + * WAL record to be written anyway, else replay starting from the * checkpoint would fail to advance the sequence past the logged - * values. In this case we may as well fetch extra values. + * values. In this case we may as well fetch extra values. */ if (log < fetch) { @@ -401,7 +402,8 @@ nextval(PG_FUNCTION_ARGS) break; /* stop fetching */ if (!seq->is_cycled) { - char buf[100]; + char buf[100]; + snprintf(buf, 100, INT64_FORMAT, maxv); elog(ERROR, "%s.nextval: reached MAXVALUE (%s)", sequence->relname, buf); @@ -421,7 +423,8 @@ nextval(PG_FUNCTION_ARGS) break; /* stop fetching */ if (!seq->is_cycled) { - char buf[100]; + char buf[100]; + snprintf(buf, 100, INT64_FORMAT, minv); elog(ERROR, "%s.nextval: reached MINVALUE (%s)", sequence->relname, buf); @@ -507,7 +510,7 @@ currval(PG_FUNCTION_ARGS) int64 result; sequence = makeRangeVarFromNameList(textToQualifiedNameList(seqin, - "currval")); + "currval")); /* open and AccessShareLock sequence */ init_sequence("currval", sequence, &elm, &seqrel); @@ -560,7 +563,10 @@ do_setval(RangeVar *sequence, int64 next, bool iscalled) if ((next < seq->min_value) || (next > seq->max_value)) { - char bufv[100], bufm[100], bufx[100]; + char bufv[100], + bufm[100], + bufx[100]; + snprintf(bufv, 100, INT64_FORMAT, next); snprintf(bufm, 100, INT64_FORMAT, seq->min_value); snprintf(bufx, 100, INT64_FORMAT, seq->max_value); @@ -632,7 +638,7 @@ setval(PG_FUNCTION_ARGS) RangeVar *sequence; sequence = makeRangeVarFromNameList(textToQualifiedNameList(seqin, - "setval")); + "setval")); do_setval(sequence, next, true); @@ -652,7 +658,7 @@ setval_and_iscalled(PG_FUNCTION_ARGS) RangeVar *sequence; sequence = makeRangeVarFromNameList(textToQualifiedNameList(seqin, - "setval")); + "setval")); do_setval(sequence, next, iscalled); @@ -672,7 +678,7 @@ init_sequence(const char *caller, RangeVar *relation, TransactionId thisxid = GetCurrentTransactionId(); SeqTable elm; Relation seqrel; - + /* Look to see if we already have a seqtable entry for relation */ for (elm = seqtab; elm != NULL; elm = elm->next) { @@ -697,9 +703,9 @@ init_sequence(const char *caller, RangeVar *relation, * Allocate new seqtable entry if we didn't find one. * * NOTE: seqtable entries remain in the list for the life of a backend. - * If the sequence itself is deleted then the entry becomes wasted memory, - * but it's small enough that this should not matter. - */ + * If the sequence itself is deleted then the entry becomes wasted + * memory, but it's small enough that this should not matter. + */ if (elm == NULL) { /* @@ -828,7 +834,9 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new) if (new->min_value >= new->max_value) { - char bufm[100], bufx[100]; + char bufm[100], + bufx[100]; + snprintf(bufm, 100, INT64_FORMAT, new->min_value); snprintf(bufx, 100, INT64_FORMAT, new->max_value); elog(ERROR, "DefineSequence: MINVALUE (%s) must be less than MAXVALUE (%s)", @@ -847,7 +855,9 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new) if (new->last_value < new->min_value) { - char bufs[100], bufm[100]; + char bufs[100], + bufm[100]; + snprintf(bufs, 100, INT64_FORMAT, new->last_value); snprintf(bufm, 100, INT64_FORMAT, new->min_value); elog(ERROR, "DefineSequence: START value (%s) can't be less than MINVALUE (%s)", @@ -855,7 +865,9 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new) } if (new->last_value > new->max_value) { - char bufs[100], bufm[100]; + char bufs[100], + bufm[100]; + snprintf(bufs, 100, INT64_FORMAT, new->last_value); snprintf(bufm, 100, INT64_FORMAT, new->max_value); elog(ERROR, "DefineSequence: START value (%s) can't be greater than MAXVALUE (%s)", @@ -866,7 +878,8 @@ init_params(CreateSeqStmt *seq, Form_pg_sequence new) new->cache_value = 1; else if ((new->cache_value = defGetInt64(cache_value)) <= 0) { - char buf[100]; + char buf[100]; + snprintf(buf, 100, INT64_FORMAT, new->cache_value); elog(ERROR, "DefineSequence: CACHE (%s) can't be <= 0", buf); diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8709111a86..3b06c6915b 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.38 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.39 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -60,11 +60,11 @@ static void setRelhassubclassInRelation(Oid relationId, bool relhassubclass); static void CheckTupleType(Form_pg_class tuple_class); static bool needs_toast_table(Relation rel); static void validateForeignKeyConstraint(FkConstraint *fkconstraint, - Relation rel, Relation pkrel); -static Oid createForeignKeyConstraint(Relation rel, Relation pkrel, - FkConstraint *fkconstraint); + Relation rel, Relation pkrel); +static Oid createForeignKeyConstraint(Relation rel, Relation pkrel, + FkConstraint *fkconstraint); static void createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, - Oid constrOid); + Oid constrOid); static char *fkMatchTypeToString(char match_type); /* Used by attribute and relation renaming routines: */ @@ -114,9 +114,8 @@ DefineRelation(CreateStmt *stmt, char relkind) /* * Look up the namespace in which we are supposed to create the - * relation. Check we have permission to create there. - * Skip check if bootstrapping, since permissions machinery may not - * be working yet. + * relation. Check we have permission to create there. Skip check if + * bootstrapping, since permissions machinery may not be working yet. */ namespaceId = RangeVarGetCreationNamespace(stmt->relation); @@ -136,7 +135,7 @@ DefineRelation(CreateStmt *stmt, char relkind) */ schema = MergeAttributes(schema, stmt->inhRelations, stmt->relation->istemp, - &inheritOids, &old_constraints, &parentHasOids); + &inheritOids, &old_constraints, &parentHasOids); numberOfAttributes = length(schema); if (numberOfAttributes <= 0) @@ -180,10 +179,10 @@ DefineRelation(CreateStmt *stmt, char relkind) else { /* - * Generate a constraint name. NB: this should match the + * Generate a constraint name. NB: this should match the * form of names that GenerateConstraintName() may produce - * for names added later. We are assured that there is - * no name conflict, because MergeAttributes() did not pass + * for names added later. We are assured that there is no + * name conflict, because MergeAttributes() did not pass * back any names of this form. */ check[ncheck].ccname = (char *) palloc(NAMEDATALEN); @@ -242,8 +241,8 @@ DefineRelation(CreateStmt *stmt, char relkind) * CREATE TABLE. * * Another task that's conveniently done at this step is to add - * dependency links between columns and supporting relations (such - * as SERIAL sequences). + * dependency links between columns and supporting relations (such as + * SERIAL sequences). * * First, scan schema to find new column defaults. */ @@ -271,7 +270,7 @@ DefineRelation(CreateStmt *stmt, char relkind) if (colDef->support != NULL) { /* Create dependency for supporting relation for this column */ - ObjectAddress colobject, + ObjectAddress colobject, suppobject; colobject.classId = RelOid_pg_class; @@ -334,9 +333,9 @@ TruncateRelation(const RangeVar *relation) Relation rel; Oid relid; Oid toastrelid; - ScanKeyData key; - Relation fkeyRel; - SysScanDesc fkeyScan; + ScanKeyData key; + Relation fkeyRel; + SysScanDesc fkeyScan; HeapTuple tuple; /* Grab exclusive lock in preparation for truncate */ @@ -366,8 +365,7 @@ TruncateRelation(const RangeVar *relation) aclcheck_error(ACLCHECK_NOT_OWNER, RelationGetRelationName(rel)); /* - * Don't allow truncate on tables which are referenced - * by foreign keys + * Don't allow truncate on tables which are referenced by foreign keys */ fkeyRel = heap_openr(ConstraintRelationName, AccessShareLock); @@ -380,8 +378,8 @@ TruncateRelation(const RangeVar *relation) SnapshotNow, 1, &key); /* - * First foreign key found with us as the reference - * should throw an error. + * First foreign key found with us as the reference should throw an + * error. */ while (HeapTupleIsValid(tuple = systable_getnext(fkeyScan))) { @@ -554,7 +552,8 @@ MergeAttributes(List *schema, List *supers, bool istemp, /* * newattno[] will contain the child-table attribute numbers for * the attributes of this parent table. (They are not the same - * for parents after the first one, nor if we have dropped columns.) + * for parents after the first one, nor if we have dropped + * columns.) */ newattno = (AttrNumber *) palloc(tupleDesc->natts * sizeof(AttrNumber)); @@ -572,9 +571,10 @@ MergeAttributes(List *schema, List *supers, bool istemp, */ if (attribute->attisdropped) { - /* - * change_varattnos_of_a_node asserts that this is greater than - * zero, so if anything tries to use it, we should find out. + /* + * change_varattnos_of_a_node asserts that this is greater + * than zero, so if anything tries to use it, we should + * find out. */ newattno[parent_attno - 1] = 0; continue; @@ -684,6 +684,7 @@ MergeAttributes(List *schema, List *supers, bool istemp, Node *expr; cdef->contype = CONSTR_CHECK; + /* * Do not inherit generated constraint names, since they * might conflict across multiple inheritance parents. @@ -857,8 +858,8 @@ StoreCatalogInheritance(Oid relationId, List *supers) return; /* - * Store INHERITS information in pg_inherits using direct ancestors only. - * Also enter dependencies on the direct ancestors. + * Store INHERITS information in pg_inherits using direct ancestors + * only. Also enter dependencies on the direct ancestors. */ relation = heap_openr(InheritsRelationName, RowExclusiveLock); desc = RelationGetDescr(relation); @@ -1076,7 +1077,7 @@ renameatt(Oid myrelid, * * normally, only the owner of a class can change its schema. */ - if (!allowSystemTableMods + if (!allowSystemTableMods && IsSystemRelation(targetrelation)) elog(ERROR, "renameatt: class \"%s\" is a system catalog", RelationGetRelationName(targetrelation)); @@ -1141,8 +1142,8 @@ renameatt(Oid myrelid, oldattname); /* - * if the attribute is inherited, forbid the renaming, unless we - * are already inside a recursive rename. + * if the attribute is inherited, forbid the renaming, unless we are + * already inside a recursive rename. */ if (attform->attisinherited && !recursing) elog(ERROR, "renameatt: inherited attribute \"%s\" may not be renamed", @@ -1233,7 +1234,8 @@ renameatt(Oid myrelid, true, false); } - relation_close(targetrelation, NoLock); /* close rel but keep lock! */ + relation_close(targetrelation, NoLock); /* close rel but keep + * lock! */ } /* @@ -1382,7 +1384,7 @@ update_ri_trigger_args(Oid relid, { Relation tgrel; ScanKeyData skey[1]; - SysScanDesc trigscan; + SysScanDesc trigscan; HeapTuple tuple; Datum values[Natts_pg_trigger]; char nulls[Natts_pg_trigger]; @@ -1577,8 +1579,8 @@ AlterTableAddColumn(Oid myrelid, HeapTuple typeTuple; Form_pg_type tform; int attndims; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; /* * Grab an exclusive lock on the target table, which we will NOT @@ -1666,7 +1668,7 @@ AlterTableAddColumn(Oid myrelid, if (colDef->is_not_null) elog(ERROR, "Adding NOT NULL columns is not implemented." - "\n\tAdd the column, then use ALTER TABLE ... SET NOT NULL."); + "\n\tAdd the column, then use ALTER TABLE ... SET NOT NULL."); pgclass = heap_openr(RelationRelationName, RowExclusiveLock); @@ -1678,8 +1680,9 @@ AlterTableAddColumn(Oid myrelid, RelationGetRelationName(rel)); /* - * this test is deliberately not attisdropped-aware, since if one tries - * to add a column matching a dropped column name, it's gonna fail anyway. + * this test is deliberately not attisdropped-aware, since if one + * tries to add a column matching a dropped column name, it's gonna + * fail anyway. */ if (SearchSysCacheExists(ATTNAME, ObjectIdGetDatum(myrelid), @@ -1706,7 +1709,7 @@ AlterTableAddColumn(Oid myrelid, tform = (Form_pg_type) GETSTRUCT(typeTuple); attributeTuple = heap_addheader(Natts_pg_attribute, - false, + false, ATTRIBUTE_TUPLE_SIZE, (void *) &attributeD); @@ -1806,8 +1809,8 @@ AlterTableAlterColumnDropNotNull(Oid myrelid, bool recurse, HeapTuple tuple; AttrNumber attnum; Relation attr_rel; - List *indexoidlist; - List *indexoidscan; + List *indexoidlist; + List *indexoidscan; rel = heap_open(myrelid, AccessExclusiveLock); @@ -1874,10 +1877,10 @@ AlterTableAlterColumnDropNotNull(Oid myrelid, bool recurse, foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsti(indexoidscan); + Oid indexoid = lfirsti(indexoidscan); HeapTuple indexTuple; - Form_pg_index indexStruct; - int i; + Form_pg_index indexStruct; + int i; indexTuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexoid), @@ -1891,11 +1894,11 @@ AlterTableAlterColumnDropNotNull(Oid myrelid, bool recurse, if (indexStruct->indisprimary) { /* - * Loop over each attribute in the primary key and - * see if it matches the to-be-altered attribute + * Loop over each attribute in the primary key and see if it + * matches the to-be-altered attribute */ for (i = 0; i < INDEX_MAX_KEYS && - indexStruct->indkey[i] != InvalidAttrNumber; i++) + indexStruct->indkey[i] != InvalidAttrNumber; i++) { if (indexStruct->indkey[i] == attnum) elog(ERROR, "ALTER TABLE: Attribute \"%s\" is in a primary key", colName); @@ -1913,7 +1916,7 @@ AlterTableAlterColumnDropNotNull(Oid myrelid, bool recurse, attr_rel = heap_openr(AttributeRelationName, RowExclusiveLock); tuple = SearchSysCacheCopyAttName(myrelid, colName); - if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ + if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ elog(ERROR, "ALTER TABLE: relation \"%s\" has no column \"%s\"", RelationGetRelationName(rel), colName); @@ -1940,7 +1943,7 @@ AlterTableAlterColumnSetNotNull(Oid myrelid, bool recurse, HeapTuple tuple; AttrNumber attnum; Relation attr_rel; - HeapScanDesc scan; + HeapScanDesc scan; TupleDesc tupdesc; rel = heap_open(myrelid, AccessExclusiveLock); @@ -2000,8 +2003,8 @@ AlterTableAlterColumnSetNotNull(Oid myrelid, bool recurse, colName); /* - * Perform a scan to ensure that there are no NULL - * values already in the relation + * Perform a scan to ensure that there are no NULL values already in + * the relation */ tupdesc = RelationGetDescr(rel); @@ -2009,7 +2012,7 @@ AlterTableAlterColumnSetNotNull(Oid myrelid, bool recurse, while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { - Datum d; + Datum d; bool isnull; d = heap_getattr(tuple, attnum, tupdesc, &isnull); @@ -2027,7 +2030,7 @@ AlterTableAlterColumnSetNotNull(Oid myrelid, bool recurse, attr_rel = heap_openr(AttributeRelationName, RowExclusiveLock); tuple = SearchSysCacheCopyAttName(myrelid, colName); - if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ + if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ elog(ERROR, "ALTER TABLE: relation \"%s\" has no column \"%s\"", RelationGetRelationName(rel), colName); @@ -2153,7 +2156,7 @@ AlterTableAlterColumnFlags(Oid myrelid, bool recurse, { Relation rel; int newtarget = 1; - char newstorage = 'p'; + char newstorage = 'p'; Relation attrelation; HeapTuple tuple; Form_pg_attribute attrtuple; @@ -2200,7 +2203,7 @@ AlterTableAlterColumnFlags(Oid myrelid, bool recurse, else if (*flagType == 'M') { /* STORAGE */ - char *storagemode; + char *storagemode; Assert(IsA(flagValue, String)); storagemode = strVal(flagValue); @@ -2246,7 +2249,7 @@ AlterTableAlterColumnFlags(Oid myrelid, bool recurse, if (childrelid == myrelid) continue; AlterTableAlterColumnFlags(childrelid, - false, colName, flagValue, flagType); + false, colName, flagValue, flagType); } } @@ -2263,6 +2266,7 @@ AlterTableAlterColumnFlags(Oid myrelid, bool recurse, if (attrtuple->attnum < 0) elog(ERROR, "ALTER TABLE: cannot change system attribute \"%s\"", colName); + /* * Now change the appropriate field */ @@ -2306,7 +2310,7 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, AttrNumber n; TupleDesc tupleDesc; bool success; - ObjectAddress object; + ObjectAddress object; rel = heap_open(myrelid, AccessExclusiveLock); @@ -2336,8 +2340,9 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, colName); /* - * Make sure there will be at least one user column left in the relation - * after we drop this one. Zero-length tuples tend to confuse us. + * Make sure there will be at least one user column left in the + * relation after we drop this one. Zero-length tuples tend to + * confuse us. */ tupleDesc = RelationGetDescr(rel); @@ -2355,7 +2360,7 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, if (!success) elog(ERROR, "ALTER TABLE: Cannot drop last column from table \"%s\"", - RelationGetRelationName(rel)); + RelationGetRelationName(rel)); /* Don't drop inherited columns */ if (tupleDesc->attrs[attnum - 1]->attisinherited && !recursing) @@ -2363,8 +2368,8 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, colName); /* - * If we are asked to drop ONLY in this table (no recursion), - * we need to mark the inheritors' attribute as non-inherited. + * If we are asked to drop ONLY in this table (no recursion), we need + * to mark the inheritors' attribute as non-inherited. */ if (!recurse && !recursing) { @@ -2378,14 +2383,14 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, attr_rel = heap_openr(AttributeRelationName, RowExclusiveLock); foreach(child, children) { - Oid childrelid = lfirsti(child); - Relation childrel; + Oid childrelid = lfirsti(child); + Relation childrel; HeapTuple tuple; childrel = heap_open(childrelid, AccessExclusiveLock); tuple = SearchSysCacheCopyAttName(childrelid, colName); - if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ + if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ elog(ERROR, "ALTER TABLE: relation %u has no column \"%s\"", childrelid, colName); @@ -2407,7 +2412,7 @@ AlterTableDropColumn(Oid myrelid, bool recurse, bool recursing, if (recurse) { List *child, - *children; + *children; /* this routine is actually in the planner */ children = find_all_inheritors(myrelid); @@ -2495,8 +2500,8 @@ AlterTableAddConstraint(Oid myrelid, bool recurse, foreach(listptr, newConstraints) { /* - * copy is because we may destructively alter the node below - * by inserting a generated name; this name is not necessarily + * copy is because we may destructively alter the node below by + * inserting a generated name; this name is not necessarily * correct for children or parents. */ Node *newConstraint = copyObject(lfirst(listptr)); @@ -2533,16 +2538,16 @@ AlterTableAddConstraint(Oid myrelid, bool recurse, if (constr->name) { if (ConstraintNameIsUsed(RelationGetRelid(rel), - RelationGetNamespace(rel), - constr->name)) + RelationGetNamespace(rel), + constr->name)) elog(ERROR, "constraint \"%s\" already exists for relation \"%s\"", constr->name, - RelationGetRelationName(rel)); + RelationGetRelationName(rel)); } else constr->name = GenerateConstraintName(RelationGetRelid(rel), - RelationGetNamespace(rel), - &counter); + RelationGetNamespace(rel), + &counter); /* * We need to make a parse state and range @@ -2552,8 +2557,8 @@ AlterTableAddConstraint(Oid myrelid, bool recurse, */ pstate = make_parsestate(NULL); rte = addRangeTableEntryForRelation(pstate, - myrelid, - makeAlias(RelationGetRelationName(rel), NIL), + myrelid, + makeAlias(RelationGetRelationName(rel), NIL), false, true); addRTEtoQuery(pstate, rte, true, true); @@ -2657,23 +2662,23 @@ AlterTableAddConstraint(Oid myrelid, bool recurse, if (fkconstraint->constr_name) { if (ConstraintNameIsUsed(RelationGetRelid(rel), - RelationGetNamespace(rel), - fkconstraint->constr_name)) + RelationGetNamespace(rel), + fkconstraint->constr_name)) elog(ERROR, "constraint \"%s\" already exists for relation \"%s\"", fkconstraint->constr_name, RelationGetRelationName(rel)); } else fkconstraint->constr_name = GenerateConstraintName(RelationGetRelid(rel), - RelationGetNamespace(rel), - &counter); + RelationGetNamespace(rel), + &counter); /* * Grab an exclusive lock on the pk table, so that * someone doesn't delete rows out from under us. * (Although a lesser lock would do for that purpose, - * we'll need exclusive lock anyway to add triggers - * to the pk table; trying to start with a lesser lock + * we'll need exclusive lock anyway to add triggers to + * the pk table; trying to start with a lesser lock * will just create a risk of deadlock.) */ pkrel = heap_openrv(fkconstraint->pktable, @@ -2716,12 +2721,14 @@ AlterTableAddConstraint(Oid myrelid, bool recurse, fkconstraint); /* - * Create the triggers that will enforce the constraint. + * Create the triggers that will enforce the + * constraint. */ createForeignKeyTriggers(rel, fkconstraint, constrOid); /* - * Close pk table, but keep lock until we've committed. + * Close pk table, but keep lock until we've + * committed. */ heap_close(pkrel, NoLock); @@ -2754,10 +2761,9 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint, int count; /* - * Scan through each tuple, calling RI_FKey_check_ins - * (insert trigger) as if that tuple had just been - * inserted. If any of those fail, it should - * elog(ERROR) and that's that. + * Scan through each tuple, calling RI_FKey_check_ins (insert trigger) + * as if that tuple had just been inserted. If any of those fail, it + * should elog(ERROR) and that's that. */ MemSet(&trig, 0, sizeof(trig)); trig.tgoid = InvalidOid; @@ -2848,7 +2854,7 @@ createForeignKeyConstraint(Relation rel, Relation pkrel, i = 0; foreach(l, fkconstraint->fk_attrs) { - char *id = strVal(lfirst(l)); + char *id = strVal(lfirst(l)); AttrNumber attno; attno = get_attnum(RelationGetRelid(rel), id); @@ -2864,7 +2870,7 @@ createForeignKeyConstraint(Relation rel, Relation pkrel, i = 0; foreach(l, fkconstraint->pk_attrs) { - char *id = strVal(lfirst(l)); + char *id = strVal(lfirst(l)); AttrNumber attno; attno = get_attnum(RelationGetRelid(pkrel), id); @@ -2883,14 +2889,14 @@ createForeignKeyConstraint(Relation rel, Relation pkrel, RelationGetRelid(rel), fkattr, fkcount, - InvalidOid, /* not a domain constraint */ + InvalidOid, /* not a domain constraint */ RelationGetRelid(pkrel), pkattr, pkcount, fkconstraint->fk_upd_action, fkconstraint->fk_del_action, fkconstraint->fk_matchtype, - NULL, /* no check constraint */ + NULL, /* no check constraint */ NULL, NULL); } @@ -2910,7 +2916,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, constrobj; /* - * Reconstruct a RangeVar for my relation (not passed in, unfortunately). + * Reconstruct a RangeVar for my relation (not passed in, + * unfortunately). */ myRel = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)), RelationGetRelationName(rel)); @@ -2956,9 +2963,9 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, fk_trigger->args = lappend(fk_trigger->args, makeString(myRel->relname)); fk_trigger->args = lappend(fk_trigger->args, - makeString(fkconstraint->pktable->relname)); + makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, - makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); + makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); fk_attr = fkconstraint->fk_attrs; pk_attr = fkconstraint->pk_attrs; if (length(fk_attr) != length(pk_attr)) @@ -2983,8 +2990,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, CommandCounterIncrement(); /* - * Build and execute a CREATE CONSTRAINT TRIGGER statement for the - * ON DELETE action on the referenced table. + * Build and execute a CREATE CONSTRAINT TRIGGER statement for the ON + * DELETE action on the referenced table. */ fk_trigger = makeNode(CreateTrigStmt); fk_trigger->trigname = fkconstraint->constr_name; @@ -3032,9 +3039,9 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, fk_trigger->args = lappend(fk_trigger->args, makeString(myRel->relname)); fk_trigger->args = lappend(fk_trigger->args, - makeString(fkconstraint->pktable->relname)); + makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, - makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); + makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); fk_attr = fkconstraint->fk_attrs; pk_attr = fkconstraint->pk_attrs; while (fk_attr != NIL) @@ -3054,8 +3061,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, CommandCounterIncrement(); /* - * Build and execute a CREATE CONSTRAINT TRIGGER statement for the - * ON UPDATE action on the referenced table. + * Build and execute a CREATE CONSTRAINT TRIGGER statement for the ON + * UPDATE action on the referenced table. */ fk_trigger = makeNode(CreateTrigStmt); fk_trigger->trigname = fkconstraint->constr_name; @@ -3103,9 +3110,9 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, fk_trigger->args = lappend(fk_trigger->args, makeString(myRel->relname)); fk_trigger->args = lappend(fk_trigger->args, - makeString(fkconstraint->pktable->relname)); + makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, - makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); + makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); fk_attr = fkconstraint->fk_attrs; pk_attr = fkconstraint->pk_attrs; while (fk_attr != NIL) @@ -3129,7 +3136,7 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, static char * fkMatchTypeToString(char match_type) { - switch (match_type) + switch (match_type) { case FKCONSTR_MATCH_FULL: return pstrdup("FULL"); @@ -3227,10 +3234,10 @@ AlterTableDropConstraint(Oid myrelid, bool recurse, void AlterTableOwner(Oid relationOid, int32 newOwnerSysId) { - Relation target_rel; - Relation class_rel; - HeapTuple tuple; - Form_pg_class tuple_class; + Relation target_rel; + Relation class_rel; + HeapTuple tuple; + Form_pg_class tuple_class; /* Get exclusive lock till end of transaction on the target table */ /* Use relation_open here so that we work on indexes... */ @@ -3250,8 +3257,8 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId) CheckTupleType(tuple_class); /* - * Okay, this is a valid tuple: change its ownership and - * write to the heap. + * Okay, this is a valid tuple: change its ownership and write to the + * heap. */ tuple_class->relowner = newOwnerSysId; simple_heap_update(class_rel, &tuple->t_self, tuple); @@ -3267,16 +3274,15 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId) if (tuple_class->relkind == RELKIND_RELATION || tuple_class->relkind == RELKIND_TOASTVALUE) { - List *index_oid_list, *i; + List *index_oid_list, + *i; /* Find all the indexes belonging to this relation */ index_oid_list = RelationGetIndexList(target_rel); /* For each index, recursively change its ownership */ foreach(i, index_oid_list) - { AlterTableOwner(lfirsti(i), newOwnerSysId); - } freeList(index_oid_list); } @@ -3285,9 +3291,7 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId) { /* If it has a toast table, recurse to change its ownership */ if (tuple_class->reltoastrelid != InvalidOid) - { AlterTableOwner(tuple_class->reltoastrelid, newOwnerSysId); - } } heap_freetuple(tuple); @@ -3355,7 +3359,7 @@ AlterTableCreateToastTable(Oid relOid, bool silent) * We cannot allow toasting a shared relation after initdb (because * there's no way to mark it toasted in other databases' pg_class). * Unfortunately we can't distinguish initdb from a manually started - * standalone backend. However, we can at least prevent this mistake + * standalone backend. However, we can at least prevent this mistake * under normal multi-user operation. */ shared_relation = rel->rd_rel->relisshared; @@ -3453,10 +3457,11 @@ AlterTableCreateToastTable(Oid relOid, bool silent) tupdesc->attrs[2]->attstorage = 'p'; /* - * Note: the toast relation is placed in the regular pg_toast namespace - * even if its master relation is a temp table. There cannot be any - * naming collision, and the toast rel will be destroyed when its master - * is, so there's no need to handle the toast rel as temp. + * Note: the toast relation is placed in the regular pg_toast + * namespace even if its master relation is a temp table. There + * cannot be any naming collision, and the toast rel will be destroyed + * when its master is, so there's no need to handle the toast rel as + * temp. */ toast_relid = heap_create_with_catalog(toast_relname, PG_TOAST_NAMESPACE, @@ -3471,12 +3476,12 @@ AlterTableCreateToastTable(Oid relOid, bool silent) /* * Create unique index on chunk_id, chunk_seq. * - * NOTE: the normal TOAST access routines could actually function with - * a single-column index on chunk_id only. However, the slice access + * NOTE: the normal TOAST access routines could actually function with a + * single-column index on chunk_id only. However, the slice access * routines use both columns for faster access to an individual chunk. - * In addition, we want it to be unique as a check against the + * In addition, we want it to be unique as a check against the * possibility of duplicate TOAST chunk OIDs. The index might also be - * a little more efficient this way, since btree isn't all that happy + * a little more efficient this way, since btree isn't all that happy * with large numbers of equal keys. */ @@ -3516,8 +3521,8 @@ AlterTableCreateToastTable(Oid relOid, bool silent) heap_freetuple(reltup); /* - * Register dependency from the toast table to the master, so that - * the toast table will be deleted if the master is. + * Register dependency from the toast table to the master, so that the + * toast table will be deleted if the master is. */ baseobject.classId = RelOid_pg_class; baseobject.objectId = relOid; diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 4b76510514..1d0e969176 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.130 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.131 2002/09/04 20:31:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ static void DeferredTriggerExecute(DeferredTriggerEvent event, int itemno, * Create a trigger. Returns the OID of the created trigger. * * forConstraint, if true, says that this trigger is being created to - * implement a constraint. The caller will then be expected to make + * implement a constraint. The caller will then be expected to make * a pg_depend entry linking the trigger to that constraint (and thereby * to the owning relation(s)). */ @@ -69,7 +69,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) Relation rel; AclResult aclresult; Relation tgrel; - SysScanDesc tgscan; + SysScanDesc tgscan; ScanKeyData key; Relation pgrel; HeapTuple tuple; @@ -82,8 +82,8 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) char *trigname; char *constrname; Oid constrrelid; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; rel = heap_openrv(stmt->relation, AccessExclusiveLock); @@ -98,7 +98,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) if (!allowSystemTableMods && IsSystemRelation(rel)) elog(ERROR, "CreateTrigger: can't create trigger for system relation %s", - stmt->relation->relname); + stmt->relation->relname); /* permission checks */ @@ -132,9 +132,9 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) /* * If trigger is an RI constraint, use specified trigger name as - * constraint name and build a unique trigger name instead. - * This is mainly for backwards compatibility with CREATE CONSTRAINT - * TRIGGER commands. + * constraint name and build a unique trigger name instead. This is + * mainly for backwards compatibility with CREATE CONSTRAINT TRIGGER + * commands. */ if (stmt->isconstraint) { @@ -183,10 +183,10 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) } /* - * Scan pg_trigger for existing triggers on relation. We do this mainly - * because we must count them; a secondary benefit is to give a nice - * error message if there's already a trigger of the same name. (The - * unique index on tgrelid/tgname would complain anyway.) + * Scan pg_trigger for existing triggers on relation. We do this + * mainly because we must count them; a secondary benefit is to give a + * nice error message if there's already a trigger of the same name. + * (The unique index on tgrelid/tgname would complain anyway.) * * NOTE that this is cool only because we have AccessExclusiveLock on the * relation, so the trigger set won't be changing underneath us. @@ -241,13 +241,13 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) values[Anum_pg_trigger_tgrelid - 1] = ObjectIdGetDatum(RelationGetRelid(rel)); values[Anum_pg_trigger_tgname - 1] = DirectFunctionCall1(namein, - CStringGetDatum(trigname)); + CStringGetDatum(trigname)); values[Anum_pg_trigger_tgfoid - 1] = ObjectIdGetDatum(funcoid); values[Anum_pg_trigger_tgtype - 1] = Int16GetDatum(tgtype); values[Anum_pg_trigger_tgenabled - 1] = BoolGetDatum(true); values[Anum_pg_trigger_tgisconstraint - 1] = BoolGetDatum(stmt->isconstraint); values[Anum_pg_trigger_tgconstrname - 1] = DirectFunctionCall1(namein, - CStringGetDatum(constrname)); + CStringGetDatum(constrname)); values[Anum_pg_trigger_tgconstrrelid - 1] = ObjectIdGetDatum(constrrelid); values[Anum_pg_trigger_tgdeferrable - 1] = BoolGetDatum(stmt->deferrable); values[Anum_pg_trigger_tginitdeferred - 1] = BoolGetDatum(stmt->initdeferred); @@ -354,8 +354,9 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) * CREATE TRIGGER command, also make trigger be auto-dropped if its * relation is dropped or if the FK relation is dropped. (Auto drop * is compatible with our pre-7.3 behavior.) If the trigger is being - * made for a constraint, we can skip the relation links; the dependency - * on the constraint will indirectly depend on the relations. + * made for a constraint, we can skip the relation links; the + * dependency on the constraint will indirectly depend on the + * relations. */ referenced.classId = RelOid_pg_proc; referenced.objectId = funcoid; @@ -389,10 +390,10 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) void DropTrigger(Oid relid, const char *trigname, DropBehavior behavior) { - Relation tgrel; - ScanKeyData skey[2]; - SysScanDesc tgscan; - HeapTuple tup; + Relation tgrel; + ScanKeyData skey[2]; + SysScanDesc tgscan; + HeapTuple tup; ObjectAddress object; /* @@ -440,14 +441,14 @@ void RemoveTriggerById(Oid trigOid) { Relation tgrel; - SysScanDesc tgscan; - ScanKeyData skey[1]; + SysScanDesc tgscan; + ScanKeyData skey[1]; HeapTuple tup; Oid relid; Relation rel; Relation pgrel; HeapTuple tuple; - Form_pg_class classForm; + Form_pg_class classForm; tgrel = heap_openr(TriggerRelationName, RowExclusiveLock); @@ -495,8 +496,8 @@ RemoveTriggerById(Oid trigOid) * rebuild relcache entries. * * Note this is OK only because we have AccessExclusiveLock on the rel, - * so no one else is creating/deleting triggers on this rel at the same - * time. + * so no one else is creating/deleting triggers on this rel at the + * same time. */ pgrel = heap_openr(RelationRelationName, RowExclusiveLock); tuple = SearchSysCacheCopy(RELOID, @@ -545,7 +546,7 @@ renametrig(Oid relid, Relation targetrel; Relation tgrel; HeapTuple tuple; - SysScanDesc tgscan; + SysScanDesc tgscan; ScanKeyData key[2]; /* @@ -555,10 +556,10 @@ renametrig(Oid relid, targetrel = heap_open(relid, AccessExclusiveLock); /* - * Scan pg_trigger twice for existing triggers on relation. We do this in - * order to ensure a trigger does not exist with newname (The unique index - * on tgrelid/tgname would complain anyway) and to ensure a trigger does - * exist with oldname. + * Scan pg_trigger twice for existing triggers on relation. We do + * this in order to ensure a trigger does not exist with newname (The + * unique index on tgrelid/tgname would complain anyway) and to ensure + * a trigger does exist with oldname. * * NOTE that this is cool only because we have AccessExclusiveLock on the * relation, so the trigger set won't be changing underneath us. @@ -601,7 +602,7 @@ renametrig(Oid relid, /* * Update pg_trigger tuple with new tgname. */ - tuple = heap_copytuple(tuple); /* need a modifiable copy */ + tuple = heap_copytuple(tuple); /* need a modifiable copy */ namestrcpy(&((Form_pg_trigger) GETSTRUCT(tuple))->tgname, newname); @@ -611,9 +612,10 @@ renametrig(Oid relid, CatalogUpdateIndexes(tgrel, tuple); /* - * Invalidate relation's relcache entry so that other backends (and - * this one too!) are sent SI message to make them rebuild relcache - * entries. (Ideally this should happen automatically...) + * Invalidate relation's relcache entry so that other backends + * (and this one too!) are sent SI message to make them rebuild + * relcache entries. (Ideally this should happen + * automatically...) */ CacheInvalidateRelcache(relid); } @@ -649,17 +651,17 @@ RelationBuildTriggers(Relation relation) int found = 0; Relation tgrel; ScanKeyData skey; - SysScanDesc tgscan; + SysScanDesc tgscan; HeapTuple htup; triggers = (Trigger *) MemoryContextAlloc(CacheMemoryContext, ntrigs * sizeof(Trigger)); /* - * Note: since we scan the triggers using TriggerRelidNameIndex, - * we will be reading the triggers in name order, except possibly - * during emergency-recovery operations (ie, IsIgnoringSystemIndexes). - * This in turn ensures that triggers will be fired in name order. + * Note: since we scan the triggers using TriggerRelidNameIndex, we + * will be reading the triggers in name order, except possibly during + * emergency-recovery operations (ie, IsIgnoringSystemIndexes). This + * in turn ensures that triggers will be fired in name order. */ ScanKeyEntryInitialize(&skey, (bits16) 0x0, @@ -1528,17 +1530,17 @@ deferredTriggerInvokeEvents(bool immediate_only) /* * If immediate_only is true, we remove fully-processed events from - * the event queue to recycle space. If immediate_only is false, - * we are going to discard the whole event queue on return anyway, - * so no need to bother with "retail" pfree's. + * the event queue to recycle space. If immediate_only is false, we + * are going to discard the whole event queue on return anyway, so no + * need to bother with "retail" pfree's. * * In a scenario with many commands in a transaction and many - * deferred-to-end-of-transaction triggers, it could get annoying - * to rescan all the deferred triggers at each command end. - * To speed this up, we could remember the actual end of the queue at - * EndQuery and examine only events that are newer. On state changes - * we simply reset the saved position to the beginning of the queue - * and process all events once with the new states. + * deferred-to-end-of-transaction triggers, it could get annoying to + * rescan all the deferred triggers at each command end. To speed this + * up, we could remember the actual end of the queue at EndQuery and + * examine only events that are newer. On state changes we simply + * reset the saved position to the beginning of the queue and process + * all events once with the new states. */ /* Make a per-tuple memory context for trigger function calls */ @@ -1559,8 +1561,8 @@ deferredTriggerInvokeEvents(bool immediate_only) /* * Check if event is already completely done. */ - if (! (event->dte_event & (TRIGGER_DEFERRED_DONE | - TRIGGER_DEFERRED_CANCELED))) + if (!(event->dte_event & (TRIGGER_DEFERRED_DONE | + TRIGGER_DEFERRED_CANCELED))) { MemoryContextReset(per_tuple_context); @@ -1577,16 +1579,16 @@ deferredTriggerInvokeEvents(bool immediate_only) * should call it now. */ if (immediate_only && - deferredTriggerCheckState(event->dte_item[i].dti_tgoid, - event->dte_item[i].dti_state)) + deferredTriggerCheckState(event->dte_item[i].dti_tgoid, + event->dte_item[i].dti_state)) { still_deferred_ones = true; continue; } /* - * So let's fire it... but first, open the correct relation - * if this is not the same relation as before. + * So let's fire it... but first, open the correct + * relation if this is not the same relation as before. */ if (rel == NULL || rel->rd_id != event->dte_relid) { @@ -1596,14 +1598,14 @@ deferredTriggerInvokeEvents(bool immediate_only) pfree(finfo); /* - * We assume that an appropriate lock is still held by the - * executor, so grab no new lock here. + * We assume that an appropriate lock is still held by + * the executor, so grab no new lock here. */ rel = heap_open(event->dte_relid, NoLock); /* - * Allocate space to cache fmgr lookup info for triggers - * of this relation. + * Allocate space to cache fmgr lookup info for + * triggers of this relation. */ finfo = (FmgrInfo *) palloc(rel->trigdesc->numtriggers * sizeof(FmgrInfo)); @@ -1615,15 +1617,15 @@ deferredTriggerInvokeEvents(bool immediate_only) per_tuple_context); event->dte_item[i].dti_state |= TRIGGER_DEFERRED_DONE; - } /* end loop over items within event */ + } /* end loop over items within event */ } /* * If it's now completely done, throw it away. * * NB: it's possible the trigger calls above added more events to the - * queue, or that calls we will do later will want to add more, - * so we have to be careful about maintaining list validity here. + * queue, or that calls we will do later will want to add more, so + * we have to be careful about maintaining list validity here. */ next_event = event->dte_next; @@ -1724,6 +1726,7 @@ DeferredTriggerBeginXact(void) oldcxt = MemoryContextSwitchTo(deftrig_cxt); deftrig_all_isset = false; + /* * If unspecified, constraints default to IMMEDIATE, per SQL */ @@ -1827,8 +1830,8 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) /* * If called outside a transaction block, we can safely return: this - * command cannot effect any subsequent transactions, and there - * are no "session-level" trigger settings. + * command cannot effect any subsequent transactions, and there are no + * "session-level" trigger settings. */ if (!IsTransactionBlock()) return; @@ -1879,7 +1882,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) { char *cname = strVal(lfirst(l)); ScanKeyData skey; - SysScanDesc tgscan; + SysScanDesc tgscan; HeapTuple htup; /* @@ -1892,7 +1895,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) * Setup to scan pg_trigger by tgconstrname ... */ ScanKeyEntryInitialize(&skey, (bits16) 0x0, - (AttrNumber) Anum_pg_trigger_tgconstrname, + (AttrNumber) Anum_pg_trigger_tgconstrname, (RegProcedure) F_NAMEEQ, PointerGetDatum(cname)); @@ -1910,9 +1913,9 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) Oid constr_oid; /* - * If we found some, check that they fit the deferrability but - * skip ON <event> RESTRICT ones, since they are silently - * never deferrable. + * If we found some, check that they fit the deferrability + * but skip ON <event> RESTRICT ones, since they are + * silently never deferrable. */ if (stmt->deferred && !pg_trigger->tgdeferrable && pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_UPD && @@ -1971,11 +1974,11 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) /* * SQL99 requires that when a constraint is set to IMMEDIATE, any - * deferred checks against that constraint must be made when the - * SET CONSTRAINTS command is executed -- i.e. the effects of the - * SET CONSTRAINTS command applies retroactively. This happens "for - * free" since we have already made the necessary modifications to - * the constraints, and deferredTriggerEndQuery() is called by + * deferred checks against that constraint must be made when the SET + * CONSTRAINTS command is executed -- i.e. the effects of the SET + * CONSTRAINTS command applies retroactively. This happens "for free" + * since we have already made the necessary modifications to the + * constraints, and deferredTriggerEndQuery() is called by * finish_xact_command(). */ } @@ -2062,6 +2065,7 @@ DeferredTriggerSaveEvent(ResultRelInfo *relinfo, int event, break; case TRIGGER_EVENT_UPDATE: + /* * Check if one of the referenced keys is changed. */ diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index bb1250b357..165a42b7c3 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.12 2002/08/29 00:17:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.13 2002/09/04 20:31:16 momjian Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -49,7 +49,7 @@ #include "utils/syscache.h" -static Oid findTypeIOFunction(List *procname, Oid typeOid, bool isOutput); +static Oid findTypeIOFunction(List *procname, Oid typeOid, bool isOutput); /* * DefineType @@ -101,15 +101,15 @@ DefineType(List *names, List *parameters) if (strcasecmp(defel->defname, "internallength") == 0) internalLength = defGetTypeLength(defel); else if (strcasecmp(defel->defname, "externallength") == 0) - ; /* ignored -- remove after 7.3 */ + ; /* ignored -- remove after 7.3 */ else if (strcasecmp(defel->defname, "input") == 0) inputName = defGetQualifiedName(defel); else if (strcasecmp(defel->defname, "output") == 0) outputName = defGetQualifiedName(defel); else if (strcasecmp(defel->defname, "send") == 0) - ; /* ignored -- remove after 7.3 */ + ; /* ignored -- remove after 7.3 */ else if (strcasecmp(defel->defname, "receive") == 0) - ; /* ignored -- remove after 7.3 */ + ; /* ignored -- remove after 7.3 */ else if (strcasecmp(defel->defname, "delimiter") == 0) { char *p = defGetString(defel); @@ -203,8 +203,9 @@ DefineType(List *names, List *parameters) outputOid = findTypeIOFunction(outputName, typoid, true); /* - * Verify that I/O procs return the expected thing. OPAQUE is an allowed, - * but deprecated, alternative to the fully type-safe choices. + * Verify that I/O procs return the expected thing. OPAQUE is an + * allowed, but deprecated, alternative to the fully type-safe + * choices. */ resulttype = get_func_rettype(inputOid); if (!(OidIsValid(typoid) && resulttype == typoid)) @@ -229,26 +230,26 @@ DefineType(List *names, List *parameters) * now have TypeCreate do all the real work. */ typoid = - TypeCreate(typeName, /* type name */ - typeNamespace, /* namespace */ - InvalidOid, /* preassigned type oid (not done here) */ - InvalidOid, /* relation oid (n/a here) */ - 0, /* relation kind (ditto) */ - internalLength, /* internal size */ - 'b', /* type-type (base type) */ - delimiter, /* array element delimiter */ - inputOid, /* input procedure */ - outputOid, /* output procedure */ - elemType, /* element type ID */ - InvalidOid, /* base type ID (only for domains) */ + TypeCreate(typeName, /* type name */ + typeNamespace, /* namespace */ + InvalidOid, /* preassigned type oid (not done here) */ + InvalidOid, /* relation oid (n/a here) */ + 0, /* relation kind (ditto) */ + internalLength, /* internal size */ + 'b', /* type-type (base type) */ + delimiter, /* array element delimiter */ + inputOid, /* input procedure */ + outputOid, /* output procedure */ + elemType, /* element type ID */ + InvalidOid, /* base type ID (only for domains) */ defaultValue, /* default type value */ - NULL, /* no binary form available */ - byValue, /* passed by value */ - alignment, /* required alignment */ - storage, /* TOAST strategy */ - -1, /* typMod (Domains only) */ - 0, /* Array Dimensions of typbasetype */ - false); /* Type NOT NULL */ + NULL, /* no binary form available */ + byValue, /* passed by value */ + alignment, /* required alignment */ + storage, /* TOAST strategy */ + -1, /* typMod (Domains only) */ + 0, /* Array Dimensions of typbasetype */ + false); /* Type NOT NULL */ /* * When we create a base type (as opposed to a complex type) we need @@ -392,7 +393,7 @@ DefineDomain(CreateDomainStmt *stmt) List *listptr; Oid basetypeoid; Oid domainoid; - Form_pg_type baseType; + Form_pg_type baseType; /* Convert list of names to a name and namespace */ domainNamespace = QualifiedNameGetCreationNamespace(stmt->domainname, @@ -406,7 +407,7 @@ DefineDomain(CreateDomainStmt *stmt) /* * Domainnames, unlike typenames don't need to account for the '_' - * prefix. So they can be one character longer. + * prefix. So they can be one character longer. */ if (strlen(domainName) > (NAMEDATALEN - 1)) elog(ERROR, "CREATE DOMAIN: domain names must be %d characters or less", @@ -421,9 +422,10 @@ DefineDomain(CreateDomainStmt *stmt) basetypeoid = HeapTupleGetOid(typeTup); /* - * Base type must be a plain base type. Domains over pseudo types would - * create a security hole. Domains of domains might be made to work in - * the future, but not today. Ditto for domains over complex types. + * Base type must be a plain base type. Domains over pseudo types + * would create a security hole. Domains of domains might be made to + * work in the future, but not today. Ditto for domains over complex + * types. */ typtype = baseType->typtype; if (typtype != 'b') @@ -450,13 +452,13 @@ DefineDomain(CreateDomainStmt *stmt) outputProcedure = baseType->typoutput; /* Inherited default value */ - datum = SysCacheGetAttr(TYPEOID, typeTup, + datum = SysCacheGetAttr(TYPEOID, typeTup, Anum_pg_type_typdefault, &isnull); if (!isnull) defaultValue = DatumGetCString(DirectFunctionCall1(textout, datum)); /* Inherited default binary value */ - datum = SysCacheGetAttr(TYPEOID, typeTup, + datum = SysCacheGetAttr(TYPEOID, typeTup, Anum_pg_type_typdefaultbin, &isnull); if (!isnull) defaultValueBin = DatumGetCString(DirectFunctionCall1(textout, datum)); @@ -469,11 +471,11 @@ DefineDomain(CreateDomainStmt *stmt) basetypelem = baseType->typelem; /* - * Run through constraints manually to avoid the additional - * processing conducted by DefineRelation() and friends. + * Run through constraints manually to avoid the additional processing + * conducted by DefineRelation() and friends. * - * Besides, we don't want any constraints to be cooked. We'll - * do that when the table is created via MergeDomainAttributes(). + * Besides, we don't want any constraints to be cooked. We'll do that + * when the table is created via MergeDomainAttributes(). */ foreach(listptr, schema) { @@ -482,77 +484,79 @@ DefineDomain(CreateDomainStmt *stmt) switch (colDef->contype) { - /* - * The inherited default value may be overridden by the user - * with the DEFAULT <expr> statement. - * - * We have to search the entire constraint tree returned as we - * don't want to cook or fiddle too much. - */ + /* + * The inherited default value may be overridden by the + * user with the DEFAULT <expr> statement. + * + * We have to search the entire constraint tree returned as + * we don't want to cook or fiddle too much. + */ case CONSTR_DEFAULT: if (defaultExpr) elog(ERROR, "CREATE DOMAIN has multiple DEFAULT expressions"); /* Create a dummy ParseState for transformExpr */ pstate = make_parsestate(NULL); + /* - * Cook the colDef->raw_expr into an expression. - * Note: Name is strictly for error message + * Cook the colDef->raw_expr into an expression. Note: + * Name is strictly for error message */ defaultExpr = cookDefault(pstate, colDef->raw_expr, basetypeoid, stmt->typename->typmod, domainName); + /* - * Expression must be stored as a nodeToString result, - * but we also require a valid textual representation - * (mainly to make life easier for pg_dump). + * Expression must be stored as a nodeToString result, but + * we also require a valid textual representation (mainly + * to make life easier for pg_dump). */ defaultValue = deparse_expression(defaultExpr, - deparse_context_for(domainName, - InvalidOid), - false); + deparse_context_for(domainName, + InvalidOid), + false); defaultValueBin = nodeToString(defaultExpr); break; - /* - * Find the NULL constraint. - */ + /* + * Find the NULL constraint. + */ case CONSTR_NOTNULL: if (nullDefined) elog(ERROR, "CREATE DOMAIN has conflicting NULL / NOT NULL constraint"); typNotNull = true; nullDefined = true; - break; + break; case CONSTR_NULL: if (nullDefined) elog(ERROR, "CREATE DOMAIN has conflicting NULL / NOT NULL constraint"); typNotNull = false; nullDefined = true; - break; + break; - case CONSTR_UNIQUE: - elog(ERROR, "CREATE DOMAIN / UNIQUE indexes not supported"); - break; + case CONSTR_UNIQUE: + elog(ERROR, "CREATE DOMAIN / UNIQUE indexes not supported"); + break; - case CONSTR_PRIMARY: - elog(ERROR, "CREATE DOMAIN / PRIMARY KEY indexes not supported"); - break; + case CONSTR_PRIMARY: + elog(ERROR, "CREATE DOMAIN / PRIMARY KEY indexes not supported"); + break; - case CONSTR_CHECK: - elog(ERROR, "DefineDomain: CHECK Constraints not supported"); - break; + case CONSTR_CHECK: + elog(ERROR, "DefineDomain: CHECK Constraints not supported"); + break; - case CONSTR_ATTR_DEFERRABLE: - case CONSTR_ATTR_NOT_DEFERRABLE: - case CONSTR_ATTR_DEFERRED: - case CONSTR_ATTR_IMMEDIATE: - elog(ERROR, "DefineDomain: DEFERRABLE, NON DEFERRABLE, DEFERRED and IMMEDIATE not supported"); - break; + case CONSTR_ATTR_DEFERRABLE: + case CONSTR_ATTR_NOT_DEFERRABLE: + case CONSTR_ATTR_DEFERRED: + case CONSTR_ATTR_IMMEDIATE: + elog(ERROR, "DefineDomain: DEFERRABLE, NON DEFERRABLE, DEFERRED and IMMEDIATE not supported"); + break; default: - elog(ERROR, "DefineDomain: unrecognized constraint node type"); - break; + elog(ERROR, "DefineDomain: unrecognized constraint node type"); + break; } } @@ -560,33 +564,33 @@ DefineDomain(CreateDomainStmt *stmt) * Have TypeCreate do all the real work. */ domainoid = - TypeCreate(domainName, /* type name */ + TypeCreate(domainName, /* type name */ domainNamespace, /* namespace */ - InvalidOid, /* preassigned type oid (none here) */ - InvalidOid, /* relation oid (n/a here) */ - 0, /* relation kind (ditto) */ + InvalidOid, /* preassigned type oid (none here) */ + InvalidOid, /* relation oid (n/a here) */ + 0, /* relation kind (ditto) */ internalLength, /* internal size */ - 'd', /* type-type (domain type) */ - delimiter, /* array element delimiter */ + 'd', /* type-type (domain type) */ + delimiter, /* array element delimiter */ inputProcedure, /* input procedure */ outputProcedure, /* output procedure */ - basetypelem, /* element type ID */ - basetypeoid, /* base type ID */ - defaultValue, /* default type value (text) */ + basetypelem, /* element type ID */ + basetypeoid, /* base type ID */ + defaultValue, /* default type value (text) */ defaultValueBin, /* default type value (binary) */ - byValue, /* passed by value */ - alignment, /* required alignment */ - storage, /* TOAST strategy */ - stmt->typename->typmod, /* typeMod value */ - typNDims, /* Array dimensions for base type */ - typNotNull); /* Type NOT NULL */ + byValue, /* passed by value */ + alignment, /* required alignment */ + storage, /* TOAST strategy */ + stmt->typename->typmod, /* typeMod value */ + typNDims, /* Array dimensions for base type */ + typNotNull); /* Type NOT NULL */ /* * Add any dependencies needed for the default expression. */ if (defaultExpr) { - ObjectAddress domobject; + ObjectAddress domobject; domobject.classId = RelOid_pg_type; domobject.objectId = domainoid; @@ -678,10 +682,10 @@ findTypeIOFunction(List *procname, Oid typeOid, bool isOutput) if (isOutput) { /* - * Output functions can take a single argument of the type, - * or two arguments (data value, element OID). The signature - * may use OPAQUE in place of the actual type name; this is the - * only possibility if the type doesn't yet exist as a shell. + * Output functions can take a single argument of the type, or two + * arguments (data value, element OID). The signature may use + * OPAQUE in place of the actual type name; this is the only + * possibility if the type doesn't yet exist as a shell. * * Note: although we could throw a NOTICE in this routine if OPAQUE * is used, we do not because of the probability that it'd be @@ -728,8 +732,8 @@ findTypeIOFunction(List *procname, Oid typeOid, bool isOutput) else { /* - * Input functions can take a single argument of type CSTRING, - * or three arguments (string, element OID, typmod). The signature + * Input functions can take a single argument of type CSTRING, or + * three arguments (string, element OID, typmod). The signature * may use OPAQUE in place of CSTRING. */ MemSet(argList, 0, FUNC_MAX_ARGS * sizeof(Oid)); @@ -793,7 +797,7 @@ DefineCompositeType(const RangeVar *typevar, List *coldeflist) if (coldeflist == NIL) elog(ERROR, "attempted to define composite type relation with" - " no attrs"); + " no attrs"); /* * now create the parameters for keys/inheritance etc. All of them are diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 8a4b31f443..620e1bed23 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.110 2002/09/02 02:47:01 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.111 2002/09/04 20:31:16 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,7 @@ extern bool Password_encryption; static void CheckPgUserAclNotNull(void); static void UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple, - List *members); + List *members); static IdList *IdListToArray(List *members); static List *IdArrayToList(IdList *oldarray); @@ -52,7 +52,8 @@ static List *IdArrayToList(IdList *oldarray); * Outputs string in quotes, with double-quotes duplicated. * We could use quote_ident(), but that expects a TEXT argument. */ -static void fputs_quote(char *str, FILE *fp) +static void +fputs_quote(char *str, FILE *fp) { fputc('"', fp); while (*str) @@ -79,7 +80,7 @@ group_getfilename(void) char *pfnam; bufsize = strlen(DataDir) + strlen("/global/") + - strlen(USER_GROUP_FILE) + 1; + strlen(USER_GROUP_FILE) + 1; pfnam = (char *) palloc(bufsize); snprintf(pfnam, bufsize, "%s/global/%s", DataDir, USER_GROUP_FILE); @@ -99,7 +100,7 @@ user_getfilename(void) char *pfnam; bufsize = strlen(DataDir) + strlen("/global/") + - strlen(PWD_FILE) + 1; + strlen(PWD_FILE) + 1; pfnam = (char *) palloc(bufsize); snprintf(pfnam, bufsize, "%s/global/%s", DataDir, PWD_FILE); @@ -125,8 +126,8 @@ write_group_file(Relation urel, Relation grel) /* * Create a temporary filename to be renamed later. This prevents the - * backend from clobbering the pg_group file while the postmaster might - * be reading from it. + * backend from clobbering the pg_group file while the postmaster + * might be reading from it. */ filename = group_getfilename(); bufsize = strlen(filename) + 12; @@ -143,14 +144,16 @@ write_group_file(Relation urel, Relation grel) scan = heap_beginscan(grel, SnapshotSelf, 0, NULL); while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { - Datum datum, grolist_datum; + Datum datum, + grolist_datum; bool isnull; char *groname; IdList *grolist_p; AclId *aidp; - int i, j, + int i, + j, num; - char *usename; + char *usename; bool first_user = true; datum = heap_getattr(tuple, Anum_pg_group_groname, dsc, &isnull); @@ -199,8 +202,8 @@ write_group_file(Relation urel, Relation grel) continue; } - /* File format is: - * "dbname" "user1" "user2" "user3" + /* + * File format is: "dbname" "user1" "user2" "user3" */ if (first_user) { @@ -833,8 +836,8 @@ AlterUserSet(AlterUserSetStmt *stmt) valuestr = flatten_set_variable_args(stmt->variable, stmt->value); /* - * RowExclusiveLock is sufficient, because we don't need to update - * the flat password file. + * RowExclusiveLock is sufficient, because we don't need to update the + * flat password file. */ rel = heap_openr(ShadowRelationName, RowExclusiveLock); oldtuple = SearchSysCache(SHADOWNAME, @@ -844,23 +847,23 @@ AlterUserSet(AlterUserSetStmt *stmt) elog(ERROR, "user \"%s\" does not exist", stmt->user); if (!(superuser() - || ((Form_pg_shadow) GETSTRUCT(oldtuple))->usesysid == GetUserId())) + || ((Form_pg_shadow) GETSTRUCT(oldtuple))->usesysid == GetUserId())) elog(ERROR, "permission denied"); for (i = 0; i < Natts_pg_shadow; i++) repl_repl[i] = ' '; - repl_repl[Anum_pg_shadow_useconfig-1] = 'r'; - if (strcmp(stmt->variable, "all")==0 && valuestr == NULL) + repl_repl[Anum_pg_shadow_useconfig - 1] = 'r'; + if (strcmp(stmt->variable, "all") == 0 && valuestr == NULL) /* RESET ALL */ - repl_null[Anum_pg_shadow_useconfig-1] = 'n'; + repl_null[Anum_pg_shadow_useconfig - 1] = 'n'; else { - Datum datum; - bool isnull; - ArrayType *array; + Datum datum; + bool isnull; + ArrayType *array; - repl_null[Anum_pg_shadow_useconfig-1] = ' '; + repl_null[Anum_pg_shadow_useconfig - 1] = ' '; datum = SysCacheGetAttr(SHADOWNAME, oldtuple, Anum_pg_shadow_useconfig, &isnull); @@ -872,7 +875,7 @@ AlterUserSet(AlterUserSetStmt *stmt) else array = GUCArrayDelete(array, stmt->variable); - repl_val[Anum_pg_shadow_useconfig-1] = PointerGetDatum(array); + repl_val[Anum_pg_shadow_useconfig - 1] = PointerGetDatum(array); } newtuple = heap_modifytuple(oldtuple, rel, repl_val, repl_null, repl_repl); @@ -1253,12 +1256,12 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) * create user */ { /* - * convert the to be added usernames to sysids and add them to - * the list + * convert the to be added usernames to sysids and add them to the + * list */ foreach(item, stmt->listUsers) { - int32 sysid; + int32 sysid; if (strcmp(tag, "ALTER GROUP") == 0) { @@ -1282,6 +1285,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) if (!intMember(sysid, newlist)) newlist = lappendi(newlist, sysid); else + /* * we silently assume here that this error will only come * up in a ALTER GROUP statement @@ -1306,8 +1310,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) else { /* - * convert the to be dropped usernames to sysids and - * remove them from the list + * convert the to be dropped usernames to sysids and remove + * them from the list */ foreach(item, stmt->listUsers) { @@ -1375,7 +1379,7 @@ UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple, new_record_repl[Anum_pg_group_grolist - 1] = 'r'; tuple = heap_modifytuple(group_tuple, group_rel, - new_record, new_record_nulls, new_record_repl); + new_record, new_record_nulls, new_record_repl); simple_heap_update(group_rel, &group_tuple->t_self, tuple); @@ -1401,12 +1405,10 @@ IdListToArray(List *members) newarray->elemtype = INT4OID; ARR_NDIM(newarray) = 1; /* one dimensional array */ ARR_LBOUND(newarray)[0] = 1; /* axis starts at one */ - ARR_DIMS(newarray)[0] = nmembers; /* axis is this long */ + ARR_DIMS(newarray)[0] = nmembers; /* axis is this long */ i = 0; foreach(item, members) - { ((int *) ARR_DATA_PTR(newarray))[i++] = lfirsti(item); - } return newarray; } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 3e8cc79596..a9b2e4206e 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.236 2002/09/02 01:05:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.237 2002/09/04 20:31:16 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -100,7 +100,7 @@ typedef struct VRelStats static MemoryContext vac_context = NULL; -static int elevel = -1; +static int elevel = -1; static TransactionId OldestXmin; static TransactionId FreezeLimit; @@ -204,8 +204,9 @@ vacuum(VacuumStmt *vacstmt) ALLOCSET_DEFAULT_MAXSIZE); /* - * If we are running only ANALYZE, we don't need per-table transactions, - * but we still need a memory context with table lifetime. + * If we are running only ANALYZE, we don't need per-table + * transactions, but we still need a memory context with table + * lifetime. */ if (vacstmt->analyze && !vacstmt->vacuum) anl_context = AllocSetContextCreate(QueryContext, @@ -221,29 +222,29 @@ vacuum(VacuumStmt *vacstmt) * Formerly, there was code here to prevent more than one VACUUM from * executing concurrently in the same database. However, there's no * good reason to prevent that, and manually removing lockfiles after - * a vacuum crash was a pain for dbadmins. So, forget about lockfiles, - * and just rely on the locks we grab on each target table + * a vacuum crash was a pain for dbadmins. So, forget about + * lockfiles, and just rely on the locks we grab on each target table * to ensure that there aren't two VACUUMs running on the same table * at the same time. */ /* - * The strangeness with committing and starting transactions here is due - * to wanting to run each table's VACUUM as a separate transaction, so - * that we don't hold locks unnecessarily long. Also, if we are doing - * VACUUM ANALYZE, the ANALYZE part runs as a separate transaction from - * the VACUUM to further reduce locking. + * The strangeness with committing and starting transactions here is + * due to wanting to run each table's VACUUM as a separate + * transaction, so that we don't hold locks unnecessarily long. Also, + * if we are doing VACUUM ANALYZE, the ANALYZE part runs as a separate + * transaction from the VACUUM to further reduce locking. * * vacuum_rel expects to be entered with no transaction active; it will * start and commit its own transaction. But we are called by an SQL * command, and so we are executing inside a transaction already. We * commit the transaction started in PostgresMain() here, and start - * another one before exiting to match the commit waiting for us back in - * PostgresMain(). + * another one before exiting to match the commit waiting for us back + * in PostgresMain(). * * In the case of an ANALYZE statement (no vacuum, just analyze) it's - * okay to run the whole thing in the outer transaction, and so we skip - * transaction start/stop operations. + * okay to run the whole thing in the outer transaction, and so we + * skip transaction start/stop operations. */ if (vacstmt->vacuum) { @@ -254,22 +255,23 @@ vacuum(VacuumStmt *vacstmt) * * Compute the initially applicable OldestXmin and FreezeLimit * XIDs, so that we can record these values at the end of the - * VACUUM. Note that individual tables may well be processed with - * newer values, but we can guarantee that no (non-shared) - * relations are processed with older ones. + * VACUUM. Note that individual tables may well be processed + * with newer values, but we can guarantee that no + * (non-shared) relations are processed with older ones. * - * It is okay to record non-shared values in pg_database, even though - * we may vacuum shared relations with older cutoffs, because only - * the minimum of the values present in pg_database matters. We - * can be sure that shared relations have at some time been - * vacuumed with cutoffs no worse than the global minimum; for, if - * there is a backend in some other DB with xmin = OLDXMIN that's - * determining the cutoff with which we vacuum shared relations, - * it is not possible for that database to have a cutoff newer - * than OLDXMIN recorded in pg_database. + * It is okay to record non-shared values in pg_database, even + * though we may vacuum shared relations with older cutoffs, + * because only the minimum of the values present in + * pg_database matters. We can be sure that shared relations + * have at some time been vacuumed with cutoffs no worse than + * the global minimum; for, if there is a backend in some + * other DB with xmin = OLDXMIN that's determining the cutoff + * with which we vacuum shared relations, it is not possible + * for that database to have a cutoff newer than OLDXMIN + * recorded in pg_database. */ vacuum_set_xid_limits(vacstmt, false, - &initialOldestXmin, &initialFreezeLimit); + &initialOldestXmin, &initialFreezeLimit); } /* matches the StartTransaction in PostgresMain() */ @@ -281,7 +283,7 @@ vacuum(VacuumStmt *vacstmt) */ foreach(cur, vrl) { - Oid relid = (Oid) lfirsti(cur); + Oid relid = (Oid) lfirsti(cur); if (vacstmt->vacuum) vacuum_rel(relid, vacstmt, RELKIND_RELATION); @@ -290,10 +292,11 @@ vacuum(VacuumStmt *vacstmt) MemoryContext old_context = NULL; /* - * If we vacuumed, use new transaction for analyze. Otherwise, - * we can use the outer transaction, but we still need to call - * analyze_rel in a memory context that will be cleaned up on - * return (else we leak memory while processing multiple tables). + * If we vacuumed, use new transaction for analyze. + * Otherwise, we can use the outer transaction, but we still + * need to call analyze_rel in a memory context that will be + * cleaned up on return (else we leak memory while processing + * multiple tables). */ if (vacstmt->vacuum) StartTransactionCommand(true); @@ -320,16 +323,17 @@ vacuum(VacuumStmt *vacstmt) /* here, we are not in a transaction */ /* - * This matches the CommitTransaction waiting for us in PostgresMain(). - * We tell xact.c not to chain the upcoming commit, so that a VACUUM - * doesn't start a transaction block, even when autocommit is off. + * This matches the CommitTransaction waiting for us in + * PostgresMain(). We tell xact.c not to chain the upcoming + * commit, so that a VACUUM doesn't start a transaction block, + * even when autocommit is off. */ StartTransactionCommand(true); /* - * If we did a database-wide VACUUM, update the database's pg_database - * row with info about the transaction IDs used, and try to truncate - * pg_clog. + * If we did a database-wide VACUUM, update the database's + * pg_database row with info about the transaction IDs used, and + * try to truncate pg_clog. */ if (vacstmt->relation == NULL) { @@ -366,7 +370,7 @@ getrels(const RangeVar *vacrel, const char *stmttype) if (vacrel) { /* Process specific relation */ - Oid relid; + Oid relid; relid = RangeVarGetRelid(vacrel, false); @@ -517,9 +521,9 @@ vac_update_relstats(Oid relid, BlockNumber num_pages, double num_tuples, /* * Invalidate the tuple in the catcaches; this also arranges to flush - * the relation's relcache entry. (If we fail to commit for some reason, - * no flush will occur, but no great harm is done since there are no - * noncritical state updates here.) + * the relation's relcache entry. (If we fail to commit for some + * reason, no flush will occur, but no great harm is done since there + * are no noncritical state updates here.) */ CacheInvalidateHeapTuple(rd, &rtup); @@ -647,8 +651,8 @@ vac_truncate_clog(TransactionId vacuumXID, TransactionId frozenXID) heap_close(relation, AccessShareLock); /* - * Do not truncate CLOG if we seem to have suffered wraparound already; - * the computed minimum XID might be bogus. + * Do not truncate CLOG if we seem to have suffered wraparound + * already; the computed minimum XID might be bogus. */ if (vacuumAlreadyWrapped) { @@ -740,7 +744,8 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind) * * We allow the user to vacuum a table if he is superuser, the table * owner, or the database owner (but in the latter case, only if it's - * not a shared relation). pg_class_ownercheck includes the superuser case. + * not a shared relation). pg_class_ownercheck includes the superuser + * case. * * Note we choose to treat permissions failure as a WARNING and keep * trying to vacuum the rest of the DB --- is this appropriate? @@ -1581,21 +1586,23 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, * by "recent" transactions then we have to move all chain of * tuples to another places. * - * NOTE: this test is not 100% accurate: it is possible for - * a tuple to be an updated one with recent xmin, and yet not - * have a corresponding tuple in the vtlinks list. Presumably + * NOTE: this test is not 100% accurate: it is possible for a + * tuple to be an updated one with recent xmin, and yet not + * have a corresponding tuple in the vtlinks list. Presumably * there was once a parent tuple with xmax matching the xmin, * but it's possible that that tuple has been removed --- for - * example, if it had xmin = xmax then HeapTupleSatisfiesVacuum - * would deem it removable as soon as the xmin xact completes. + * example, if it had xmin = xmax then + * HeapTupleSatisfiesVacuum would deem it removable as soon as + * the xmin xact completes. * * To be on the safe side, we abandon the repair_frag process if - * we cannot find the parent tuple in vtlinks. This may be overly - * conservative; AFAICS it would be safe to move the chain. + * we cannot find the parent tuple in vtlinks. This may be + * overly conservative; AFAICS it would be safe to move the + * chain. */ if (((tuple.t_data->t_infomask & HEAP_UPDATED) && !TransactionIdPrecedes(HeapTupleHeaderGetXmin(tuple.t_data), - OldestXmin)) || + OldestXmin)) || (!(tuple.t_data->t_infomask & (HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE)) && !(ItemPointerEquals(&(tuple.t_self), @@ -1626,7 +1633,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, if (vacrelstats->vtlinks == NULL) { elog(WARNING, "Parent item in update-chain not found - can't continue repair_frag"); - break; /* out of walk-along-page loop */ + break; /* out of walk-along-page loop */ } vtmove = (VTupleMove) palloc(100 * sizeof(VTupleMoveData)); @@ -1638,7 +1645,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, * we have to move to the end of chain. */ while (!(tp.t_data->t_infomask & (HEAP_XMAX_INVALID | - HEAP_MARKED_FOR_UPDATE)) && + HEAP_MARKED_FOR_UPDATE)) && !(ItemPointerEquals(&(tp.t_self), &(tp.t_data->t_ctid)))) { @@ -1704,7 +1711,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, { /* can't move item anywhere */ chain_move_failed = true; - break; /* out of check-all-items loop */ + break; /* out of check-all-items loop */ } to_item = i; to_vacpage = fraged_pages->pagedesc[to_item]; @@ -1732,8 +1739,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, /* At beginning of chain? */ if (!(tp.t_data->t_infomask & HEAP_UPDATED) || - TransactionIdPrecedes(HeapTupleHeaderGetXmin(tp.t_data), - OldestXmin)) + TransactionIdPrecedes(HeapTupleHeaderGetXmin(tp.t_data), + OldestXmin)) break; /* No, move to tuple with prior row version */ @@ -1749,14 +1756,14 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, /* see discussion above */ elog(WARNING, "Parent item in update-chain not found - can't continue repair_frag"); chain_move_failed = true; - break; /* out of check-all-items loop */ + break; /* out of check-all-items loop */ } tp.t_self = vtlp->this_tid; Pbuf = ReadBuffer(onerel, - ItemPointerGetBlockNumber(&(tp.t_self))); + ItemPointerGetBlockNumber(&(tp.t_self))); Ppage = BufferGetPage(Pbuf); Pitemid = PageGetItemId(Ppage, - ItemPointerGetOffsetNumber(&(tp.t_self))); + ItemPointerGetOffsetNumber(&(tp.t_self))); /* this can't happen since we saw tuple earlier: */ if (!ItemIdIsUsed(Pitemid)) elog(ERROR, "Parent itemid marked as unused"); @@ -1768,25 +1775,24 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, &(Ptp.t_data->t_ctid))); /* - * Read above about cases when - * !ItemIdIsUsed(Citemid) (child item is - * removed)... Due to the fact that at the moment - * we don't remove unuseful part of update-chain, - * it's possible to get too old parent row here. - * Like as in the case which caused this problem, - * we stop shrinking here. I could try to find - * real parent row but want not to do it because - * of real solution will be implemented anyway, - * later, and we are too close to 6.5 release. - - * vadim 06/11/99 + * Read above about cases when !ItemIdIsUsed(Citemid) + * (child item is removed)... Due to the fact that at + * the moment we don't remove unuseful part of + * update-chain, it's possible to get too old parent + * row here. Like as in the case which caused this + * problem, we stop shrinking here. I could try to + * find real parent row but want not to do it because + * of real solution will be implemented anyway, later, + * and we are too close to 6.5 release. - vadim + * 06/11/99 */ if (!(TransactionIdEquals(HeapTupleHeaderGetXmax(Ptp.t_data), - HeapTupleHeaderGetXmin(tp.t_data)))) + HeapTupleHeaderGetXmin(tp.t_data)))) { ReleaseBuffer(Pbuf); elog(WARNING, "Too old parent tuple found - can't continue repair_frag"); chain_move_failed = true; - break; /* out of check-all-items loop */ + break; /* out of check-all-items loop */ } tp.t_datamcxt = Ptp.t_datamcxt; tp.t_data = Ptp.t_data; @@ -1795,7 +1801,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, ReleaseBuffer(Cbuf); Cbuf = Pbuf; freeCbuf = true; - } /* end of check-all-items loop */ + } /* end of check-all-items loop */ if (freeCbuf) ReleaseBuffer(Cbuf); @@ -1804,9 +1810,9 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, if (chain_move_failed) { /* - * Undo changes to offsets_used state. We don't bother - * cleaning up the amount-free state, since we're not - * going to do any further tuple motion. + * Undo changes to offsets_used state. We don't + * bother cleaning up the amount-free state, since + * we're not going to do any further tuple motion. */ for (i = 0; i < num_vtmove; i++) { @@ -1939,7 +1945,10 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, } else { - /* No XLOG record, but still need to flag that XID exists on disk */ + /* + * No XLOG record, but still need to flag that XID + * exists on disk + */ MyXactMadeTempRelUpdate = true; } @@ -1985,7 +1994,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, WriteBuffer(cur_buffer); WriteBuffer(Cbuf); - } /* end of move-the-tuple-chain loop */ + } /* end of move-the-tuple-chain loop */ cur_buffer = InvalidBuffer; pfree(vtmove); @@ -1993,7 +2002,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, /* advance to next tuple in walk-along-page loop */ continue; - } /* end of is-tuple-in-chain test */ + } /* end of is-tuple-in-chain test */ /* try to find new page for this tuple */ if (cur_buffer == InvalidBuffer || @@ -2031,10 +2040,9 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, /* * register invalidation of source tuple in catcaches. * - * (Note: we do not need to register the copied tuple, - * because we are not changing the tuple contents and - * so there cannot be any need to flush negative - * catcache entries.) + * (Note: we do not need to register the copied tuple, because we + * are not changing the tuple contents and so there cannot be + * any need to flush negative catcache entries.) */ CacheInvalidateHeapTuple(onerel, &tuple); @@ -2090,7 +2098,10 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, } else { - /* No XLOG record, but still need to flag that XID exists on disk */ + /* + * No XLOG record, but still need to flag that XID exists + * on disk + */ MyXactMadeTempRelUpdate = true; } @@ -2116,8 +2127,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, } /* walk along page */ /* - * If we broke out of the walk-along-page loop early (ie, still have - * offnum <= maxoff), then we failed to move some tuple off + * If we broke out of the walk-along-page loop early (ie, still + * have offnum <= maxoff), then we failed to move some tuple off * this page. No point in shrinking any more, so clean up and * exit the per-page loop. */ @@ -2126,7 +2137,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, OffsetNumber off; /* - * Fix vacpage state for any unvisited tuples remaining on page + * Fix vacpage state for any unvisited tuples remaining on + * page */ for (off = OffsetNumberNext(offnum); off <= maxoff; @@ -2389,7 +2401,10 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, } else { - /* No XLOG record, but still need to flag that XID exists on disk */ + /* + * No XLOG record, but still need to flag that XID exists + * on disk + */ MyXactMadeTempRelUpdate = true; } diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index 4fb613cc67..023472e221 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -31,7 +31,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/vacuumlazy.c,v 1.18 2002/08/06 02:36:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/vacuumlazy.c,v 1.19 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -93,7 +93,7 @@ typedef struct LVRelStats } LVRelStats; -static int elevel = -1; +static int elevel = -1; static TransactionId OldestXmin; static TransactionId FreezeLimit; @@ -756,7 +756,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats) */ elog(elevel, "Truncated %u --> %u pages.\n\t%s", old_rel_pages, - new_rel_pages, vac_show_rusage(&ru0)); + new_rel_pages, vac_show_rusage(&ru0)); } /* diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c index 55a11a766c..6f6f50a908 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.70 2002/07/18 02:02:29 ishii Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.71 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -111,8 +111,8 @@ assign_datestyle(const char *value, bool doit, bool interactive) * Easiest way to get the current DEFAULT state is to fetch * the DEFAULT string from guc.c and recursively parse it. * - * We can't simply "return assign_datestyle(...)" because we - * need to handle constructs like "DEFAULT, ISO". + * We can't simply "return assign_datestyle(...)" because we need + * to handle constructs like "DEFAULT, ISO". */ int saveDateStyle = DateStyle; bool saveEuroDates = EuroDates; @@ -164,7 +164,7 @@ assign_datestyle(const char *value, bool doit, bool interactive) return value; /* - * Prepare the canonical string to return. GUC wants it malloc'd. + * Prepare the canonical string to return. GUC wants it malloc'd. */ result = (char *) malloc(32); if (!result) @@ -188,8 +188,8 @@ assign_datestyle(const char *value, bool doit, bool interactive) strcat(result, newEuroDates ? ", EURO" : ", US"); /* - * Finally, it's safe to assign to the global variables; - * the assignment cannot fail now. + * Finally, it's safe to assign to the global variables; the + * assignment cannot fail now. */ DateStyle = newDateStyle; EuroDates = newEuroDates; @@ -203,7 +203,7 @@ assign_datestyle(const char *value, bool doit, bool interactive) const char * show_datestyle(void) { - static char buf[64]; + static char buf[64]; switch (DateStyle) { @@ -270,6 +270,7 @@ assign_timezone(const char *value, bool doit, bool interactive) return NULL; } *endptr = '\0'; + /* * Try to parse it. XXX an invalid interval format will result in * elog, which is not desirable for GUC. We did what we could to @@ -277,9 +278,9 @@ assign_timezone(const char *value, bool doit, bool interactive) * coming in from postgresql.conf might contain anything. */ interval = DatumGetIntervalP(DirectFunctionCall3(interval_in, - CStringGetDatum(val), - ObjectIdGetDatum(InvalidOid), - Int32GetDatum(-1))); + CStringGetDatum(val), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1))); pfree(val); if (interval->month != 0) { @@ -318,8 +319,8 @@ assign_timezone(const char *value, bool doit, bool interactive) * available under Solaris, among others. Apparently putenv() * called as below clears the process-specific environment * variables. Other reasonable arguments to putenv() (e.g. - * "TZ=", "TZ", "") result in a core dump (under Linux anyway). - * - thomas 1998-01-26 + * "TZ=", "TZ", "") result in a core dump (under Linux + * anyway). - thomas 1998-01-26 */ if (doit) { @@ -339,13 +340,14 @@ assign_timezone(const char *value, bool doit, bool interactive) * Otherwise assume it is a timezone name. * * XXX unfortunately we have no reasonable way to check whether a - * timezone name is good, so we have to just assume that it is. + * timezone name is good, so we have to just assume that it + * is. */ if (doit) { strcpy(tzbuf, "TZ="); - strncat(tzbuf, value, sizeof(tzbuf)-4); - if (putenv(tzbuf) != 0) /* shouldn't happen? */ + strncat(tzbuf, value, sizeof(tzbuf) - 4); + if (putenv(tzbuf) != 0) /* shouldn't happen? */ elog(LOG, "assign_timezone: putenv failed"); tzset(); HasCTZSet = false; @@ -360,7 +362,7 @@ assign_timezone(const char *value, bool doit, bool interactive) return value; /* - * Prepare the canonical string to return. GUC wants it malloc'd. + * Prepare the canonical string to return. GUC wants it malloc'd. */ result = (char *) malloc(sizeof(tzbuf)); if (!result) @@ -372,13 +374,9 @@ assign_timezone(const char *value, bool doit, bool interactive) (double) CTimeZone / 3600.0); } else if (tzbuf[0] == 'T') - { strcpy(result, tzbuf + 3); - } else - { strcpy(result, "UNKNOWN"); - } return result; } @@ -399,7 +397,7 @@ show_timezone(void) interval.time = CTimeZone; tzn = DatumGetCString(DirectFunctionCall1(interval_out, - IntervalPGetDatum(&interval))); + IntervalPGetDatum(&interval))); } else tzn = getenv("TZ"); @@ -422,11 +420,20 @@ assign_XactIsoLevel(const char *value, bool doit, bool interactive) elog(ERROR, "SET TRANSACTION ISOLATION LEVEL must be called before any query"); if (strcmp(value, "serializable") == 0) - { if (doit) XactIsoLevel = XACT_SERIALIZABLE; } + { + if (doit) + XactIsoLevel = XACT_SERIALIZABLE; + } else if (strcmp(value, "read committed") == 0) - { if (doit) XactIsoLevel = XACT_READ_COMMITTED; } + { + if (doit) + XactIsoLevel = XACT_READ_COMMITTED; + } else if (strcmp(value, "default") == 0) - { if (doit) XactIsoLevel = DefaultXactIsoLevel; } + { + if (doit) + XactIsoLevel = DefaultXactIsoLevel; + } else return NULL; @@ -475,11 +482,12 @@ assign_client_encoding(const char *value, bool doit, bool interactive) encoding = pg_valid_client_encoding(value); if (encoding < 0) return NULL; - - /* XXX SetClientEncoding depends on namespace functions which are - * not available at startup time. So we accept requested client - * encoding anyway which might not be valid (e.g. no conversion - * procs available). + + /* + * XXX SetClientEncoding depends on namespace functions which are not + * available at startup time. So we accept requested client encoding + * anyway which might not be valid (e.g. no conversion procs + * available). */ if (SetClientEncoding(encoding, doit) < 0) { diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index 91420319a8..0ce309750c 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.70 2002/09/02 20:04:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.71 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace) * the (non-junk) targetlist items from the view's SELECT list. */ attrList = NIL; - foreach (t, tlist) + foreach(t, tlist) { TargetEntry *entry = lfirst(t); Resdom *res = entry->resdom; @@ -115,32 +115,32 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace) * Create a tuple descriptor to compare against the existing view, * and verify it matches. */ - descriptor = BuildDescForRelation(attrList); + descriptor = BuildDescForRelation(attrList); checkViewTupleDesc(descriptor, rel->rd_att); /* * Seems okay, so return the OID of the pre-existing view. */ - relation_close(rel, NoLock); /* keep the lock! */ + relation_close(rel, NoLock); /* keep the lock! */ return viewOid; } else { /* - * now create the parameters for keys/inheritance etc. All of them are - * nil... + * now create the parameters for keys/inheritance etc. All of them + * are nil... */ createStmt->relation = (RangeVar *) relation; createStmt->tableElts = attrList; createStmt->inhRelations = NIL; createStmt->constraints = NIL; createStmt->hasoids = false; - + /* - * finally create the relation (this will error out if there's - * an existing view, so we don't need more code to complain - * if "replace" is false). + * finally create the relation (this will error out if there's an + * existing view, so we don't need more code to complain if + * "replace" is false). */ return DefineRelation(createStmt, RELKIND_VIEW); } @@ -179,6 +179,7 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc) NameStr(oldattr->attname)); /* We can ignore the remaining attributes of an attribute... */ } + /* * We ignore the constraint fields. The new view desc can't have any * constraints, and the only ones that could be on the old view are @@ -316,8 +317,8 @@ DefineView(const RangeVar *view, Query *viewParse, bool replace) /* * Create the view relation * - * NOTE: if it already exists and replace is false, the xact will - * be aborted. + * NOTE: if it already exists and replace is false, the xact will be + * aborted. */ viewOid = DefineVirtualRelation(view, viewParse->targetList, replace); diff --git a/src/backend/executor/execJunk.c b/src/backend/executor/execJunk.c index d808b85337..761ff403dd 100644 --- a/src/backend/executor/execJunk.c +++ b/src/backend/executor/execJunk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.31 2002/07/20 05:16:57 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.32 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -383,8 +383,8 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot) * information for the new "clean" tuple. * * Note: we use memory on the stack to optimize things when we are - * dealing with a small number of attributes. for large tuples we - * just use palloc. + * dealing with a small number of attributes. for large tuples we just + * use palloc. */ if (cleanLength > 64) { diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index fd4431ce5f..300c415a01 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -27,7 +27,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.177 2002/09/02 01:05:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.178 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,14 +63,14 @@ static TupleTableSlot *ExecutePlan(EState *estate, Plan *plan, ScanDirection direction, DestReceiver *destfunc); static void ExecSelect(TupleTableSlot *slot, - DestReceiver *destfunc, - EState *estate); + DestReceiver *destfunc, + EState *estate); static void ExecInsert(TupleTableSlot *slot, ItemPointer tupleid, EState *estate); static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid, EState *estate); static void ExecUpdate(TupleTableSlot *slot, ItemPointer tupleid, - EState *estate); + EState *estate); static TupleTableSlot *EvalPlanQualNext(EState *estate); static void EndEvalPlanQual(EState *estate); static void ExecCheckQueryPerms(CmdType operation, Query *parseTree, @@ -116,9 +116,9 @@ ExecutorStart(QueryDesc *queryDesc, EState *estate) /* * Make our own private copy of the current query snapshot data. * - * This "freezes" our idea of which tuples are good and which are not - * for the life of this query, even if it outlives the current command - * and current snapshot. + * This "freezes" our idea of which tuples are good and which are not for + * the life of this query, even if it outlives the current command and + * current snapshot. */ estate->es_snapshot = CopyQuerySnapshot(); @@ -353,12 +353,13 @@ ExecCheckRTEPerms(RangeTblEntry *rte, CmdType operation) Oid userid; AclResult aclcheck_result; - /* + /* * Only plain-relation RTEs need to be checked here. Subquery RTEs - * will be checked when ExecCheckPlanPerms finds the SubqueryScan node, - * and function RTEs are checked by init_fcache when the function is - * prepared for execution. Join and special RTEs need no checks. - */ + * will be checked when ExecCheckPlanPerms finds the SubqueryScan + * node, and function RTEs are checked by init_fcache when the + * function is prepared for execution. Join and special RTEs need no + * checks. + */ if (rte->rtekind != RTE_RELATION) return; @@ -1071,7 +1072,8 @@ lnext: ; slot = ExecStoreTuple(newTuple, /* tuple to store */ junkfilter->jf_resultSlot, /* dest slot */ - InvalidBuffer, /* this tuple has no buffer */ + InvalidBuffer, /* this tuple has no + * buffer */ true); /* tuple should be pfreed */ } @@ -1083,8 +1085,9 @@ lnext: ; switch (operation) { case CMD_SELECT: - ExecSelect(slot, /* slot containing tuple */ - destfunc, /* destination's tuple-receiver obj */ + ExecSelect(slot, /* slot containing tuple */ + destfunc, /* destination's tuple-receiver + * obj */ estate); result = slot; break; @@ -1357,8 +1360,8 @@ ldelete:; */ static void ExecUpdate(TupleTableSlot *slot, - ItemPointer tupleid, - EState *estate) + ItemPointer tupleid, + EState *estate) { HeapTuple tuple; ResultRelInfo *resultRelInfo; diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c index 12b2089fd7..5718983ca1 100644 --- a/src/backend/executor/execQual.c +++ b/src/backend/executor/execQual.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.107 2002/09/02 01:05:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.108 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -55,7 +55,7 @@ static Datum ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull); static Datum ExecEvalOper(Expr *opClause, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalDistinct(Expr *opClause, ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone); + bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalFunc(Expr *funcClause, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static ExprDoneCond ExecEvalFuncArgs(FunctionCallInfo fcinfo, @@ -70,8 +70,8 @@ static Datum ExecEvalNullTest(NullTest *ntest, ExprContext *econtext, static Datum ExecEvalBooleanTest(BooleanTest *btest, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalConstraintTest(ConstraintTest *constraint, - ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone); + ExprContext *econtext, + bool *isNull, ExprDoneCond *isDone); /*---------- @@ -848,7 +848,7 @@ ExecMakeFunctionResult(FunctionCachePtr fcache, * ExecMakeTableFunctionResult * * Evaluate a table function, producing a materialized result in a Tuplestore - * object. (If function returns an empty set, we just return NULL instead.) + * object. (If function returns an empty set, we just return NULL instead.) */ Tuplestorestate * ExecMakeTableFunctionResult(Expr *funcexpr, @@ -871,13 +871,14 @@ ExecMakeTableFunctionResult(Expr *funcexpr, bool returnsTuple = false; /* Extract data from function-call expression node */ - if (!funcexpr || !IsA(funcexpr, Expr) || funcexpr->opType != FUNC_EXPR) + if (!funcexpr || !IsA(funcexpr, Expr) ||funcexpr->opType != FUNC_EXPR) elog(ERROR, "ExecMakeTableFunctionResult: expression is not a function call"); func = (Func *) funcexpr->oper; argList = funcexpr->args; /* - * get the fcache from the Func node. If it is NULL, then initialize it + * get the fcache from the Func node. If it is NULL, then initialize + * it */ fcache = func->func_fcache; if (fcache == NULL) @@ -892,7 +893,7 @@ ExecMakeTableFunctionResult(Expr *funcexpr, * * Note: ideally, we'd do this in the per-tuple context, but then the * argument values would disappear when we reset the context in the - * inner loop. So do it in caller context. Perhaps we should make a + * inner loop. So do it in caller context. Perhaps we should make a * separate context just to hold the evaluated arguments? */ MemSet(&fcinfo, 0, sizeof(fcinfo)); @@ -921,8 +922,9 @@ ExecMakeTableFunctionResult(Expr *funcexpr, } /* - * Prepare a resultinfo node for communication. We always do this even - * if not expecting a set result, so that we can pass expectedDesc. + * Prepare a resultinfo node for communication. We always do this + * even if not expecting a set result, so that we can pass + * expectedDesc. */ fcinfo.resultinfo = (Node *) &rsinfo; rsinfo.type = T_ReturnSetInfo; @@ -948,8 +950,9 @@ ExecMakeTableFunctionResult(Expr *funcexpr, HeapTuple tuple; /* - * reset per-tuple memory context before each call of the function. - * This cleans up any local memory the function may leak when called. + * reset per-tuple memory context before each call of the + * function. This cleans up any local memory the function may leak + * when called. */ ResetExprContext(econtext); @@ -964,18 +967,20 @@ ExecMakeTableFunctionResult(Expr *funcexpr, /* * Check for end of result set. * - * Note: if function returns an empty set, we don't build a + * Note: if function returns an empty set, we don't build a * tupdesc or tuplestore (since we can't get a tupdesc in the * function-returning-tuple case) */ if (rsinfo.isDone == ExprEndResult) break; + /* - * If first time through, build tupdesc and tuplestore for result + * If first time through, build tupdesc and tuplestore for + * result */ if (first_time) { - Oid funcrettype = funcexpr->typeOid; + Oid funcrettype = funcexpr->typeOid; oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory); if (funcrettype == RECORDOID || @@ -1006,7 +1011,7 @@ ExecMakeTableFunctionResult(Expr *funcexpr, 0, false); } - tupstore = tuplestore_begin_heap(true, /* randomAccess */ + tupstore = tuplestore_begin_heap(true, /* randomAccess */ SortMem); MemoryContextSwitchTo(oldcontext); rsinfo.setResult = tupstore; @@ -1026,7 +1031,7 @@ ExecMakeTableFunctionResult(Expr *funcexpr, } else { - char nullflag; + char nullflag; nullflag = fcinfo.isnull ? 'n' : ' '; tuple = heap_formtuple(tupdesc, &result, &nullflag); @@ -1180,7 +1185,7 @@ ExecEvalDistinct(Expr *opClause, bool *isNull, ExprDoneCond *isDone) { - bool result; + bool result; FunctionCachePtr fcache; FunctionCallInfoData fcinfo; ExprDoneCond argDone; diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index e07fd8719a..1a5f835be1 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.58 2002/09/02 01:05:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.59 2002/09/04 20:31:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -681,7 +681,7 @@ ExecTypeFromTL(List *targetList, bool hasoid) TupleTableSlot * TupleDescGetSlot(TupleDesc tupdesc) { - TupleTableSlot *slot; + TupleTableSlot *slot; /* Make a standalone slot */ slot = MakeTupleTableSlot(); @@ -701,19 +701,20 @@ TupleDescGetSlot(TupleDesc tupdesc) AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc) { - int natts = tupdesc->natts; - int i; - Oid atttypeid; - Oid attinfuncid; - FmgrInfo *attinfuncinfo; - Oid *attelems; - int32 *atttypmods; - AttInMetadata *attinmeta; + int natts = tupdesc->natts; + int i; + Oid atttypeid; + Oid attinfuncid; + FmgrInfo *attinfuncinfo; + Oid *attelems; + int32 *atttypmods; + AttInMetadata *attinmeta; attinmeta = (AttInMetadata *) palloc(sizeof(AttInMetadata)); /* - * Gather info needed later to call the "in" function for each attribute + * Gather info needed later to call the "in" function for each + * attribute */ attinfuncinfo = (FmgrInfo *) palloc(natts * sizeof(FmgrInfo)); attelems = (Oid *) palloc(natts * sizeof(Oid)); @@ -741,14 +742,14 @@ TupleDescGetAttInMetadata(TupleDesc tupdesc) HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) { - TupleDesc tupdesc = attinmeta->tupdesc; - int natts = tupdesc->natts; - Datum *dvalues; - char *nulls; - int i; - Oid attelem; - int32 atttypmod; - HeapTuple tuple; + TupleDesc tupdesc = attinmeta->tupdesc; + int natts = tupdesc->natts; + Datum *dvalues; + char *nulls; + int i; + Oid attelem; + int32 atttypmod; + HeapTuple tuple; dvalues = (Datum *) palloc(natts * sizeof(Datum)); nulls = (char *) palloc(natts * sizeof(char)); @@ -843,13 +844,14 @@ do_text_output_multiline(TupOutputState *tstate, char *text) { while (*text) { - char *eol; + char *eol; eol = strchr(text, '\n'); if (eol) *eol++ = '\0'; else - eol = text + strlen(text); + eol = text +strlen(text); + do_tup_output(tstate, &text); text = eol; } diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 3e8cf203b1..86440d10f9 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.89 2002/09/02 01:05:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.90 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -297,19 +297,19 @@ ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate) /* * This is pretty grotty: we need to ensure that result tuples have * space for an OID iff they are going to be stored into a relation - * that has OIDs. We assume that estate->es_result_relation_info - * is already set up to describe the target relation. One reason - * this is ugly is that all plan nodes in the plan tree will emit - * tuples with space for an OID, though we really only need the topmost - * plan to do so. + * that has OIDs. We assume that estate->es_result_relation_info is + * already set up to describe the target relation. One reason this is + * ugly is that all plan nodes in the plan tree will emit tuples with + * space for an OID, though we really only need the topmost plan to do + * so. * * It would be better to have InitPlan adjust the topmost plan node's * output descriptor after plan tree initialization. However, that * doesn't quite work because in an UPDATE that spans an inheritance - * tree, some of the target relations may have OIDs and some not. - * We have to make the decision on a per-relation basis as we initialize - * each of the child plans of the topmost Append plan. So, this is ugly - * but it works, for now ... + * tree, some of the target relations may have OIDs and some not. We + * have to make the decision on a per-relation basis as we initialize + * each of the child plans of the topmost Append plan. So, this is + * ugly but it works, for now ... */ ri = node->state->es_result_relation_info; if (ri != NULL) @@ -319,7 +319,7 @@ ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate) if (rel != NULL) hasoid = rel->rd_rel->relhasoids; } - + tupDesc = ExecTypeFromTL(node->targetlist, hasoid); ExecAssignResultType(commonstate, tupDesc, true); } @@ -696,7 +696,7 @@ ExecInsertIndexTuples(TupleTableSlot *slot, nullv); /* - * The index AM does the rest. Note we suppress unique-index + * The index AM does the rest. Note we suppress unique-index * checks if we are being called from VACUUM, since VACUUM may * need to move dead tuples that have the same keys as live ones. */ @@ -705,7 +705,7 @@ ExecInsertIndexTuples(TupleTableSlot *slot, nullv, /* info on nulls */ &(heapTuple->t_self), /* tid of heap tuple */ heapRelation, - relationDescs[i]->rd_index->indisunique && !is_vacuum); + relationDescs[i]->rd_index->indisunique && !is_vacuum); /* * keep track of index inserts for debugging @@ -753,7 +753,7 @@ RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg) { - ExprContext_CB *ecxt_callback; + ExprContext_CB *ecxt_callback; /* Save the info in appropriate memory context */ ecxt_callback = (ExprContext_CB *) @@ -779,8 +779,8 @@ UnregisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg) { - ExprContext_CB **prev_callback; - ExprContext_CB *ecxt_callback; + ExprContext_CB **prev_callback; + ExprContext_CB *ecxt_callback; prev_callback = &econtext->ecxt_callbacks; @@ -792,9 +792,7 @@ UnregisterExprContextCallback(ExprContext *econtext, pfree(ecxt_callback); } else - { prev_callback = &ecxt_callback->next; - } } } @@ -807,7 +805,7 @@ UnregisterExprContextCallback(ExprContext *econtext, static void ShutdownExprContext(ExprContext *econtext) { - ExprContext_CB *ecxt_callback; + ExprContext_CB *ecxt_callback; /* * Call each callback function in reverse registration order. diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index fe473404b9..b8bf811a5e 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.56 2002/08/29 00:17:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.57 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -269,7 +269,7 @@ postquel_start(execution_state *es) static TupleTableSlot * postquel_getnext(execution_state *es) { - long count; + long count; if (es->qd->operation == CMD_UTILITY) { @@ -566,8 +566,8 @@ fmgr_sql(PG_FUNCTION_ARGS) elog(ERROR, "Set-valued function called in context that cannot accept a set"); /* - * Ensure we will get shut down cleanly if the exprcontext is - * not run to completion. + * Ensure we will get shut down cleanly if the exprcontext is not + * run to completion. */ if (!fcache->shutdown_reg) { diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index de839269cc..1a9239c57b 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -46,7 +46,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.85 2002/06/20 20:29:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.86 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -877,8 +877,8 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent) &peraggstate->transtypeByVal); /* - * initval is potentially null, so don't try to access it as a struct - * field. Must do it the hard way with SysCacheGetAttr. + * initval is potentially null, so don't try to access it as a + * struct field. Must do it the hard way with SysCacheGetAttr. */ textInitVal = SysCacheGetAttr(AGGFNOID, aggTuple, Anum_pg_aggregate_agginitval, @@ -907,8 +907,8 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent) if (peraggstate->transfn.fn_strict && peraggstate->initValueIsNull) { /* - * Note: use the type from the input expression here, not - * from pg_proc.proargtypes, because the latter might be 0. + * Note: use the type from the input expression here, not from + * pg_proc.proargtypes, because the latter might be 0. * (Consider COUNT(*).) */ Oid inputType = exprType(aggref->target); @@ -921,8 +921,8 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent) if (aggref->aggdistinct) { /* - * Note: use the type from the input expression here, not - * from pg_proc.proargtypes, because the latter might be 0. + * Note: use the type from the input expression here, not from + * pg_proc.proargtypes, because the latter might be 0. * (Consider COUNT(*).) */ Oid inputType = exprType(aggref->target); diff --git a/src/backend/executor/nodeFunctionscan.c b/src/backend/executor/nodeFunctionscan.c index 8a9ac848e7..cf8d74a06f 100644 --- a/src/backend/executor/nodeFunctionscan.c +++ b/src/backend/executor/nodeFunctionscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v 1.11 2002/09/02 01:05:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeFunctionscan.c,v 1.12 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -50,13 +50,13 @@ static bool tupledesc_mismatch(TupleDesc tupdesc1, TupleDesc tupdesc2); static TupleTableSlot * FunctionNext(FunctionScan *node) { - TupleTableSlot *slot; - EState *estate; - ScanDirection direction; - Tuplestorestate *tuplestorestate; - FunctionScanState *scanstate; - bool should_free; - HeapTuple heapTuple; + TupleTableSlot *slot; + EState *estate; + ScanDirection direction; + Tuplestorestate *tuplestorestate; + FunctionScanState *scanstate; + bool should_free; + HeapTuple heapTuple; /* * get information from the estate and scan state @@ -69,12 +69,13 @@ FunctionNext(FunctionScan *node) /* * If first time through, read all tuples from function and put them - * in a tuplestore. Subsequent calls just fetch tuples from tuplestore. + * in a tuplestore. Subsequent calls just fetch tuples from + * tuplestore. */ if (tuplestorestate == NULL) { - ExprContext *econtext = scanstate->csstate.cstate.cs_ExprContext; - TupleDesc funcTupdesc; + ExprContext *econtext = scanstate->csstate.cstate.cs_ExprContext; + TupleDesc funcTupdesc; scanstate->tuplestorestate = tuplestorestate = ExecMakeTableFunctionResult((Expr *) scanstate->funcexpr, @@ -83,9 +84,9 @@ FunctionNext(FunctionScan *node) &funcTupdesc); /* - * If function provided a tupdesc, cross-check it. We only really - * need to do this for functions returning RECORD, but might as well - * do it always. + * If function provided a tupdesc, cross-check it. We only really + * need to do this for functions returning RECORD, but might as + * well do it always. */ if (funcTupdesc && tupledesc_mismatch(scanstate->tupdesc, funcTupdesc)) @@ -98,7 +99,7 @@ FunctionNext(FunctionScan *node) slot = scanstate->csstate.css_ScanTupleSlot; if (tuplestorestate) heapTuple = tuplestore_getheaptuple(tuplestorestate, - ScanDirectionIsForward(direction), + ScanDirectionIsForward(direction), &should_free); else { @@ -135,11 +136,11 @@ ExecFunctionScan(FunctionScan *node) bool ExecInitFunctionScan(FunctionScan *node, EState *estate, Plan *parent) { - FunctionScanState *scanstate; - RangeTblEntry *rte; - Oid funcrettype; - char functyptype; - TupleDesc tupdesc = NULL; + FunctionScanState *scanstate; + RangeTblEntry *rte; + Oid funcrettype; + char functyptype; + TupleDesc tupdesc = NULL; /* * FunctionScan should not have any children. @@ -266,8 +267,8 @@ ExecCountSlotsFunctionScan(FunctionScan *node) void ExecEndFunctionScan(FunctionScan *node) { - FunctionScanState *scanstate; - EState *estate; + FunctionScanState *scanstate; + EState *estate; /* * get information from node @@ -308,7 +309,7 @@ ExecEndFunctionScan(FunctionScan *node) void ExecFunctionMarkPos(FunctionScan *node) { - FunctionScanState *scanstate; + FunctionScanState *scanstate; scanstate = (FunctionScanState *) node->scan.scanstate; @@ -330,7 +331,7 @@ ExecFunctionMarkPos(FunctionScan *node) void ExecFunctionRestrPos(FunctionScan *node) { - FunctionScanState *scanstate; + FunctionScanState *scanstate; scanstate = (FunctionScanState *) node->scan.scanstate; @@ -352,7 +353,7 @@ ExecFunctionRestrPos(FunctionScan *node) void ExecFunctionReScan(FunctionScan *node, ExprContext *exprCtxt, Plan *parent) { - FunctionScanState *scanstate; + FunctionScanState *scanstate; /* * get information from node diff --git a/src/backend/executor/nodeHash.c b/src/backend/executor/nodeHash.c index 466452df8e..8bb5bde84c 100644 --- a/src/backend/executor/nodeHash.c +++ b/src/backend/executor/nodeHash.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $Id: nodeHash.c,v 1.65 2002/09/02 02:47:02 momjian Exp $ + * $Id: nodeHash.c,v 1.66 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,7 @@ #include "utils/lsyscache.h" -static uint32 hashFunc(Datum key, int typLen, bool byVal); +static uint32 hashFunc(Datum key, int typLen, bool byVal); /* ---------------------------------------------------------------- * ExecHash @@ -639,11 +639,11 @@ hashFunc(Datum key, int typLen, bool byVal) { /* * If it's a by-value data type, just hash the whole Datum value. - * This assumes that datatypes narrower than Datum are consistently - * padded (either zero-extended or sign-extended, but not random - * bits) to fill Datum; see the XXXGetDatum macros in postgres.h. - * NOTE: it would not work to do hash_any(&key, len) since this - * would get the wrong bytes on a big-endian machine. + * This assumes that datatypes narrower than Datum are + * consistently padded (either zero-extended or sign-extended, but + * not random bits) to fill Datum; see the XXXGetDatum macros in + * postgres.h. NOTE: it would not work to do hash_any(&key, len) + * since this would get the wrong bytes on a big-endian machine. */ k = (unsigned char *) &key; typLen = sizeof(Datum); @@ -658,14 +658,14 @@ hashFunc(Datum key, int typLen, bool byVal) else if (typLen == -1) { /* - * It's a varlena type, so 'key' points to a - * "struct varlena". NOTE: VARSIZE returns the - * "real" data length plus the sizeof the "vl_len" attribute of - * varlena (the length information). 'key' points to the beginning - * of the varlena struct, so we have to use "VARDATA" to find the - * beginning of the "real" data. Also, we have to be careful to - * detoast the datum if it's toasted. (We don't worry about - * freeing the detoasted copy; that happens for free when the + * It's a varlena type, so 'key' points to a "struct varlena". + * NOTE: VARSIZE returns the "real" data length plus the + * sizeof the "vl_len" attribute of varlena (the length + * information). 'key' points to the beginning of the varlena + * struct, so we have to use "VARDATA" to find the beginning + * of the "real" data. Also, we have to be careful to detoast + * the datum if it's toasted. (We don't worry about freeing + * the detoasted copy; that happens for free when the * per-tuple memory context is reset in ExecHashGetBucket.) */ struct varlena *vkey = PG_DETOAST_DATUM(key); diff --git a/src/backend/executor/nodeIndexscan.c b/src/backend/executor/nodeIndexscan.c index 5eb15f7f5c..78f5ad0ba2 100644 --- a/src/backend/executor/nodeIndexscan.c +++ b/src/backend/executor/nodeIndexscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.70 2002/06/23 21:29:32 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.71 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -165,22 +165,21 @@ IndexNext(IndexScan *node) while ((tuple = index_getnext(scandesc, direction)) != NULL) { /* - * store the scanned tuple in the scan tuple slot of the - * scan state. Note: we pass 'false' because tuples - * returned by amgetnext are pointers onto disk pages and - * must not be pfree()'d. + * store the scanned tuple in the scan tuple slot of the scan + * state. Note: we pass 'false' because tuples returned by + * amgetnext are pointers onto disk pages and must not be + * pfree()'d. */ - ExecStoreTuple(tuple, /* tuple to store */ + ExecStoreTuple(tuple, /* tuple to store */ slot, /* slot to store in */ - scandesc->xs_cbuf, /* buffer containing tuple */ - false); /* don't pfree */ + scandesc->xs_cbuf, /* buffer containing tuple */ + false); /* don't pfree */ /* * We must check to see if the current tuple was already - * matched by an earlier index, so we don't double-report - * it. We do this by passing the tuple through ExecQual - * and checking for failure with all previous - * qualifications. + * matched by an earlier index, so we don't double-report it. + * We do this by passing the tuple through ExecQual and + * checking for failure with all previous qualifications. */ if (indexstate->iss_IndexPtr > 0) { @@ -485,8 +484,9 @@ ExecEndIndexScan(IndexScan *node) * close the heap relation. * * Currently, we do not release the AccessShareLock acquired by - * ExecInitIndexScan. This lock should be held till end of transaction. - * (There is a faction that considers this too much locking, however.) + * ExecInitIndexScan. This lock should be held till end of + * transaction. (There is a faction that considers this too much + * locking, however.) */ heap_close(relation, NoLock); @@ -1009,7 +1009,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent) elog(ERROR, "indexes of the relation %u was inactivated", reloid); scanstate->css_currentRelation = currentRelation; - scanstate->css_currentScanDesc = NULL; /* no heap scan here */ + scanstate->css_currentScanDesc = NULL; /* no heap scan here */ /* * get the scan type from the relation descriptor. diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c index 4467fef9e1..4237618b0e 100644 --- a/src/backend/executor/nodeMergejoin.c +++ b/src/backend/executor/nodeMergejoin.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.50 2002/06/20 20:29:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.51 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -93,7 +93,7 @@ static bool MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) * This takes the mergeclause which is a qualification of the * form ((= expr expr) (= expr expr) ...) and forms new lists * of the forms ((< expr expr) (< expr expr) ...) and - * ((> expr expr) (> expr expr) ...). These lists will be used + * ((> expr expr) (> expr expr) ...). These lists will be used * by ExecMergeJoin() to determine if we should skip tuples. * (We expect there to be suitable operators because the "=" operators * were marked mergejoinable; however, there might be a different diff --git a/src/backend/executor/nodeSeqscan.c b/src/backend/executor/nodeSeqscan.c index ddfcd3b8da..074a52731c 100644 --- a/src/backend/executor/nodeSeqscan.c +++ b/src/backend/executor/nodeSeqscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.36 2002/06/20 20:29:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeSeqscan.c,v 1.37 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -284,8 +284,9 @@ ExecEndSeqScan(SeqScan *node) * close the heap relation. * * Currently, we do not release the AccessShareLock acquired by - * InitScanRelation. This lock should be held till end of transaction. - * (There is a faction that considers this too much locking, however.) + * InitScanRelation. This lock should be held till end of + * transaction. (There is a faction that considers this too much + * locking, however.) */ heap_close(relation, NoLock); diff --git a/src/backend/executor/nodeTidscan.c b/src/backend/executor/nodeTidscan.c index 300735fff0..f5e477663b 100644 --- a/src/backend/executor/nodeTidscan.c +++ b/src/backend/executor/nodeTidscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.25 2002/06/20 20:29:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.26 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -109,8 +109,8 @@ TidNext(TidScan *node) return slot; /* return empty slot */ /* - * XXX shouldn't we check here to make sure tuple matches TID list? - * In runtime-key case this is not certain, is it? + * XXX shouldn't we check here to make sure tuple matches TID + * list? In runtime-key case this is not certain, is it? */ ExecStoreTuple(estate->es_evTuple[node->scan.scanrelid - 1], @@ -468,7 +468,7 @@ ExecInitTidScan(TidScan *node, EState *estate, Plan *parent) currentRelation = heap_open(reloid, AccessShareLock); scanstate->css_currentRelation = currentRelation; - scanstate->css_currentScanDesc = NULL; /* no heap scan here */ + scanstate->css_currentScanDesc = NULL; /* no heap scan here */ /* * get the scan type from the relation descriptor. diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index f0cc3fe17a..273fe6fee1 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.73 2002/09/02 01:05:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.74 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -433,6 +433,7 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, if (i == natts) /* no errors in *attnum */ { mtuple = heap_formtuple(rel->rd_att, v, n); + /* * copy the identification info of the old tuple: t_ctid, t_self, * and OID (if any) @@ -1098,7 +1099,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount) ParamListInfo paramLI; paramLI = (ParamListInfo) palloc((nargs + 1) * - sizeof(ParamListInfoData)); + sizeof(ParamListInfoData)); MemSet(paramLI, 0, (nargs + 1) * sizeof(ParamListInfoData)); state->es_param_list_info = paramLI; @@ -1266,9 +1267,9 @@ _SPI_cursor_operation(Portal portal, bool forward, int count, ExecutorRun(querydesc, estate, direction, (long) count); if (estate->es_processed > 0) - portal->atStart = false; /* OK to back up now */ + portal->atStart = false; /* OK to back up now */ if (count <= 0 || (int) estate->es_processed < count) - portal->atEnd = true; /* we retrieved 'em all */ + portal->atEnd = true; /* we retrieved 'em all */ } else { @@ -1280,9 +1281,9 @@ _SPI_cursor_operation(Portal portal, bool forward, int count, ExecutorRun(querydesc, estate, direction, (long) count); if (estate->es_processed > 0) - portal->atEnd = false; /* OK to go forward now */ + portal->atEnd = false; /* OK to go forward now */ if (count <= 0 || (int) estate->es_processed < count) - portal->atStart = true; /* we retrieved 'em all */ + portal->atStart = true; /* we retrieved 'em all */ } _SPI_current->processed = estate->es_processed; diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c index 62f63a547f..9b9fc3d180 100644 --- a/src/backend/lib/stringinfo.c +++ b/src/backend/lib/stringinfo.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: stringinfo.c,v 1.31 2002/06/20 20:29:28 momjian Exp $ + * $Id: stringinfo.c,v 1.32 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -120,7 +120,7 @@ appendStringInfo(StringInfo str, const char *fmt,...) * an example of a platform with such a bug. */ #ifdef USE_ASSERT_CHECKING - str->data[str->maxlen-1] = '\0'; + str->data[str->maxlen - 1] = '\0'; #endif va_start(args, fmt); @@ -128,7 +128,7 @@ appendStringInfo(StringInfo str, const char *fmt,...) fmt, args); va_end(args); - Assert(str->data[str->maxlen-1] == '\0'); + Assert(str->data[str->maxlen - 1] == '\0'); /* * Note: some versions of vsnprintf return the number of chars diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index 09129dd13e..7be74c58a7 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.89 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/auth.c,v 1.90 2002/09/04 20:31:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -130,7 +130,6 @@ pg_krb4_recvauth(Port *port) elog(LOG, "pg_krb4_recvauth: Kerberos not implemented on this server"); return STATUS_ERROR; } - #endif /* KRB4 */ @@ -310,7 +309,6 @@ pg_krb5_recvauth(Port *port) elog(LOG, "pg_krb5_recvauth: Kerberos not implemented on this server"); return STATUS_ERROR; } - #endif /* KRB5 */ @@ -416,7 +414,7 @@ ClientAuthentication(Port *port) if (port->raddr.sa.sa_family == AF_INET) hostinfo = inet_ntoa(port->raddr.in.sin_addr); elog(FATAL, - "No pg_hba.conf entry for host %s, user %s, database %s", + "No pg_hba.conf entry for host %s, user %s, database %s", hostinfo, port->user, port->database); break; } @@ -513,8 +511,8 @@ sendAuthRequest(Port *port, AuthRequest areq) pq_endmessage(&buf); /* - * Flush message so client will see it, except for AUTH_REQ_OK, - * which need not be sent until we are ready for queries. + * Flush message so client will see it, except for AUTH_REQ_OK, which + * need not be sent until we are ready for queries. */ if (areq != AUTH_REQ_OK) pq_flush(); @@ -688,7 +686,7 @@ CheckPAMAuth(Port *port, char *user, char *password) pam_strerror(pamh, retval)); } - pam_passwd = NULL; /* Unset pam_passwd */ + pam_passwd = NULL; /* Unset pam_passwd */ return (retval == PAM_SUCCESS ? STATUS_OK : STATUS_ERROR); } @@ -714,13 +712,14 @@ recv_and_check_password_packet(Port *port) pfree(buf.data); return STATUS_EOF; } + /* - * We don't actually use the password packet length the frontend - * sent us; however, it's a reasonable sanity check to ensure that - * we actually read as much data as we expected to. + * We don't actually use the password packet length the frontend sent + * us; however, it's a reasonable sanity check to ensure that we + * actually read as much data as we expected to. * - * The password packet size is the length of the buffer, plus the - * size field itself (4 bytes), plus a 1-byte terminator. + * The password packet size is the length of the buffer, plus the size + * field itself (4 bytes), plus a 1-byte terminator. */ if (len != (buf.len + 4 + 1)) elog(LOG, "unexpected password packet size: read %d, expected %d", diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c index 7b895de227..d7dca96528 100644 --- a/src/backend/libpq/be-secure.c +++ b/src/backend/libpq/be-secure.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.12 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.13 2002/09/04 20:31:19 momjian Exp $ * * Since the server static private key ($DataDir/server.key) * will normally be stored unencrypted so that the database @@ -30,13 +30,13 @@ * impersonations. * * Another benefit of EDH is that it allows the backend and - * clients to use DSA keys. DSA keys can only provide digital + * clients to use DSA keys. DSA keys can only provide digital * signatures, not encryption, and are often acceptable in * jurisdictions where RSA keys are unacceptable. * * The downside to EDH is that it makes it impossible to * use ssldump(1) if there's a problem establishing an SSL - * session. In this case you'll need to temporarily disable + * session. In this case you'll need to temporarily disable * EDH by commenting out the callback. * * ... @@ -49,7 +49,7 @@ * milestone 1: fix basic coding errors * [*] existing SSL code pulled out of existing files. * [*] SSL_get_error() after SSL_read() and SSL_write(), - * SSL_shutdown(), default to TLSv1. + * SSL_shutdown(), default to TLSv1. * * milestone 2: provide endpoint authentication (server) * [*] client verifies server cert @@ -112,22 +112,22 @@ extern void ExitPostmaster(int); extern void postmaster_error(const char *fmt,...); -int secure_initialize(void); -void secure_destroy(void); -int secure_open_server(Port *); -void secure_close(Port *); -ssize_t secure_read(Port *, void *ptr, size_t len); -ssize_t secure_write(Port *, const void *ptr, size_t len); +int secure_initialize(void); +void secure_destroy(void); +int secure_open_server(Port *); +void secure_close(Port *); +ssize_t secure_read(Port *, void *ptr, size_t len); +ssize_t secure_write(Port *, const void *ptr, size_t len); #ifdef USE_SSL -static DH *load_dh_file(int keylength); -static DH *load_dh_buffer(const char *, size_t); -static DH *tmp_dh_cb(SSL *s, int is_export, int keylength); -static int verify_cb(int, X509_STORE_CTX *); +static DH *load_dh_file(int keylength); +static DH *load_dh_buffer(const char *, size_t); +static DH *tmp_dh_cb(SSL *s, int is_export, int keylength); +static int verify_cb(int, X509_STORE_CTX *); static void info_cb(SSL *ssl, int type, int args); -static int initialize_SSL(void); +static int initialize_SSL(void); static void destroy_SSL(void); -static int open_server_SSL(Port *); +static int open_server_SSL(Port *); static void close_SSL(Port *); static const char *SSLerrmessage(void); #endif @@ -137,13 +137,13 @@ static const char *SSLerrmessage(void); * How much data can be sent across a secure connection * (total in both directions) before we require renegotiation. */ -#define RENEGOTIATION_LIMIT (64 * 1024) -#define CA_PATH NULL +#define RENEGOTIATION_LIMIT (64 * 1024) +#define CA_PATH NULL static SSL_CTX *SSL_context = NULL; #endif /* ------------------------------------------------------------ */ -/* Hardcoded values */ +/* Hardcoded values */ /* ------------------------------------------------------------ */ /* @@ -207,16 +207,16 @@ KWbuHn491xNO25CQWMtem80uKw+pTnisBRF/454n1Jnhub144YRBoN8CAQI=\n\ -----END DH PARAMETERS-----\n"; /* ------------------------------------------------------------ */ -/* Procedures common to all secure sessions */ +/* Procedures common to all secure sessions */ /* ------------------------------------------------------------ */ /* * Initialize global context */ int -secure_initialize (void) +secure_initialize(void) { - int r = 0; + int r = 0; #ifdef USE_SSL r = initialize_SSL(); @@ -229,7 +229,7 @@ secure_initialize (void) * Destroy global context */ void -secure_destroy (void) +secure_destroy(void) { #ifdef USE_SSL destroy_SSL(); @@ -240,9 +240,9 @@ secure_destroy (void) * Attempt to negotiate secure session. */ int -secure_open_server (Port *port) +secure_open_server(Port *port) { - int r = 0; + int r = 0; #ifdef USE_SSL r = open_server_SSL(port); @@ -255,7 +255,7 @@ secure_open_server (Port *port) * Close secure session. */ void -secure_close (Port *port) +secure_close(Port *port) { #ifdef USE_SSL if (port->ssl) @@ -267,9 +267,9 @@ secure_close (Port *port) * Read data from a secure connection. */ ssize_t -secure_read (Port *port, void *ptr, size_t len) +secure_read(Port *port, void *ptr, size_t len) { - ssize_t n; + ssize_t n; #ifdef USE_SSL if (port->ssl) @@ -283,28 +283,28 @@ secure_read (Port *port, void *ptr, size_t len) n = SSL_read(port->ssl, ptr, len); switch (SSL_get_error(port->ssl, n)) { - case SSL_ERROR_NONE: - port->count += n; - break; - case SSL_ERROR_WANT_READ: - break; - case SSL_ERROR_SYSCALL: - errno = get_last_socket_error(); - elog(ERROR, "SSL SYSCALL error: %s", strerror(errno)); - break; - case SSL_ERROR_SSL: - elog(ERROR, "SSL error: %s", SSLerrmessage()); - /* fall through */ - case SSL_ERROR_ZERO_RETURN: - secure_close(port); - errno = ECONNRESET; - n = -1; - break; + case SSL_ERROR_NONE: + port->count += n; + break; + case SSL_ERROR_WANT_READ: + break; + case SSL_ERROR_SYSCALL: + errno = get_last_socket_error(); + elog(ERROR, "SSL SYSCALL error: %s", strerror(errno)); + break; + case SSL_ERROR_SSL: + elog(ERROR, "SSL error: %s", SSLerrmessage()); + /* fall through */ + case SSL_ERROR_ZERO_RETURN: + secure_close(port); + errno = ECONNRESET; + n = -1; + break; } } else #endif - n = recv(port->sock, ptr, len, 0); + n = recv(port->sock, ptr, len, 0); return n; } @@ -313,12 +313,12 @@ secure_read (Port *port, void *ptr, size_t len) * Write data to a secure connection. */ ssize_t -secure_write (Port *port, const void *ptr, size_t len) +secure_write(Port *port, const void *ptr, size_t len) { - ssize_t n; + ssize_t n; #ifndef WIN32 - pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN); + pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN); #endif #ifdef USE_SSL @@ -333,28 +333,28 @@ secure_write (Port *port, const void *ptr, size_t len) n = SSL_write(port->ssl, ptr, len); switch (SSL_get_error(port->ssl, n)) { - case SSL_ERROR_NONE: - port->count += n; - break; - case SSL_ERROR_WANT_WRITE: - break; - case SSL_ERROR_SYSCALL: - errno = get_last_socket_error(); - elog(ERROR, "SSL SYSCALL error: %s", strerror(errno)); - break; - case SSL_ERROR_SSL: - elog(ERROR, "SSL error: %s", SSLerrmessage()); - /* fall through */ - case SSL_ERROR_ZERO_RETURN: - secure_close(port); - errno = ECONNRESET; - n = -1; - break; + case SSL_ERROR_NONE: + port->count += n; + break; + case SSL_ERROR_WANT_WRITE: + break; + case SSL_ERROR_SYSCALL: + errno = get_last_socket_error(); + elog(ERROR, "SSL SYSCALL error: %s", strerror(errno)); + break; + case SSL_ERROR_SSL: + elog(ERROR, "SSL error: %s", SSLerrmessage()); + /* fall through */ + case SSL_ERROR_ZERO_RETURN: + secure_close(port); + errno = ECONNRESET; + n = -1; + break; } } else #endif - n = send(port->sock, ptr, len, 0); + n = send(port->sock, ptr, len, 0); #ifndef WIN32 pqsignal(SIGPIPE, oldsighandler); @@ -364,7 +364,7 @@ secure_write (Port *port, const void *ptr, size_t len) } /* ------------------------------------------------------------ */ -/* SSL specific code */ +/* SSL specific code */ /* ------------------------------------------------------------ */ #ifdef USE_SSL /* @@ -374,13 +374,13 @@ secure_write (Port *port, const void *ptr, size_t len) * to verify that the DBA-generated DH parameters file contains * what we expect it to contain. */ -static DH * -load_dh_file (int keylength) +static DH * +load_dh_file(int keylength) { - FILE *fp; - char fnbuf[2048]; - DH *dh = NULL; - int codes; + FILE *fp; + char fnbuf[2048]; + DH *dh = NULL; + int codes; /* attempt to open file. It's not an error if it doesn't exist. */ snprintf(fnbuf, sizeof fnbuf, "%s/dh%d.pem", DataDir, keylength); @@ -393,10 +393,10 @@ load_dh_file (int keylength) fclose(fp); /* is the prime the correct size? */ - if (dh != NULL && 8*DH_size(dh) < keylength) + if (dh != NULL && 8 * DH_size(dh) < keylength) { elog(LOG, "DH errors (%s): %d bits expected, %d bits found", - fnbuf, keylength, 8*DH_size(dh)); + fnbuf, keylength, 8 * DH_size(dh)); dh = NULL; } @@ -417,8 +417,8 @@ load_dh_file (int keylength) (codes & DH_CHECK_P_NOT_SAFE_PRIME)) { elog(LOG, - "DH error (%s): neither suitable generator or safe prime", - fnbuf); + "DH error (%s): neither suitable generator or safe prime", + fnbuf); return NULL; } } @@ -432,11 +432,11 @@ load_dh_file (int keylength) * To prevent problems if the DH parameters files don't even * exist, we can load DH parameters hardcoded into this file. */ -static DH * -load_dh_buffer (const char *buffer, size_t len) +static DH * +load_dh_buffer(const char *buffer, size_t len) { - BIO *bio; - DH *dh = NULL; + BIO *bio; + DH *dh = NULL; bio = BIO_new_mem_buf((char *) buffer, len); if (bio == NULL) @@ -462,58 +462,58 @@ load_dh_buffer (const char *buffer, size_t len) * the OpenSSL library can efficiently generate random keys from * the information provided. */ -static DH * -tmp_dh_cb (SSL *s, int is_export, int keylength) +static DH * +tmp_dh_cb(SSL *s, int is_export, int keylength) { - DH *r = NULL; - static DH *dh = NULL; - static DH *dh512 = NULL; - static DH *dh1024 = NULL; - static DH *dh2048 = NULL; - static DH *dh4096 = NULL; + DH *r = NULL; + static DH *dh = NULL; + static DH *dh512 = NULL; + static DH *dh1024 = NULL; + static DH *dh2048 = NULL; + static DH *dh4096 = NULL; switch (keylength) { - case 512: - if (dh512 == NULL) - dh512 = load_dh_file(keylength); - if (dh512 == NULL) - dh512 = load_dh_buffer(file_dh512, sizeof file_dh512); - r = dh512; - break; - - case 1024: - if (dh1024 == NULL) - dh1024 = load_dh_file(keylength); - if (dh1024 == NULL) - dh1024 = load_dh_buffer(file_dh1024, sizeof file_dh1024); - r = dh1024; - break; - - case 2048: - if (dh2048 == NULL) - dh2048 = load_dh_file(keylength); - if (dh2048 == NULL) - dh2048 = load_dh_buffer(file_dh2048, sizeof file_dh2048); - r = dh2048; - break; - - case 4096: - if (dh4096 == NULL) - dh4096 = load_dh_file(keylength); - if (dh4096 == NULL) - dh4096 = load_dh_buffer(file_dh4096, sizeof file_dh4096); - r = dh4096; - break; - - default: - if (dh == NULL) - dh = load_dh_file(keylength); - r = dh; + case 512: + if (dh512 == NULL) + dh512 = load_dh_file(keylength); + if (dh512 == NULL) + dh512 = load_dh_buffer(file_dh512, sizeof file_dh512); + r = dh512; + break; + + case 1024: + if (dh1024 == NULL) + dh1024 = load_dh_file(keylength); + if (dh1024 == NULL) + dh1024 = load_dh_buffer(file_dh1024, sizeof file_dh1024); + r = dh1024; + break; + + case 2048: + if (dh2048 == NULL) + dh2048 = load_dh_file(keylength); + if (dh2048 == NULL) + dh2048 = load_dh_buffer(file_dh2048, sizeof file_dh2048); + r = dh2048; + break; + + case 4096: + if (dh4096 == NULL) + dh4096 = load_dh_file(keylength); + if (dh4096 == NULL) + dh4096 = load_dh_buffer(file_dh4096, sizeof file_dh4096); + r = dh4096; + break; + + default: + if (dh == NULL) + dh = load_dh_file(keylength); + r = dh; } /* this may take a long time, but it may be necessary... */ - if (r == NULL || 8*DH_size(r) < keylength) + if (r == NULL || 8 * DH_size(r) < keylength) { elog(DEBUG1, "DH: generating parameters (%d bits)....", keylength); r = DH_generate_parameters(keylength, DH_GENERATOR_2, NULL, NULL); @@ -534,7 +534,7 @@ tmp_dh_cb (SSL *s, int is_export, int keylength) * for now we accept the default checks. */ static int -verify_cb (int ok, X509_STORE_CTX *ctx) +verify_cb(int ok, X509_STORE_CTX *ctx) { return ok; } @@ -544,7 +544,7 @@ verify_cb (int ok, X509_STORE_CTX *ctx) * into the PostgreSQL log. */ static void -info_cb (SSL *ssl, int type, int args) +info_cb(SSL *ssl, int type, int args) { switch (type) { @@ -579,9 +579,9 @@ info_cb (SSL *ssl, int type, int args) * Initialize global SSL context. */ static int -initialize_SSL (void) +initialize_SSL(void) { - char fnbuf[2048]; + char fnbuf[2048]; struct stat buf; if (!SSL_context) @@ -597,7 +597,7 @@ initialize_SSL (void) } /* - * Load and verify certificate and private key + * Load and verify certificate and private key */ snprintf(fnbuf, sizeof(fnbuf), "%s/server.crt", DataDir); if (!SSL_CTX_use_certificate_file(SSL_context, fnbuf, SSL_FILETYPE_PEM)) @@ -647,7 +647,7 @@ initialize_SSL (void) ExitPostmaster(1); } SSL_CTX_set_verify(SSL_context, - SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_cb); + SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, verify_cb); return 0; } @@ -656,7 +656,7 @@ initialize_SSL (void) * Destroy global SSL context. */ static void -destroy_SSL (void) +destroy_SSL(void) { if (SSL_context) { @@ -669,7 +669,7 @@ destroy_SSL (void) * Attempt to negotiate SSL connection. */ static int -open_server_SSL (Port *port) +open_server_SSL(Port *port) { if (!(port->ssl = SSL_new(SSL_context)) || !SSL_set_fd(port->ssl, port->sock) || @@ -685,17 +685,17 @@ open_server_SSL (Port *port) port->peer = SSL_get_peer_certificate(port->ssl); if (port->peer == NULL) { - strncpy(port->peer_dn, "(anonymous)", sizeof (port->peer_dn)); - strncpy(port->peer_cn, "(anonymous)", sizeof (port->peer_cn)); + strncpy(port->peer_dn, "(anonymous)", sizeof(port->peer_dn)); + strncpy(port->peer_cn, "(anonymous)", sizeof(port->peer_cn)); } else { X509_NAME_oneline(X509_get_subject_name(port->peer), - port->peer_dn, sizeof (port->peer_dn)); - port->peer_dn[sizeof(port->peer_dn)-1] = '\0'; + port->peer_dn, sizeof(port->peer_dn)); + port->peer_dn[sizeof(port->peer_dn) - 1] = '\0'; X509_NAME_get_text_by_NID(X509_get_subject_name(port->peer), - NID_commonName, port->peer_cn, sizeof (port->peer_cn)); - port->peer_cn[sizeof(port->peer_cn)-1] = '\0'; + NID_commonName, port->peer_cn, sizeof(port->peer_cn)); + port->peer_cn[sizeof(port->peer_cn) - 1] = '\0'; } elog(DEBUG1, "secure connection from '%s'", port->peer_cn); @@ -709,7 +709,7 @@ open_server_SSL (Port *port) * Close SSL connection. */ static void -close_SSL (Port *port) +close_SSL(Port *port) { if (port->ssl) { @@ -729,9 +729,9 @@ close_SSL (Port *port) static const char * SSLerrmessage(void) { - unsigned long errcode; - const char *errreason; - static char errbuf[32]; + unsigned long errcode; + const char *errreason; + static char errbuf[32]; errcode = ERR_get_error(); if (errcode == 0) @@ -743,4 +743,4 @@ SSLerrmessage(void) return errbuf; } -#endif /* USE_SSL */ +#endif /* USE_SSL */ diff --git a/src/backend/libpq/crypt.c b/src/backend/libpq/crypt.c index 9636a067c7..9cc6b483ed 100644 --- a/src/backend/libpq/crypt.c +++ b/src/backend/libpq/crypt.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.48 2002/06/20 20:29:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/crypt.c,v 1.49 2002/09/04 20:31:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -35,9 +35,9 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass) *valuntil = NULL, *crypt_pwd; int retval = STATUS_ERROR; - List **line; - List *token; - + List **line; + List *token; + if ((line = get_user_line(user)) == NULL) return STATUS_ERROR; @@ -50,7 +50,7 @@ md5_crypt_verify(const Port *port, const char *user, const char *pgpass) if (token) valuntil = lfirst(token); } - + if (passwd == NULL || *passwd == '\0') return STATUS_ERROR; diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index 0bf6371ff9..cda4bc93ae 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.86 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.87 2002/09/04 20:31:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,7 @@ /* Max size of username ident server can return */ /* This is used to separate values in multi-valued column strings */ -#define MULTI_VALUE_SEP "\001" +#define MULTI_VALUE_SEP "\001" /* * These variables hold the pre-parsed contents of the hba and ident @@ -54,14 +54,16 @@ */ static List *hba_lines = NIL; /* pre-parsed contents of hba file */ static List *ident_lines = NIL; /* pre-parsed contents of ident file */ -static List *group_lines = NIL; /* pre-parsed contents of group file */ -static List *user_lines = NIL; /* pre-parsed contents of user password file */ +static List *group_lines = NIL; /* pre-parsed contents of group file */ +static List *user_lines = NIL; /* pre-parsed contents of user password + * file */ /* sorted entries so we can do binary search lookups */ -static List **user_sorted = NULL; /* sorted user list, for bsearch() */ -static List **group_sorted = NULL; /* sorted group list, for bsearch() */ -static int user_length; -static int group_length; +static List **user_sorted = NULL; /* sorted user list, for bsearch() */ +static List **group_sorted = NULL; /* sorted group list, for + * bsearch() */ +static int user_length; +static int group_length; static List *tokenize_file(FILE *file); static char *tokenize_inc_file(const char *inc_filename); @@ -78,14 +80,14 @@ isblank(const char c) /* - * Grab one token out of fp. Tokens are strings of non-blank - * characters bounded by blank characters, beginning of line, and - * end of line. Blank means space or tab. Return the token as - * *buf. Leave file positioned to character immediately after the - * token or EOF, whichever comes first. If no more tokens on line, - * return null string as *buf and position file to beginning of - * next line or EOF, whichever comes first. Allow spaces in quoted - * strings. Terminate on unquoted commas. Handle comments. + * Grab one token out of fp. Tokens are strings of non-blank + * characters bounded by blank characters, beginning of line, and + * end of line. Blank means space or tab. Return the token as + * *buf. Leave file positioned to character immediately after the + * token or EOF, whichever comes first. If no more tokens on line, + * return null string as *buf and position file to beginning of + * next line or EOF, whichever comes first. Allow spaces in quoted + * strings. Terminate on unquoted commas. Handle comments. */ void next_token(FILE *fp, char *buf, const int bufsz) @@ -102,8 +104,8 @@ next_token(FILE *fp, char *buf, const int bufsz) if (c != EOF && c != '\n') { /* - * Build a token in buf of next characters up to EOF, EOL, unquoted - * comma, or unquoted whitespace. + * Build a token in buf of next characters up to EOF, EOL, + * unquoted comma, or unquoted whitespace. */ while (c != EOF && c != '\n' && (!isblank(c) || in_quote == true)) @@ -156,9 +158,9 @@ next_token(FILE *fp, char *buf, const int bufsz) } /* - * Tokenize file and handle file inclusion and comma lists. We have - * to break apart the commas to expand any file names then - * reconstruct with commas. + * Tokenize file and handle file inclusion and comma lists. We have + * to break apart the commas to expand any file names then + * reconstruct with commas. */ static char * next_token_expand(FILE *file) @@ -174,17 +176,17 @@ next_token_expand(FILE *file) if (!*buf) break; - if (buf[strlen(buf)-1] == ',') + if (buf[strlen(buf) - 1] == ',') { trailing_comma = true; - buf[strlen(buf)-1] = '\0'; + buf[strlen(buf) - 1] = '\0'; } else trailing_comma = false; /* Is this referencing a file? */ if (buf[0] == '@') - incbuf = tokenize_inc_file(buf+1); + incbuf = tokenize_inc_file(buf + 1); else incbuf = pstrdup(buf); @@ -238,7 +240,7 @@ tokenize_inc_file(const char *inc_filename) { char *inc_fullname; FILE *inc_file; - List *inc_lines; + List *inc_lines; List *line; char *comma_str = pstrdup(""); @@ -279,7 +281,7 @@ tokenize_inc_file(const char *inc_filename) strcat(comma_str, MULTI_VALUE_SEP); } comma_str = repalloc(comma_str, - strlen(comma_str) + strlen(lfirst(token)) + 1); + strlen(comma_str) + strlen(lfirst(token)) + 1); strcat(comma_str, lfirst(token)); } } @@ -341,9 +343,9 @@ tokenize_file(FILE *file) static int user_group_qsort_cmp(const void *list1, const void *list2) { - /* first node is line number */ - char *user1 = lfirst(lnext(*(List **)list1)); - char *user2 = lfirst(lnext(*(List **)list2)); + /* first node is line number */ + char *user1 = lfirst(lnext(*(List **) list1)); + char *user2 = lfirst(lnext(*(List **) list2)); return strcmp(user1, user2); } @@ -357,8 +359,8 @@ user_group_qsort_cmp(const void *list1, const void *list2) static int user_group_bsearch_cmp(const void *user, const void *list) { - /* first node is line number */ - char *user2 = lfirst(lnext(*(List **)list)); + /* first node is line number */ + char *user2 = lfirst(lnext(*(List **) list)); return strcmp(user, user2); } @@ -371,24 +373,24 @@ static List ** get_group_line(const char *group) { return (List **) bsearch((void *) group, - (void *) group_sorted, - group_length, - sizeof(List *), - user_group_bsearch_cmp); + (void *) group_sorted, + group_length, + sizeof(List *), + user_group_bsearch_cmp); } /* * Lookup a user name in the pg_shadow file */ -List ** +List ** get_user_line(const char *user) { return (List **) bsearch((void *) user, - (void *) user_sorted, - user_length, - sizeof(List *), - user_group_bsearch_cmp); + (void *) user_sorted, + user_length, + sizeof(List *), + user_group_bsearch_cmp); } @@ -398,13 +400,14 @@ get_user_line(const char *user) static int check_group(char *group, char *user) { - List **line, *l; + List **line, + *l; if ((line = get_group_line(group)) != NULL) { foreach(l, lnext(lnext(*line))) if (strcmp(lfirst(l), user) == 0) - return 1; + return 1; } return 0; @@ -416,17 +419,17 @@ check_group(char *group, char *user) static int check_user(char *user, char *param_str) { - char *tok; + char *tok; for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, MULTI_VALUE_SEP)) { if (tok[0] == '+') { - if (check_group(tok+1, user)) + if (check_group(tok + 1, user)) return 1; } else if (strcmp(tok, user) == 0 || - strcmp(tok, "all") == 0) + strcmp(tok, "all") == 0) return 1; } @@ -439,7 +442,7 @@ check_user(char *user, char *param_str) static int check_db(char *dbname, char *user, char *param_str) { - char *tok; + char *tok; for (tok = strtok(param_str, MULTI_VALUE_SEP); tok != NULL; tok = strtok(NULL, MULTI_VALUE_SEP)) { @@ -744,7 +747,7 @@ void load_group() { FILE *group_file; - List *line; + List *line; if (group_lines) free_lines(&group_lines); @@ -761,7 +764,7 @@ load_group() group_length = length(group_lines); if (group_length) { - int i = 0; + int i = 0; group_sorted = palloc(group_length * sizeof(List *)); @@ -799,7 +802,7 @@ load_user() user_length = length(user_lines); if (user_length) { - int i = 0; + int i = 0; user_sorted = palloc(user_length * sizeof(List *)); @@ -825,7 +828,7 @@ load_hba(void) { int bufsize; FILE *file; /* The config file we have to read */ - char *conf_file; /* The name of the config file */ + char *conf_file; /* The name of the config file */ if (hba_lines) free_lines(&hba_lines); @@ -935,8 +938,8 @@ check_ident_usermap(const char *usermap_name, if (usermap_name[0] == '\0') { elog(LOG, "check_ident_usermap: hba configuration file does not " - "have the usermap field filled in in the entry that pertains " - "to this connection. That field is essential for Ident-based " + "have the usermap field filled in in the entry that pertains " + "to this connection. That field is essential for Ident-based " "authentication."); found_entry = false; } @@ -999,7 +1002,7 @@ load_ident(void) /* * Parse the string "*ident_response" as a response from a query to an Ident * server. If it's a normal response indicating a user name, return true - * and store the user name at *ident_user. If it's anything else, + * and store the user name at *ident_user. If it's anything else, * return false. */ static bool @@ -1140,7 +1143,7 @@ ident_inet(const struct in_addr remote_ip_addr, if (rc != 0) { /* save_errno is in case inet_ntoa changes errno */ - int save_errno = errno; + int save_errno = errno; elog(LOG, "Unable to connect to Ident server on the host which is " "trying to connect to Postgres " @@ -1157,12 +1160,13 @@ ident_inet(const struct in_addr remote_ip_addr, snprintf(ident_query, 80, "%d,%d\n", ntohs(remote_port), ntohs(local_port)); /* loop in case send is interrupted */ - do { + do + { rc = send(sock_fd, ident_query, strlen(ident_query), 0); } while (rc < 0 && errno == EINTR); if (rc < 0) { - int save_errno = errno; + int save_errno = errno; elog(LOG, "Unable to send query to Ident server on the host which is " "trying to connect to Postgres (Host %s, Port %d), " @@ -1179,11 +1183,11 @@ ident_inet(const struct in_addr remote_ip_addr, sizeof(ident_response) - 1, 0); if (rc < 0) { - int save_errno = errno; + int save_errno = errno; elog(LOG, "Unable to receive response from Ident server " "on the host which is " - "trying to connect to Postgres (Host %s, Port %d), " + "trying to connect to Postgres (Host %s, Port %d), " "even though we successfully sent our query to it: %s", inet_ntoa(remote_ip_addr), IDENT_PORT, strerror(save_errno)); @@ -1369,4 +1373,3 @@ hba_getauthmethod(hbaPort *port) else return STATUS_ERROR; } - diff --git a/src/backend/libpq/md5.c b/src/backend/libpq/md5.c index 0ecf839657..5c12e70c7f 100644 --- a/src/backend/libpq/md5.c +++ b/src/backend/libpq/md5.c @@ -14,7 +14,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.17 2002/06/20 20:29:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.18 2002/09/04 20:31:19 momjian Exp $ */ @@ -22,10 +22,10 @@ * NOTE: * * There are two copies of this file, one in backend/libpq and another - * in interfaces/odbc. They should be identical. This is done so ODBC + * in interfaces/odbc. They should be identical. This is done so ODBC * can be compiled stand-alone. */ - + #ifndef MD5_ODBC #include "postgres.h" #include "libpq/crypt.h" diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index b8d3b8b7c2..c0d832bd3d 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -29,7 +29,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pqcomm.c,v 1.139 2002/09/03 21:45:42 petere Exp $ + * $Id: pqcomm.c,v 1.140 2002/09/04 20:31:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -469,10 +469,9 @@ pq_recvbuf(void) continue; /* Ok if interrupted */ /* - * Careful: an elog() that tries to write to the client - * would cause recursion to here, leading to stack overflow - * and core dump! This message must go *only* to the postmaster - * log. + * Careful: an elog() that tries to write to the client would + * cause recursion to here, leading to stack overflow and core + * dump! This message must go *only* to the postmaster log. */ elog(COMMERROR, "pq_recvbuf: recv() failed: %m"); return EOF; @@ -574,12 +573,12 @@ pq_getstring(StringInfo s) s->data[0] = '\0'; /* Read until we get the terminating '\0' */ - for(;;) + for (;;) { while (PqRecvPointer >= PqRecvLength) { - if (pq_recvbuf()) /* If nothing in buffer, then recv some */ - return EOF; /* Failed to recv data */ + if (pq_recvbuf()) /* If nothing in buffer, then recv some */ + return EOF; /* Failed to recv data */ } for (i = PqRecvPointer; i < PqRecvLength; i++) @@ -589,7 +588,7 @@ pq_getstring(StringInfo s) /* does not copy the \0 */ appendBinaryStringInfo(s, PqRecvBuffer + PqRecvPointer, i - PqRecvPointer); - PqRecvPointer = i + 1; /* advance past \0 */ + PqRecvPointer = i + 1; /* advance past \0 */ return 0; } } @@ -639,7 +638,7 @@ pq_putbytes(const char *s, size_t len) int pq_flush(void) { - static int last_reported_send_errno = 0; + static int last_reported_send_errno = 0; unsigned char *bufptr = PqSendBuffer; unsigned char *bufend = PqSendBuffer + PqSendPointer; @@ -656,13 +655,12 @@ pq_flush(void) continue; /* Ok if we were interrupted */ /* - * Careful: an elog() that tries to write to the client - * would cause recursion to here, leading to stack overflow - * and core dump! This message must go *only* to the postmaster - * log. + * Careful: an elog() that tries to write to the client would + * cause recursion to here, leading to stack overflow and core + * dump! This message must go *only* to the postmaster log. * - * If a client disconnects while we're in the midst of output, - * we might write quite a bit of data before we get to a safe + * If a client disconnects while we're in the midst of output, we + * might write quite a bit of data before we get to a safe * query abort point. So, suppress duplicate log messages. */ if (errno != last_reported_send_errno) @@ -679,7 +677,7 @@ pq_flush(void) return EOF; } - last_reported_send_errno = 0; /* reset after any successful send */ + last_reported_send_errno = 0; /* reset after any successful send */ bufptr += r; } diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 595052a91c..52edda5aee 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.53 2002/08/09 22:52:04 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.54 2002/09/04 20:31:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -121,21 +121,24 @@ main(int argc, char *argv[]) new_argv[argc] = NULL; /* - * Set up locale information from environment. Note that CTYPE - * and COLLATE will be overridden later from pg_control if we are - * in an already-initialized database. We set them here so that - * they will be available to fill pg_control during initdb. The - * other ones will get reset later in InitializeGUCOptions, but we set - * them here to get already localized behavior during startup - * (e.g., error messages). + * Set up locale information from environment. Note that CTYPE and + * COLLATE will be overridden later from pg_control if we are in an + * already-initialized database. We set them here so that they will + * be available to fill pg_control during initdb. The other ones will + * get reset later in InitializeGUCOptions, but we set them here to + * get already localized behavior during startup (e.g., error + * messages). */ setlocale(LC_COLLATE, ""); setlocale(LC_CTYPE, ""); #ifdef LC_MESSAGES setlocale(LC_MESSAGES, ""); #endif - /* We don't use these during startup. See also pg_locale.c about - * why these are set to "C". */ + + /* + * We don't use these during startup. See also pg_locale.c about why + * these are set to "C". + */ setlocale(LC_MONETARY, "C"); setlocale(LC_NUMERIC, "C"); setlocale(LC_TIME, "C"); diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 8a69af3de5..2964085e0a 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.210 2002/09/02 02:13:01 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.211 2002/09/04 20:31:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1518,7 +1518,7 @@ _copyAExpr(A_Expr *from) static ColumnRef * _copyColumnRef(ColumnRef *from) { - ColumnRef *newnode = makeNode(ColumnRef); + ColumnRef *newnode = makeNode(ColumnRef); Node_Copy(from, newnode, fields); Node_Copy(from, newnode, indirection); @@ -1529,7 +1529,7 @@ _copyColumnRef(ColumnRef *from) static ParamRef * _copyParamRef(ParamRef *from) { - ParamRef *newnode = makeNode(ParamRef); + ParamRef *newnode = makeNode(ParamRef); newnode->number = from->number; Node_Copy(from, newnode, fields); @@ -1595,7 +1595,7 @@ _copyAIndices(A_Indices *from) static ExprFieldSelect * _copyExprFieldSelect(ExprFieldSelect *from) { - ExprFieldSelect *newnode = makeNode(ExprFieldSelect); + ExprFieldSelect *newnode = makeNode(ExprFieldSelect); Node_Copy(from, newnode, arg); Node_Copy(from, newnode, fields); @@ -1688,7 +1688,7 @@ _copyRangeSubselect(RangeSubselect *from) static RangeFunction * _copyRangeFunction(RangeFunction *from) { - RangeFunction *newnode = makeNode(RangeFunction); + RangeFunction *newnode = makeNode(RangeFunction); Node_Copy(from, newnode, funccallnode); Node_Copy(from, newnode, alias); @@ -2223,7 +2223,7 @@ _copyTransactionStmt(TransactionStmt *from) static CompositeTypeStmt * _copyCompositeTypeStmt(CompositeTypeStmt *from) { - CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt); + CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt); Node_Copy(from, newnode, typevar); Node_Copy(from, newnode, coldeflist); diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index ee716a5a84..8363fccfa6 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.33 2002/06/20 20:29:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.34 2002/09/04 20:31:19 momjian Exp $ */ #include "postgres.h" @@ -233,7 +233,7 @@ makeRelabelType(Node *arg, Oid rtype, int32 rtypmod) RangeVar * makeRangeVar(char *schemaname, char *relname) { - RangeVar *r = makeNode(RangeVar); + RangeVar *r = makeNode(RangeVar); r->catalogname = NULL; r->schemaname = schemaname; diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 8c25505806..8873c4e3d2 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -5,7 +5,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.172 2002/08/31 22:10:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.173 2002/09/04 20:31:19 momjian Exp $ * * NOTES * Every (plan) node in POSTGRES has an associated "out" routine which @@ -232,10 +232,10 @@ _outQuery(StringInfo str, Query *node) /* * Hack to work around missing outfuncs routines for a lot of the - * utility-statement node types. (The only one we actually *need* - * for rules support is NotifyStmt.) Someday we ought to support - * 'em all, but for the meantime do this to avoid getting lots of - * warnings when running with debug_print_parse on. + * utility-statement node types. (The only one we actually *need* for + * rules support is NotifyStmt.) Someday we ought to support 'em all, + * but for the meantime do this to avoid getting lots of warnings when + * running with debug_print_parse on. */ if (node->utilityStmt) { @@ -832,13 +832,13 @@ static void _outArrayRef(StringInfo str, ArrayRef *node) { appendStringInfo(str, - " ARRAYREF :refrestype %u :refattrlength %d :refelemlength %d ", + " ARRAYREF :refrestype %u :refattrlength %d :refelemlength %d ", node->refrestype, node->refattrlength, node->refelemlength); appendStringInfo(str, - ":refelembyval %s :refelemalign %c :refupperindexpr ", + ":refelembyval %s :refelemalign %c :refupperindexpr ", booltostr(node->refelembyval), node->refelemalign); _outNode(str, node->refupperindexpr); @@ -860,7 +860,7 @@ static void _outFunc(StringInfo str, Func *node) { appendStringInfo(str, - " FUNC :funcid %u :funcresulttype %u :funcretset %s ", + " FUNC :funcid %u :funcresulttype %u :funcretset %s ", node->funcid, node->funcresulttype, booltostr(node->funcretset)); @@ -873,7 +873,7 @@ static void _outOper(StringInfo str, Oper *node) { appendStringInfo(str, - " OPER :opno %u :opid %u :opresulttype %u :opretset %s ", + " OPER :opno %u :opid %u :opresulttype %u :opretset %s ", node->opno, node->opid, node->opresulttype, @@ -1324,6 +1324,7 @@ static void _outRangeVar(StringInfo str, RangeVar *node) { appendStringInfo(str, " RANGEVAR :relation "); + /* * we deliberately ignore catalogname here, since it is presently not * semantically meaningful @@ -1332,8 +1333,8 @@ _outRangeVar(StringInfo str, RangeVar *node) appendStringInfo(str, " . "); _outToken(str, node->relname); appendStringInfo(str, " :inhopt %d :istemp %s", - (int) node->inhOpt, - booltostr(node->istemp)); + (int) node->inhOpt, + booltostr(node->istemp)); appendStringInfo(str, " :alias "); _outNode(str, node->alias); } diff --git a/src/backend/nodes/print.c b/src/backend/nodes/print.c index 4e81ed14f2..e8afda6b20 100644 --- a/src/backend/nodes/print.c +++ b/src/backend/nodes/print.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.56 2002/06/20 20:29:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.57 2002/09/04 20:31:20 momjian Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -97,7 +97,7 @@ char * format_node_dump(const char *dump) { #define LINELEN 78 - char line[LINELEN+1]; + char line[LINELEN + 1]; StringInfoData str; int i; int j; @@ -118,13 +118,13 @@ format_node_dump(const char *dump) } else { - for (k = j-1; k > 0; k--) + for (k = j - 1; k > 0; k--) if (line[k] == ' ') break; if (k > 0) { /* back up; will reprint all after space */ - i -= (j-k-1); + i -= (j - k - 1); j = k; } } @@ -153,7 +153,7 @@ pretty_format_node_dump(const char *dump) #define INDENTSTOP 3 #define MAXINDENT 60 #define LINELEN 78 - char line[LINELEN+1]; + char line[LINELEN + 1]; StringInfoData str; int indentLev; int indentDist; @@ -182,7 +182,7 @@ pretty_format_node_dump(const char *dump) } /* print the } at indentDist */ line[indentDist] = '}'; - line[indentDist+1] = '\0'; + line[indentDist + 1] = '\0'; appendStringInfo(&str, "%s\n", line); /* outdent */ if (indentLev > 0) diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 4d4001d213..14edd8e3d1 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.131 2002/08/31 22:10:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.132 2002/09/04 20:31:20 momjian Exp $ * * NOTES * Most of the read functions for plan nodes are tested. (In fact, they @@ -1459,7 +1459,8 @@ _readRangeVar(void) local_node = makeNode(RangeVar); - local_node->catalogname = NULL; /* not currently saved in output format */ + local_node->catalogname = NULL; /* not currently saved in output + * format */ token = pg_strtok(&length); /* eat :relation */ token = pg_strtok(&length); /* get schemaname */ @@ -1468,11 +1469,11 @@ _readRangeVar(void) token = pg_strtok(&length); /* eat "." */ token = pg_strtok(&length); /* get relname */ local_node->relname = nullable_string(token, length); - + token = pg_strtok(&length); /* eat :inhopt */ token = pg_strtok(&length); /* get inhopt */ local_node->inhOpt = (InhOption) atoi(token); - + token = pg_strtok(&length); /* eat :istemp */ token = pg_strtok(&length); /* get istemp */ local_node->istemp = strtobool(token); @@ -1493,10 +1494,10 @@ _readColumnRef(void) local_node = makeNode(ColumnRef); token = pg_strtok(&length); /* eat :fields */ - local_node->fields = nodeRead(true); /* now read it */ + local_node->fields = nodeRead(true); /* now read it */ token = pg_strtok(&length); /* eat :indirection */ - local_node->indirection = nodeRead(true); /* now read it */ + local_node->indirection = nodeRead(true); /* now read it */ return local_node; } @@ -1515,7 +1516,7 @@ _readColumnDef(void) local_node->colname = nullable_string(token, length); token = pg_strtok(&length); /* eat :typename */ - local_node->typename = nodeRead(true); /* now read it */ + local_node->typename = nodeRead(true); /* now read it */ token = pg_strtok(&length); /* eat :is_inherited */ token = pg_strtok(&length); /* get :is_inherited */ @@ -1526,7 +1527,7 @@ _readColumnDef(void) local_node->is_not_null = strtobool(token); token = pg_strtok(&length); /* eat :raw_default */ - local_node->raw_default = nodeRead(true); /* now read it */ + local_node->raw_default = nodeRead(true); /* now read it */ token = pg_strtok(&length); /* eat :cooked_default */ token = pg_strtok(&length); /* now read it */ @@ -1536,7 +1537,7 @@ _readColumnDef(void) local_node->constraints = nodeRead(true); /* now read it */ token = pg_strtok(&length); /* eat :support */ - local_node->support = nodeRead(true); /* now read it */ + local_node->support = nodeRead(true); /* now read it */ return local_node; } @@ -1544,7 +1545,7 @@ _readColumnDef(void) static TypeName * _readTypeName(void) { - TypeName *local_node; + TypeName *local_node; char *token; int length; @@ -1574,7 +1575,7 @@ _readTypeName(void) local_node->typmod = atoi(token); token = pg_strtok(&length); /* eat :arrayBounds */ - local_node->arrayBounds = nodeRead(true); /* now read it */ + local_node->arrayBounds = nodeRead(true); /* now read it */ return local_node; } @@ -1582,20 +1583,20 @@ _readTypeName(void) static ExprFieldSelect * _readExprFieldSelect(void) { - ExprFieldSelect *local_node; + ExprFieldSelect *local_node; char *token; int length; local_node = makeNode(ExprFieldSelect); token = pg_strtok(&length); /* eat :arg */ - local_node->arg = nodeRead(true); /* now read it */ + local_node->arg = nodeRead(true); /* now read it */ token = pg_strtok(&length); /* eat :fields */ - local_node->fields = nodeRead(true); /* now read it */ + local_node->fields = nodeRead(true); /* now read it */ token = pg_strtok(&length); /* eat :indirection */ - local_node->indirection = nodeRead(true); /* now read it */ + local_node->indirection = nodeRead(true); /* now read it */ return local_node; } @@ -1614,7 +1615,7 @@ _readAlias(void) local_node->aliasname = debackslash(token, length); token = pg_strtok(&length); /* eat :colnames */ - local_node->colnames = nodeRead(true); /* now read it */ + local_node->colnames = nodeRead(true); /* now read it */ return local_node; } @@ -1671,7 +1672,7 @@ _readRangeTblEntry(void) local_node->jointype = (JoinType) atoi(token); token = pg_strtok(&length); /* eat :joinaliasvars */ - local_node->joinaliasvars = nodeRead(true); /* now read it */ + local_node->joinaliasvars = nodeRead(true); /* now read it */ break; default: diff --git a/src/backend/optimizer/geqo/geqo_misc.c b/src/backend/optimizer/geqo/geqo_misc.c index 6ffc02b1c5..ef7b489f59 100644 --- a/src/backend/optimizer/geqo/geqo_misc.c +++ b/src/backend/optimizer/geqo/geqo_misc.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: geqo_misc.c,v 1.33 2002/07/20 04:59:10 momjian Exp $ + * $Id: geqo_misc.c,v 1.34 2002/09/04 20:31:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -250,4 +250,4 @@ geqo_print_rel(Query *root, RelOptInfo *rel) geqo_print_path(root, rel->cheapest_total_path, 1); } -#endif /* GEQO_DEBUG */ +#endif /* GEQO_DEBUG */ diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index c1ee656b51..7d8d6a6beb 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.87 2002/08/29 16:03:48 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.88 2002/09/04 20:31:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,14 +43,14 @@ static void set_inherited_rel_pathlist(Query *root, RelOptInfo *rel, static void set_subquery_pathlist(Query *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte); static void set_function_pathlist(Query *root, RelOptInfo *rel, - RangeTblEntry *rte); + RangeTblEntry *rte); static RelOptInfo *make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels); static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery); static bool recurse_pushdown_safe(Node *setOp, Query *topquery); static void subquery_push_qual(Query *subquery, Index rti, Node *qual); static void recurse_push_qual(Node *setOp, Query *topquery, - Index rti, Node *qual); + Index rti, Node *qual); /* @@ -304,9 +304,10 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel, * * There are several cases where we cannot push down clauses. * Restrictions involving the subquery are checked by - * subquery_is_pushdown_safe(). Also, we do not push down clauses that - * contain subselects, mainly because I'm not sure it will work correctly - * (the subplan hasn't yet transformed sublinks to subselects). + * subquery_is_pushdown_safe(). Also, we do not push down clauses + * that contain subselects, mainly because I'm not sure it will work + * correctly (the subplan hasn't yet transformed sublinks to + * subselects). * * Non-pushed-down clauses will get evaluated as qpquals of the * SubqueryScan node. @@ -542,7 +543,7 @@ make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels) * quals into it, because that would change the results. For subqueries * using UNION/UNION ALL/INTERSECT/INTERSECT ALL, we can push the quals * into each component query, so long as all the component queries share - * identical output types. (That restriction could probably be relaxed, + * identical output types. (That restriction could probably be relaxed, * but it would take much more code to include type coercion code into * the quals, and I'm also concerned about possible semantic gotchas.) */ @@ -633,14 +634,14 @@ subquery_push_qual(Query *subquery, Index rti, Node *qual) else { /* - * We need to replace Vars in the qual (which must refer - * to outputs of the subquery) with copies of the - * subquery's targetlist expressions. Note that at this - * point, any uplevel Vars in the qual should have been - * replaced with Params, so they need no work. + * We need to replace Vars in the qual (which must refer to + * outputs of the subquery) with copies of the subquery's + * targetlist expressions. Note that at this point, any uplevel + * Vars in the qual should have been replaced with Params, so they + * need no work. * - * This step also ensures that when we are pushing into a setop - * tree, each component query gets its own copy of the qual. + * This step also ensures that when we are pushing into a setop tree, + * each component query gets its own copy of the qual. */ qual = ResolveNew(qual, rti, 0, subquery->targetList, @@ -649,10 +650,9 @@ subquery_push_qual(Query *subquery, Index rti, Node *qual) qual); /* - * We need not change the subquery's hasAggs or - * hasSublinks flags, since we can't be pushing down any - * aggregates that weren't there before, and we don't push - * down subselects at all. + * We need not change the subquery's hasAggs or hasSublinks flags, + * since we can't be pushing down any aggregates that weren't + * there before, and we don't push down subselects at all. */ } } diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 11e18c3d0b..9f987a4395 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -42,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.89 2002/07/04 15:23:56 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.90 2002/09/04 20:31:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -408,8 +408,8 @@ cost_functionscan(Path *path, Query *root, RelOptInfo *baserel) /* * For now, estimate function's cost at one operator eval per function - * call. Someday we should revive the function cost estimate columns in - * pg_proc... + * call. Someday we should revive the function cost estimate columns + * in pg_proc... */ cpu_per_tuple = cpu_operator_cost; @@ -607,7 +607,7 @@ cost_mergejoin(Path *path, Query *root, double outer_rows, inner_rows; double ntuples; - Selectivity outerscansel, + Selectivity outerscansel, innerscansel; Path sort_path; /* dummy for result of cost_sort */ @@ -617,15 +617,15 @@ cost_mergejoin(Path *path, Query *root, /* * A merge join will stop as soon as it exhausts either input stream. * Estimate fraction of the left and right inputs that will actually - * need to be scanned. We use only the first (most significant) - * merge clause for this purpose. + * need to be scanned. We use only the first (most significant) merge + * clause for this purpose. * - * Since this calculation is somewhat expensive, and will be the same - * for all mergejoin paths associated with the merge clause, we cache - * the results in the RestrictInfo node. + * Since this calculation is somewhat expensive, and will be the same for + * all mergejoin paths associated with the merge clause, we cache the + * results in the RestrictInfo node. */ firstclause = (RestrictInfo *) lfirst(mergeclauses); - if (firstclause->left_mergescansel < 0) /* not computed yet? */ + if (firstclause->left_mergescansel < 0) /* not computed yet? */ mergejoinscansel(root, (Node *) firstclause->clause, &firstclause->left_mergescansel, &firstclause->right_mergescansel); @@ -697,10 +697,10 @@ cost_mergejoin(Path *path, Query *root, /* * The number of tuple comparisons needed depends drastically on the * number of equal keys in the two source relations, which we have no - * good way of estimating. (XXX could the MCV statistics help?) - * Somewhat arbitrarily, we charge one tuple - * comparison (one cpu_operator_cost) for each tuple in the two source - * relations. This is probably a lower bound. + * good way of estimating. (XXX could the MCV statistics help?) + * Somewhat arbitrarily, we charge one tuple comparison (one + * cpu_operator_cost) for each tuple in the two source relations. + * This is probably a lower bound. */ run_cost += cpu_operator_cost * (outer_rows + inner_rows); diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 3d9ec2eb23..5595e1aec9 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.121 2002/09/02 06:22:18 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.122 2002/09/04 20:31:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1332,7 +1332,7 @@ pred_test_simple_clause(Expr *predicate, Node *clause) test_oper = makeOper(test_op, /* opno */ InvalidOid, /* opid */ BOOLOID, /* opresulttype */ - false); /* opretset */ + false); /* opretset */ replace_opid(test_oper); test_expr = make_opclause(test_oper, (Var *) clause_const, @@ -1712,7 +1712,7 @@ match_special_index_operator(Expr *clause, Oid opclass, case OID_BYTEA_LIKE_OP: isIndexable = pattern_fixed_prefix(patt, Pattern_Type_Like, - &prefix, &rest) != Pattern_Prefix_None; + &prefix, &rest) != Pattern_Prefix_None; break; case OID_TEXT_ICLIKE_OP: @@ -1922,7 +1922,7 @@ expand_indexqual_conditions(List *indexquals) case OID_CIDR_SUBEQ_OP: resultquals = nconc(resultquals, network_prefix_quals(leftop, expr_op, - patt->constvalue)); + patt->constvalue)); break; default: diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c index f1e2acac81..8e73bd2f41 100644 --- a/src/backend/optimizer/path/joinpath.c +++ b/src/backend/optimizer/path/joinpath.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.70 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.71 2002/09/04 20:31:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -171,7 +171,7 @@ sort_inner_and_outer(Query *root, default: elog(ERROR, "sort_inner_and_outer: unexpected join type %d", (int) jointype); - useallclauses = false; /* keep compiler quiet */ + useallclauses = false; /* keep compiler quiet */ break; } diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 5e4aff3247..fc33d5296a 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.39 2002/06/20 20:29:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.40 2002/09/04 20:31:20 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -519,7 +519,7 @@ build_index_pathkeys(Query *root, funcnode->funcid = index->indproc; funcnode->funcresulttype = get_func_rettype(index->indproc); - funcnode->funcretset = false; /* can never be a set */ + funcnode->funcretset = false; /* can never be a set */ funcnode->func_fcache = NULL; while (*indexkeys != 0) @@ -769,22 +769,22 @@ find_mergeclauses_for_pathkeys(Query *root, /* * We can match a pathkey against either left or right side of any - * mergejoin clause. (We examine both sides since we aren't told if - * the given pathkeys are for inner or outer input path; no confusion - * is possible.) Furthermore, if there are multiple matching - * clauses, take them all. In plain inner-join scenarios we expect - * only one match, because redundant-mergeclause elimination will - * have removed any redundant mergeclauses from the input list. - * However, in outer-join scenarios there might be multiple matches. - * An example is + * mergejoin clause. (We examine both sides since we aren't told + * if the given pathkeys are for inner or outer input path; no + * confusion is possible.) Furthermore, if there are multiple + * matching clauses, take them all. In plain inner-join scenarios + * we expect only one match, because redundant-mergeclause + * elimination will have removed any redundant mergeclauses from + * the input list. However, in outer-join scenarios there might be + * multiple matches. An example is * - * select * from a full join b on - * a.v1 = b.v1 and a.v2 = b.v2 and a.v1 = b.v2; + * select * from a full join b on a.v1 = b.v1 and a.v2 = b.v2 and + * a.v1 = b.v2; * - * Given the pathkeys ((a.v1), (a.v2)) it is okay to return all - * three clauses (in the order a.v1=b.v1, a.v1=b.v2, a.v2=b.v2) - * and indeed we *must* do so or we will be unable to form a - * valid plan. + * Given the pathkeys ((a.v1), (a.v2)) it is okay to return all three + * clauses (in the order a.v1=b.v1, a.v1=b.v2, a.v2=b.v2) and + * indeed we *must* do so or we will be unable to form a valid + * plan. */ foreach(j, restrictinfos) { @@ -812,8 +812,8 @@ find_mergeclauses_for_pathkeys(Query *root, break; /* - * If we did find usable mergeclause(s) for this sort-key position, - * add them to result list. + * If we did find usable mergeclause(s) for this sort-key + * position, add them to result list. */ mergeclauses = nconc(mergeclauses, matched_restrictinfos); } diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 908d36bccc..da3568bbd7 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.117 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.118 2002/09/04 20:31:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -79,7 +79,7 @@ static IndexScan *make_indexscan(List *qptlist, List *qpqual, Index scanrelid, static TidScan *make_tidscan(List *qptlist, List *qpqual, Index scanrelid, List *tideval); static FunctionScan *make_functionscan(List *qptlist, List *qpqual, - Index scanrelid); + Index scanrelid); static NestLoop *make_nestloop(List *tlist, List *joinclauses, List *otherclauses, Plan *lefttree, Plan *righttree, @@ -206,8 +206,8 @@ create_scan_plan(Query *root, Path *best_path) case T_FunctionScan: plan = (Scan *) create_functionscan_plan(best_path, - tlist, - scan_clauses); + tlist, + scan_clauses); break; default: @@ -1346,8 +1346,8 @@ make_functionscan(List *qptlist, List *qpqual, Index scanrelid) { - FunctionScan *node = makeNode(FunctionScan); - Plan *plan = &node->scan.plan; + FunctionScan *node = makeNode(FunctionScan); + Plan *plan = &node->scan.plan; /* cost should be inserted by caller */ plan->state = (EState *) NULL; diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index 0187c21d29..e06282c126 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.74 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.75 2002/09/04 20:31:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -108,12 +108,15 @@ add_base_rels_to_query(Query *root, Node *jtnode) add_base_rels_to_query(root, j->rarg)); /* the join's own rtindex is NOT added to result */ jrel = build_other_rel(root, j->rtindex); + /* - * Mark the join's otherrel with outerjoinset = list of baserel ids - * included in the join. Note we must copy here because result list - * is destructively modified by nconcs at higher levels. + * Mark the join's otherrel with outerjoinset = list of baserel + * ids included in the join. Note we must copy here because + * result list is destructively modified by nconcs at higher + * levels. */ jrel->outerjoinset = listCopy(result); + /* * Safety check: join RTEs should not be SELECT FOR UPDATE targets */ @@ -172,8 +175,8 @@ add_vars_to_targetlist(Query *root, List *vars) if (rel->reloptkind == RELOPT_OTHER_JOIN_REL) { /* Var is an alias */ - Node *expansion; - List *varsused; + Node *expansion; + List *varsused; expansion = flatten_join_alias_vars((Node *) var, root->rtable, true); @@ -196,7 +199,7 @@ add_vars_to_targetlist(Query *root, List *vars) * distribute_quals_to_rels * Recursively scan the query's join tree for WHERE and JOIN/ON qual * clauses, and add these to the appropriate RestrictInfo and JoinInfo - * lists belonging to base RelOptInfos. Also, base RelOptInfos are marked + * lists belonging to base RelOptInfos. Also, base RelOptInfos are marked * with outerjoinset information, to aid in proper positioning of qual * clauses that appear above outer joins. * @@ -400,7 +403,8 @@ distribute_qual_to_rels(Query *root, Node *clause, restrictinfo->right_sortop = InvalidOid; restrictinfo->left_pathkey = NIL; /* not computable yet */ restrictinfo->right_pathkey = NIL; - restrictinfo->left_mergescansel = -1; /* not computed until needed */ + restrictinfo->left_mergescansel = -1; /* not computed until + * needed */ restrictinfo->right_mergescansel = -1; restrictinfo->hashjoinoperator = InvalidOid; restrictinfo->left_bucketsize = -1; /* not computed until needed */ @@ -419,7 +423,7 @@ distribute_qual_to_rels(Query *root, Node *clause, * earlier by add_base_rels_to_query. * * We can combine this step with a cross-check that the clause contains - * no relids not within its scope. If the first crosscheck succeeds, + * no relids not within its scope. If the first crosscheck succeeds, * the clause contains no aliases and we needn't look more closely. */ if (!is_subseti(relids, qualscope)) @@ -763,10 +767,10 @@ process_implied_equality(Query *root, Node *item1, Node *item2, clause = makeNode(Expr); clause->typeOid = BOOLOID; clause->opType = OP_EXPR; - clause->oper = (Node *) makeOper(oprid(eq_operator),/* opno */ + clause->oper = (Node *) makeOper(oprid(eq_operator), /* opno */ InvalidOid, /* opid */ - BOOLOID, /* opresulttype */ - false); /* opretset */ + BOOLOID, /* opresulttype */ + false); /* opretset */ clause->args = makeList2(item1, item2); ReleaseSysCache(eq_operator); diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index b55f8380d4..5510a74957 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.123 2002/08/28 20:46:23 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.124 2002/09/04 20:31:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -42,7 +42,7 @@ static Node *pull_up_subqueries(Query *parse, Node *jtnode, - bool below_outer_join); + bool below_outer_join); static bool is_simple_subquery(Query *subquery); static bool has_nullable_targetlist(Query *subquery); static void resolvenew_in_jointree(Node *jtnode, int varno, List *subtlist); @@ -301,16 +301,16 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) * * If we are inside an outer join, only pull up subqueries whose * targetlists are nullable --- otherwise substituting their tlist - * entries for upper Var references would do the wrong thing - * (the results wouldn't become NULL when they're supposed to). - * XXX This could be improved by generating pseudo-variables for - * such expressions; we'd have to figure out how to get the pseudo- - * variables evaluated at the right place in the modified plan tree. - * Fix it someday. + * entries for upper Var references would do the wrong thing (the + * results wouldn't become NULL when they're supposed to). XXX + * This could be improved by generating pseudo-variables for such + * expressions; we'd have to figure out how to get the pseudo- + * variables evaluated at the right place in the modified plan + * tree. Fix it someday. * * Note: even if the subquery itself is simple enough, we can't pull - * it up if there is a reference to its whole tuple result. Perhaps - * a pseudo-variable is the answer here too. + * it up if there is a reference to its whole tuple result. + * Perhaps a pseudo-variable is the answer here too. */ if (rte->rtekind == RTE_SUBQUERY && is_simple_subquery(subquery) && (!below_outer_join || has_nullable_targetlist(subquery)) && @@ -336,8 +336,8 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) below_outer_join); /* - * Now make a modifiable copy of the subquery that we can - * run OffsetVarNodes on. + * Now make a modifiable copy of the subquery that we can run + * OffsetVarNodes on. */ subquery = copyObject(subquery); @@ -352,7 +352,8 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) * Replace all of the top query's references to the subquery's * outputs with copies of the adjusted subtlist items, being * careful not to replace any of the jointree structure. - * (This'd be a lot cleaner if we could use query_tree_mutator.) + * (This'd be a lot cleaner if we could use + * query_tree_mutator.) */ subtlist = subquery->targetList; parse->targetList = (List *) @@ -375,15 +376,16 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) } /* - * Now append the adjusted rtable entries to upper query. - * (We hold off until after fixing the upper rtable entries; - * no point in running that code on the subquery ones too.) + * Now append the adjusted rtable entries to upper query. (We + * hold off until after fixing the upper rtable entries; no + * point in running that code on the subquery ones too.) */ parse->rtable = nconc(parse->rtable, subquery->rtable); /* * Pull up any FOR UPDATE markers, too. (OffsetVarNodes - * already adjusted the marker values, so just nconc the list.) + * already adjusted the marker values, so just nconc the + * list.) */ parse->rowMarks = nconc(parse->rowMarks, subquery->rowMarks); @@ -500,9 +502,9 @@ is_simple_subquery(Query *subquery) /* * Don't pull up a subquery that has any set-returning functions in - * its targetlist. Otherwise we might well wind up inserting - * set-returning functions into places where they mustn't go, - * such as quals of higher queries. + * its targetlist. Otherwise we might well wind up inserting + * set-returning functions into places where they mustn't go, such as + * quals of higher queries. */ if (expression_returns_set((Node *) subquery->targetList)) return false; @@ -724,8 +726,8 @@ preprocess_expression(Query *parse, Node *expr, int kind) /* * If the query has any join RTEs, try to replace join alias variables - * with base-relation variables, to allow quals to be pushed down. - * We must do this after sublink processing, since it does not recurse + * with base-relation variables, to allow quals to be pushed down. We + * must do this after sublink processing, since it does not recurse * into sublinks. * * The flattening pass is expensive enough that it seems worthwhile to diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index b685cfa3ba..66998b036f 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.80 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.81 2002/09/04 20:31:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -423,7 +423,7 @@ join_references_mutator(Node *node, resdom = tlist_member((Node *) var, context->outer_tlist); if (resdom) { - Var *newvar = (Var *) copyObject(var); + Var *newvar = (Var *) copyObject(var); newvar->varno = OUTER; newvar->varattno = resdom->resno; @@ -432,7 +432,7 @@ join_references_mutator(Node *node, resdom = tlist_member((Node *) var, context->inner_tlist); if (resdom) { - Var *newvar = (Var *) copyObject(var); + Var *newvar = (Var *) copyObject(var); newvar->varno = INNER; newvar->varattno = resdom->resno; diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index c1ab186b01..1dcebba2e7 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.54 2002/06/20 20:29:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.55 2002/09/04 20:31:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -369,7 +369,7 @@ make_subplan(SubLink *slink) } if (use_material) { - Plan *matplan; + Plan *matplan; matplan = (Plan *) make_material(plan->targetlist, plan); /* kluge --- see comments above */ @@ -663,8 +663,8 @@ SS_finalize_plan(Plan *plan, List *rtable) case T_Append: foreach(lst, ((Append *) plan)->appendplans) results.paramids = set_unioni(results.paramids, - SS_finalize_plan((Plan *) lfirst(lst), - rtable)); + SS_finalize_plan((Plan *) lfirst(lst), + rtable)); break; case T_NestLoop: diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 41f9b2f947..5b930e2b5e 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.55 2002/08/31 22:10:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.56 2002/09/04 20:31:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -128,7 +128,8 @@ expand_targetlist(List *tlist, int command_type, /* * The rewriter should have already ensured that the TLEs are in - * correct order; but we have to insert TLEs for any missing attributes. + * correct order; but we have to insert TLEs for any missing + * attributes. * * Scan the tuple description in the relation's relcache entry to make * sure we have all the user attributes in the right order. @@ -161,14 +162,14 @@ expand_targetlist(List *tlist, int command_type, /* * Didn't find a matching tlist entry, so make one. * - * For INSERT, generate a NULL constant. (We assume the - * rewriter would have inserted any available default value.) - * Also, if the column isn't dropped, apply any domain constraints - * that might exist --- this is to catch domain NOT NULL. + * For INSERT, generate a NULL constant. (We assume the rewriter + * would have inserted any available default value.) Also, if + * the column isn't dropped, apply any domain constraints that + * might exist --- this is to catch domain NOT NULL. * * For UPDATE, generate a Var reference to the existing value of - * the attribute, so that it gets copied to the new tuple. - * But generate a NULL for dropped columns (we want to drop any + * the attribute, so that it gets copied to the new tuple. But + * generate a NULL for dropped columns (we want to drop any * old values). */ Oid atttype = att_tup->atttypid; @@ -181,13 +182,13 @@ expand_targetlist(List *tlist, int command_type, new_expr = (Node *) makeConst(atttype, att_tup->attlen, (Datum) 0, - true, /* isnull */ + true, /* isnull */ att_tup->attbyval, - false, /* not a set */ + false, /* not a set */ false); if (!att_tup->attisdropped) new_expr = coerce_type_constraints(NULL, new_expr, - atttype, false); + atttype, false); break; case CMD_UPDATE: /* Insert NULLs for dropped columns */ @@ -215,7 +216,7 @@ expand_targetlist(List *tlist, int command_type, new_tle = makeTargetEntry(makeResdom(attrno, atttype, atttypmod, - pstrdup(NameStr(att_tup->attname)), + pstrdup(NameStr(att_tup->attname)), false), new_expr); } diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index 492492b9f7..fb4fd3e1d3 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.77 2002/09/02 02:47:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.78 2002/09/04 20:31:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -63,8 +63,8 @@ static List *generate_setop_tlist(List *colTypes, int flag, List *input_tlist, List *refnames_tlist); static List *generate_append_tlist(List *colTypes, bool flag, - List *input_plans, - List *refnames_tlist); + List *input_plans, + List *refnames_tlist); static Node *adjust_inherited_attrs_mutator(Node *node, adjust_inherited_attrs_context *context); @@ -172,8 +172,9 @@ recurse_set_operations(Node *setOp, Query *parse, * This would fail if the Vars generated by generate_setop_tlist() * were not exactly equal() to the corresponding tlist entries of * the subplan. However, since the subplan was generated by - * generate_union_plan() or generate_nonunion_plan(), and hence its - * tlist was generated by generate_append_tlist(), this will work. + * generate_union_plan() or generate_nonunion_plan(), and hence + * its tlist was generated by generate_append_tlist(), this will + * work. */ if (flag >= 0 || !tlist_same_datatypes(plan->targetlist, colTypes, junkOK)) @@ -485,15 +486,15 @@ generate_append_tlist(List *colTypes, bool flag, /* * First extract typmods to use. * - * If the inputs all agree on type and typmod of a particular column, - * use that typmod; else use -1. + * If the inputs all agree on type and typmod of a particular column, use + * that typmod; else use -1. */ colTypmods = (int32 *) palloc(length(colTypes) * sizeof(int32)); foreach(planl, input_plans) { - Plan *subplan = (Plan *) lfirst(planl); - List *subtlist; + Plan *subplan = (Plan *) lfirst(planl); + List *subtlist; curColType = colTypes; colindex = 0; @@ -796,8 +797,8 @@ adjust_inherited_attrs_mutator(Node *node, var->varno = context->new_rt_index; if (var->varattno > 0) { - char *attname = get_attname(context->old_relid, - var->varattno); + char *attname = get_attname(context->old_relid, + var->varattno); var->varattno = get_attnum(context->new_relid, attname); if (var->varattno == InvalidAttrNumber) @@ -819,10 +820,10 @@ adjust_inherited_attrs_mutator(Node *node, if (IsA(node, JoinExpr)) { /* Copy the JoinExpr node with correct mutation of subnodes */ - JoinExpr *j; + JoinExpr *j; j = (JoinExpr *) expression_tree_mutator(node, - adjust_inherited_attrs_mutator, + adjust_inherited_attrs_mutator, (void *) context); /* now fix JoinExpr's rtindex */ if (j->rtindex == context->old_rt_index) diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 3b5e698839..edf77faff0 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.107 2002/08/31 22:10:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.108 2002/09/04 20:31:22 momjian Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -43,7 +43,7 @@ typedef struct { Query *query; List *groupClauses; -} check_subplans_for_ungrouped_vars_context; +} check_subplans_for_ungrouped_vars_context; static bool contain_agg_clause_walker(Node *node, void *context); static bool pull_agg_clause_walker(Node *node, List **listptr); @@ -51,7 +51,7 @@ static bool expression_returns_set_walker(Node *node, void *context); static bool contain_subplans_walker(Node *node, void *context); static bool pull_subplans_walker(Node *node, List **listptr); static bool check_subplans_for_ungrouped_vars_walker(Node *node, - check_subplans_for_ungrouped_vars_context * context); + check_subplans_for_ungrouped_vars_context *context); static bool contain_mutable_functions_walker(Node *node, void *context); static bool contain_volatile_functions_walker(Node *node, void *context); static Node *eval_const_expressions_mutator(Node *node, void *context); @@ -479,7 +479,7 @@ expression_returns_set_walker(Node *node, void *context) return false; if (IsA(node, Expr)) { - Expr *expr = (Expr *) node; + Expr *expr = (Expr *) node; switch (expr->opType) { @@ -633,7 +633,7 @@ check_subplans_for_ungrouped_vars(Query *query) static bool check_subplans_for_ungrouped_vars_walker(Node *node, - check_subplans_for_ungrouped_vars_context * context) + check_subplans_for_ungrouped_vars_context *context) { List *gl; @@ -786,11 +786,11 @@ contain_mutable_functions_walker(Node *node, void *context) * Recursively search for volatile functions within a clause. * * Returns true if any volatile function (or operator implemented by a - * volatile function) is found. This test prevents invalid conversions + * volatile function) is found. This test prevents invalid conversions * of volatile expressions into indexscan quals. * * XXX we do not examine sublinks/subplans to see if they contain uses of - * volatile functions. It's not real clear if that is correct or not... + * volatile functions. It's not real clear if that is correct or not... */ bool contain_volatile_functions(Node *clause) @@ -837,7 +837,7 @@ contain_volatile_functions_walker(Node *node, void *context) * of the current query level and no uses of volatile functions. * Such a clause is not necessarily a true constant: it can still contain * Params and outer-level Vars, not to mention functions whose results - * may vary from one statement to the next. However, the clause's value + * may vary from one statement to the next. However, the clause's value * will be constant over any one scan of the current query, so it can be * used as an indexscan key or (if a top-level qual) can be pushed up to * become a gating qual. @@ -1143,7 +1143,7 @@ eval_const_expressions_mutator(Node *node, void *context) * expression_tree_mutator directly rather than recursing to self. */ args = (List *) expression_tree_mutator((Node *) expr->args, - eval_const_expressions_mutator, + eval_const_expressions_mutator, (void *) context); switch (expr->opType) @@ -1166,13 +1166,14 @@ eval_const_expressions_mutator(Node *node, void *context) break; case DISTINCT_EXPR: { - List *arg; - bool has_null_input = false; - bool all_null_input = true; - bool has_nonconst_input = false; + List *arg; + bool has_null_input = false; + bool all_null_input = true; + bool has_nonconst_input = false; /* - * Check for constant inputs and especially constant-NULL inputs. + * Check for constant inputs and especially + * constant-NULL inputs. */ Assert(length(args) == 2); foreach(arg, args) @@ -1183,9 +1184,7 @@ eval_const_expressions_mutator(Node *node, void *context) all_null_input &= ((Const *) lfirst(arg))->constisnull; } else - { has_nonconst_input = true; - } } /* all nulls? then not distinct */ if (all_null_input) @@ -1206,18 +1205,23 @@ eval_const_expressions_mutator(Node *node, void *context) bool const_is_null; Oper *oper = (Oper *) expr->oper; - replace_opid(oper); /* OK to scribble on input to this extent */ + + replace_opid(oper); /* OK to scribble on input + * to this extent */ result_typeid = oper->opresulttype; /* - * OK, looks like we can simplify this operator/function. + * OK, looks like we can simplify this + * operator/function. * - * We use the executor's routine ExecEvalExpr() to avoid duplication of - * code and ensure we get the same result as the executor would get. + * We use the executor's routine ExecEvalExpr() to + * avoid duplication of code and ensure we get the + * same result as the executor would get. * - * Build a new Expr node containing the already-simplified arguments. The - * only other setup needed here is the replace_opid() that we already - * did for the OP_EXPR case. + * Build a new Expr node containing the + * already-simplified arguments. The only other + * setup needed here is the replace_opid() that we + * already did for the OP_EXPR case. */ newexpr = makeNode(Expr); newexpr->typeOid = expr->typeOid; @@ -1229,17 +1233,22 @@ eval_const_expressions_mutator(Node *node, void *context) get_typlenbyval(result_typeid, &resultTypLen, &resultTypByVal); /* - * It is OK to pass a dummy econtext because none of the - * ExecEvalExpr() code used in this situation will use econtext. That - * might seem fortuitous, but it's not so unreasonable --- a constant - * expression does not depend on context, by definition, n'est ce pas? + * It is OK to pass a dummy econtext because none + * of the ExecEvalExpr() code used in this + * situation will use econtext. That might seem + * fortuitous, but it's not so unreasonable --- a + * constant expression does not depend on context, + * by definition, n'est ce pas? */ econtext = MakeExprContext(NULL, CurrentMemoryContext); const_val = ExecEvalExprSwitchContext((Node *) newexpr, econtext, - &const_is_null, NULL); + &const_is_null, NULL); - /* Must copy result out of sub-context used by expression eval */ + /* + * Must copy result out of sub-context used by + * expression eval + */ if (!const_is_null) const_val = datumCopy(const_val, resultTypByVal, resultTypLen); @@ -1250,8 +1259,8 @@ eval_const_expressions_mutator(Node *node, void *context) * Make the constant result node. */ return (Node *) makeConst(result_typeid, resultTypLen, - const_val, const_is_null, - resultTypByVal, false, false); + const_val, const_is_null, + resultTypByVal, false, false); } break; } @@ -1952,6 +1961,7 @@ expression_tree_walker(Node *node, return true; if (walker(join->quals, context)) return true; + /* * alias clause, using list are deemed uninteresting. */ diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index b9a91d1862..3aee668448 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.73 2002/06/20 20:29:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.74 2002/09/04 20:31:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -163,7 +163,7 @@ find_secondary_indexes(Oid relationObjectId) MemSet(info->ordering, 0, sizeof(Oid) * (INDEX_MAX_KEYS + 1)); if (amorderstrategy != 0) { - int oprindex = amorderstrategy - 1; + int oprindex = amorderstrategy - 1; for (i = 0; i < info->ncolumns; i++) { diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 978d9f0b30..49e2f1f0a2 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.38 2002/06/20 20:29:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.39 2002/09/04 20:31:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -157,16 +157,16 @@ make_base_rel(Query *root, int relid) switch (rte->rtekind) { case RTE_RELATION: - { - /* Table --- retrieve statistics from the system catalogs */ - bool indexed; - - get_relation_info(rte->relid, - &indexed, &rel->pages, &rel->tuples); - if (indexed) - rel->indexlist = find_secondary_indexes(rte->relid); - break; - } + { + /* Table --- retrieve statistics from the system catalogs */ + bool indexed; + + get_relation_info(rte->relid, + &indexed, &rel->pages, &rel->tuples); + if (indexed) + rel->indexlist = find_secondary_indexes(rte->relid); + break; + } case RTE_SUBQUERY: case RTE_FUNCTION: /* Subquery or function --- nothing to do here */ @@ -379,11 +379,11 @@ build_join_rel(Query *root, * of the outer and inner join relations and then merging the results * together. * - * XXX right now we don't remove any irrelevant elements, we just - * append the two tlists together. Someday consider pruning vars from the + * XXX right now we don't remove any irrelevant elements, we just append + * the two tlists together. Someday consider pruning vars from the * join's targetlist if they are needed only to evaluate restriction - * clauses of this join, and will never be accessed at higher levels of - * the plantree. + * clauses of this join, and will never be accessed at higher levels + * of the plantree. * * NOTE: the tlist order for a join rel will depend on which pair of * outer and inner rels we first try to build it from. But the @@ -396,12 +396,12 @@ build_join_rel(Query *root, /* * If there are any alias variables attached to the matching join RTE, - * attach them to the tlist too, so that they will be evaluated for use - * at higher plan levels. + * attach them to the tlist too, so that they will be evaluated for + * use at higher plan levels. */ if (joinrterel) { - List *jrtetl; + List *jrtetl; foreach(jrtetl, joinrterel->targetlist) { diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c index 776636ff59..ccccdbf180 100644 --- a/src/backend/optimizer/util/var.c +++ b/src/backend/optimizer/util/var.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.38 2002/06/20 20:29:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.39 2002/09/04 20:31:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,7 +53,7 @@ static bool contain_var_clause_walker(Node *node, void *context); static bool pull_var_clause_walker(Node *node, pull_var_clause_context *context); static Node *flatten_join_alias_vars_mutator(Node *node, - flatten_join_alias_vars_context *context); + flatten_join_alias_vars_context *context); /* @@ -317,7 +317,7 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context) * If force is TRUE then we will reduce all JOIN alias Vars to non-alias Vars * or expressions thereof (there may be COALESCE and/or type conversions * involved). If force is FALSE we will not expand a Var to a non-Var - * expression. This is a hack to avoid confusing mergejoin planning, which + * expression. This is a hack to avoid confusing mergejoin planning, which * currently cannot cope with non-Var join items --- we leave the join vars * as Vars till after planning is done, then expand them during setrefs.c. * @@ -346,9 +346,9 @@ flatten_join_alias_vars_mutator(Node *node, return NULL; if (IsA(node, Var)) { - Var *var = (Var *) node; + Var *var = (Var *) node; RangeTblEntry *rte; - Node *newvar; + Node *newvar; if (var->varlevelsup != 0) return node; /* no need to copy, really */ @@ -357,7 +357,7 @@ flatten_join_alias_vars_mutator(Node *node, return node; Assert(var->varattno > 0); newvar = (Node *) nth(var->varattno - 1, rte->joinaliasvars); - if (IsA(newvar, Var) || context->force) + if (IsA(newvar, Var) ||context->force) { /* expand it; recurse in case join input is itself a join */ return flatten_join_alias_vars_mutator(newvar, context); diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 9896011df3..97b242b9b6 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.247 2002/09/02 06:11:42 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.248 2002/09/04 20:31:22 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -54,7 +54,8 @@ typedef struct List *tables; /* CREATE TABLE items */ List *views; /* CREATE VIEW items */ List *grants; /* GRANT items */ - List *fwconstraints; /* Forward referencing FOREIGN KEY constraints */ + List *fwconstraints; /* Forward referencing FOREIGN KEY + * constraints */ List *alters; /* Generated ALTER items (from the above) */ List *ixconstraints; /* index-creating constraints */ List *blist; /* "before list" of things to do before @@ -84,13 +85,13 @@ typedef struct static Query *transformStmt(ParseState *pstate, Node *stmt, - List **extras_before, List **extras_after); + List **extras_before, List **extras_after); static Query *transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt); static Query *transformInsertStmt(ParseState *pstate, InsertStmt *stmt, - List **extras_before, List **extras_after); + List **extras_before, List **extras_after); static Query *transformIndexStmt(ParseState *pstate, IndexStmt *stmt); static Query *transformRuleStmt(ParseState *query, RuleStmt *stmt, - List **extras_before, List **extras_after); + List **extras_before, List **extras_after); static Query *transformSelectStmt(ParseState *pstate, SelectStmt *stmt); static Query *transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt); static Node *transformSetOperationTree(ParseState *pstate, SelectStmt *stmt); @@ -98,7 +99,7 @@ static Query *transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt); static Query *transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt); static Query *transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt); static Query *transformCreateStmt(ParseState *pstate, CreateStmt *stmt, - List **extras_before, List **extras_after); + List **extras_before, List **extras_after); static Query *transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt, List **extras_before, List **extras_after); static void transformColumnDefinition(ParseState *pstate, @@ -139,6 +140,7 @@ parse_analyze(Node *parseTree, ParseState *parentParseState) { List *result = NIL; ParseState *pstate = make_parsestate(parentParseState); + /* Lists to return extra commands from transformation */ List *extras_before = NIL; List *extras_after = NIL; @@ -163,13 +165,13 @@ parse_analyze(Node *parseTree, ParseState *parentParseState) } /* - * Make sure that only the original query is marked original. - * We have to do this explicitly since recursive calls of parse_analyze - * will have set originalQuery in some of the added-on queries. + * Make sure that only the original query is marked original. We have + * to do this explicitly since recursive calls of parse_analyze will + * have set originalQuery in some of the added-on queries. */ foreach(listscan, result) { - Query *q = lfirst(listscan); + Query *q = lfirst(listscan); q->originalQuery = (q == query); } @@ -194,7 +196,7 @@ release_pstate_resources(ParseState *pstate) */ static Query * transformStmt(ParseState *pstate, Node *parseTree, - List **extras_before, List **extras_after) + List **extras_before, List **extras_after) { Query *result = NULL; @@ -205,7 +207,7 @@ transformStmt(ParseState *pstate, Node *parseTree, */ case T_CreateStmt: result = transformCreateStmt(pstate, (CreateStmt *) parseTree, - extras_before, extras_after); + extras_before, extras_after); break; case T_IndexStmt: @@ -214,7 +216,7 @@ transformStmt(ParseState *pstate, Node *parseTree, case T_RuleStmt: result = transformRuleStmt(pstate, (RuleStmt *) parseTree, - extras_before, extras_after); + extras_before, extras_after); break; case T_ViewStmt: @@ -222,7 +224,7 @@ transformStmt(ParseState *pstate, Node *parseTree, ViewStmt *n = (ViewStmt *) parseTree; n->query = transformStmt(pstate, (Node *) n->query, - extras_before, extras_after); + extras_before, extras_after); /* * If a list of column names was given, run through and @@ -270,14 +272,14 @@ transformStmt(ParseState *pstate, Node *parseTree, result = makeNode(Query); result->commandType = CMD_UTILITY; n->query = transformStmt(pstate, (Node *) n->query, - extras_before, extras_after); + extras_before, extras_after); result->utilityStmt = (Node *) parseTree; } break; case T_AlterTableStmt: result = transformAlterTableStmt(pstate, (AlterTableStmt *) parseTree, - extras_before, extras_after); + extras_before, extras_after); break; case T_PrepareStmt: @@ -293,7 +295,7 @@ transformStmt(ParseState *pstate, Node *parseTree, */ case T_InsertStmt: result = transformInsertStmt(pstate, (InsertStmt *) parseTree, - extras_before, extras_after); + extras_before, extras_after); break; case T_DeleteStmt: @@ -341,7 +343,7 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt) /* set up range table with just the result rel */ qry->resultRelation = setTargetTable(pstate, stmt->relation, - interpretInhOption(stmt->relation->inhOpt), + interpretInhOption(stmt->relation->inhOpt), true); qry->distinctClause = NIL; @@ -434,10 +436,11 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt, /* * Note: we are not expecting that extras_before and extras_after - * are going to be used by the transformation of the SELECT statement. + * are going to be used by the transformation of the SELECT + * statement. */ selectQuery = transformStmt(sub_pstate, stmt->selectStmt, - extras_before, extras_after); + extras_before, extras_after); release_pstate_resources(sub_pstate); pfree(sub_pstate); @@ -525,7 +528,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt, foreach(tl, qry->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(tl); - ResTarget *col; + ResTarget *col; if (icolumns == NIL || attnos == NIL) elog(ERROR, "INSERT has more expressions than target columns"); @@ -541,7 +544,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt, Assert(IsA(col, ResTarget)); Assert(!tle->resdom->resjunk); updateTargetListEntry(pstate, tle, col->name, lfirsti(attnos), - col->indirection); + col->indirection); } else { @@ -555,9 +558,9 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt, } /* - * Ensure that the targetlist has the same number of entries - * that were present in the columns list. Don't do the check - * for select statements. + * Ensure that the targetlist has the same number of entries that + * were present in the columns list. Don't do the check for select + * statements. */ if (stmt->cols != NIL && (icolumns != NIL || attnos != NIL)) elog(ERROR, "INSERT has more target columns than expressions"); @@ -780,8 +783,8 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt, q->utilityStmt = (Node *) stmt; stmt->tableElts = cxt.columns; stmt->constraints = cxt.ckconstraints; - *extras_before = nconc (*extras_before, cxt.blist); - *extras_after = nconc (cxt.alist, *extras_after); + *extras_before = nconc(*extras_before, cxt.blist); + *extras_after = nconc(cxt.alist, *extras_after); return q; } @@ -839,7 +842,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, snamespace = get_namespace_name(RangeVarGetCreationNamespace(cxt->relation)); elog(NOTICE, "%s will create implicit sequence '%s' for SERIAL column '%s.%s'", - cxt->stmtType, sname, cxt->relation->relname, column->colname); + cxt->stmtType, sname, cxt->relation->relname, column->colname); /* * Build a CREATE SEQUENCE command to create the sequence object, @@ -1213,9 +1216,10 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) /* * Scan the index list and remove any redundant index specifications. - * This can happen if, for instance, the user writes UNIQUE PRIMARY KEY. - * A strict reading of SQL92 would suggest raising an error instead, - * but that strikes me as too anal-retentive. - tgl 2001-02-14 + * This can happen if, for instance, the user writes UNIQUE PRIMARY + * KEY. A strict reading of SQL92 would suggest raising an error + * instead, but that strikes me as too anal-retentive. - tgl + * 2001-02-14 * * XXX in ALTER TABLE case, it'd be nice to look for duplicate * pre-existing indexes, too. @@ -1279,7 +1283,7 @@ transformIndexConstraints(ParseState *pstate, CreateStmtContext *cxt) iparam = lfirst(index->indexParams); index->idxname = CreateIndexName(cxt->relation->relname, iparam->name ? iparam->name : - strVal(llast(iparam->funcname)), + strVal(llast(iparam->funcname)), "key", cxt->alist); } if (index->idxname == NULL) /* should not happen */ @@ -1352,7 +1356,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) IndexElem *ielem = lfirst(attr); char *iname = ielem->name; - Assert(iname); /* no func index here */ + Assert(iname); /* no func index here */ fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs, makeString(iname)); if (attnum >= INDEX_MAX_KEYS) @@ -1417,7 +1421,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) elog(ERROR, "Can only have %d keys in a foreign key", INDEX_MAX_KEYS); pktypoid[attnum++] = transformFkeyGetColType(cxt, - pkattr); + pkattr); } if (found) break; @@ -1444,8 +1448,8 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) * fktypoid[i] is the foreign key table's i'th element's type * pktypoid[i] is the primary key table's i'th element's type * - * We let oper() do our work for us, including elog(ERROR) if - * the types don't compare with = + * We let oper() do our work for us, including elog(ERROR) if the + * types don't compare with = */ Operator o = oper(makeList1(makeString("=")), fktypoid[i], pktypoid[i], false); @@ -1462,7 +1466,7 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt) { AlterTableStmt *alterstmt = makeNode(AlterTableStmt); - alterstmt->subtype = 'c'; /* preprocessed add constraint */ + alterstmt->subtype = 'c'; /* preprocessed add constraint */ alterstmt->relation = cxt->relation; alterstmt->name = NULL; alterstmt->def = (Node *) makeList1(fkconstraint); @@ -1528,7 +1532,7 @@ transformIndexStmt(ParseState *pstate, IndexStmt *stmt) */ static Query * transformRuleStmt(ParseState *pstate, RuleStmt *stmt, - List **extras_before, List **extras_after) + List **extras_before, List **extras_after) { Query *qry; RangeTblEntry *oldrte; @@ -1658,7 +1662,7 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt, /* Transform the rule action statement */ top_subqry = transformStmt(sub_pstate, action, - extras_before, extras_after); + extras_before, extras_after); /* * We cannot support utility-statement actions (eg NOTIFY) @@ -2015,8 +2019,8 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) } /* - * Any column names from CREATE TABLE AS need to be attached to both the - * top level and the leftmost subquery. We do not do this earlier + * Any column names from CREATE TABLE AS need to be attached to both + * the top level and the leftmost subquery. We do not do this earlier * because we do *not* want the targetnames list to be affected. */ if (intoColNames) @@ -2299,7 +2303,7 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt) pstate->p_is_update = true; qry->resultRelation = setTargetTable(pstate, stmt->relation, - interpretInhOption(stmt->relation->inhOpt), + interpretInhOption(stmt->relation->inhOpt), true); /* @@ -2445,6 +2449,7 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt, break; case 'c': + /* * Already-transformed ADD CONSTRAINT, so just make it look * like the standard case. @@ -2466,12 +2471,12 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt, static Query * transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt) { - Query *result = makeNode(Query); - List *extras_before = NIL, - *extras_after = NIL; - List *argtype_oids = NIL; /* argtype OIDs in a list */ - Oid *argtoids = NULL; /* as an array for parser_param_set */ - int nargs; + Query *result = makeNode(Query); + List *extras_before = NIL, + *extras_after = NIL; + List *argtype_oids = NIL; /* argtype OIDs in a list */ + Oid *argtoids = NULL; /* as an array for parser_param_set */ + int nargs; result->commandType = CMD_UTILITY; result->utilityStmt = (Node *) stmt; @@ -2481,15 +2486,15 @@ transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt) if (nargs) { - List *l; - int i = 0; + List *l; + int i = 0; argtoids = (Oid *) palloc(nargs * sizeof(Oid)); - foreach (l, stmt->argtypes) + foreach(l, stmt->argtypes) { - TypeName *tn = lfirst(l); - Oid toid = typenameTypeId(tn); + TypeName *tn = lfirst(l); + Oid toid = typenameTypeId(tn); argtype_oids = lappendi(argtype_oids, toid); argtoids[i++] = toid; @@ -2499,12 +2504,12 @@ transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt) stmt->argtype_oids = argtype_oids; /* - * We need to adjust the parameters expected by the - * rest of the system, so that $1, ... $n are parsed properly. + * We need to adjust the parameters expected by the rest of the + * system, so that $1, ... $n are parsed properly. * - * This is somewhat of a hack; however, the main parser interface - * only allows parameters to be specified when working with a - * raw query string, which is not helpful here. + * This is somewhat of a hack; however, the main parser interface only + * allows parameters to be specified when working with a raw query + * string, which is not helpful here. */ parser_param_set(argtoids, nargs); @@ -2524,8 +2529,8 @@ transformPrepareStmt(ParseState *pstate, PrepareStmt *stmt) static Query * transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt) { - Query *result = makeNode(Query); - List *paramtypes; + Query *result = makeNode(Query); + List *paramtypes; result->commandType = CMD_UTILITY; result->utilityStmt = (Node *) stmt; @@ -2534,20 +2539,20 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt) if (stmt->params || paramtypes) { - int nparams = length(stmt->params); - int nexpected = length(paramtypes); - List *l; - int i = 1; + int nparams = length(stmt->params); + int nexpected = length(paramtypes); + List *l; + int i = 1; if (nparams != nexpected) elog(ERROR, "Wrong number of parameters, expected %d but got %d", nexpected, nparams); - foreach (l, stmt->params) + foreach(l, stmt->params) { - Node *expr = lfirst(l); - Oid expected_type_id, - given_type_id; + Node *expr = lfirst(l); + Oid expected_type_id, + given_type_id; expr = transformExpr(pstate, expr); @@ -2571,7 +2576,7 @@ transformExecuteStmt(ParseState *pstate, ExecuteStmt *stmt) if (!expr) elog(ERROR, "Parameter $%d of type %s cannot be coerced into the expected type %s" - "\n\tYou will need to rewrite or cast the expression", + "\n\tYou will need to rewrite or cast the expression", i, format_type_be(given_type_id), format_type_be(expected_type_id)); @@ -2833,7 +2838,7 @@ transformFkeyGetPrimaryKey(FkConstraint *fkconstraint, Oid *pktypoid) pktypoid[attnum++] = attnumTypeId(pkrel, pkattno); fkconstraint->pk_attrs = lappend(fkconstraint->pk_attrs, - makeString(pstrdup(NameStr(*attnumAttName(pkrel, pkattno))))); + makeString(pstrdup(NameStr(*attnumAttName(pkrel, pkattno))))); } ReleaseSysCache(indexTuple); @@ -3145,8 +3150,8 @@ analyzeCreateSchemaStmt(CreateSchemaStmt *stmt) elp->relation->schemaname = cxt.schemaname; else if (strcmp(cxt.schemaname, elp->relation->schemaname) != 0) elog(ERROR, "New table specifies a schema (%s)" - " different from the one being created (%s)", - elp->relation->schemaname, cxt.schemaname); + " different from the one being created (%s)", + elp->relation->schemaname, cxt.schemaname); /* * XXX todo: deal with constraints @@ -3158,14 +3163,14 @@ analyzeCreateSchemaStmt(CreateSchemaStmt *stmt) case T_ViewStmt: { - ViewStmt *elp = (ViewStmt *) element; + ViewStmt *elp = (ViewStmt *) element; if (elp->view->schemaname == NULL) elp->view->schemaname = cxt.schemaname; else if (strcmp(cxt.schemaname, elp->view->schemaname) != 0) elog(ERROR, "New view specifies a schema (%s)" - " different from the one being created (%s)", - elp->view->schemaname, cxt.schemaname); + " different from the one being created (%s)", + elp->view->schemaname, cxt.schemaname); /* * XXX todo: deal with references between views diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 95f45a942a..a46ff5e2fc 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.96 2002/08/18 18:46:15 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.97 2002/09/04 20:31:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,8 +41,8 @@ static char *clauseText[] = {"ORDER BY", "GROUP BY", "DISTINCT ON"}; static void extractRemainingColumns(List *common_colnames, - List *src_colnames, List *src_colvars, - List **res_colnames, List **res_colvars); + List *src_colnames, List *src_colvars, + List **res_colnames, List **res_colvars); static Node *transformJoinUsingClause(ParseState *pstate, List *leftVars, List *rightVars); static Node *transformJoinOnClause(ParseState *pstate, JoinExpr *j, @@ -51,11 +51,11 @@ static RangeTblRef *transformTableEntry(ParseState *pstate, RangeVar *r); static RangeTblRef *transformRangeSubselect(ParseState *pstate, RangeSubselect *r); static RangeTblRef *transformRangeFunction(ParseState *pstate, - RangeFunction *r); + RangeFunction *r); static Node *transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels); static Node *buildMergedJoinVar(JoinType jointype, - Var *l_colvar, Var *r_colvar); + Var *l_colvar, Var *r_colvar); static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause); static List *addTargetToSortList(TargetEntry *tle, List *sortlist, @@ -85,9 +85,9 @@ transformFromClause(ParseState *pstate, List *frmList) /* * The grammar will have produced a list of RangeVars, - * RangeSubselects, RangeFunctions, and/or JoinExprs. Transform each one - * (possibly adding entries to the rtable), check for duplicate refnames, - * and then add it to the joinlist and namespace. + * RangeSubselects, RangeFunctions, and/or JoinExprs. Transform each + * one (possibly adding entries to the rtable), check for duplicate + * refnames, and then add it to the joinlist and namespace. */ foreach(fl, frmList) { @@ -466,13 +466,14 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r) funcname = strVal(llast(((FuncCall *) r->funccallnode)->funcname)); /* - * Transform the raw FuncCall node. This is a bit tricky because we don't - * want the function expression to be able to see any FROM items already - * created in the current query (compare to transformRangeSubselect). - * But it does need to be able to see any further-up parent states. - * So, temporarily make the current query level have an empty namespace. - * NOTE: this code is OK only because the expression can't legally alter - * the namespace by causing implicit relation refs to be added. + * Transform the raw FuncCall node. This is a bit tricky because we + * don't want the function expression to be able to see any FROM items + * already created in the current query (compare to + * transformRangeSubselect). But it does need to be able to see any + * further-up parent states. So, temporarily make the current query + * level have an empty namespace. NOTE: this code is OK only because + * the expression can't legally alter the namespace by causing + * implicit relation refs to be added. */ save_namespace = pstate->p_namespace; pstate->p_namespace = NIL; @@ -482,18 +483,18 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r) pstate->p_namespace = save_namespace; /* - * We still need to check that the function parameters don't refer - * to any other rels. That could happen despite our hack on the namespace - * if fully-qualified names are used. So, check there are no local - * Var references in the transformed expression. (Outer references - * are OK, and are ignored here.) + * We still need to check that the function parameters don't refer to + * any other rels. That could happen despite our hack on the + * namespace if fully-qualified names are used. So, check there are + * no local Var references in the transformed expression. (Outer + * references are OK, and are ignored here.) */ if (pull_varnos(funcexpr) != NIL) elog(ERROR, "FROM function expression may not refer to other relations of same query level"); /* - * Disallow aggregate functions in the expression. (No reason to postpone - * this check until parseCheckAggregates.) + * Disallow aggregate functions in the expression. (No reason to + * postpone this check until parseCheckAggregates.) */ if (pstate->p_hasAggs) { @@ -503,8 +504,9 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r) /* * Insist we have a bare function call (explain.c is the only place - * that depends on this, I think). If this fails, it's probably because - * transformExpr interpreted the function notation as a type coercion. + * that depends on this, I think). If this fails, it's probably + * because transformExpr interpreted the function notation as a type + * coercion. */ if (!funcexpr || !IsA(funcexpr, Expr) || @@ -596,8 +598,8 @@ transformFromClauseItem(ParseState *pstate, Node *n, List **containedRels) j->rarg = transformFromClauseItem(pstate, j->rarg, &r_containedRels); /* - * Generate combined list of relation indexes for possible use - * by transformJoinOnClause below. + * Generate combined list of relation indexes for possible use by + * transformJoinOnClause below. */ my_containedRels = nconc(l_containedRels, r_containedRels); @@ -893,6 +895,7 @@ buildMergedJoinVar(JoinType jointype, Var *l_colvar, Var *r_colvar) switch (jointype) { case JOIN_INNER: + /* * We can use either var; prefer non-coerced one if available. */ @@ -912,25 +915,25 @@ buildMergedJoinVar(JoinType jointype, Var *l_colvar, Var *r_colvar) res_node = r_node; break; case JOIN_FULL: - { - /* - * Here we must build a COALESCE expression to ensure that - * the join output is non-null if either input is. - */ - CaseExpr *c = makeNode(CaseExpr); - CaseWhen *w = makeNode(CaseWhen); - NullTest *n = makeNode(NullTest); - - n->arg = l_node; - n->nulltesttype = IS_NOT_NULL; - w->expr = (Node *) n; - w->result = l_node; - c->casetype = outcoltype; - c->args = makeList1(w); - c->defresult = r_node; - res_node = (Node *) c; - break; - } + { + /* + * Here we must build a COALESCE expression to ensure that + * the join output is non-null if either input is. + */ + CaseExpr *c = makeNode(CaseExpr); + CaseWhen *w = makeNode(CaseWhen); + NullTest *n = makeNode(NullTest); + + n->arg = l_node; + n->nulltesttype = IS_NOT_NULL; + w->expr = (Node *) n; + w->result = l_node; + c->casetype = outcoltype; + c->args = makeList1(w); + c->defresult = r_node; + res_node = (Node *) c; + break; + } default: elog(ERROR, "buildMergedJoinVar: unexpected jointype %d", (int) jointype); diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 18224a7e3f..d57e18f232 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.82 2002/09/01 02:27:32 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.83 2002/09/04 20:31:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,8 +29,8 @@ static Oid PreferredType(CATEGORY category, Oid type); static bool find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, - bool isExplicit, - Oid *funcid); + bool isExplicit, + Oid *funcid); static Oid find_typmod_coercion_function(Oid typeId); static Node *build_func_call(Oid funcid, Oid rettype, List *args); @@ -71,8 +71,8 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, * XXX if the typinput function is not cachable, we really ought to * postpone evaluation of the function call until runtime. But * there is no way to represent a typinput function call as an - * expression tree, because C-string values are not Datums. - * (XXX This *is* possible as of 7.3, do we want to do it?) + * expression tree, because C-string values are not Datums. (XXX + * This *is* possible as of 7.3, do we want to do it?) */ Const *con = (Const *) node; Const *newcon = makeNode(Const); @@ -91,10 +91,11 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, con->constvalue)); /* - * If target is a domain, use the typmod it applies to the base - * type. Note that we call stringTypeDatum using the domain's - * pg_type row, though. This works because the domain row has - * the same typinput and typelem as the base type --- ugly... + * If target is a domain, use the typmod it applies to the + * base type. Note that we call stringTypeDatum using the + * domain's pg_type row, though. This works because the + * domain row has the same typinput and typelem as the base + * type --- ugly... */ if (targetTyptype == 'd') atttypmod = getBaseTypeMod(targetTypeId, atttypmod); @@ -127,11 +128,12 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, if (OidIsValid(funcId)) { /* - * Generate an expression tree representing run-time application - * of the conversion function. If we are dealing with a domain - * target type, the conversion function will yield the base type. + * Generate an expression tree representing run-time + * application of the conversion function. If we are dealing + * with a domain target type, the conversion function will + * yield the base type. */ - Oid baseTypeId = getBaseType(targetTypeId); + Oid baseTypeId = getBaseType(targetTypeId); result = build_func_call(funcId, baseTypeId, makeList1(node)); @@ -147,19 +149,20 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, } /* - * If the input is a constant, apply the type conversion function - * now instead of delaying to runtime. (We could, of course, just - * leave this to be done during planning/optimization; but it's a - * very frequent special case, and we save cycles in the rewriter - * if we fold the expression now.) + * If the input is a constant, apply the type conversion + * function now instead of delaying to runtime. (We could, of + * course, just leave this to be done during + * planning/optimization; but it's a very frequent special + * case, and we save cycles in the rewriter if we fold the + * expression now.) * * Note that no folding will occur if the conversion function is * not marked 'immutable'. * * HACK: if constant is NULL, don't fold it here. This is needed * by make_subplan(), which calls this routine on placeholder - * Const nodes that mustn't be collapsed. (It'd be a lot cleaner - * to make a separate node type for that purpose...) + * Const nodes that mustn't be collapsed. (It'd be a lot + * cleaner to make a separate node type for that purpose...) */ if (IsA(node, Const) && !((Const *) node)->constisnull) @@ -168,21 +171,23 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, else { /* - * We don't need to do a physical conversion, but we do need to - * attach a RelabelType node so that the expression will be seen - * to have the intended type when inspected by higher-level code. + * We don't need to do a physical conversion, but we do need + * to attach a RelabelType node so that the expression will be + * seen to have the intended type when inspected by + * higher-level code. * * Also, domains may have value restrictions beyond the base type * that must be accounted for. */ result = coerce_type_constraints(pstate, node, targetTypeId, true); + /* * XXX could we label result with exprTypmod(node) instead of - * default -1 typmod, to save a possible length-coercion later? - * Would work if both types have same interpretation of typmod, - * which is likely but not certain (wrong if target is a domain, - * in any case). + * default -1 typmod, to save a possible length-coercion + * later? Would work if both types have same interpretation of + * typmod, which is likely but not certain (wrong if target is + * a domain, in any case). */ result = (Node *) makeRelabelType(result, targetTypeId, -1); } @@ -190,9 +195,9 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, else if (typeInheritsFrom(inputTypeId, targetTypeId)) { /* - * Input class type is a subclass of target, so nothing to do - * --- except relabel the type. This is binary compatibility - * for complex types. + * Input class type is a subclass of target, so nothing to do --- + * except relabel the type. This is binary compatibility for + * complex types. */ result = (Node *) makeRelabelType(node, targetTypeId, -1); } @@ -254,12 +259,15 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids, if (targetTypeId == ANYOID) continue; - /* if target is ANYARRAY and source is a varlena array type, accept */ + /* + * if target is ANYARRAY and source is a varlena array type, + * accept + */ if (targetTypeId == ANYARRAYOID) { - Oid typOutput; - Oid typElem; - bool typIsVarlena; + Oid typOutput; + Oid typElem; + bool typIsVarlena; if (getTypeOutputInfo(inputTypeId, &typOutput, &typElem, &typIsVarlena)) @@ -267,10 +275,11 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids, if (OidIsValid(typElem) && typIsVarlena) continue; } + /* - * Otherwise reject; this assumes there are no explicit coercions - * to ANYARRAY. If we don't reject then parse_coerce would have - * to repeat the above test. + * Otherwise reject; this assumes there are no explicit + * coercions to ANYARRAY. If we don't reject then + * parse_coerce would have to repeat the above test. */ return false; } @@ -301,15 +310,15 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids, /* * Create an expression tree to enforce the constraints (if any) - * that should be applied by the type. Currently this is only + * that should be applied by the type. Currently this is only * interesting for domain types. */ Node * coerce_type_constraints(ParseState *pstate, Node *arg, Oid typeId, bool applyTypmod) { - char *notNull = NULL; - int32 typmod = -1; + char *notNull = NULL; + int32 typmod = -1; for (;;) { @@ -351,9 +360,9 @@ coerce_type_constraints(ParseState *pstate, Node *arg, arg = coerce_type_typmod(pstate, arg, typeId, typmod); /* - * Only need to add one NOT NULL check regardless of how many - * domains in the stack request it. The topmost domain that - * requested it is used as the constraint name. + * Only need to add one NOT NULL check regardless of how many domains + * in the stack request it. The topmost domain that requested it is + * used as the constraint name. */ if (notNull) { @@ -361,11 +370,11 @@ coerce_type_constraints(ParseState *pstate, Node *arg, r->arg = arg; r->testtype = CONSTR_TEST_NOTNULL; - r->name = notNull; + r->name = notNull; r->check_expr = NULL; arg = (Node *) r; - } + } return arg; } @@ -904,7 +913,7 @@ build_func_call(Oid funcid, Oid rettype, List *args) funcnode = makeNode(Func); funcnode->funcid = funcid; funcnode->funcresulttype = rettype; - funcnode->funcretset = false; /* only possible case here */ + funcnode->funcretset = false; /* only possible case here */ funcnode->func_fcache = NULL; expr = makeNode(Expr); diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index de07d39b4d..7be413f6b5 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.127 2002/08/31 22:10:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.128 2002/09/04 20:31:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -194,7 +194,7 @@ transformExpr(ParseState *pstate, Node *expr) */ if (Transform_null_equals && length(a->name) == 1 && - strcmp(strVal(lfirst(a->name)), "=") == 0 && + strcmp(strVal(lfirst(a->name)), "=") == 0 && (exprIsNullConstant(a->lexpr) || exprIsNullConstant(a->rexpr))) { @@ -213,9 +213,9 @@ transformExpr(ParseState *pstate, Node *expr) else { Node *lexpr = transformExpr(pstate, - a->lexpr); + a->lexpr); Node *rexpr = transformExpr(pstate, - a->rexpr); + a->rexpr); result = (Node *) make_op(a->name, lexpr, @@ -277,41 +277,48 @@ transformExpr(ParseState *pstate, Node *expr) a->lexpr); Node *rexpr = transformExpr(pstate, a->rexpr); + result = (Node *) make_op(a->name, lexpr, rexpr); - ((Expr *)result)->opType = DISTINCT_EXPR; + ((Expr *) result)->opType = DISTINCT_EXPR; } break; case OF: { - List *telem; - A_Const *n; - Oid ltype, rtype; - bool matched = FALSE; + List *telem; + A_Const *n; + Oid ltype, + rtype; + bool matched = FALSE; - /* Checking an expression for match to type. + /* + * Checking an expression for match to type. * Will result in a boolean constant node. */ Node *lexpr = transformExpr(pstate, a->lexpr); + ltype = exprType(lexpr); foreach(telem, (List *) a->rexpr) { rtype = LookupTypeName(lfirst(telem)); matched = (rtype == ltype); - if (matched) break; + if (matched) + break; } - /* Expect two forms: equals or not equals. - * Flip the sense of the result for not equals. + /* + * Expect two forms: equals or not equals. + * Flip the sense of the result for not + * equals. */ if (strcmp(strVal(lfirst(a->name)), "!=") == 0) - matched = (! matched); + matched = (!matched); n = makeNode(A_Const); n->val.type = T_String; - n->val.val.str = (matched? "t": "f"); + n->val.val.str = (matched ? "t" : "f"); n->typename = SystemTypeName("bool"); result = transformExpr(pstate, (Node *) n); @@ -411,7 +418,7 @@ transformExpr(ParseState *pstate, Node *expr) /* Combining operators other than =/<> is dubious... */ if (length(left_list) != 1 && - strcmp(opname, "=") != 0 && strcmp(opname, "<>") != 0) + strcmp(opname, "=") != 0 && strcmp(opname, "<>") != 0) elog(ERROR, "Row comparison cannot use operator %s", opname); @@ -453,7 +460,7 @@ transformExpr(ParseState *pstate, Node *expr) if (opform->oprresult != BOOLOID) elog(ERROR, "%s has result type of %s, but must return %s" " to be used with quantified predicate subquery", - opname, format_type_be(opform->oprresult), + opname, format_type_be(opform->oprresult), format_type_be(BOOLOID)); if (get_func_retset(opform->oprcode)) @@ -613,7 +620,7 @@ transformExpr(ParseState *pstate, Node *expr) default: elog(ERROR, "transformExpr: unexpected booltesttype %d", (int) b->booltesttype); - clausename = NULL; /* keep compiler quiet */ + clausename = NULL; /* keep compiler quiet */ } b->arg = transformExpr(pstate, b->arg); @@ -624,14 +631,14 @@ transformExpr(ParseState *pstate, Node *expr) break; } - /********************************************* - * Quietly accept node types that may be presented when we are - * called on an already-transformed tree. - * - * Do any other node types need to be accepted? For now we are - * taking a conservative approach, and only accepting node - * types that are demonstrably necessary to accept. - *********************************************/ + /********************************************* + * Quietly accept node types that may be presented when we are + * called on an already-transformed tree. + * + * Do any other node types need to be accepted? For now we are + * taking a conservative approach, and only accepting node + * types that are demonstrably necessary to accept. + *********************************************/ case T_Expr: case T_Var: case T_Const: @@ -705,146 +712,148 @@ transformColumnRef(ParseState *pstate, ColumnRef *cref) switch (numnames) { case 1: - { - char *name = strVal(lfirst(cref->fields)); + { + char *name = strVal(lfirst(cref->fields)); - /* Try to identify as an unqualified column */ - node = colnameToVar(pstate, name); + /* Try to identify as an unqualified column */ + node = colnameToVar(pstate, name); + + if (node == NULL) + { + /* + * Not known as a column of any range-table entry, so + * try to find the name as a relation ... but not if + * subscripts appear. Note also that only relations + * already entered into the rangetable will be + * recognized. + * + * This is a hack for backwards compatibility with + * PostQUEL- inspired syntax. The preferred form now + * is "rel.*". + */ + int levels_up; - if (node == NULL) + if (cref->indirection == NIL && + refnameRangeTblEntry(pstate, NULL, name, + &levels_up) != NULL) + { + rv = makeNode(RangeVar); + rv->relname = name; + rv->inhOpt = INH_DEFAULT; + node = (Node *) rv; + } + else + elog(ERROR, "Attribute \"%s\" not found", name); + } + break; + } + case 2: { - /* - * Not known as a column of any range-table entry, so - * try to find the name as a relation ... but not if - * subscripts appear. Note also that only relations - * already entered into the rangetable will be recognized. - * - * This is a hack for backwards compatibility with PostQUEL- - * inspired syntax. The preferred form now is "rel.*". - */ - int levels_up; + char *name1 = strVal(lfirst(cref->fields)); + char *name2 = strVal(lsecond(cref->fields)); - if (cref->indirection == NIL && - refnameRangeTblEntry(pstate, NULL, name, - &levels_up) != NULL) + /* Whole-row reference? */ + if (strcmp(name2, "*") == 0) { rv = makeNode(RangeVar); - rv->relname = name; + rv->relname = name1; rv->inhOpt = INH_DEFAULT; node = (Node *) rv; + break; } - else - elog(ERROR, "Attribute \"%s\" not found", name); - } - break; - } - case 2: - { - char *name1 = strVal(lfirst(cref->fields)); - char *name2 = strVal(lsecond(cref->fields)); - /* Whole-row reference? */ - if (strcmp(name2, "*") == 0) - { - rv = makeNode(RangeVar); - rv->relname = name1; - rv->inhOpt = INH_DEFAULT; - node = (Node *) rv; + /* Try to identify as a once-qualified column */ + node = qualifiedNameToVar(pstate, NULL, name1, name2, true); + if (node == NULL) + { + /* + * Not known as a column of any range-table entry, so + * try it as a function call. Here, we will create an + * implicit RTE for tables not already entered. + */ + rv = makeNode(RangeVar); + rv->relname = name1; + rv->inhOpt = INH_DEFAULT; + node = ParseFuncOrColumn(pstate, + makeList1(makeString(name2)), + makeList1(rv), + false, false, true); + } break; } - - /* Try to identify as a once-qualified column */ - node = qualifiedNameToVar(pstate, NULL, name1, name2, true); - if (node == NULL) - { - /* - * Not known as a column of any range-table entry, so - * try it as a function call. Here, we will create an - * implicit RTE for tables not already entered. - */ - rv = makeNode(RangeVar); - rv->relname = name1; - rv->inhOpt = INH_DEFAULT; - node = ParseFuncOrColumn(pstate, - makeList1(makeString(name2)), - makeList1(rv), - false, false, true); - } - break; - } case 3: - { - char *name1 = strVal(lfirst(cref->fields)); - char *name2 = strVal(lsecond(cref->fields)); - char *name3 = strVal(lfirst(lnext(lnext(cref->fields)))); - - /* Whole-row reference? */ - if (strcmp(name3, "*") == 0) { - rv = makeNode(RangeVar); - rv->schemaname = name1; - rv->relname = name2; - rv->inhOpt = INH_DEFAULT; - node = (Node *) rv; - break; - } + char *name1 = strVal(lfirst(cref->fields)); + char *name2 = strVal(lsecond(cref->fields)); + char *name3 = strVal(lfirst(lnext(lnext(cref->fields)))); - /* Try to identify as a twice-qualified column */ - node = qualifiedNameToVar(pstate, name1, name2, name3, true); - if (node == NULL) - { - /* Try it as a function call */ - rv = makeNode(RangeVar); - rv->schemaname = name1; - rv->relname = name2; - rv->inhOpt = INH_DEFAULT; - node = ParseFuncOrColumn(pstate, - makeList1(makeString(name3)), - makeList1(rv), - false, false, true); + /* Whole-row reference? */ + if (strcmp(name3, "*") == 0) + { + rv = makeNode(RangeVar); + rv->schemaname = name1; + rv->relname = name2; + rv->inhOpt = INH_DEFAULT; + node = (Node *) rv; + break; + } + + /* Try to identify as a twice-qualified column */ + node = qualifiedNameToVar(pstate, name1, name2, name3, true); + if (node == NULL) + { + /* Try it as a function call */ + rv = makeNode(RangeVar); + rv->schemaname = name1; + rv->relname = name2; + rv->inhOpt = INH_DEFAULT; + node = ParseFuncOrColumn(pstate, + makeList1(makeString(name3)), + makeList1(rv), + false, false, true); + } + break; } - break; - } case 4: - { - char *name1 = strVal(lfirst(cref->fields)); - char *name2 = strVal(lsecond(cref->fields)); - char *name3 = strVal(lfirst(lnext(lnext(cref->fields)))); - char *name4 = strVal(lfirst(lnext(lnext(lnext(cref->fields))))); - - /* - * We check the catalog name and then ignore it. - */ - if (strcmp(name1, DatabaseName) != 0) - elog(ERROR, "Cross-database references are not implemented"); - - /* Whole-row reference? */ - if (strcmp(name4, "*") == 0) { - rv = makeNode(RangeVar); - rv->schemaname = name2; - rv->relname = name3; - rv->inhOpt = INH_DEFAULT; - node = (Node *) rv; - break; - } + char *name1 = strVal(lfirst(cref->fields)); + char *name2 = strVal(lsecond(cref->fields)); + char *name3 = strVal(lfirst(lnext(lnext(cref->fields)))); + char *name4 = strVal(lfirst(lnext(lnext(lnext(cref->fields))))); - /* Try to identify as a twice-qualified column */ - node = qualifiedNameToVar(pstate, name2, name3, name4, true); - if (node == NULL) - { - /* Try it as a function call */ - rv = makeNode(RangeVar); - rv->schemaname = name2; - rv->relname = name3; - rv->inhOpt = INH_DEFAULT; - node = ParseFuncOrColumn(pstate, - makeList1(makeString(name4)), - makeList1(rv), - false, false, true); + /* + * We check the catalog name and then ignore it. + */ + if (strcmp(name1, DatabaseName) != 0) + elog(ERROR, "Cross-database references are not implemented"); + + /* Whole-row reference? */ + if (strcmp(name4, "*") == 0) + { + rv = makeNode(RangeVar); + rv->schemaname = name2; + rv->relname = name3; + rv->inhOpt = INH_DEFAULT; + node = (Node *) rv; + break; + } + + /* Try to identify as a twice-qualified column */ + node = qualifiedNameToVar(pstate, name2, name3, name4, true); + if (node == NULL) + { + /* Try it as a function call */ + rv = makeNode(RangeVar); + rv->schemaname = name2; + rv->relname = name3; + rv->inhOpt = INH_DEFAULT; + node = ParseFuncOrColumn(pstate, + makeList1(makeString(name4)), + makeList1(rv), + false, false, true); + } + break; } - break; - } default: elog(ERROR, "Invalid qualified name syntax (too many names)"); node = NULL; /* keep compiler quiet */ @@ -1095,8 +1104,9 @@ exprIsLengthCoercion(Node *expr, int32 *coercedTypmod) } /* - * Furthermore, the name and namespace of the function must be the same - * as its result type's name/namespace (cf. find_coercion_function). + * Furthermore, the name and namespace of the function must be the + * same as its result type's name/namespace (cf. + * find_coercion_function). */ typeTuple = SearchSysCache(TYPEOID, ObjectIdGetDatum(procStruct->prorettype), @@ -1206,7 +1216,7 @@ parser_typecast_expression(ParseState *pstate, { expr = CoerceTargetExpr(pstate, expr, inputType, targetType, typename->typmod, - true); /* explicit coercion */ + true); /* explicit coercion */ if (expr == NULL) elog(ERROR, "Cannot cast type '%s' to '%s'", format_type_be(inputType), diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index 87e432b7cf..648ddfbaf0 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.135 2002/08/22 00:01:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.136 2002/09/04 20:31:23 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -45,14 +45,14 @@ static void make_arguments(ParseState *pstate, Oid *input_typeids, Oid *function_typeids); static int match_argtypes(int nargs, - Oid *input_typeids, - FuncCandidateList function_typeids, - FuncCandidateList *candidates); + Oid *input_typeids, + FuncCandidateList function_typeids, + FuncCandidateList *candidates); static FieldSelect *setup_field_select(Node *input, char *attname, Oid relid); static FuncCandidateList func_select_candidate(int nargs, Oid *input_typeids, - FuncCandidateList candidates); + FuncCandidateList candidates); static void unknown_attribute(const char *schemaname, const char *relname, - const char *attname); + const char *attname); /* @@ -111,8 +111,8 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, /* * check for column projection: if function has one argument, and that * argument is of complex type, and function name is not qualified, - * then the "function call" could be a projection. We also check - * that there wasn't any aggregate decoration. + * then the "function call" could be a projection. We also check that + * there wasn't any aggregate decoration. */ if (nargs == 1 && !agg_star && !agg_distinct && length(funcname) == 1) { @@ -123,7 +123,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, { /* First arg is a relation. This could be a projection. */ retval = qualifiedNameToVar(pstate, - ((RangeVar *) first_arg)->schemaname, + ((RangeVar *) first_arg)->schemaname, ((RangeVar *) first_arg)->relname, cname, true); @@ -144,9 +144,9 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, } /* - * Okay, it's not a column projection, so it must really be a function. - * Extract arg type info and transform RangeVar arguments into varnodes - * of the appropriate form. + * Okay, it's not a column projection, so it must really be a + * function. Extract arg type info and transform RangeVar arguments + * into varnodes of the appropriate form. */ MemSet(oid_array, 0, FUNC_MAX_ARGS * sizeof(Oid)); @@ -199,6 +199,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, toid = exprType(rte->funcexpr); break; default: + /* * RTE is a join or subselect; must fail for lack of a * named tuple type @@ -209,7 +210,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, else elog(ERROR, "Cannot pass result of sub-select or join %s to a function", relname); - toid = InvalidOid; /* keep compiler quiet */ + toid = InvalidOid; /* keep compiler quiet */ break; } @@ -228,10 +229,10 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, /* * func_get_detail looks up the function in the catalogs, does - * disambiguation for polymorphic functions, handles inheritance, - * and returns the funcid and type and set or singleton status of - * the function's return value. it also returns the true argument - * types to the function. + * disambiguation for polymorphic functions, handles inheritance, and + * returns the funcid and type and set or singleton status of the + * function's return value. it also returns the true argument types + * to the function. */ fdresult = func_get_detail(funcname, fargs, nargs, oid_array, &funcid, &rettype, &retset, @@ -263,13 +264,13 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, /* * Oops. Time to die. * - * If we are dealing with the attribute notation rel.function, - * give an error message that is appropriate for that case. + * If we are dealing with the attribute notation rel.function, give + * an error message that is appropriate for that case. */ if (is_column) { - char *colname = strVal(lfirst(funcname)); - Oid relTypeId; + char *colname = strVal(lfirst(funcname)); + Oid relTypeId; Assert(nargs == 1); if (IsA(first_arg, RangeVar)) @@ -284,6 +285,7 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, elog(ERROR, "Attribute \"%s\" not found in datatype %s", colname, format_type_be(relTypeId)); } + /* * Else generate a detailed complaint for a function */ @@ -351,7 +353,7 @@ static int match_argtypes(int nargs, Oid *input_typeids, FuncCandidateList function_typeids, - FuncCandidateList *candidates) /* return value */ + FuncCandidateList *candidates) /* return value */ { FuncCandidateList current_candidate; FuncCandidateList next_candidate; @@ -863,7 +865,7 @@ func_get_detail(List *funcname, ftup = SearchSysCache(PROCOID, ObjectIdGetDatum(best_candidate->oid), 0, 0, 0); - if (!HeapTupleIsValid(ftup)) /* should not happen */ + if (!HeapTupleIsValid(ftup)) /* should not happen */ elog(ERROR, "function %u not found", best_candidate->oid); pform = (Form_pg_proc) GETSTRUCT(ftup); *rettype = pform->prorettype; @@ -1172,7 +1174,7 @@ setup_field_select(Node *input, char *attname, Oid relid) * ParseComplexProjection - * handles function calls with a single argument that is of complex type. * If the function call is actually a column projection, return a suitably - * transformed expression tree. If not, return NULL. + * transformed expression tree. If not, return NULL. * * NB: argument is expected to be transformed already, ie, not a RangeVar. */ @@ -1194,7 +1196,8 @@ ParseComplexProjection(ParseState *pstate, return NULL; /* funcname does not match any column */ /* - * Check for special cases where we don't want to return a FieldSelect. + * Check for special cases where we don't want to return a + * FieldSelect. */ switch (nodeTag(first_arg)) { @@ -1208,8 +1211,8 @@ ParseComplexProjection(ParseState *pstate, */ if (var->varattno == InvalidAttrNumber) { - Oid vartype; - int32 vartypmod; + Oid vartype; + int32 vartypmod; get_atttypetypmod(argrelid, attnum, &vartype, &vartypmod); @@ -1313,7 +1316,7 @@ find_aggregate_func(const char *caller, List *aggname, Oid basetype) ftup = SearchSysCache(PROCOID, ObjectIdGetDatum(oid), 0, 0, 0); - if (!HeapTupleIsValid(ftup)) /* should not happen */ + if (!HeapTupleIsValid(ftup)) /* should not happen */ elog(ERROR, "function %u not found", oid); pform = (Form_pg_proc) GETSTRUCT(ftup); @@ -1367,10 +1370,10 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes) Oid LookupFuncNameTypeNames(List *funcname, List *argtypes, const char *caller) { - Oid funcoid; - Oid argoids[FUNC_MAX_ARGS]; - int argcount; - int i; + Oid funcoid; + Oid argoids[FUNC_MAX_ARGS]; + int argcount; + int i; MemSet(argoids, 0, FUNC_MAX_ARGS * sizeof(Oid)); argcount = length(argtypes); diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c index 33ee300fb2..391694fa19 100644 --- a/src/backend/parser/parse_node.c +++ b/src/backend/parser/parse_node.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.67 2002/08/26 17:53:58 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.68 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -135,8 +135,8 @@ make_op(List *opname, Node *ltree, Node *rtree) newop = makeOper(oprid(tup), /* opno */ InvalidOid, /* opid */ - opform->oprresult, /* opresulttype */ - get_func_retset(opform->oprcode)); /* opretset */ + opform->oprresult, /* opresulttype */ + get_func_retset(opform->oprcode)); /* opretset */ result = makeNode(Expr); result->typeOid = opform->oprresult; diff --git a/src/backend/parser/parse_oper.c b/src/backend/parser/parse_oper.c index 78128b4f69..ecf1a2abec 100644 --- a/src/backend/parser/parse_oper.c +++ b/src/backend/parser/parse_oper.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.58 2002/07/20 05:16:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_oper.c,v 1.59 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -29,10 +29,10 @@ #include "utils/fmgroids.h" #include "utils/syscache.h" -static Oid binary_oper_exact(Oid arg1, Oid arg2, - FuncCandidateList candidates); -static Oid oper_select_candidate(int nargs, Oid *input_typeids, - FuncCandidateList candidates); +static Oid binary_oper_exact(Oid arg1, Oid arg2, + FuncCandidateList candidates); +static Oid oper_select_candidate(int nargs, Oid *input_typeids, + FuncCandidateList candidates); static void op_error(List *op, Oid arg1, Oid arg2); static void unary_op_error(List *op, Oid arg, bool is_left_op); @@ -52,7 +52,7 @@ Oid LookupOperName(List *opername, Oid oprleft, Oid oprright) { FuncCandidateList clist; - char oprkind; + char oprkind; if (!OidIsValid(oprleft)) oprkind = 'l'; @@ -85,9 +85,9 @@ Oid LookupOperNameTypeNames(List *opername, TypeName *oprleft, TypeName *oprright, const char *caller) { - Oid operoid; - Oid leftoid, - rightoid; + Oid operoid; + Oid leftoid, + rightoid; if (oprleft == NULL) leftoid = InvalidOid; @@ -652,7 +652,10 @@ oper(List *opname, Oid ltypeId, Oid rtypeId, bool noError) * Otherwise, search for the most suitable candidate. */ - /* Unspecified type for one of the arguments? then use the other */ + /* + * Unspecified type for one of the arguments? then use the + * other + */ if (rtypeId == InvalidOid) rtypeId = ltypeId; else if (ltypeId == InvalidOid) diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 174c05790d..65c386a937 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.78 2002/08/29 00:17:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.79 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,14 +36,14 @@ static Node *scanNameSpaceForRefname(ParseState *pstate, Node *nsnode, const char *refname); static Node *scanNameSpaceForRelid(ParseState *pstate, Node *nsnode, - Oid relid); + Oid relid); static void scanNameSpaceForConflict(ParseState *pstate, Node *nsnode, RangeTblEntry *rte1, const char *aliasname1); static Node *scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname); static bool isForUpdate(ParseState *pstate, char *refname); static bool get_rte_attribute_is_dropped(RangeTblEntry *rte, - AttrNumber attnum); + AttrNumber attnum); static int specialAttNum(const char *attname); static void warnAutoRange(ParseState *pstate, RangeVar *relation); @@ -64,7 +64,7 @@ static void warnAutoRange(ParseState *pstate, RangeVar *relation); * * A qualified refname (schemaname != NULL) can only match a relation RTE * that (a) has no alias and (b) is for the same relation identified by - * schemaname.refname. In this case we convert schemaname.refname to a + * schemaname.refname. In this case we convert schemaname.refname to a * relation OID and search by relid, rather than by alias name. This is * peculiar, but it's what SQL92 says to do. */ @@ -189,7 +189,7 @@ scanNameSpaceForRefname(ParseState *pstate, Node *nsnode, /* * Recursively search a namespace for a relation RTE matching the - * given relation OID. Return the node if a unique match, or NULL + * given relation OID. Return the node if a unique match, or NULL * if no match. Raise error if multiple matches (which shouldn't * happen if the namespace was checked correctly when it was created). * @@ -313,9 +313,7 @@ checkNameSpaceConflicts(ParseState *pstate, Node *namespace1, List *l; foreach(l, (List *) namespace1) - { checkNameSpaceConflicts(pstate, lfirst(l), namespace2); - } } else elog(ERROR, "checkNameSpaceConflicts: unexpected node type %d", @@ -353,6 +351,7 @@ scanNameSpaceForConflict(ParseState *pstate, Node *nsnode, if (strcmp(j->alias->aliasname, aliasname1) == 0) elog(ERROR, "Table name \"%s\" specified more than once", aliasname1); + /* * Tables within an aliased join are invisible from outside * the join, according to the scope rules of SQL92 (the join @@ -368,9 +367,7 @@ scanNameSpaceForConflict(ParseState *pstate, Node *nsnode, List *l; foreach(l, (List *) nsnode) - { scanNameSpaceForConflict(pstate, lfirst(l), rte1, aliasname1); - } } else elog(ERROR, "scanNameSpaceForConflict: unexpected node type %d", @@ -438,16 +435,16 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname) * Scan the user column names (or aliases) for a match. Complain if * multiple matches. * - * Note: because eref->colnames may include names of dropped columns, - * we need to check for non-droppedness before accepting a match. - * This takes an extra cache lookup, but we can skip the lookup most - * of the time by exploiting the knowledge that dropped columns are - * assigned dummy names starting with '.', which is an unusual choice - * for actual column names. + * Note: because eref->colnames may include names of dropped columns, we + * need to check for non-droppedness before accepting a match. This + * takes an extra cache lookup, but we can skip the lookup most of the + * time by exploiting the knowledge that dropped columns are assigned + * dummy names starting with '.', which is an unusual choice for + * actual column names. * - * Should the user try to fool us by altering pg_attribute.attname - * for a dropped column, we'll still catch it by virtue of the checks - * in get_rte_attribute_type(), which is called by make_var(). That + * Should the user try to fool us by altering pg_attribute.attname for a + * dropped column, we'll still catch it by virtue of the checks in + * get_rte_attribute_type(), which is called by make_var(). That * routine has to do a cache lookup anyway, so the check there is * cheap. */ @@ -456,7 +453,7 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname) attnum++; if (strcmp(strVal(lfirst(c)), colname) == 0) { - if (colname[0] == '.' && /* see note above */ + if (colname[0] == '.' && /* see note above */ get_rte_attribute_is_dropped(rte, attnum)) continue; if (result) @@ -903,8 +900,8 @@ addRangeTableEntryForFunction(ParseState *pstate, if (coldeflist != NIL) { /* - * we *only* allow a coldeflist for functions returning a - * RECORD pseudo-type + * we *only* allow a coldeflist for functions returning a RECORD + * pseudo-type */ if (funcrettype != RECORDOID) elog(ERROR, "A column definition list is only allowed for functions returning RECORD"); @@ -935,14 +932,14 @@ addRangeTableEntryForFunction(ParseState *pstate, funcrettype); /* - * Get the rel's relcache entry. This access ensures that we have an - * up-to-date relcache entry for the rel. + * Get the rel's relcache entry. This access ensures that we have + * an up-to-date relcache entry for the rel. */ rel = relation_open(funcrelid, AccessShareLock); /* - * Since the rel is open anyway, let's check that the number of column - * aliases is reasonable. + * Since the rel is open anyway, let's check that the number of + * column aliases is reasonable. */ maxattrs = RelationGetNumberOfAttributes(rel); if (maxattrs < numaliases) @@ -960,16 +957,16 @@ addRangeTableEntryForFunction(ParseState *pstate, /* * Drop the rel refcount, but keep the access lock till end of - * transaction so that the table can't be deleted or have its schema - * modified underneath us. + * transaction so that the table can't be deleted or have its + * schema modified underneath us. */ relation_close(rel, NoLock); } else if (functyptype == 'b' || functyptype == 'd') { /* - * Must be a base data type, i.e. scalar. - * Just add one alias column named for the function. + * Must be a base data type, i.e. scalar. Just add one alias + * column named for the function. */ if (numaliases > 1) elog(ERROR, "Too many column aliases specified for function %s", @@ -1270,17 +1267,17 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte, case RTE_FUNCTION: { /* Function RTE */ - Oid funcrettype = exprType(rte->funcexpr); - char functyptype = get_typtype(funcrettype); - List *coldeflist = rte->coldeflist; + Oid funcrettype = exprType(rte->funcexpr); + char functyptype = get_typtype(funcrettype); + List *coldeflist = rte->coldeflist; if (functyptype == 'c') { /* - * Composite data type, i.e. a table's row type - * Same as ordinary relation RTE + * Composite data type, i.e. a table's row type Same + * as ordinary relation RTE */ - Oid funcrelid = typeidTypeRelid(funcrettype); + Oid funcrelid = typeidTypeRelid(funcrettype); Relation rel; int maxattrs; int numaliases; @@ -1373,10 +1370,10 @@ expandRTE(ParseState *pstate, RangeTblEntry *rte, atttypid = typenameTypeId(colDef->typename); varnode = makeVar(rtindex, - attnum, - atttypid, - -1, - sublevels_up); + attnum, + atttypid, + -1, + sublevels_up); *colvars = lappend(*colvars, varnode); } @@ -1495,9 +1492,9 @@ get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum) /* * If the RTE is a relation, go to the system catalogs not the - * eref->colnames list. This is a little slower but it will give - * the right answer if the column has been renamed since the eref - * list was built (which can easily happen for rules). + * eref->colnames list. This is a little slower but it will give the + * right answer if the column has been renamed since the eref list was + * built (which can easily happen for rules). */ if (rte->rtekind == RTE_RELATION) { @@ -1509,7 +1506,8 @@ get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum) } /* - * Otherwise use the column name from eref. There should always be one. + * Otherwise use the column name from eref. There should always be + * one. */ if (attnum > 0 && attnum <= length(rte->eref->colnames)) return strVal(nth(attnum - 1, rte->eref->colnames)); @@ -1544,13 +1542,14 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, elog(ERROR, "Relation \"%s\" does not have attribute %d", get_rel_name(rte->relid), attnum); att_tup = (Form_pg_attribute) GETSTRUCT(tp); + /* * If dropped column, pretend it ain't there. See notes * in scanRTEForColumn. */ if (att_tup->attisdropped) elog(ERROR, "Relation \"%s\" has no column \"%s\"", - get_rel_name(rte->relid), NameStr(att_tup->attname)); + get_rel_name(rte->relid), NameStr(att_tup->attname)); *vartype = att_tup->atttypid; *vartypmod = att_tup->atttypmod; ReleaseSysCache(tp); @@ -1579,19 +1578,19 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, case RTE_FUNCTION: { /* Function RTE */ - Oid funcrettype = exprType(rte->funcexpr); - char functyptype = get_typtype(funcrettype); - List *coldeflist = rte->coldeflist; + Oid funcrettype = exprType(rte->funcexpr); + char functyptype = get_typtype(funcrettype); + List *coldeflist = rte->coldeflist; if (functyptype == 'c') { /* - * Composite data type, i.e. a table's row type - * Same as ordinary relation RTE + * Composite data type, i.e. a table's row type Same + * as ordinary relation RTE */ - Oid funcrelid = typeidTypeRelid(funcrettype); - HeapTuple tp; - Form_pg_attribute att_tup; + Oid funcrelid = typeidTypeRelid(funcrettype); + HeapTuple tp; + Form_pg_attribute att_tup; if (!OidIsValid(funcrelid)) elog(ERROR, "Invalid typrelid for complex type %u", @@ -1606,9 +1605,10 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, elog(ERROR, "Relation \"%s\" does not have attribute %d", get_rel_name(funcrelid), attnum); att_tup = (Form_pg_attribute) GETSTRUCT(tp); + /* - * If dropped column, pretend it ain't there. See notes - * in scanRTEForColumn. + * If dropped column, pretend it ain't there. See + * notes in scanRTEForColumn. */ if (att_tup->attisdropped) elog(ERROR, "Relation \"%s\" has no column \"%s\"", @@ -1639,11 +1639,14 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, break; case RTE_JOIN: { - /* Join RTE --- get type info from join RTE's alias variable */ - Node *aliasvar; + /* + * Join RTE --- get type info from join RTE's alias + * variable + */ + Node *aliasvar; Assert(attnum > 0 && attnum <= length(rte->joinaliasvars)); - aliasvar = (Node *) nth(attnum-1, rte->joinaliasvars); + aliasvar = (Node *) nth(attnum - 1, rte->joinaliasvars); *vartype = exprType(aliasvar); *vartypmod = exprTypmod(aliasvar); } @@ -1661,7 +1664,7 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum, static bool get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum) { - bool result; + bool result; switch (rte->rtekind) { @@ -1698,11 +1701,11 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum) if (OidIsValid(funcrelid)) { /* - * Composite data type, i.e. a table's row type - * Same as ordinary relation RTE + * Composite data type, i.e. a table's row type Same + * as ordinary relation RTE */ - HeapTuple tp; - Form_pg_attribute att_tup; + HeapTuple tp; + Form_pg_attribute att_tup; tp = SearchSysCache(ATTNUM, ObjectIdGetDatum(funcrelid), @@ -1748,7 +1751,7 @@ attnameAttNum(Relation rd, const char *attname, bool sysColOK) for (i = 0; i < rd->rd_rel->relnatts; i++) { - Form_pg_attribute att = rd->rd_att->attrs[i]; + Form_pg_attribute att = rd->rd_att->attrs[i]; if (namestrcmp(&(att->attname), attname) == 0 && !att->attisdropped) return i + 1; diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 26983c48cf..b9c5b6cb13 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.88 2002/08/19 15:08:47 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.89 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -114,7 +114,7 @@ transformTargetList(ParseState *pstate, List *targetlist) p_target = nconc(p_target, ExpandAllTables(pstate)); } - else if (strcmp(strVal(nth(numnames-1, fields)), "*") == 0) + else if (strcmp(strVal(nth(numnames - 1, fields)), "*") == 0) { /* * Target item is relation.*, expand that table (eg. @@ -136,21 +136,22 @@ transformTargetList(ParseState *pstate, List *targetlist) relname = strVal(lsecond(fields)); break; case 4: - { - char *name1 = strVal(lfirst(fields)); - - /* - * We check the catalog name and then ignore it. - */ - if (strcmp(name1, DatabaseName) != 0) - elog(ERROR, "Cross-database references are not implemented"); - schemaname = strVal(lsecond(fields)); - relname = strVal(lfirst(lnext(lnext(fields)))); - break; - } + { + char *name1 = strVal(lfirst(fields)); + + /* + * We check the catalog name and then ignore + * it. + */ + if (strcmp(name1, DatabaseName) != 0) + elog(ERROR, "Cross-database references are not implemented"); + schemaname = strVal(lsecond(fields)); + relname = strVal(lfirst(lnext(lnext(fields)))); + break; + } default: elog(ERROR, "Invalid qualified name syntax (too many names)"); - schemaname = NULL; /* keep compiler quiet */ + schemaname = NULL; /* keep compiler quiet */ relname = NULL; break; } @@ -180,8 +181,8 @@ transformTargetList(ParseState *pstate, List *targetlist) InsertDefault *newnode = makeNode(InsertDefault); /* - * If this is a DEFAULT element, we make a junk entry - * which will get dropped on return to transformInsertStmt(). + * If this is a DEFAULT element, we make a junk entry which + * will get dropped on return to transformInsertStmt(). */ p_target = lappend(p_target, newnode); } @@ -385,7 +386,7 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos) for (i = 0; i < numcol; i++) { - ResTarget *col; + ResTarget *col; if (attr[i]->attisdropped) continue; @@ -503,7 +504,7 @@ FigureColnameInternal(Node *node, char **name) { case T_ColumnRef: { - char *cname = strVal(llast(((ColumnRef *) node)->fields)); + char *cname = strVal(llast(((ColumnRef *) node)->fields)); if (strcmp(cname, "*") != 0) { @@ -514,7 +515,7 @@ FigureColnameInternal(Node *node, char **name) break; case T_ExprFieldSelect: { - char *fname = strVal(llast(((ExprFieldSelect *) node)->fields)); + char *fname = strVal(llast(((ExprFieldSelect *) node)->fields)); if (strcmp(fname, "*") != 0) { diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c index e75c193eff..26ae3c2743 100644 --- a/src/backend/parser/parse_type.c +++ b/src/backend/parser/parse_type.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.49 2002/08/31 22:10:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.50 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -112,7 +112,7 @@ LookupTypeName(const TypeName *typename) if (schemaname) { /* Look in specific schema only */ - Oid namespaceId; + Oid namespaceId; namespaceId = LookupExplicitNamespace(schemaname); restype = GetSysCacheOid(TYPENAMENSP, @@ -147,7 +147,7 @@ TypeNameToString(const TypeName *typename) if (typename->names != NIL) { /* Emit possibly-qualified name as-is */ - List *l; + List *l; foreach(l, typename->names) { @@ -218,7 +218,7 @@ typenameType(const TypeName *typename) if (!HeapTupleIsValid(tup)) elog(ERROR, "Type \"%s\" does not exist", TypeNameToString(typename)); - if (! ((Form_pg_type) GETSTRUCT(tup))->typisdefined) + if (!((Form_pg_type) GETSTRUCT(tup))->typisdefined) elog(ERROR, "Type \"%s\" is only a shell", TypeNameToString(typename)); return (Type) tup; @@ -431,7 +431,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod) List *raw_parsetree_list; SelectStmt *stmt; ResTarget *restarget; - TypeCast *typecast; + TypeCast *typecast; TypeName *typename; initStringInfo(&buf); diff --git a/src/backend/parser/parser.c b/src/backend/parser/parser.c index 8c129cb916..c8614b5731 100644 --- a/src/backend/parser/parser.c +++ b/src/backend/parser/parser.c @@ -14,7 +14,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.54 2002/08/27 04:55:11 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.55 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,7 +30,7 @@ List *parsetree; /* result of parsing is left here */ -static Oid *param_type_info; /* state for param_type() */ +static Oid *param_type_info; /* state for param_type() */ static int param_count; static int lookahead_token; /* one-token lookahead */ diff --git a/src/backend/port/dynloader/bsdi.h b/src/backend/port/dynloader/bsdi.h index 79a707a64a..6a76ad01ff 100644 --- a/src/backend/port/dynloader/bsdi.h +++ b/src/backend/port/dynloader/bsdi.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: bsdi.h,v 1.16 2002/06/20 20:29:33 momjian Exp $ + * $Id: bsdi.h,v 1.17 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,7 +46,6 @@ do { \ dld_unlink_by_file(handle, 1); \ free(handle); \ } while (0) - #endif /* not HAVE_DLOPEN */ #endif /* PORT_PROTOS_H */ diff --git a/src/backend/port/ipc_test.c b/src/backend/port/ipc_test.c index 2421a7e5a0..ee1ed186cb 100644 --- a/src/backend/port/ipc_test.c +++ b/src/backend/port/ipc_test.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.4 2002/08/10 20:29:18 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.5 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -52,7 +52,7 @@ int MaxBackends = DEF_MAXBACKENDS; int NBuffers = DEF_NBUFFERS; #ifndef assert_enabled -bool assert_enabled = true; +bool assert_enabled = true; #endif @@ -87,7 +87,7 @@ shmem_exit(int code) } void -on_shmem_exit(void (*function) (), Datum arg) + on_shmem_exit(void (*function) (), Datum arg) { if (on_shmem_exit_index >= MAX_ON_EXITS) elog(FATAL, "Out of on_shmem_exit slots"); @@ -144,17 +144,17 @@ elog(int lev, const char *fmt,...) typedef struct MyStorage { - PGShmemHeader header; - int flag; - PGSemaphoreData sem; -} MyStorage; + PGShmemHeader header; + int flag; + PGSemaphoreData sem; +} MyStorage; int main(int argc, char **argv) { - MyStorage *storage; - int cpid; + MyStorage *storage; + int cpid; printf("Creating shared memory ... "); fflush(stdout); diff --git a/src/backend/port/posix_sema.c b/src/backend/port/posix_sema.c index 207a5fba96..21af7d3ac2 100644 --- a/src/backend/port/posix_sema.c +++ b/src/backend/port/posix_sema.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/posix_sema.c,v 1.5 2002/06/20 20:29:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/posix_sema.c,v 1.6 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -95,15 +95,15 @@ PosixSemaphoreCreate(void) } /* - * Unlink the semaphore immediately, so it can't be accessed externally. - * This also ensures that it will go away if we crash. + * Unlink the semaphore immediately, so it can't be accessed + * externally. This also ensures that it will go away if we crash. */ sem_unlink(semname); return mySem; } -#else /* !USE_NAMED_POSIX_SEMAPHORES */ +#else /* !USE_NAMED_POSIX_SEMAPHORES */ /* * PosixSemaphoreCreate @@ -111,7 +111,7 @@ PosixSemaphoreCreate(void) * Attempt to create a new unnamed semaphore. */ static void -PosixSemaphoreCreate(sem_t *sem) +PosixSemaphoreCreate(sem_t * sem) { if (sem_init(sem, 1, 1) < 0) { @@ -120,15 +120,14 @@ PosixSemaphoreCreate(sem_t *sem) proc_exit(1); } } - -#endif /* USE_NAMED_POSIX_SEMAPHORES */ +#endif /* USE_NAMED_POSIX_SEMAPHORES */ /* * PosixSemaphoreKill - removes a semaphore */ static void -PosixSemaphoreKill(sem_t *sem) +PosixSemaphoreKill(sem_t * sem) { #ifdef USE_NAMED_POSIX_SEMAPHORES /* Got to use sem_close for named semaphores */ @@ -149,7 +148,7 @@ PosixSemaphoreKill(sem_t *sem) * * This is called during postmaster start or shared memory reinitialization. * It should do whatever is needed to be able to support up to maxSemas - * subsequent PGSemaphoreCreate calls. Also, if any system resources + * subsequent PGSemaphoreCreate calls. Also, if any system resources * are acquired here or in PGSemaphoreCreate, register an on_shmem_exit * callback to release them. * @@ -197,7 +196,7 @@ ReleaseSemaphores(int status, Datum arg) void PGSemaphoreCreate(PGSemaphore sema) { - sem_t *newsem; + sem_t *newsem; /* Can't do this in a backend, because static state is postmaster's */ Assert(!IsUnderPostmaster); @@ -260,21 +259,21 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK) * * Each time around the loop, we check for a cancel/die interrupt. We * assume that if such an interrupt comes in while we are waiting, it - * will cause the sem_wait() call to exit with errno == EINTR, so that we - * will be able to service the interrupt (if not in a critical section - * already). + * will cause the sem_wait() call to exit with errno == EINTR, so that + * we will be able to service the interrupt (if not in a critical + * section already). * * Once we acquire the lock, we do NOT check for an interrupt before * returning. The caller needs to be able to record ownership of the * lock before any interrupt can be accepted. * * There is a window of a few instructions between CHECK_FOR_INTERRUPTS - * and entering the sem_wait() call. If a cancel/die interrupt occurs in - * that window, we would fail to notice it until after we acquire the - * lock (or get another interrupt to escape the sem_wait()). We can - * avoid this problem by temporarily setting ImmediateInterruptOK to - * true before we do CHECK_FOR_INTERRUPTS; then, a die() interrupt in - * this interval will execute directly. However, there is a huge + * and entering the sem_wait() call. If a cancel/die interrupt occurs + * in that window, we would fail to notice it until after we acquire + * the lock (or get another interrupt to escape the sem_wait()). We + * can avoid this problem by temporarily setting ImmediateInterruptOK + * to true before we do CHECK_FOR_INTERRUPTS; then, a die() interrupt + * in this interval will execute directly. However, there is a huge * pitfall: there is another window of a few instructions after the * sem_wait() before we are able to reset ImmediateInterruptOK. If an * interrupt occurs then, we'll lose control, which means that the diff --git a/src/backend/port/qnx4/tstsem.c b/src/backend/port/qnx4/tstsem.c index 0d69a76b48..ebc6abe7d0 100644 --- a/src/backend/port/qnx4/tstsem.c +++ b/src/backend/port/qnx4/tstsem.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/tstsem.c,v 1.7 2001/11/11 22:12:00 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/tstsem.c,v 1.8 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,7 +26,7 @@ #define SEMMAX 16 #define OPSMAX 1 -int MaxBackends = SEMMAX; +int MaxBackends = SEMMAX; static int semid; diff --git a/src/backend/port/sysv_sema.c b/src/backend/port/sysv_sema.c index dc34786422..cef6cc0646 100644 --- a/src/backend/port/sysv_sema.c +++ b/src/backend/port/sysv_sema.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/sysv_sema.c,v 1.3 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/sysv_sema.c,v 1.4 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -58,19 +58,20 @@ typedef int IpcSemaphoreId; /* semaphore ID returned by semget(2) */ #define PGSemaMagic 537 /* must be less than SEMVMX */ -static IpcSemaphoreId *mySemaSets; /* IDs of sema sets acquired so far */ +static IpcSemaphoreId *mySemaSets; /* IDs of sema sets acquired so + * far */ static int numSemaSets; /* number of sema sets acquired so far */ static int maxSemaSets; /* allocated size of mySemaSets array */ -static IpcSemaphoreKey nextSemaKey; /* next key to try using */ +static IpcSemaphoreKey nextSemaKey; /* next key to try using */ static int nextSemaNumber; /* next free sem num in last sema set */ static IpcSemaphoreId InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, - int numSems); + int numSems); static void IpcSemaphoreInitialize(IpcSemaphoreId semId, int semNum, - int value); + int value); static void IpcSemaphoreKill(IpcSemaphoreId semId); -static int IpcSemaphoreGetValue(IpcSemaphoreId semId, int semNum); +static int IpcSemaphoreGetValue(IpcSemaphoreId semId, int semNum); static pid_t IpcSemaphoreGetLastPID(IpcSemaphoreId semId, int semNum); static IpcSemaphoreId IpcSemaphoreCreate(int numSems); static void ReleaseSemaphores(int status, Datum arg); @@ -113,7 +114,7 @@ InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems) * Else complain and abort */ fprintf(stderr, "IpcSemaphoreCreate: semget(key=%d, num=%d, 0%o) failed: %s\n", - (int) semKey, numSems, (IPC_CREAT | IPC_EXCL | IPCProtection), + (int) semKey, numSems, (IPC_CREAT | IPC_EXCL | IPCProtection), strerror(errno)); if (errno == ENOSPC) @@ -154,7 +155,7 @@ IpcSemaphoreInitialize(IpcSemaphoreId semId, int semNum, int value) if (errno == ERANGE) fprintf(stderr, "You possibly need to raise your kernel's SEMVMX value to be at least\n" - "%d. Look into the PostgreSQL documentation for details.\n", + "%d. Look into the PostgreSQL documentation for details.\n", value); proc_exit(1); @@ -221,7 +222,7 @@ IpcSemaphoreCreate(int numSems) PGSemaphoreData mysema; /* Loop till we find a free IPC key */ - for (nextSemaKey++; ; nextSemaKey++) + for (nextSemaKey++;; nextSemaKey++) { pid_t creatorPID; @@ -296,12 +297,12 @@ IpcSemaphoreCreate(int numSems) * * This is called during postmaster start or shared memory reinitialization. * It should do whatever is needed to be able to support up to maxSemas - * subsequent PGSemaphoreCreate calls. Also, if any system resources + * subsequent PGSemaphoreCreate calls. Also, if any system resources * are acquired here or in PGSemaphoreCreate, register an on_shmem_exit * callback to release them. * * The port number is passed for possible use as a key (for SysV, we use - * it to generate the starting semaphore key). In a standalone backend, + * it to generate the starting semaphore key). In a standalone backend, * zero will be passed. * * In the SysV implementation, we acquire semaphore sets on-demand; the @@ -311,14 +312,15 @@ IpcSemaphoreCreate(int numSems) void PGReserveSemaphores(int maxSemas, int port) { - maxSemaSets = (maxSemas + SEMAS_PER_SET-1) / SEMAS_PER_SET; + maxSemaSets = (maxSemas + SEMAS_PER_SET - 1) / SEMAS_PER_SET; mySemaSets = (IpcSemaphoreId *) malloc(maxSemaSets * sizeof(IpcSemaphoreId)); if (mySemaSets == NULL) elog(PANIC, "Out of memory in PGReserveSemaphores"); numSemaSets = 0; nextSemaKey = port * 1000; - nextSemaNumber = SEMAS_PER_SET; /* force sema set alloc on 1st call */ + nextSemaNumber = SEMAS_PER_SET; /* force sema set alloc on 1st + * call */ on_shmem_exit(ReleaseSemaphores, 0); } @@ -359,7 +361,7 @@ PGSemaphoreCreate(PGSemaphore sema) nextSemaNumber = 0; } /* Assign the next free semaphore in the current set */ - sema->semId = mySemaSets[numSemaSets-1]; + sema->semId = mySemaSets[numSemaSets - 1]; sema->semNum = nextSemaNumber++; /* Initialize it to count 1 */ IpcSemaphoreInitialize(sema->semId, sema->semNum, 1); diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index aadf3da202..60e5d0b478 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -10,7 +10,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.3 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.4 2002/09/04 20:31:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -88,7 +88,7 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size) * Else complain and abort */ fprintf(stderr, "IpcMemoryCreate: shmget(key=%d, size=%u, 0%o) failed: %s\n", - (int) memKey, size, (IPC_CREAT | IPC_EXCL | IPCProtection), + (int) memKey, size, (IPC_CREAT | IPC_EXCL | IPCProtection), strerror(errno)); if (errno == EINVAL) @@ -147,7 +147,7 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size) /* use intimate shared memory on SPARC Solaris */ memAddress = shmat(shmid, 0, SHM_SHARE_MMU); #else - memAddress = shmat(shmid, 0, 0); + memAddress = shmat(shmid, 0, 0); #endif if (memAddress == (void *) -1) @@ -283,11 +283,11 @@ PrivateMemoryDelete(int status, Datum memaddr) * the storage. * * Dead Postgres segments are recycled if found, but we do not fail upon - * collision with non-Postgres shmem segments. The idea here is to detect and + * collision with non-Postgres shmem segments. The idea here is to detect and * re-use keys that may have been assigned by a crashed postmaster or backend. * * The port number is passed for possible use as a key (for SysV, we use - * it to generate the starting shmem key). In a standalone backend, + * it to generate the starting shmem key). In a standalone backend, * zero will be passed. */ PGShmemHeader * @@ -328,7 +328,7 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port) /* use intimate shared memory on SPARC Solaris */ memAddress = shmat(shmid, 0, SHM_SHARE_MMU); #else - memAddress = shmat(shmid, 0, 0); + memAddress = shmat(shmid, 0, 0); #endif if (memAddress == (void *) -1) diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 9492cb6ee5..4959550867 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -16,7 +16,7 @@ * * Copyright (c) 2001, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.26 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.27 2002/09/04 20:31:24 momjian Exp $ * ---------- */ #include "postgres.h" @@ -431,7 +431,7 @@ pgstat_report_activity(char *what) return; len = strlen(what); - len = pg_mbcliplen((const unsigned char *)what, len, PGSTAT_ACTIVITY_SIZE - 1); + len = pg_mbcliplen((const unsigned char *) what, len, PGSTAT_ACTIVITY_SIZE - 1); memcpy(msg.m_what, what, len); msg.m_what[len] = '\0'; @@ -581,7 +581,7 @@ pgstat_vacuum_tabstat(void) if (msg.m_nentries >= PGSTAT_NUM_TABPURGE) { len = offsetof(PgStat_MsgTabpurge, m_tableid[0]) - + msg.m_nentries * sizeof(Oid); + +msg.m_nentries * sizeof(Oid); pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE); pgstat_send(&msg, len); @@ -596,7 +596,7 @@ pgstat_vacuum_tabstat(void) if (msg.m_nentries > 0) { len = offsetof(PgStat_MsgTabpurge, m_tableid[0]) - + msg.m_nentries * sizeof(Oid); + +msg.m_nentries * sizeof(Oid); pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_TABPURGE); pgstat_send(&msg, len); @@ -1793,7 +1793,7 @@ pgstat_add_backend(PgStat_MsgHdr *msg) if (dbentry->tables == NULL) { elog(LOG, "PGSTAT: failed to initialize hash table for " - "new database entry"); + "new database entry"); exit(1); } } @@ -1918,7 +1918,7 @@ pgstat_write_statsfile(void) HASH_REMOVE, NULL) == NULL) { elog(LOG, "PGSTAT: database hash table corrupted " - "during cleanup - abort"); + "during cleanup - abort"); exit(1); } } @@ -1954,9 +1954,9 @@ pgstat_write_statsfile(void) HASH_REMOVE, NULL) == NULL) { elog(LOG, "PGSTAT: tables hash table for " - "database %d corrupted during " - "cleanup - abort", - dbentry->databaseid); + "database %d corrupted during " + "cleanup - abort", + dbentry->databaseid); exit(1); } } @@ -2029,7 +2029,7 @@ pgstat_write_statsfile(void) HASH_REMOVE, NULL) == NULL) { elog(LOG, "PGSTAT: dead backend hash table corrupted " - "during cleanup - abort"); + "during cleanup - abort"); exit(1); } } @@ -2520,7 +2520,7 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len) if (tabentry == NULL) { elog(LOG, "PGSTAT: tables hash table out of memory for " - "database %d - abort", dbentry->databaseid); + "database %d - abort", dbentry->databaseid); exit(1); } @@ -2700,7 +2700,7 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len) if (dbentry->tables == NULL) { elog(LOG, "PGSTAT: failed to reinitialize hash table for " - "database entry"); + "database entry"); exit(1); } } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 2217fbbe19..85139188b2 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.287 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.288 2002/09/04 20:31:24 momjian Exp $ * * NOTES * @@ -115,6 +115,7 @@ sigset_t UnBlockSig, BlockSig, AuthBlockSig; + #else int UnBlockSig, BlockSig, @@ -218,7 +219,8 @@ static int Shutdown = NoShutdown; static bool FatalError = false; /* T if recovering from backend crash */ -bool ClientAuthInProgress = false; /* T during new-client authentication */ +bool ClientAuthInProgress = false; /* T during new-client + * authentication */ /* * State for assigning random salts and cancel keys. @@ -250,9 +252,9 @@ static void sigusr1_handler(SIGNAL_ARGS); static void dummy_handler(SIGNAL_ARGS); static void CleanupProc(int pid, int exitstatus); static void LogChildExit(int lev, const char *procname, - int pid, int exitstatus); + int pid, int exitstatus); static int DoBackend(Port *port); - void ExitPostmaster(int status); +void ExitPostmaster(int status); static void usage(const char *); static int ServerLoop(void); static int BackendStartup(Port *port); @@ -271,7 +273,7 @@ static void SignalChildren(int signal); static int CountChildren(void); static bool CreateOptsFile(int argc, char *argv[]); static pid_t SSDataBase(int xlop); - void +void postmaster_error(const char *fmt,...) /* This lets gcc check the format string for consistency. */ __attribute__((format(printf, 1, 2))); @@ -281,11 +283,11 @@ __attribute__((format(printf, 1, 2))); #define ShutdownDataBase() SSDataBase(BS_XLOG_SHUTDOWN) #ifdef USE_SSL -extern int secure_initialize(void); +extern int secure_initialize(void); extern void secure_destroy(void); -extern int secure_open_server(Port *); +extern int secure_open_server(Port *); extern void secure_close(Port *); -#endif /* USE_SSL */ +#endif /* USE_SSL */ static void @@ -293,6 +295,7 @@ checkDataDir(const char *checkdir) { char path[MAXPGPATH]; FILE *fp; + #ifndef __CYGWIN__ struct stat stat_buf; #endif @@ -311,9 +314,9 @@ checkDataDir(const char *checkdir) /* * Check if the directory has group or world access. If so, reject. * - * XXX temporarily suppress check when on Windows, because there may - * not be proper support for Unix-y file permissions. Need to think - * of a reasonable check to apply on Windows. + * XXX temporarily suppress check when on Windows, because there may not + * be proper support for Unix-y file permissions. Need to think of a + * reasonable check to apply on Windows. */ #ifndef __CYGWIN__ @@ -329,8 +332,7 @@ checkDataDir(const char *checkdir) if (stat_buf.st_mode & (S_IRWXG | S_IRWXO)) elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)", checkdir); - -#endif /* !__CYGWIN__ */ +#endif /* !__CYGWIN__ */ /* Look for PG_VERSION before looking for pg_control */ ValidatePgVersion(checkdir); @@ -442,15 +444,16 @@ PostmasterMain(int argc, char *argv[]) potential_DataDir = optarg; break; case 'd': - { - /* Turn on debugging for the postmaster. */ - char *debugstr = palloc(strlen("debug") + strlen(optarg) + 1); - sprintf(debugstr, "debug%s", optarg); - SetConfigOption("server_min_messages", debugstr, - PGC_POSTMASTER, PGC_S_ARGV); - pfree(debugstr); - break; - } + { + /* Turn on debugging for the postmaster. */ + char *debugstr = palloc(strlen("debug") + strlen(optarg) + 1); + + sprintf(debugstr, "debug%s", optarg); + SetConfigOption("server_min_messages", debugstr, + PGC_POSTMASTER, PGC_S_ARGV); + pfree(debugstr); + break; + } case 'F': SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV); break; @@ -582,7 +585,7 @@ PostmasterMain(int argc, char *argv[]) * Force an exit if ReservedBackends is not less than MaxBackends. */ if (ReservedBackends >= MaxBackends) - elog(FATAL,"superuser_reserved_connections must be less than max_connections."); + elog(FATAL, "superuser_reserved_connections must be less than max_connections."); /* * Now that we are done processing the postmaster arguments, reset @@ -598,7 +601,7 @@ PostmasterMain(int argc, char *argv[]) extern char **environ; char **p; - elog(DEBUG2, "%s: PostmasterMain: initial environ dump:", progname); + elog(DEBUG2, "%s: PostmasterMain: initial environ dump:", progname); elog(DEBUG2, "-----------------------------------------"); for (p = environ; *p; ++p) elog(DEBUG2, "\t%s", *p); @@ -705,8 +708,8 @@ PostmasterMain(int argc, char *argv[]) /* * Set up signal handlers for the postmaster process. * - * CAUTION: when changing this list, check for side-effects on the - * signal handling setup of child processes. See tcop/postgres.c, + * CAUTION: when changing this list, check for side-effects on the signal + * handling setup of child processes. See tcop/postgres.c, * bootstrap/bootstrap.c, and postmaster/pgstat.c. */ pqinitmask(); @@ -737,8 +740,9 @@ PostmasterMain(int argc, char *argv[]) /* * On many platforms, the first call of localtime() incurs significant * overhead to load timezone info from the system configuration files. - * By doing it once in the postmaster, we avoid having to do it in every - * started child process. The savings are not huge, but they add up... + * By doing it once in the postmaster, we avoid having to do it in + * every started child process. The savings are not huge, but they + * add up... */ { time_t now = time(NULL); @@ -783,6 +787,7 @@ pmdaemonize(int argc, char *argv[]) { int i; pid_t pid; + #ifdef LINUX_PROFILE struct itimerval prof_itimer; #endif @@ -1128,7 +1133,7 @@ ProcessStartupPacket(Port *port, bool SSLdone) #ifdef USE_SSL if (SSLok == 'S' && secure_open_server(port) == -1) - return STATUS_ERROR; + return STATUS_ERROR; #endif /* regular startup packet, cancel, etc packet should follow... */ /* but not another SSL negotiation request */ @@ -1174,20 +1179,21 @@ ProcessStartupPacket(Port *port, bool SSLdone) elog(FATAL, "no PostgreSQL user name specified in startup packet"); if (Db_user_namespace) - { + { /* - * If user@, it is a global user, remove '@'. - * We only want to do this if there is an '@' at the end and no - * earlier in the user string or they may fake as a local user - * of another database attaching to this database. + * If user@, it is a global user, remove '@'. We only want to do + * this if there is an '@' at the end and no earlier in the user + * string or they may fake as a local user of another database + * attaching to this database. */ - if (strchr(port->user, '@') == port->user + strlen(port->user)-1) + if (strchr(port->user, '@') == port->user + strlen(port->user) - 1) *strchr(port->user, '@') = '\0'; else { /* Append '@' and dbname */ - char hold_user[SM_DATABASE_USER+1]; - snprintf(hold_user, SM_DATABASE_USER+1, "%s@%s", port->user, + char hold_user[SM_DATABASE_USER + 1]; + + snprintf(hold_user, SM_DATABASE_USER + 1, "%s@%s", port->user, port->database); strcpy(port->user, hold_user); } @@ -1263,7 +1269,7 @@ processCancelRequest(Port *port, void *pkt) else /* Right PID, wrong key: no way, Jose */ elog(DEBUG1, "bad key in cancel request for process %d", - backendPID); + backendPID); return; } } @@ -1388,8 +1394,8 @@ reset_shared(unsigned short port) * * Note: in each "cycle of life" we will normally assign the same IPC * keys (if using SysV shmem and/or semas), since the port number is - * used to determine IPC keys. This helps ensure that we will clean up - * dead IPC objects if the postmaster crashes and is restarted. + * used to determine IPC keys. This helps ensure that we will clean + * up dead IPC objects if the postmaster crashes and is restarted. */ CreateSharedMemoryAndSemaphores(false, MaxBackends, port); } @@ -1832,6 +1838,7 @@ BackendStartup(Port *port) { Backend *bn; /* for backend cleanup */ pid_t pid; + #ifdef LINUX_PROFILE struct itimerval prof_itimer; #endif @@ -1866,11 +1873,13 @@ BackendStartup(Port *port) fflush(stderr); #ifdef LINUX_PROFILE + /* - * Linux's fork() resets the profiling timer in the child process. - * If we want to profile child processes then we need to save and restore - * the timer setting. This is a waste of time if not profiling, however, - * so only do it if commanded by specific -DLINUX_PROFILE switch. + * Linux's fork() resets the profiling timer in the child process. If + * we want to profile child processes then we need to save and restore + * the timer setting. This is a waste of time if not profiling, + * however, so only do it if commanded by specific -DLINUX_PROFILE + * switch. */ getitimer(ITIMER_PROF, &prof_itimer); #endif @@ -1924,7 +1933,7 @@ BackendStartup(Port *port) /* in parent, normal */ elog(DEBUG1, "BackendStartup: forked pid=%d socket=%d", (int) pid, - port->sock); + port->sock); /* * Everything's been successful, it's safe to add this backend to our @@ -1940,7 +1949,7 @@ BackendStartup(Port *port) /* * Try to report backend fork() failure to client before we close the - * connection. Since we do not care to risk blocking the postmaster on + * connection. Since we do not care to risk blocking the postmaster on * this connection, we set the connection to non-blocking and try only once. * * This is grungy special-purpose code; we cannot use backend libpq since @@ -1950,6 +1959,7 @@ static void report_fork_failure_to_client(Port *port, int errnum) { char buffer[1000]; + #ifdef __BEOS__ int on = 1; #endif @@ -1968,7 +1978,7 @@ report_fork_failure_to_client(Port *port, int errnum) return; #endif - send(port->sock, buffer, strlen(buffer)+1, 0); + send(port->sock, buffer, strlen(buffer) + 1, 0); } @@ -2033,7 +2043,7 @@ DoBackend(Port *port) IsUnderPostmaster = true; /* we are a postmaster subprocess now */ - ClientAuthInProgress = true; /* limit visibility of log messages */ + ClientAuthInProgress = true; /* limit visibility of log messages */ /* We don't want the postmaster's proc_exit() handlers */ on_exit_reset(); @@ -2260,7 +2270,8 @@ DoBackend(Port *port) elog(DEBUG2, "\t%s", av[i]); elog(DEBUG2, ")"); - ClientAuthInProgress = false; /* client_min_messages is active now */ + ClientAuthInProgress = false; /* client_min_messages is active + * now */ return (PostgresMain(ac, av, port->user)); } @@ -2459,6 +2470,7 @@ SSDataBase(int xlop) { pid_t pid; Backend *bn; + #ifdef LINUX_PROFILE struct itimerval prof_itimer; #endif @@ -2647,7 +2659,7 @@ CreateOptsFile(int argc, char *argv[]) /* * This should be used only for reporting "interactive" errors (ie, errors - * during startup. Once the postmaster is launched, use elog. + * during startup. Once the postmaster is launched, use elog. */ void postmaster_error(const char *fmt,...) diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c index 2e2d7c6ab2..71e69dea61 100644 --- a/src/backend/regex/regcomp.c +++ b/src/backend/regex/regcomp.c @@ -51,12 +51,12 @@ struct cclass { - char *name; - char *chars; - char *multis; + char *name; + char *chars; + char *multis; }; -static struct cclass* cclasses = NULL; -static struct cclass* cclass_init(void); +static struct cclass *cclasses = NULL; +static struct cclass *cclass_init(void); /* * parse structure, passed up and down to avoid global variables and @@ -179,8 +179,8 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags) size_t len; pg_wchar *wcp; - if ( cclasses == NULL ) - cclasses = cclass_init(); + if (cclasses == NULL) + cclasses = cclass_init(); #ifdef REDEBUG #define GOODFLAGS(f) (f) @@ -862,7 +862,7 @@ p_b_cclass(struct parse * p, cset *cs) struct cclass *cp; size_t len; char *u; - unsigned char c; + unsigned char c; while (MORE() && pg_isalpha(PEEK())) NEXT(); @@ -1684,77 +1684,105 @@ pg_ispunct(int c) static struct cclass * cclass_init(void) { - static struct cclass cclasses_C[] = { - { "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "" }, - { "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "" }, - { "blank", " \t", "" }, - { "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37\177", "" }, - { "digit", "0123456789", "" }, - { "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "" }, - { "lower", "abcdefghijklmnopqrstuvwxyz", "" }, - { "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", "" }, - { "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "" }, - { "space", "\t\n\v\f\r ", "" }, - { "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "" }, - { "xdigit", "0123456789ABCDEFabcdef", "" }, - { NULL, NULL, "" } - }; - struct cclass *cp = NULL; - struct cclass *classes = NULL; - struct cclass_factory - { - char *name; - int (*func)(int); - char *chars; - } cclass_factories [] = - { - { "alnum", pg_isalnum, NULL }, - { "alpha", pg_isalpha, NULL }, - { "blank", NULL, " \t" }, - { "cntrl", pg_iscntrl, NULL }, - { "digit", NULL, "0123456789" }, - { "graph", pg_isgraph, NULL }, - { "lower", pg_islower, NULL }, - { "print", pg_isprint, NULL }, - { "punct", pg_ispunct, NULL }, - { "space", NULL, "\t\n\v\f\r " }, - { "upper", pg_isupper, NULL }, - { "xdigit", NULL, "0123456789ABCDEFabcdef" }, - { NULL, NULL, NULL } - }; - struct cclass_factory *cf = NULL; - - if ( strcmp( setlocale( LC_CTYPE, NULL ), "C" ) == 0 ) - return cclasses_C; - - classes = malloc(sizeof(struct cclass) * (sizeof(cclass_factories) / sizeof(struct cclass_factory))); - if (classes == NULL) - elog(ERROR,"cclass_init: out of memory"); - - cp = classes; - for(cf = cclass_factories; cf->name != NULL; cf++) - { - cp->name = strdup(cf->name); - if ( cf->chars ) - cp->chars = strdup(cf->chars); - else - { - int x = 0, y = 0; - cp->chars = malloc(sizeof(char) * 256); - if (cp->chars == NULL) - elog(ERROR,"cclass_init: out of memory"); - for (x = 0; x < 256; x++) - { - if((cf->func)(x)) - *(cp->chars + y++) = x; - } - *(cp->chars + y) = '\0'; - } - cp->multis = ""; - cp++; - } - cp->name = cp->chars = NULL; - cp->multis = ""; - - return classes; + static struct cclass cclasses_C[] = { + {"alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", ""}, + {"alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", ""}, + {"blank", " \t", ""}, + {"cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37\177", ""}, + {"digit", "0123456789", ""}, + {"graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", ""}, + {"lower", "abcdefghijklmnopqrstuvwxyz", ""}, + {"print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", ""}, + {"punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", ""}, + {"space", "\t\n\v\f\r ", ""}, + {"upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", ""}, + {"xdigit", "0123456789ABCDEFabcdef", ""}, + {NULL, NULL, ""} + }; + struct cclass *cp = NULL; + struct cclass *classes = NULL; + struct cclass_factory + { + char *name; + int (*func) (int); + char *chars; + } cclass_factories[] = + { + { + "alnum", pg_isalnum, NULL + }, + { + "alpha", pg_isalpha, NULL + }, + { + "blank", NULL, " \t" + }, + { + "cntrl", pg_iscntrl, NULL + }, + { + "digit", NULL, "0123456789" + }, + { + "graph", pg_isgraph, NULL + }, + { + "lower", pg_islower, NULL + }, + { + "print", pg_isprint, NULL + }, + { + "punct", pg_ispunct, NULL + }, + { + "space", NULL, "\t\n\v\f\r " + }, + { + "upper", pg_isupper, NULL + }, + { + "xdigit", NULL, "0123456789ABCDEFabcdef" + }, + { + NULL, NULL, NULL + } + }; + struct cclass_factory *cf = NULL; + + if (strcmp(setlocale(LC_CTYPE, NULL), "C") == 0) + return cclasses_C; + + classes = malloc(sizeof(struct cclass) * (sizeof(cclass_factories) / sizeof(struct cclass_factory))); + if (classes == NULL) + elog(ERROR, "cclass_init: out of memory"); + + cp = classes; + for (cf = cclass_factories; cf->name != NULL; cf++) + { + cp->name = strdup(cf->name); + if (cf->chars) + cp->chars = strdup(cf->chars); + else + { + int x = 0, + y = 0; + + cp->chars = malloc(sizeof(char) * 256); + if (cp->chars == NULL) + elog(ERROR, "cclass_init: out of memory"); + for (x = 0; x < 256; x++) + { + if ((cf->func) (x)) + *(cp->chars + y++) = x; + } + *(cp->chars + y) = '\0'; + } + cp->multis = ""; + cp++; + } + cp->name = cp->chars = NULL; + cp->multis = ""; + + return classes; } diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c index f276189426..2aa4fdd892 100644 --- a/src/backend/rewrite/rewriteDefine.c +++ b/src/backend/rewrite/rewriteDefine.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.78 2002/09/02 02:13:01 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.79 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -62,8 +62,8 @@ InsertRule(char *rulname, HeapTuple tup, oldtup; Oid rewriteObjectId; - ObjectAddress myself, - referenced; + ObjectAddress myself, + referenced; bool is_update = false; /* @@ -73,13 +73,13 @@ InsertRule(char *rulname, i = 0; namestrcpy(&rname, rulname); - values[i++] = NameGetDatum(&rname); /* rulename */ - values[i++] = ObjectIdGetDatum(eventrel_oid); /* ev_class */ - values[i++] = Int16GetDatum(evslot_index); /* ev_attr */ - values[i++] = CharGetDatum(evtype + '0'); /* ev_type */ - values[i++] = BoolGetDatum(evinstead); /* is_instead */ - values[i++] = DirectFunctionCall1(textin, CStringGetDatum(evqual)); /* ev_qual */ - values[i++] = DirectFunctionCall1(textin, CStringGetDatum(actiontree)); /* ev_action */ + values[i++] = NameGetDatum(&rname); /* rulename */ + values[i++] = ObjectIdGetDatum(eventrel_oid); /* ev_class */ + values[i++] = Int16GetDatum(evslot_index); /* ev_attr */ + values[i++] = CharGetDatum(evtype + '0'); /* ev_type */ + values[i++] = BoolGetDatum(evinstead); /* is_instead */ + values[i++] = DirectFunctionCall1(textin, CStringGetDatum(evqual)); /* ev_qual */ + values[i++] = DirectFunctionCall1(textin, CStringGetDatum(actiontree)); /* ev_action */ /* * Ready to store new pg_rewrite tuple @@ -97,7 +97,7 @@ InsertRule(char *rulname, if (HeapTupleIsValid(oldtup)) { if (!replace) - elog(ERROR,"Attempt to insert rule \"%s\" failed: already exists", + elog(ERROR, "Attempt to insert rule \"%s\" failed: already exists", rulname); /* @@ -138,8 +138,8 @@ InsertRule(char *rulname, rewriteObjectId); /* - * Install dependency on rule's relation to ensure it will go away - * on relation deletion. If the rule is ON SELECT, make the dependency + * Install dependency on rule's relation to ensure it will go away on + * relation deletion. If the rule is ON SELECT, make the dependency * implicit --- this prevents deleting a view's SELECT rule. Other * kinds of rules can be AUTO. */ @@ -152,7 +152,7 @@ InsertRule(char *rulname, referenced.objectSubId = 0; recordDependencyOn(&myself, &referenced, - (evtype == CMD_SELECT) ? DEPENDENCY_INTERNAL : DEPENDENCY_AUTO); + (evtype == CMD_SELECT) ? DEPENDENCY_INTERNAL : DEPENDENCY_AUTO); /* * Also install dependencies on objects referenced in action and qual. @@ -163,7 +163,7 @@ InsertRule(char *rulname, if (event_qual != NULL) { /* Find query containing OLD/NEW rtable entries */ - Query *qry = (Query *) lfirst(action); + Query *qry = (Query *) lfirst(action); qry = getInsertSelectQuery(qry, NULL); recordDependencyOnExpr(&myself, event_qual, qry->rtable, @@ -272,7 +272,7 @@ DefineQueryRewrite(RuleStmt *stmt) * event relation, ... */ i = 0; - foreach (tllist, query->targetList) + foreach(tllist, query->targetList) { TargetEntry *tle = (TargetEntry *) lfirst(tllist); Resdom *resdom = tle->resdom; @@ -289,11 +289,12 @@ DefineQueryRewrite(RuleStmt *stmt) attname = NameStr(attr->attname); /* - * Disallow dropped columns in the relation. This won't happen - * in the cases we actually care about (namely creating a view - * via CREATE TABLE then CREATE RULE). Trying to cope with it - * is much more trouble than it's worth, because we'd have to - * modify the rule to insert dummy NULLs at the right positions. + * Disallow dropped columns in the relation. This won't + * happen in the cases we actually care about (namely creating + * a view via CREATE TABLE then CREATE RULE). Trying to cope + * with it is much more trouble than it's worth, because we'd + * have to modify the rule to insert dummy NULLs at the right + * positions. */ if (attr->attisdropped) elog(ERROR, "cannot convert relation containing dropped columns to view"); @@ -343,11 +344,11 @@ DefineQueryRewrite(RuleStmt *stmt) /* * In versions before 7.3, the expected name was _RETviewname. * For backwards compatibility with old pg_dump output, accept - * that and silently change it to _RETURN. Since this is just + * that and silently change it to _RETURN. Since this is just * a quick backwards-compatibility hack, limit the number of * characters checked to a few less than NAMEDATALEN; this - * saves having to worry about where a multibyte character might - * have gotten truncated. + * saves having to worry about where a multibyte character + * might have gotten truncated. */ if (strncmp(stmt->rulename, "_RET", 4) != 0 || strncmp(stmt->rulename + 4, event_obj->relname, diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index b183f85f08..d434e9e2fb 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.107 2002/08/29 06:05:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.108 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -42,7 +42,7 @@ static Query *rewriteRuleAction(Query *parsetree, static List *adjustJoinTreeList(Query *parsetree, bool removert, int rt_index); static void rewriteTargetList(Query *parsetree, Relation target_relation); static TargetEntry *process_matched_tle(TargetEntry *src_tle, - TargetEntry *prior_tle); + TargetEntry *prior_tle); static void markQueryForUpdate(Query *qry, bool skipOldNew); static List *matchLocks(CmdType event, RuleLock *rulelocks, int varno, Query *parsetree); @@ -239,7 +239,7 @@ adjustJoinTreeList(Query *parsetree, bool removert, int rt_index) * then junk fields (these in no particular order). * * We must do items 1 and 2 before firing rewrite rules, else rewritten - * references to NEW.foo will produce wrong or incomplete results. Item 3 + * references to NEW.foo will produce wrong or incomplete results. Item 3 * is not needed for rewriting, but will be needed by the planner, and we * can do it essentially for free while handling items 1 and 2. */ @@ -261,7 +261,7 @@ rewriteTargetList(Query *parsetree, Relation target_relation) for (attrno = 1; attrno <= numattrs; attrno++) { - Form_pg_attribute att_tup = target_relation->rd_att->attrs[attrno-1]; + Form_pg_attribute att_tup = target_relation->rd_att->attrs[attrno - 1]; TargetEntry *new_tle = NULL; /* We can ignore deleted attributes */ @@ -269,7 +269,7 @@ rewriteTargetList(Query *parsetree, Relation target_relation) continue; /* - * Look for targetlist entries matching this attr. We match by + * Look for targetlist entries matching this attr. We match by * resno, but the resname should match too. * * Junk attributes are not candidates to be matched. @@ -291,9 +291,9 @@ rewriteTargetList(Query *parsetree, Relation target_relation) if (new_tle == NULL && commandType == CMD_INSERT) { /* - * Didn't find a matching tlist entry; if it's an INSERT, - * look for a default value, and add a tlist entry computing - * the default if we find one. + * Didn't find a matching tlist entry; if it's an INSERT, look + * for a default value, and add a tlist entry computing the + * default if we find one. */ Node *new_expr; @@ -303,7 +303,7 @@ rewriteTargetList(Query *parsetree, Relation target_relation) new_tle = makeTargetEntry(makeResdom(attrno, att_tup->atttypid, att_tup->atttypmod, - pstrdup(NameStr(att_tup->attname)), + pstrdup(NameStr(att_tup->attname)), false), new_expr); } @@ -448,30 +448,28 @@ build_column_default(Relation rel, int attrno) if (expr == NULL) { /* - * No per-column default, so look for a default for the type itself. + * No per-column default, so look for a default for the type + * itself. */ if (att_tup->attisset) { /* - * Set attributes are represented as OIDs no matter what the set - * element type is, and the element type's default is irrelevant - * too. + * Set attributes are represented as OIDs no matter what the + * set element type is, and the element type's default is + * irrelevant too. */ } else - { expr = get_typdefault(atttype); - } } if (expr == NULL) return NULL; /* No default anywhere */ /* - * Make sure the value is coerced to the target column - * type (might not be right type yet if it's not a - * constant!) This should match the parser's processing of - * non-defaulted expressions --- see + * Make sure the value is coerced to the target column type (might not + * be right type yet if it's not a constant!) This should match the + * parser's processing of non-defaulted expressions --- see * updateTargetListEntry(). */ exprtype = exprType(expr); @@ -482,8 +480,8 @@ build_column_default(Relation rel, int attrno) atttype, atttypmod, false); /* - * This really shouldn't fail; should have checked the - * default's type when it was created ... + * This really shouldn't fail; should have checked the default's + * type when it was created ... */ if (expr == NULL) elog(ERROR, "Column \"%s\" is of type %s" @@ -495,8 +493,8 @@ build_column_default(Relation rel, int attrno) } /* - * If the column is a fixed-length type, it may need a - * length coercion as well as a type coercion. + * If the column is a fixed-length type, it may need a length coercion + * as well as a type coercion. */ expr = coerce_type_typmod(NULL, expr, atttype, atttypmod); diff --git a/src/backend/rewrite/rewriteManip.c b/src/backend/rewrite/rewriteManip.c index 87fe1c9526..16eef1bfb8 100644 --- a/src/backend/rewrite/rewriteManip.c +++ b/src/backend/rewrite/rewriteManip.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.64 2002/06/20 20:29:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteManip.c,v 1.65 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -142,7 +142,7 @@ OffsetVarNodes_walker(Node *node, OffsetVarNodes_context *context) } if (IsA(node, JoinExpr)) { - JoinExpr *j = (JoinExpr *) node; + JoinExpr *j = (JoinExpr *) node; if (context->sublevels_up == 0) j->rtindex += context->offset; @@ -251,7 +251,7 @@ ChangeVarNodes_walker(Node *node, ChangeVarNodes_context *context) } if (IsA(node, JoinExpr)) { - JoinExpr *j = (JoinExpr *) node; + JoinExpr *j = (JoinExpr *) node; if (context->sublevels_up == 0 && j->rtindex == context->rt_index) @@ -429,7 +429,7 @@ rangeTableEntry_used_walker(Node *node, } if (IsA(node, JoinExpr)) { - JoinExpr *j = (JoinExpr *) node; + JoinExpr *j = (JoinExpr *) node; if (j->rtindex == context->rt_index && context->sublevels_up == 0) @@ -573,10 +573,10 @@ getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr) * they've been pushed down to the SELECT. */ if (length(parsetree->rtable) >= 2 && - strcmp(rt_fetch(PRS2_OLD_VARNO, parsetree->rtable)->eref->aliasname, - "*OLD*") == 0 && - strcmp(rt_fetch(PRS2_NEW_VARNO, parsetree->rtable)->eref->aliasname, - "*NEW*") == 0) + strcmp(rt_fetch(PRS2_OLD_VARNO, parsetree->rtable)->eref->aliasname, + "*OLD*") == 0 && + strcmp(rt_fetch(PRS2_NEW_VARNO, parsetree->rtable)->eref->aliasname, + "*NEW*") == 0) return parsetree; Assert(parsetree->jointree && IsA(parsetree->jointree, FromExpr)); if (length(parsetree->jointree->fromlist) != 1) @@ -589,10 +589,10 @@ getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr) selectquery->commandType == CMD_SELECT)) elog(ERROR, "getInsertSelectQuery: expected to find SELECT subquery"); if (length(selectquery->rtable) >= 2 && - strcmp(rt_fetch(PRS2_OLD_VARNO, selectquery->rtable)->eref->aliasname, - "*OLD*") == 0 && - strcmp(rt_fetch(PRS2_NEW_VARNO, selectquery->rtable)->eref->aliasname, - "*NEW*") == 0) + strcmp(rt_fetch(PRS2_OLD_VARNO, selectquery->rtable)->eref->aliasname, + "*OLD*") == 0 && + strcmp(rt_fetch(PRS2_NEW_VARNO, selectquery->rtable)->eref->aliasname, + "*NEW*") == 0) { if (subquery_ptr) *subquery_ptr = &(selectrte->subquery); diff --git a/src/backend/rewrite/rewriteRemove.c b/src/backend/rewrite/rewriteRemove.c index 1fd5f36ce5..deb46128ca 100644 --- a/src/backend/rewrite/rewriteRemove.c +++ b/src/backend/rewrite/rewriteRemove.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.52 2002/07/20 05:16:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.53 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -85,8 +85,8 @@ void RemoveRewriteRuleById(Oid ruleOid) { Relation RewriteRelation; - ScanKeyData skey[1]; - SysScanDesc rcscan; + ScanKeyData skey[1]; + SysScanDesc rcscan; Relation event_relation; HeapTuple tuple; Oid eventRelationOid; diff --git a/src/backend/storage/buffer/buf_init.c b/src/backend/storage/buffer/buf_init.c index 5e6650dc96..dd6478c195 100644 --- a/src/backend/storage/buffer/buf_init.c +++ b/src/backend/storage/buffer/buf_init.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.51 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_init.c,v 1.52 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -231,6 +231,7 @@ InitBufferPoolAccess(void) BufferBlockPointers = (Block *) calloc(NBuffers, sizeof(Block)); PrivateRefCount = (long *) calloc(NBuffers, sizeof(long)); BufferLocks = (bits8 *) calloc(NBuffers, sizeof(bits8)); + /* * Convert shmem offsets into addresses as seen by this process. This * is just to speed up the BufferGetBlock() macro. diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index bea4854bb7..b6c9112030 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.131 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.132 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -75,6 +75,7 @@ static Buffer ReadBufferInternal(Relation reln, BlockNumber blockNum, static BufferDesc *BufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr); static int BufferReplace(BufferDesc *bufHdr); + #ifdef NOT_USED void PrintBufferDescs(void); #endif @@ -552,7 +553,7 @@ BufferAlloc(Relation reln, /* * write_buffer -- common functionality for - * WriteBuffer and WriteNoReleaseBuffer + * WriteBuffer and WriteNoReleaseBuffer */ static void write_buffer(Buffer buffer, bool release) @@ -870,14 +871,14 @@ ShowBufferUsage(void) localhitrate = (float) LocalBufferHitCount *100.0 / ReadLocalBufferCount; appendStringInfo(&str, - "!\tShared blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n", + "!\tShared blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n", ReadBufferCount - BufferHitCount, BufferFlushCount, hitrate); appendStringInfo(&str, - "!\tLocal blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n", - ReadLocalBufferCount - LocalBufferHitCount, LocalBufferFlushCount, localhitrate); + "!\tLocal blocks: %10ld read, %10ld written, buffer hit rate = %.2f%%\n", + ReadLocalBufferCount - LocalBufferHitCount, LocalBufferFlushCount, localhitrate); appendStringInfo(&str, - "!\tDirect blocks: %10ld read, %10ld written\n", - NDirectFileRead, NDirectFileWrite); + "!\tDirect blocks: %10ld read, %10ld written\n", + NDirectFileRead, NDirectFileWrite); return str.data; } @@ -917,7 +918,7 @@ AtEOXact_Buffers(bool isCommit) if (isCommit) elog(WARNING, "Buffer Leak: [%03d] (freeNext=%d, freePrev=%d, " - "rel=%u/%u, blockNum=%u, flags=0x%x, refcount=%d %ld)", + "rel=%u/%u, blockNum=%u, flags=0x%x, refcount=%d %ld)", i, buf->freeNext, buf->freePrev, buf->tag.rnode.tblNode, buf->tag.rnode.relNode, buf->tag.blockNum, buf->flags, diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c index 50168c8b30..5f4033b583 100644 --- a/src/backend/storage/buffer/localbuf.c +++ b/src/backend/storage/buffer/localbuf.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.45 2002/08/06 02:36:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.46 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -83,8 +83,8 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) elog(ERROR, "no empty local buffer."); /* - * this buffer is not referenced but it might still be dirty. - * if that's the case, write it out before reusing it! + * this buffer is not referenced but it might still be dirty. if + * that's the case, write it out before reusing it! */ if (bufHdr->flags & BM_DIRTY || bufHdr->cntxDirty) { @@ -108,9 +108,9 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr) /* * lazy memory allocation: allocate space on first use of a buffer. * - * Note this path cannot be taken for a buffer that was previously - * in use, so it's okay to do it (and possibly error out) before - * marking the buffer as valid. + * Note this path cannot be taken for a buffer that was previously in + * use, so it's okay to do it (and possibly error out) before marking + * the buffer as valid. */ if (bufHdr->data == (SHMEM_OFFSET) 0) { diff --git a/src/backend/storage/freespace/freespace.c b/src/backend/storage/freespace/freespace.c index 2c0eb3ced8..7dc91a4e80 100644 --- a/src/backend/storage/freespace/freespace.c +++ b/src/backend/storage/freespace/freespace.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v 1.12 2002/06/20 20:29:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v 1.13 2002/09/04 20:31:25 momjian Exp $ * * * NOTES: @@ -850,7 +850,7 @@ insert_fsm_page_entry(FSMRelation *fsmrel, BlockNumber page, Size spaceAvail, FSMChunk *newChunk; if ((newChunk = FreeSpaceMap->freeChunks) == NULL) - return false; /* can't do it */ + return false; /* can't do it */ FreeSpaceMap->freeChunks = newChunk->next; FreeSpaceMap->numFreeChunks--; newChunk->next = NULL; @@ -874,21 +874,25 @@ insert_fsm_page_entry(FSMRelation *fsmrel, BlockNumber page, Size spaceAvail, } } - /* Try to insert it the easy way, ie, just move down subsequent data */ + /* + * Try to insert it the easy way, ie, just move down subsequent + * data + */ if (chunk && push_fsm_page_entry(page, spaceAvail, chunk, chunkRelIndex)) { fsmrel->numPages++; - fsmrel->nextPage++; /* don't return same page twice running */ + fsmrel->nextPage++; /* don't return same page twice running */ return true; } /* - * There is space available, but evidently it's before the place where - * the page entry needs to go. Compact the list and try again. This - * will require us to redo the search for the appropriate place. - * Furthermore, compact_fsm_page_list deletes empty end chunks, so - * we may need to repeat the action of grabbing a new end chunk. + * There is space available, but evidently it's before the place + * where the page entry needs to go. Compact the list and try + * again. This will require us to redo the search for the + * appropriate place. Furthermore, compact_fsm_page_list deletes + * empty end chunks, so we may need to repeat the action of + * grabbing a new end chunk. */ compact_fsm_page_list(fsmrel); if (lookup_fsm_page_entry(fsmrel, page, &chunk, &chunkRelIndex)) diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c index e71bb0c17a..989ee1bcb6 100644 --- a/src/backend/storage/ipc/ipc.c +++ b/src/backend/storage/ipc/ipc.c @@ -4,7 +4,7 @@ * POSTGRES inter-process communication definitions. * * This file is misnamed, as it no longer has much of anything directly - * to do with IPC. The functionality here is concerned with managing + * to do with IPC. The functionality here is concerned with managing * exit-time cleanup for either a postmaster or a backend. * * @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.80 2002/06/20 20:29:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.81 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 70dfb83375..ff9a83a684 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.66 2002/06/20 20:29:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.67 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -133,6 +133,7 @@ ShmemAlloc(Size size) { uint32 newFree; void *newSpace; + /* use volatile pointer to prevent code rearrangement */ volatile PGShmemHeader *shmemseghdr = ShmemSegHdr; diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c index a328ea4830..87f7a29245 100644 --- a/src/backend/storage/ipc/sinval.c +++ b/src/backend/storage/ipc/sinval.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.51 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.52 2002/09/04 20:31:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -96,7 +96,8 @@ ReceiveSharedInvalidMessages( * The routines later in this file that use shared mode are okay with * this, because they aren't looking at the ProcState fields * associated with SI message transfer; they only use the - * ProcState array as an easy way to find all the PGPROC structures. + * ProcState array as an easy way to find all the PGPROC + * structures. */ LWLockAcquire(SInvalLock, LW_SHARED); getResult = SIGetDataEntry(shmInvalBuffer, MyBackendId, &data); @@ -380,9 +381,9 @@ GetSnapshotData(bool serializable) * running a transaction, and xacts started since we read the * next transaction ID. There's no need to store XIDs above * what we got from ReadNewTransactionId, since we'll treat - * them as running anyway. We also assume that such xacts can't - * compute an xmin older than ours, so they needn't be considered - * in computing globalxmin. + * them as running anyway. We also assume that such xacts + * can't compute an xmin older than ours, so they needn't be + * considered in computing globalxmin. */ if (proc == MyProc || !TransactionIdIsNormal(xid) || @@ -411,9 +412,9 @@ GetSnapshotData(bool serializable) Assert(TransactionIdIsValid(MyProc->xmin)); /* - * Update globalxmin to include actual process xids. This is a slightly - * different way of computing it than GetOldestXmin uses, but should give - * the same result. + * Update globalxmin to include actual process xids. This is a + * slightly different way of computing it than GetOldestXmin uses, but + * should give the same result. */ if (TransactionIdPrecedes(xmin, globalxmin)) globalxmin = xmin; @@ -551,7 +552,7 @@ BackendIdGetProc(BackendId procId) int CountEmptyBackendSlots(void) { - int count; + int count; LWLockAcquire(SInvalLock, LW_SHARED); diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c index cf6838cbb6..155b1a42ea 100644 --- a/src/backend/storage/lmgr/deadlock.c +++ b/src/backend/storage/lmgr/deadlock.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.12 2002/07/19 00:17:40 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/deadlock.c,v 1.13 2002/09/04 20:31:25 momjian Exp $ * * Interface: * @@ -66,7 +66,7 @@ static void PrintLockQueue(LOCK *lock, const char *info); */ /* Workspace for FindLockCycle */ -static PGPROC **visitedProcs; /* Array of visited procs */ +static PGPROC **visitedProcs; /* Array of visited procs */ static int nVisitedProcs; /* Workspace for TopoSort */ @@ -77,7 +77,7 @@ static int *afterConstraints; /* List head for after-constraints */ /* Output area for ExpandConstraints */ static WAIT_ORDER *waitOrders; /* Array of proposed queue rearrangements */ static int nWaitOrders; -static PGPROC **waitOrderProcs; /* Space for waitOrders queue contents */ +static PGPROC **waitOrderProcs; /* Space for waitOrders queue contents */ /* Current list of constraints being considered */ static EDGE *curConstraints; @@ -377,7 +377,7 @@ FindLockCycleRecurse(PGPROC *checkProc, { PGPROC *proc; LOCK *lock; - PROCLOCK *holder; + PROCLOCK *holder; SHM_QUEUE *lockHolders; LOCKMETHODTABLE *lockMethodTable; PROC_QUEUE *waitQueue; @@ -428,7 +428,7 @@ FindLockCycleRecurse(PGPROC *checkProc, lockHolders = &(lock->lockHolders); holder = (PROCLOCK *) SHMQueueNext(lockHolders, lockHolders, - offsetof(PROCLOCK, lockLink)); + offsetof(PROCLOCK, lockLink)); while (holder) { @@ -452,7 +452,7 @@ FindLockCycleRecurse(PGPROC *checkProc, } holder = (PROCLOCK *) SHMQueueNext(lockHolders, &holder->lockLink, - offsetof(PROCLOCK, lockLink)); + offsetof(PROCLOCK, lockLink)); } /* diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index fd300a4c9e..03d16d60ae 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.114 2002/09/02 02:47:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.115 2002/09/04 20:31:25 momjian Exp $ * * NOTES * Outside modules can create a lock table and acquire/release @@ -127,9 +127,9 @@ inline static void PROCLOCK_PRINT(const char *where, const PROCLOCK *holderP) { if ( - (((PROCLOCK_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks) - || (PROCLOCK_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks)) - && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin)) + (((PROCLOCK_LOCKMETHOD(*holderP) == DEFAULT_LOCKMETHOD && Trace_locks) + || (PROCLOCK_LOCKMETHOD(*holderP) == USER_LOCKMETHOD && Trace_userlocks)) + && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId >= (Oid) Trace_lock_oidmin)) || (Trace_lock_table && (((LOCK *) MAKE_PTR(holderP->tag.lock))->tag.relId == Trace_lock_table)) ) elog(LOG, @@ -310,7 +310,7 @@ LockMethodTableInit(char *tabName, Assert(lockMethodTable->lockHash->hash == tag_hash); /* - * allocate a hash table for PROCLOCK structs. This is used to store + * allocate a hash table for PROCLOCK structs. This is used to store * per-lock-holder information. */ info.keysize = sizeof(PROCLOCKTAG); @@ -434,8 +434,8 @@ bool LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, TransactionId xid, LOCKMODE lockmode, bool dontWait) { - PROCLOCK *holder; - PROCLOCKTAG holdertag; + PROCLOCK *holder; + PROCLOCKTAG holdertag; HTAB *holderTable; bool found; LOCK *lock; @@ -507,7 +507,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, /* * Create the hash key for the holder table. */ - MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding, + MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding, * needed */ holdertag.lock = MAKE_OFFSET(lock); holdertag.proc = MAKE_OFFSET(MyProc); @@ -518,8 +518,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, */ holderTable = lockMethodTable->holderHash; holder = (PROCLOCK *) hash_search(holderTable, - (void *) &holdertag, - HASH_ENTER, &found); + (void *) &holdertag, + HASH_ENTER, &found); if (!holder) { LWLockRelease(masterLock); @@ -645,8 +645,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag, SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&holder->procLink); holder = (PROCLOCK *) hash_search(holderTable, - (void *) holder, - HASH_REMOVE, NULL); + (void *) holder, + HASH_REMOVE, NULL); if (!holder) elog(WARNING, "LockAcquire: remove holder, table corrupted"); } @@ -808,13 +808,13 @@ static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, int *myHolding) { SHM_QUEUE *procHolders = &(proc->procHolders); - PROCLOCK *holder; + PROCLOCK *holder; int i; MemSet(myHolding, 0, MAX_LOCKMODES * sizeof(int)); holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders, - offsetof(PROCLOCK, procLink)); + offsetof(PROCLOCK, procLink)); while (holder) { @@ -825,7 +825,7 @@ LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, int *myHolding) } holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink, - offsetof(PROCLOCK, procLink)); + offsetof(PROCLOCK, procLink)); } } @@ -978,8 +978,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, LOCK *lock; LWLockId masterLock; LOCKMETHODTABLE *lockMethodTable; - PROCLOCK *holder; - PROCLOCKTAG holdertag; + PROCLOCK *holder; + PROCLOCKTAG holdertag; HTAB *holderTable; bool wakeupNeeded = false; @@ -1025,7 +1025,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, /* * Find the holder entry for this holder. */ - MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding, + MemSet(&holdertag, 0, sizeof(PROCLOCKTAG)); /* must clear padding, * needed */ holdertag.lock = MAKE_OFFSET(lock); holdertag.proc = MAKE_OFFSET(MyProc); @@ -1033,8 +1033,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, holderTable = lockMethodTable->holderHash; holder = (PROCLOCK *) hash_search(holderTable, - (void *) &holdertag, - HASH_FIND_SAVE, NULL); + (void *) &holdertag, + HASH_FIND_SAVE, NULL); if (!holder) { LWLockRelease(masterLock); @@ -1135,8 +1135,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag, SHMQueueDelete(&holder->lockLink); SHMQueueDelete(&holder->procLink); holder = (PROCLOCK *) hash_search(holderTable, - (void *) &holder, - HASH_REMOVE_SAVED, NULL); + (void *) &holder, + HASH_REMOVE_SAVED, NULL); if (!holder) { LWLockRelease(masterLock); @@ -1171,8 +1171,8 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, bool allxids, TransactionId xid) { SHM_QUEUE *procHolders = &(proc->procHolders); - PROCLOCK *holder; - PROCLOCK *nextHolder; + PROCLOCK *holder; + PROCLOCK *nextHolder; LWLockId masterLock; LOCKMETHODTABLE *lockMethodTable; int i, @@ -1199,7 +1199,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, LWLockAcquire(masterLock, LW_EXCLUSIVE); holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders, - offsetof(PROCLOCK, procLink)); + offsetof(PROCLOCK, procLink)); while (holder) { @@ -1207,7 +1207,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, /* Get link first, since we may unlink/delete this holder */ nextHolder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink, - offsetof(PROCLOCK, procLink)); + offsetof(PROCLOCK, procLink)); Assert(holder->tag.proc == MAKE_OFFSET(proc)); @@ -1249,7 +1249,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, * Read comments in LockRelease */ if (!wakeupNeeded && - lockMethodTable->conflictTab[i] & lock->waitMask) + lockMethodTable->conflictTab[i] & lock->waitMask) wakeupNeeded = true; } } @@ -1287,9 +1287,9 @@ LockReleaseAll(LOCKMETHOD lockmethod, PGPROC *proc, * remove the holder entry from the hashtable */ holder = (PROCLOCK *) hash_search(lockMethodTable->holderHash, - (void *) holder, - HASH_REMOVE, - NULL); + (void *) holder, + HASH_REMOVE, + NULL); if (!holder) { LWLockRelease(masterLock); @@ -1340,8 +1340,7 @@ LockShmemSize(int maxBackends) size += MAXALIGN(sizeof(PROC_HDR)); /* ProcGlobal */ size += maxBackends * MAXALIGN(sizeof(PGPROC)); /* each MyProc */ - size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LOCKMETHODTABLE)); /* each - * lockMethodTable */ + size += MAX_LOCK_METHODS * MAXALIGN(sizeof(LOCKMETHODTABLE)); /* each lockMethodTable */ /* lockHash table */ size += hash_estimate_size(max_table_size, sizeof(LOCK)); @@ -1375,11 +1374,11 @@ LockShmemSize(int maxBackends) LockData * GetLockStatusData(void) { - LockData *data; - HTAB *holderTable; - PROCLOCK *holder; + LockData *data; + HTAB *holderTable; + PROCLOCK *holder; HASH_SEQ_STATUS seqstat; - int i; + int i; data = (LockData *) palloc(sizeof(LockData)); @@ -1400,10 +1399,10 @@ GetLockStatusData(void) hash_seq_init(&seqstat, holderTable); i = 0; - while ( (holder = hash_seq_search(&seqstat)) ) + while ((holder = hash_seq_search(&seqstat))) { - PGPROC *proc = (PGPROC *) MAKE_PTR(holder->tag.proc); - LOCK *lock = (LOCK *) MAKE_PTR(holder->tag.lock); + PGPROC *proc = (PGPROC *) MAKE_PTR(holder->tag.proc); + LOCK *lock = (LOCK *) MAKE_PTR(holder->tag.lock); data->holderaddrs[i] = MAKE_OFFSET(holder); memcpy(&(data->holders[i]), holder, sizeof(PROCLOCK)); @@ -1439,7 +1438,7 @@ DumpLocks(void) { PGPROC *proc; SHM_QUEUE *procHolders; - PROCLOCK *holder; + PROCLOCK *holder; LOCK *lock; int lockmethod = DEFAULT_LOCKMETHOD; LOCKMETHODTABLE *lockMethodTable; @@ -1459,7 +1458,7 @@ DumpLocks(void) LOCK_PRINT("DumpLocks: waiting on", proc->waitLock, 0); holder = (PROCLOCK *) SHMQueueNext(procHolders, procHolders, - offsetof(PROCLOCK, procLink)); + offsetof(PROCLOCK, procLink)); while (holder) { @@ -1471,7 +1470,7 @@ DumpLocks(void) LOCK_PRINT("DumpLocks", lock, 0); holder = (PROCLOCK *) SHMQueueNext(procHolders, &holder->procLink, - offsetof(PROCLOCK, procLink)); + offsetof(PROCLOCK, procLink)); } } @@ -1482,7 +1481,7 @@ void DumpAllLocks(void) { PGPROC *proc; - PROCLOCK *holder; + PROCLOCK *holder; LOCK *lock; int lockmethod = DEFAULT_LOCKMETHOD; LOCKMETHODTABLE *lockMethodTable; diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 10f666aadc..e2559be0e6 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.12 2002/06/20 20:29:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lwlock.c,v 1.13 2002/09/04 20:31:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -211,21 +211,21 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode) HOLD_INTERRUPTS(); /* - * Loop here to try to acquire lock after each time we are signaled - * by LWLockRelease. + * Loop here to try to acquire lock after each time we are signaled by + * LWLockRelease. * - * NOTE: it might seem better to have LWLockRelease actually grant us - * the lock, rather than retrying and possibly having to go back to - * sleep. But in practice that is no good because it means a process - * swap for every lock acquisition when two or more processes are - * contending for the same lock. Since LWLocks are normally used to - * protect not-very-long sections of computation, a process needs to - * be able to acquire and release the same lock many times during a - * single CPU time slice, even in the presence of contention. The - * efficiency of being able to do that outweighs the inefficiency of - * sometimes wasting a process dispatch cycle because the lock is not - * free when a released waiter finally gets to run. See pgsql-hackers - * archives for 29-Dec-01. + * NOTE: it might seem better to have LWLockRelease act |