7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.25 1998/10/21 16:21:20 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.26 1998/11/08 19:38:34 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -38,6 +38,7 @@ typedef struct ExplainState
38
38
} ExplainState ;
39
39
40
40
static char * Explain_PlanToString (Plan * plan , ExplainState * es );
41
+ static void printLongNotice (const char * header , const char * message );
41
42
static void ExplainOneQuery (Query * query , bool verbose , CommandDest dest );
42
43
43
44
@@ -87,11 +88,9 @@ ExplainQuery(Query *query, bool verbose, CommandDest dest)
87
88
static void
88
89
ExplainOneQuery (Query * query , bool verbose , CommandDest dest )
89
90
{
90
- char * s = NULL ,
91
- * s2 ;
91
+ char * s ;
92
92
Plan * plan ;
93
93
ExplainState * es ;
94
- int len ;
95
94
96
95
/* plan the queries (XXX we've ignored rewrite!!) */
97
96
plan = planner (query );
@@ -111,30 +110,25 @@ ExplainOneQuery(Query *query, bool verbose, CommandDest dest)
111
110
es -> rtable = query -> rtable ;
112
111
113
112
if (es -> printNodes )
113
+ {
114
114
s = nodeToString (plan );
115
+ if (s )
116
+ {
117
+ printLongNotice ("QUERY DUMP:\n\n" , s );
118
+ pfree (s );
119
+ }
120
+ }
115
121
116
122
if (es -> printCost )
117
123
{
118
- s2 = Explain_PlanToString (plan , es );
119
- if (s == NULL )
120
- s = s2 ;
121
- else
124
+ s = Explain_PlanToString (plan , es );
125
+ if (s )
122
126
{
123
- strcat ( s , " \n\n" );
124
- strcat ( s , s2 );
127
+ printLongNotice ( "QUERY PLAN: \n\n", s );
128
+ pfree ( s );
125
129
}
126
130
}
127
131
128
- /* output the plan */
129
- len = strlen (s );
130
- elog (NOTICE , "QUERY PLAN:\n\n%.*s" , ELOG_MAXLEN - 64 , s );
131
- len -= ELOG_MAXLEN - 64 ;
132
- while (len > 0 )
133
- {
134
- s += ELOG_MAXLEN - 64 ;
135
- elog (NOTICE , "%.*s" , ELOG_MAXLEN - 64 , s );
136
- len -= ELOG_MAXLEN - 64 ;
137
- }
138
132
if (es -> printNodes )
139
133
pprint (plan ); /* display in postmaster log file */
140
134
@@ -361,3 +355,22 @@ Explain_PlanToString(Plan *plan, ExplainState *es)
361
355
362
356
return s ;
363
357
}
358
+
359
+ /*
360
+ * Print a message that might exceed the size of the elog message buffer.
361
+ * This is a crock ... there shouldn't be an upper limit to what you can elog().
362
+ */
363
+ static void
364
+ printLongNotice (const char * header , const char * message )
365
+ {
366
+ int len = strlen (message );
367
+
368
+ elog (NOTICE , "%.20s%.*s" , header , ELOG_MAXLEN - 64 , message );
369
+ len -= ELOG_MAXLEN - 64 ;
370
+ while (len > 0 )
371
+ {
372
+ message += ELOG_MAXLEN - 64 ;
373
+ elog (NOTICE , "%.*s" , ELOG_MAXLEN - 64 , message );
374
+ len -= ELOG_MAXLEN - 64 ;
375
+ }
376
+ }
0 commit comments