Attached is a patch that replaces a bunch of places where StringInfos
are unnecessarily allocated on the heap rather than the stack. That is,
this is sub-optimal:
{
StringInfo str;
str = makeStringInfo();
/* use str */
pfree(str->data);
pfree(str);
}
If the StringInfo doesn't outlive the stack frame in which it is
created, there is no need to allocate it on the heap via
makeStringInfo() -- stack allocation is faster:
{
StringInfoData str;
initStringInfo(&str);
/* use str */
pfree(str.data);
}
While it's not a big deal unless the code is in a critical path, I don't
see a reason not to save a few cycles -- using stack allocation is not
less readable.
A bunch of places in the tree (mostly contrib/) were using
makeStringInfo() when there was no need to do so -- this patch replaces
that with a stack-allocated StringInfoData and initStringInfo(). I also
cleaned up a bit of code along the way: moved variable declarations into
a more tightly-enclosing scope where possible, fixed some pointless
copying of strings in dblink, etc.
Barring any objections I'll apply this tomorrow.
-Neil
============================================================
*** contrib/dblink/dblink.c 039b7c90248c9087a49f8fe3c21e214b6287389b
--- contrib/dblink/dblink.c e8702fb1e2f2f73c553276f55d26eeceb38adb20
***************
*** 301,311 ****
char *curname = NULL;
char *sql = NULL;
char *conname = NULL;
! StringInfo str = makeStringInfo();
remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible behavior */
DBLINK_INIT;
if (PG_NARGS() == 2)
{
--- 301,312 ----
char *curname = NULL;
char *sql = NULL;
char *conname = NULL;
! StringInfoData buf;
remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible behavior */
DBLINK_INIT;
+ initStringInfo(&buf);
if (PG_NARGS() == 2)
{
***************
*** 361,368 ****
if (rconn->newXactForCursor)
(rconn->openCursorCount)++;
! appendStringInfo(str, "DECLARE %s CURSOR FOR %s", curname, sql);
! res = PQexec(conn, str->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
if (fail)
--- 362,369 ----
if (rconn->newXactForCursor)
(rconn->openCursorCount)++;
! appendStringInfo(&buf, "DECLARE %s CURSOR FOR %s", curname, sql);
! res = PQexec(conn, buf.data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
if (fail)
***************
*** 389,400 ****
PGresult *res = NULL;
char *curname = NULL;
char *conname = NULL;
! StringInfo str = makeStringInfo();
char *msg;
remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible behavior */
DBLINK_INIT;
if (PG_NARGS() == 1)
{
--- 390,402 ----
PGresult *res = NULL;
char *curname = NULL;
char *conname = NULL;
! StringInfoData buf;
char *msg;
remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible behavior */
DBLINK_INIT;
+ initStringInfo(&buf);
if (PG_NARGS() == 1)
{
***************
*** 432,441 ****
else
conn = rconn->conn;
! appendStringInfo(str, "CLOSE %s", curname);
/* close the cursor */
! res = PQexec(conn, str->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
if (fail)
--- 434,443 ----
else
conn = rconn->conn;
! appendStringInfo(&buf, "CLOSE %s", curname);
/* close the cursor */
! res = PQexec(conn, buf.data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{
if (fail)
***************
*** 493,499 ****
if (SRF_IS_FIRSTCALL())
{
PGconn *conn = NULL;
! StringInfo str = makeStringInfo();
char *curname = NULL;
int howmany = 0;
bool fail = true; /* default to backward compatible */
--- 495,501 ----
if (SRF_IS_FIRSTCALL())
{
PGconn *conn = NULL;
! StringInfoData buf;
char *curname = NULL;
int howmany = 0;
bool fail = true; /* default to backward compatible */
***************
*** 542,547 ****
--- 544,552 ----
if (!conn)
DBLINK_CONN_NOT_AVAIL;
+ initStringInfo(&buf);
+ appendStringInfo(&buf, "FETCH %d FROM %s", howmany, curname);
+
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
***************
*** 550,558 ****
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
! appendStringInfo(str, "FETCH %d FROM %s", howmany, curname);
!
! res = PQexec(conn, str->data);
if (!res ||
(PQresultStatus(res) != PGRES_COMMAND_OK &&
PQresultStatus(res) != PGRES_TUPLES_OK))
--- 555,561 ----
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
! res = PQexec(conn, buf.data);
if (!res ||
(PQresultStatus(res) != PGRES_COMMAND_OK &&
PQresultStatus(res) != PGRES_TUPLES_OK))
***************
*** 1547,1554 ****
HeapTuple tuple;
TupleDesc tupdesc;
int natts;
! StringInfo str = makeStringInfo();
! char *sql;
char *val;
int16 key;
int i;
--- 1550,1556 ----
HeapTuple tuple;
TupleDesc tupdesc;
int natts;
! StringInfoData buf;
char *val;
int16 key;
int i;
***************
*** 1554,1559 ****
--- 1556,1563 ----
int i;
bool needComma;
+ initStringInfo(&buf);
+
/* get relation name including any needed schema prefix and quoting */
relname = generate_relation_name(relid);
***************
*** 1570,1576 ****
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source row not found")));
! appendStringInfo(str, "INSERT INTO %s(", relname);
needComma = false;
for (i = 0; i < natts; i++)
--- 1574,1580 ----
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source row not found")));
! appendStringInfo(&buf, "INSERT INTO %s(", relname);
needComma = false;
for (i = 0; i < natts; i++)
***************
*** 1579,1592 ****
continue;
if (needComma)
! appendStringInfo(str, ",");
! appendStringInfo(str, "%s",
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
needComma = true;
}
! appendStringInfo(str, ") VALUES(");
/*
* remember attvals are 1 based
--- 1583,1596 ----
continue;
if (needComma)
! appendStringInfo(&buf, ",");
! appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
needComma = true;
}
! appendStringInfo(&buf, ") VALUES(");
/*
* remember attvals are 1 based
***************
*** 1598,1604 ****
continue;
if (needComma)
! appendStringInfo(str, ",");
if (tgt_pkattvals != NULL)
key = get_attnum_pk_pos(pkattnums, pknumatts, i + 1);
--- 1602,1608 ----
continue;
if (needComma)
! appendStringInfo(&buf, ",");
if (tgt_pkattvals != NULL)
key = get_attnum_pk_pos(pkattnums, pknumatts, i + 1);
***************
*** 1612,1632 ****
if (val != NULL)
{
! appendStringInfo(str, "%s", quote_literal_cstr(val));
pfree(val);
}
else
! appendStringInfo(str, "NULL");
needComma = true;
}
! appendStringInfo(str, ")");
- sql = pstrdup(str->data);
- pfree(str->data);
- pfree(str);
relation_close(rel, AccessShareLock);
!
! return (sql);
}
static char *
--- 1616,1632 ----
if (val != NULL)
{
! appendStringInfoString(&buf, quote_literal_cstr(val));
pfree(val);
}
else
! appendStringInfo(&buf, "NULL");
needComma = true;
}
! appendStringInfo(&buf, ")");
relation_close(rel, AccessShareLock);
! return (buf.data);
}
static char *
***************
*** 1636,1645 ****
char *relname;
TupleDesc tupdesc;
int natts;
! StringInfo str = makeStringInfo();
! char *sql;
int i;
/* get relation name including any needed schema prefix and quoting */
relname = generate_relation_name(relid);
--- 1636,1646 ----
char *relname;
TupleDesc tupdesc;
int natts;
! StringInfoData buf;
int i;
+ initStringInfo(&buf);
+
/* get relation name including any needed schema prefix and quoting */
relname = generate_relation_name(relid);
***************
*** 1650,1664 ****
tupdesc = rel->rd_att;
natts = tupdesc->natts;
! appendStringInfo(str, "DELETE FROM %s WHERE ", relname);
for (i = 0; i < pknumatts; i++)
{
int16 pkattnum = pkattnums->values[i];
if (i > 0)
! appendStringInfo(str, " AND ");
! appendStringInfo(str, "%s",
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (tgt_pkattvals == NULL)
--- 1651,1665 ----
tupdesc = rel->rd_att;
natts = tupdesc->natts;
! appendStringInfo(&buf, "DELETE FROM %s WHERE ", relname);
for (i = 0; i < pknumatts; i++)
{
int16 pkattnum = pkattnums->values[i];
if (i > 0)
! appendStringInfo(&buf, " AND ");
! appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (tgt_pkattvals == NULL)
***************
*** 1666,1683 ****
elog(ERROR, "target key array must not be NULL");
if (tgt_pkattvals[i] != NULL)
! appendStringInfo(str, " = %s",
quote_literal_cstr(tgt_pkattvals[i]));
else
! appendStringInfo(str, " IS NULL");
}
- sql = pstrdup(str->data);
- pfree(str->data);
- pfree(str);
relation_close(rel, AccessShareLock);
!
! return (sql);
}
static char *
--- 1667,1680 ----
elog(ERROR, "target key array must not be NULL");
if (tgt_pkattvals[i] != NULL)
! appendStringInfo(&buf, " = %s",
quote_literal_cstr(tgt_pkattvals[i]));
else
! appendStringInfo(&buf, " IS NULL");
}
relation_close(rel, AccessShareLock);
! return (buf.data);
}
static char *
***************
*** 1688,1695 ****
HeapTuple tuple;
TupleDesc tupdesc;
int natts;
! StringInfo str = makeStringInfo();
! char *sql;
char *val;
int16 key;
int i;
--- 1685,1691 ----
HeapTuple tuple;
TupleDesc tupdesc;
int natts;
! StringInfoData buf;
char *val;
int16 key;
int i;
***************
*** 1695,1700 ****
--- 1691,1698 ----
int i;
bool needComma;
+ initStringInfo(&buf);
+
/* get relation name including any needed schema prefix and quoting */
relname = generate_relation_name(relid);
***************
*** 1711,1717 ****
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source row not found")));
! appendStringInfo(str, "UPDATE %s SET ", relname);
needComma = false;
for (i = 0; i < natts; i++)
--- 1709,1715 ----
(errcode(ERRCODE_CARDINALITY_VIOLATION),
errmsg("source row not found")));
! appendStringInfo(&buf, "UPDATE %s SET ", relname);
needComma = false;
for (i = 0; i < natts; i++)
***************
*** 1720,1728 ****
continue;
if (needComma)
! appendStringInfo(str, ", ");
! appendStringInfo(str, "%s = ",
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
if (tgt_pkattvals != NULL)
--- 1718,1726 ----
continue;
if (needComma)
! appendStringInfo(&buf, ", ");
! appendStringInfo(&buf, "%s = ",
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
if (tgt_pkattvals != NULL)
***************
*** 1737,1751 ****
if (val != NULL)
{
! appendStringInfo(str, "%s", quote_literal_cstr(val));
pfree(val);
}
else
! appendStringInfo(str, "NULL");
needComma = true;
}
! appendStringInfo(str, " WHERE ");
for (i = 0; i < pknumatts; i++)
{
--- 1735,1749 ----
if (val != NULL)
{
! appendStringInfoString(&buf, quote_literal_cstr(val));
pfree(val);
}
else
! appendStringInfoString(&buf, "NULL");
needComma = true;
}
! appendStringInfo(&buf, " WHERE ");
for (i = 0; i < pknumatts; i++)
{
***************
*** 1752,1760 ****
int16 pkattnum = pkattnums->values[i];
if (i > 0)
! appendStringInfo(str, " AND ");
! appendStringInfo(str, "%s",
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (tgt_pkattvals != NULL)
--- 1750,1758 ----
int16 pkattnum = pkattnums->values[i];
if (i > 0)
! appendStringInfo(&buf, " AND ");
! appendStringInfo(&buf, "%s",
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (tgt_pkattvals != NULL)
***************
*** 1764,1782 ****
if (val != NULL)
{
! appendStringInfo(str, " = %s", quote_literal_cstr(val));
pfree(val);
}
else
! appendStringInfo(str, " IS NULL");
}
- sql = pstrdup(str->data);
- pfree(str->data);
- pfree(str);
relation_close(rel, AccessShareLock);
!
! return (sql);
}
/*
--- 1762,1776 ----
if (val != NULL)
{
! appendStringInfo(&buf, " = %s", quote_literal_cstr(val));
pfree(val);
}
else
! appendStringInfo(&buf, " IS NULL");
}
relation_close(rel, AccessShareLock);
! return (buf.data);
}
/*
***************
*** 1836,1847 ****
Relation rel;
char *relname;
TupleDesc tupdesc;
! StringInfo str = makeStringInfo();
! char *sql = NULL;
int ret;
HeapTuple tuple;
int i;
/* get relation name including any needed schema prefix and quoting */
relname = generate_relation_name(relid);
--- 1830,1842 ----
Relation rel;
char *relname;
TupleDesc tupdesc;
! StringInfoData buf;
int ret;
HeapTuple tuple;
int i;
+ initStringInfo(&buf);
+
/* get relation name including any needed schema prefix and quoting */
relname = generate_relation_name(relid);
***************
*** 1863,1869 ****
* Build sql statement to look up tuple of interest Use src_pkattvals as
* the criteria.
*/
! appendStringInfo(str, "SELECT * FROM %s WHERE ", relname);
for (i = 0; i < pknumatts; i++)
{
--- 1858,1864 ----
* Build sql statement to look up tuple of interest Use src_pkattvals as
* the criteria.
*/
! appendStringInfo(&buf, "SELECT * FROM %s WHERE ", relname);
for (i = 0; i < pknumatts; i++)
{
***************
*** 1870,1891 ****
int16 pkattnum = pkattnums->values[i];
if (i > 0)
! appendStringInfo(str, " AND ");
! appendStringInfo(str, "%s",
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (src_pkattvals[i] != NULL)
! appendStringInfo(str, " = %s",
quote_literal_cstr(src_pkattvals[i]));
else
! appendStringInfo(str, " IS NULL");
}
- sql = pstrdup(str->data);
- pfree(str->data);
- pfree(str);
-
/*
* Retrieve the desired tuple
*/
--- 1865,1882 ----
int16 pkattnum = pkattnums->values[i];
if (i > 0)
! appendStringInfo(&buf, " AND ");
! appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum - 1]->attname)));
if (src_pkattvals[i] != NULL)
! appendStringInfo(&buf, " = %s",
quote_literal_cstr(src_pkattvals[i]));
else
! appendStringInfo(&buf, " IS NULL");
}
/*
* Retrieve the desired tuple
*/
***************
*** 1889,1896 ****
/*
* Retrieve the desired tuple
*/
! ret = SPI_exec(sql, 0);
! pfree(sql);
/*
* Only allow one qualifying tuple
--- 1880,1887 ----
/*
* Retrieve the desired tuple
*/
! ret = SPI_exec(buf.data, 0);
! pfree(buf.data);
/*
* Only allow one qualifying tuple
============================================================
*** contrib/tablefunc/tablefunc.c ec0ff1857e0f769090c87ad659dad5005be3721c
--- contrib/tablefunc/tablefunc.c a4763149b913031b2eacdf6020c84250cbcf4252
***************
*** 1260,1272 ****
{
TupleDesc tupdesc = attinmeta->tupdesc;
MemoryContext oldcontext;
- StringInfo sql = makeStringInfo();
int ret;
int proc;
int serial_column;
! StringInfo branchstr = NULL;
! StringInfo chk_branchstr = NULL;
! StringInfo chk_current_key = NULL;
char **values;
char *current_key;
char *current_key_parent;
--- 1260,1269 ----
{
TupleDesc tupdesc = attinmeta->tupdesc;
MemoryContext oldcontext;
int ret;
int proc;
int serial_column;
! StringInfoData sql;
char **values;
char *current_key;
char *current_key_parent;
***************
*** 1278,1290 ****
if (max_depth > 0 && level > max_depth)
return tupstore;
! /* start a new branch */
! branchstr = makeStringInfo();
- /* need these to check for recursion */
- chk_branchstr = makeStringInfo();
- chk_current_key = makeStringInfo();
-
/* Build initial sql statement */
if (!show_serial)
{
--- 1275,1282 ----
if (max_depth > 0 && level > max_depth)
return tupstore;
! initStringInfo(&sql);
/* Build initial sql statement */
if (!show_serial)
{
***************
*** 1288,1294 ****
/* Build initial sql statement */
if (!show_serial)
{
! appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s",
key_fld,
parent_key_fld,
relname,
--- 1280,1286 ----
/* Build initial sql statement */
if (!show_serial)
{
! appendStringInfo(&sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s",
key_fld,
parent_key_fld,
relname,
***************
*** 1299,1305 ****
}
else
{
! appendStringInfo(sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s ORDER BY %s",
key_fld,
parent_key_fld,
relname,
--- 1291,1297 ----
}
else
{
! appendStringInfo(&sql, "SELECT %s, %s FROM %s WHERE %s = %s AND %s IS NOT NULL AND %s <> %s ORDER BY %s",
key_fld,
parent_key_fld,
relname,
***************
*** 1359,1365 ****
}
/* Retrieve the desired rows */
! ret = SPI_execute(sql->data, true, 0);
proc = SPI_processed;
/* Check for qualifying tuples */
--- 1351,1357 ----
}
/* Retrieve the desired rows */
! ret = SPI_execute(sql.data, true, 0);
proc = SPI_processed;
/* Check for qualifying tuples */
***************
*** 1369,1374 ****
--- 1361,1369 ----
SPITupleTable *tuptable = SPI_tuptable;
TupleDesc spi_tupdesc = tuptable->tupdesc;
int i;
+ StringInfoData branchstr;
+ StringInfoData chk_branchstr;
+ StringInfoData chk_current_key;
/* First time through, do a little more setup */
if (level == 0)
***************
*** 1389,1397 ****
for (i = 0; i < proc; i++)
{
/* initialize branch for this pass */
! appendStringInfo(branchstr, "%s", branch);
! appendStringInfo(chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim);
/* get the next sql result tuple */
spi_tuple = tuptable->vals[i];
--- 1384,1399 ----
for (i = 0; i < proc; i++)
{
+ /* start a new branch */
+ initStringInfo(&branchstr);
+
+ /* need these to check for recursion */
+ initStringInfo(&chk_branchstr);
+ initStringInfo(&chk_current_key);
+
/* initialize branch for this pass */
! appendStringInfo(&branchstr, "%s", branch);
! appendStringInfo(&chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim);
/* get the next sql result tuple */
spi_tuple = tuptable->vals[i];
***************
*** 1398,1404 ****
/* get the current key and parent */
current_key = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
! appendStringInfo(chk_current_key, "%s%s%s", branch_delim, current_key, branch_delim);
current_key_parent = pstrdup(SPI_getvalue(spi_tuple, spi_tupdesc, 2));
/* get the current level */
--- 1400,1406 ----
/* get the current key and parent */
current_key = SPI_getvalue(spi_tuple, spi_tupdesc, 1);
! appendStringInfo(&chk_current_key, "%s%s%s", branch_delim, current_key, branch_delim);
current_key_parent = pstrdup(SPI_getvalue(spi_tuple, spi_tupdesc, 2));
/* get the current level */
***************
*** 1405,1416 ****
sprintf(current_level, "%d", level);
/* check to see if this key is also an ancestor */
! if (strstr(chk_branchstr->data, chk_current_key->data))
elog(ERROR, "infinite recursion detected");
/* OK, extend the branch */
! appendStringInfo(branchstr, "%s%s", branch_delim, current_key);
! current_branch = branchstr->data;
/* build a tuple */
values[0] = pstrdup(current_key);
--- 1407,1418 ----
sprintf(current_level, "%d", level);
/* check to see if this key is also an ancestor */
! if (strstr(chk_branchstr.data, chk_current_key.data))
elog(ERROR, "infinite recursion detected");
/* OK, extend the branch */
! appendStringInfo(&branchstr, "%s%s", branch_delim, current_key);
! current_branch = branchstr.data;
/* build a tuple */
values[0] = pstrdup(current_key);
***************
*** 1461,1474 ****
tupstore);
/* reset branch for next pass */
! xpfree(branchstr->data);
! initStringInfo(branchstr);
!
! xpfree(chk_branchstr->data);
! initStringInfo(chk_branchstr);
!
! xpfree(chk_current_key->data);
! initStringInfo(chk_current_key);
}
}
--- 1463,1471 ----
tupstore);
/* reset branch for next pass */
! xpfree(branchstr.data);
! xpfree(chk_branchstr.data);
! xpfree(chk_current_key.data);
}
}
============================================================
*** contrib/xml2/xpath.c 20bc45f075a2db3b7aa8bcb43dea7f656d9effbc
--- contrib/xml2/xpath.c e44e5d0cfd485af58b38ce34c682409dc13c8e26
***************
*** 668,674 ****
* document */
int had_values; /* To determine end of nodeset results */
! StringInfo querysql;
/* We only have a valid tuple description in table function mode */
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
--- 668,674 ----
* document */
int had_values; /* To determine end of nodeset results */
! StringInfoData query_buf;
/* We only have a valid tuple description in table function mode */
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
***************
*** 746,756 ****
} while ((pos != NULL) && (numpaths < (ret_tupdesc->natts - 1)));
/* Now build query */
- querysql = makeStringInfo();
-
/* Build initial sql statement */
! appendStringInfo(querysql, "SELECT %s, %s FROM %s WHERE %s",
pkeyfield,
xmlfield,
relname,
--- 746,755 ----
} while ((pos != NULL) && (numpaths < (ret_tupdesc->natts - 1)));
/* Now build query */
+ initStringInfo(&query_buf);
/* Build initial sql statement */
! appendStringInfo(&query_buf, "SELECT %s, %s FROM %s WHERE %s",
pkeyfield,
xmlfield,
relname,
***************
*** 761,768 ****
if ((ret = SPI_connect()) < 0)
elog(ERROR, "xpath_table: SPI_connect returned %d", ret);
! if ((ret = SPI_exec(querysql->data, 0)) != SPI_OK_SELECT)
! elog(ERROR, "xpath_table: SPI execution failed for query %s", querysql->data);
proc = SPI_processed;
/* elog(DEBUG1,"xpath_table: SPI returned %d rows",proc); */
--- 760,767 ----
if ((ret = SPI_connect()) < 0)
elog(ERROR, "xpath_table: SPI_connect returned %d", ret);
! if ((ret = SPI_exec(query_buf.data, 0)) != SPI_OK_SELECT)
! elog(ERROR, "xpath_table: SPI execution failed for query %s", query_buf.data);
proc = SPI_processed;
/* elog(DEBUG1,"xpath_table: SPI returned %d rows",proc); */
============================================================
*** src/backend/commands/explain.c 8e496378aa3841a6ecf74ad836d499d7e72e2aa1
--- src/backend/commands/explain.c 8ada5a404e8b97b28bb923e3e5cd2f3a171af0eb
***************
*** 232,238 ****
instr_time starttime;
double totaltime = 0;
ExplainState *es;
! StringInfo str;
int eflags;
INSTR_TIME_SET_CURRENT(starttime);
--- 232,238 ----
instr_time starttime;
double totaltime = 0;
ExplainState *es;
! StringInfoData buf;
int eflags;
INSTR_TIME_SET_CURRENT(starttime);
***************
*** 285,293 ****
}
}
! str = makeStringInfo();
!
! explain_outNode(str, queryDesc->plantree, queryDesc->planstate,
NULL, 0, es);
/*
--- 285,292 ----
}
}
! initStringInfo(&buf);
! explain_outNode(&buf, queryDesc->plantree, queryDesc->planstate,
NULL, 0, es);
/*
***************
*** 335,352 ****
if (trig->tgisconstraint &&
(conname = GetConstraintNameForTrigger(trig->tgoid)) != NULL)
{
! appendStringInfo(str, "Trigger for constraint %s",
conname);
pfree(conname);
}
else
! appendStringInfo(str, "Trigger %s", trig->tgname);
if (numrels > 1)
! appendStringInfo(str, " on %s",
RelationGetRelationName(rInfo->ri_RelationDesc));
! appendStringInfo(str, ": time=%.3f calls=%.0f\n",
1000.0 * instr->total,
instr->ntuples);
}
--- 334,351 ----
if (trig->tgisconstraint &&
(conname = GetConstraintNameForTrigger(trig->tgoid)) != NULL)
{
! appendStringInfo(&buf, "Trigger for constraint %s",
conname);
pfree(conname);
}
else
! appendStringInfo(&buf, "Trigger %s", trig->tgname);
if (numrels > 1)
! appendStringInfo(&buf, " on %s",
RelationGetRelationName(rInfo->ri_RelationDesc));
! appendStringInfo(&buf, ": time=%.3f calls=%.0f\n",
1000.0 * instr->total,
instr->ntuples);
}
***************
*** 370,381 ****
totaltime += elapsed_time(&starttime);
if (stmt->analyze)
! appendStringInfo(str, "Total runtime: %.3f ms\n",
1000.0 * totaltime);
! do_text_output_multiline(tstate, str->data);
! pfree(str->data);
! pfree(str);
pfree(es);
}
--- 369,379 ----
totaltime += elapsed_time(&starttime);
if (stmt->analyze)
! appendStringInfo(&buf, "Total runtime: %.3f ms\n",
1000.0 * totaltime);
! do_text_output_multiline(tstate, buf.data);
! pfree(buf.data);
pfree(es);
}
============================================================
*** src/backend/utils/adt/varlena.c 76910454cf301573d23d47c32e96ca7e23005e37
--- src/backend/utils/adt/varlena.c 76404114358345e5358d6b0e0cda7838fb015fd8
***************
*** 2038,2044 ****
text *buf_text;
text *ret_text;
int curr_posn;
! StringInfo str;
if (src_text_len == 0 || from_sub_text_len == 0)
PG_RETURN_TEXT_P(src_text);
--- 2038,2044 ----
text *buf_text;
text *ret_text;
int curr_posn;
! StringInfoData str;
if (src_text_len == 0 || from_sub_text_len == 0)
PG_RETURN_TEXT_P(src_text);
***************
*** 2049,2055 ****
if (curr_posn == 0)
PG_RETURN_TEXT_P(src_text);
! str = makeStringInfo();
buf_text = src_text;
while (curr_posn > 0)
--- 2049,2055 ----
if (curr_posn == 0)
PG_RETURN_TEXT_P(src_text);
! initStringInfo(&str);
buf_text = src_text;
while (curr_posn > 0)
***************
*** 2059,2066 ****
right_text = text_substring(PointerGetDatum(buf_text),
curr_posn + from_sub_text_len, -1, true);
! appendStringInfoText(str, left_text);
! appendStringInfoText(str, to_sub_text);
if (buf_text != src_text)
pfree(buf_text);
--- 2059,2066 ----
right_text = text_substring(PointerGetDatum(buf_text),
curr_posn + from_sub_text_len, -1, true);
! appendStringInfoText(&str, left_text);
! appendStringInfoText(&str, to_sub_text);
if (buf_text != src_text)
pfree(buf_text);
***************
*** 2069,2081 ****
curr_posn = TEXTPOS(buf_text, from_sub_text);
}
! appendStringInfoText(str, buf_text);
if (buf_text != src_text)
pfree(buf_text);
! ret_text = PG_STR_GET_TEXT(str->data);
! pfree(str->data);
! pfree(str);
PG_RETURN_TEXT_P(ret_text);
}
--- 2069,2080 ----
curr_posn = TEXTPOS(buf_text, from_sub_text);
}
! appendStringInfoText(&str, buf_text);
if (buf_text != src_text)
pfree(buf_text);
! ret_text = PG_STR_GET_TEXT(str.data);
! pfree(str.data);
PG_RETURN_TEXT_P(ret_text);
}
***************
*** 2227,2234 ****
text *ret_text;
regex_t *re = (regex_t *) regexp;
int src_text_len = VARSIZE(src_text) - VARHDRSZ;
! StringInfo str = makeStringInfo();
! int regexec_result;
regmatch_t pmatch[REGEXP_REPLACE_BACKREF_CNT];
pg_wchar *data;
size_t data_len;
--- 2226,2232 ----
text *ret_text;
regex_t *re = (regex_t *) regexp;
int src_text_len = VARSIZE(src_text) - VARHDRSZ;
! StringInfoData buf;
regmatch_t pmatch[REGEXP_REPLACE_BACKREF_CNT];
pg_wchar *data;
size_t data_len;
***************
*** 2236,2241 ****
--- 2234,2241 ----
int data_pos;
bool have_escape;
+ initStringInfo(&buf);
+
/* Convert data string to wide characters. */
data = (pg_wchar *) palloc((src_text_len + 1) * sizeof(pg_wchar));
data_len = pg_mb2wchar_with_len(VARDATA(src_text), data, src_text_len);
***************
*** 2245,2250 ****
--- 2245,2252 ----
for (search_start = data_pos = 0; search_start <= data_len;)
{
+ int regexec_result;
+
regexec_result = pg_regexec(re,
data,
data_len,
***************
*** 2254,2264 ****
pmatch,
0);
! if (regexec_result != REG_OKAY && regexec_result != REG_NOMATCH)
{
char errMsg[100];
- /* re failed??? */
pg_regerror(regexec_result, re, errMsg, sizeof(errMsg));
ereport(ERROR,
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
--- 2256,2268 ----
pmatch,
0);
! if (regexec_result == REG_NOMATCH)
! break;
!
! if (regexec_result != REG_OKAY)
{
char errMsg[100];
pg_regerror(regexec_result, re, errMsg, sizeof(errMsg));
ereport(ERROR,
(errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
***************
*** 2265,2273 ****
errmsg("regular expression failed: %s", errMsg)));
}
- if (regexec_result == REG_NOMATCH)
- break;
-
/*
* Copy the text to the left of the match position. Because we are
* working with character not byte indexes, it's easiest to use
--- 2269,2274 ----
***************
*** 2281,2287 ****
data_pos + 1,
pmatch[0].rm_so - data_pos,
false);
! appendStringInfoText(str, left_text);
pfree(left_text);
}
--- 2282,2288 ----
data_pos + 1,
pmatch[0].rm_so - data_pos,
false);
! appendStringInfoText(&buf, left_text);
pfree(left_text);
}
***************
*** 2290,2298 ****
* replace_text has escape characters.
*/
if (have_escape)
! appendStringInfoRegexpSubstr(str, replace_text, pmatch, src_text);
else
! appendStringInfoText(str, replace_text);
search_start = data_pos = pmatch[0].rm_eo;
--- 2291,2299 ----
* replace_text has escape characters.
*/
if (have_escape)
! appendStringInfoRegexpSubstr(&buf, replace_text, pmatch, src_text);
else
! appendStringInfoText(&buf, replace_text);
search_start = data_pos = pmatch[0].rm_eo;
***************
*** 2318,2330 ****
right_text = text_substring(PointerGetDatum(src_text),
data_pos + 1, -1, true);
! appendStringInfoText(str, right_text);
pfree(right_text);
}
! ret_text = PG_STR_GET_TEXT(str->data);
! pfree(str->data);
! pfree(str);
pfree(data);
return ret_text;
--- 2319,2330 ----
right_text = text_substring(PointerGetDatum(src_text),
data_pos + 1, -1, true);
! appendStringInfoText(&buf, right_text);
pfree(right_text);
}
! ret_text = PG_STR_GET_TEXT(buf.data);
! pfree(buf.data);
pfree(data);
return ret_text;
***************
*** 2512,2518 ****
int typlen;
bool typbyval;
char typalign;
! StringInfo result_str = makeStringInfo();
bool printed = false;
char *p;
bits8 *bitmap;
--- 2512,2518 ----
int typlen;
bool typbyval;
char typalign;
! StringInfoData buf;
bool printed = false;
char *p;
bits8 *bitmap;
***************
*** 2529,2534 ****
--- 2529,2535 ----
PG_RETURN_TEXT_P(PG_STR_GET_TEXT(""));
element_type = ARR_ELEMTYPE(v);
+ initStringInfo(&buf);
/*
* We arrange to look up info about element type, including its output
***************
*** 2583,2591 ****
itemvalue));
if (printed)
! appendStringInfo(result_str, "%s%s", fldsep, value);
else
! appendStringInfoString(result_str, value);
printed = true;
p = att_addlength(p, typlen, PointerGetDatum(p));
--- 2584,2592 ----
itemvalue));
if (printed)
! appendStringInfo(&buf, "%s%s", fldsep, value);
else
! appendStringInfoString(&buf, value);
printed = true;
p = att_addlength(p, typlen, PointerGetDatum(p));
***************
*** 2604,2610 ****
}
}
! PG_RETURN_TEXT_P(PG_STR_GET_TEXT(result_str->data));
}
#define HEXBASE 16
--- 2605,2611 ----
}
}
! PG_RETURN_TEXT_P(PG_STR_GET_TEXT(buf.data));
}
#define HEXBASE 16
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly