Skip to content

Commit 846c364

Browse files
committed
Change do_tup_output() to take Datum/isnull arrays instead of a char * array,
so it doesn't go through BuildTupleFromCStrings. This is more or less a wash for current uses, but will avoid inefficiency for planned changes to EXPLAIN. Robert Haas
1 parent ea38242 commit 846c364

File tree

3 files changed

+60
-32
lines changed

3 files changed

+60
-32
lines changed

src/backend/executor/execTuples.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.107 2009/06/11 14:48:57 momjian Exp $
18+
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.108 2009/07/22 17:00:20 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -95,6 +95,7 @@
9595
#include "catalog/pg_type.h"
9696
#include "nodes/nodeFuncs.h"
9797
#include "storage/bufmgr.h"
98+
#include "utils/builtins.h"
9899
#include "utils/lsyscache.h"
99100
#include "utils/typcache.h"
100101

@@ -1195,7 +1196,7 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
11951196
* Functions for sending tuples to the frontend (or other specified destination)
11961197
* as though it is a SELECT result. These are used by utility commands that
11971198
* need to project directly to the destination and don't need or want full
1198-
* Table Function capability. Currently used by EXPLAIN and SHOW ALL
1199+
* table function capability. Currently used by EXPLAIN and SHOW ALL.
11991200
*/
12001201
TupOutputState *
12011202
begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc)
@@ -1204,7 +1205,6 @@ begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc)
12041205

12051206
tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
12061207

1207-
tstate->metadata = TupleDescGetAttInMetadata(tupdesc);
12081208
tstate->slot = MakeSingleTupleTableSlot(tupdesc);
12091209
tstate->dest = dest;
12101210

@@ -1216,17 +1216,17 @@ begin_tup_output_tupdesc(DestReceiver *dest, TupleDesc tupdesc)
12161216
/*
12171217
* write a single tuple
12181218
*
1219-
* values is a list of the external C string representations of the values
1220-
* to be projected.
1221-
*
12221219
* XXX This could be made more efficient, since in reality we probably only
12231220
* need a virtual tuple.
12241221
*/
12251222
void
1226-
do_tup_output(TupOutputState *tstate, char **values)
1223+
do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
12271224
{
1228-
/* build a tuple from the input strings using the tupdesc */
1229-
HeapTuple tuple = BuildTupleFromCStrings(tstate->metadata, values);
1225+
TupleDesc tupdesc = tstate->slot->tts_tupleDescriptor;
1226+
HeapTuple tuple;
1227+
1228+
/* form a tuple */
1229+
tuple = heap_form_tuple(tupdesc, values, isnull);
12301230

12311231
/* put it in a slot */
12321232
ExecStoreTuple(tuple, tstate->slot, InvalidBuffer, true);
@@ -1241,24 +1241,34 @@ do_tup_output(TupOutputState *tstate, char **values)
12411241
/*
12421242
* write a chunk of text, breaking at newline characters
12431243
*
1244-
* NB: scribbles on its input!
1245-
*
12461244
* Should only be used with a single-TEXT-attribute tupdesc.
12471245
*/
12481246
void
12491247
do_text_output_multiline(TupOutputState *tstate, char *text)
12501248
{
1249+
Datum values[1];
1250+
bool isnull[1] = { false };
1251+
12511252
while (*text)
12521253
{
12531254
char *eol;
1255+
int len;
12541256

12551257
eol = strchr(text, '\n');
12561258
if (eol)
1257-
*eol++ = '\0';
1259+
{
1260+
len = eol - text;
1261+
eol++;
1262+
}
12581263
else
1259-
eol = text +strlen(text);
1264+
{
1265+
len = strlen(text);
1266+
eol += len;
1267+
}
12601268

1261-
do_tup_output(tstate, &text);
1269+
values[0] = PointerGetDatum(cstring_to_text_with_len(text, len));
1270+
do_tup_output(tstate, values, isnull);
1271+
pfree(DatumGetPointer(values[0]));
12621272
text = eol;
12631273
}
12641274
}
@@ -1269,6 +1279,5 @@ end_tup_output(TupOutputState *tstate)
12691279
(*tstate->dest->rShutdown) (tstate->dest);
12701280
/* note that destroying the dest is not ours to do */
12711281
ExecDropSingleTupleTableSlot(tstate->slot);
1272-
/* XXX worth cleaning up the attinmetadata? */
12731282
pfree(tstate);
12741283
}

src/backend/utils/misc/guc.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.508 2009/07/16 20:55:44 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.509 2009/07/22 17:00:23 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -5986,7 +5986,8 @@ ShowAllGUCConfig(DestReceiver *dest)
59865986
int i;
59875987
TupOutputState *tstate;
59885988
TupleDesc tupdesc;
5989-
char *values[3];
5989+
Datum values[3];
5990+
bool isnull[3] = { false, false, false };
59905991

59915992
/* need a tuple descriptor representing three TEXT columns */
59925993
tupdesc = CreateTemplateTupleDesc(3, false);
@@ -5997,29 +5998,46 @@ ShowAllGUCConfig(DestReceiver *dest)
59975998
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
59985999
TEXTOID, -1, 0);
59996000

6000-
60016001
/* prepare for projection of tuples */
60026002
tstate = begin_tup_output_tupdesc(dest, tupdesc);
60036003

60046004
for (i = 0; i < num_guc_variables; i++)
60056005
{
60066006
struct config_generic *conf = guc_variables[i];
6007+
char *setting;
60076008

60086009
if ((conf->flags & GUC_NO_SHOW_ALL) ||
60096010
((conf->flags & GUC_SUPERUSER_ONLY) && !am_superuser))
60106011
continue;
60116012

60126013
/* assign to the values array */
6013-
values[0] = (char *) conf->name;
6014-
values[1] = _ShowOption(conf, true);
6015-
values[2] = (char *) conf->short_desc;
6014+
values[0] = PointerGetDatum(cstring_to_text(conf->name));
6015+
6016+
setting = _ShowOption(conf, true);
6017+
if (setting)
6018+
{
6019+
values[1] = PointerGetDatum(cstring_to_text(setting));
6020+
isnull[1] = false;
6021+
}
6022+
else
6023+
{
6024+
values[1] = PointerGetDatum(NULL);
6025+
isnull[1] = true;
6026+
}
6027+
6028+
values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
60166029

60176030
/* send it to dest */
6018-
do_tup_output(tstate, values);
6031+
do_tup_output(tstate, values, isnull);
60196032

60206033
/* clean up */
6021-
if (values[1] != NULL)
6022-
pfree(values[1]);
6034+
pfree(DatumGetPointer(values[0]));
6035+
if (setting)
6036+
{
6037+
pfree(setting);
6038+
pfree(DatumGetPointer(values[1]));
6039+
}
6040+
pfree(DatumGetPointer(values[2]));
60236041
}
60246042

60256043
end_tup_output(tstate);

src/include/executor/executor.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.156 2009/07/18 19:15:42 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.157 2009/07/22 17:00:23 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -223,15 +223,13 @@ extern void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg);
223223

224224
typedef struct TupOutputState
225225
{
226-
/* use "struct" here to allow forward reference */
227-
struct AttInMetadata *metadata;
228226
TupleTableSlot *slot;
229227
DestReceiver *dest;
230228
} TupOutputState;
231229

232230
extern TupOutputState *begin_tup_output_tupdesc(DestReceiver *dest,
233231
TupleDesc tupdesc);
234-
extern void do_tup_output(TupOutputState *tstate, char **values);
232+
extern void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull);
235233
extern void do_text_output_multiline(TupOutputState *tstate, char *text);
236234
extern void end_tup_output(TupOutputState *tstate);
237235

@@ -240,11 +238,14 @@ extern void end_tup_output(TupOutputState *tstate);
240238
*
241239
* Should only be used with a single-TEXT-attribute tupdesc.
242240
*/
243-
#define do_text_output_oneline(tstate, text_to_emit) \
241+
#define do_text_output_oneline(tstate, str_to_emit) \
244242
do { \
245-
char *values_[1]; \
246-
values_[0] = (text_to_emit); \
247-
do_tup_output(tstate, values_); \
243+
Datum values_[1]; \
244+
bool isnull_[1]; \
245+
values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
246+
isnull_[0] = false; \
247+
do_tup_output(tstate, values_, isnull_); \
248+
pfree(DatumGetPointer(values_[0])); \
248249
} while (0)
249250

250251

0 commit comments

Comments
 (0)