Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite25e6a6

Browse files
committed
Commit the bulk of Mike Ansley's long-query changes in the
backend. Still much left to do.
1 parentab5cafa commite25e6a6

File tree

6 files changed

+67
-109
lines changed

6 files changed

+67
-109
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* Copyright (c) 1994, Regents of the University of California
3030
*
31-
*$Id: pqcomm.c,v 1.81 1999/07/23 03:00:10 tgl Exp $
31+
*$Id: pqcomm.c,v 1.82 1999/08/31 04:26:37 tgl Exp $
3232
*
3333
*-------------------------------------------------------------------------
3434
*/
@@ -526,38 +526,32 @@ pq_getbytes(char *s, size_t len)
526526
/* --------------------------------
527527
*pq_getstring- get a null terminated string from connection
528528
*
529+
*The return value is placed in an expansible StringInfo.
530+
*Note that space allocation comes from the current memory context!
531+
*
529532
*NOTE: this routine does not do any MULTIBYTE conversion,
530533
*even though it is presumably useful only for text, because
531534
*no code in this module should depend on MULTIBYTE mode.
532535
*See pq_getstr in pqformat.c for that.
533536
*
534-
*FIXME: we ought to use an expansible StringInfo buffer,
535-
*rather than dropping data if the message is too long.
536-
*
537537
*returns 0 if OK, EOF if trouble
538538
* --------------------------------
539539
*/
540540
int
541-
pq_getstring(char*s,size_tlen)
541+
pq_getstring(StringInfos)
542542
{
543543
intc;
544544

545-
/*
546-
* Keep on reading until we get the terminating '\0', discarding any
547-
* bytes we don't have room for.
548-
*/
545+
/* Reset string to empty */
546+
s->len=0;
547+
s->data[0]='\0';
549548

549+
/* Read until we get the terminating '\0' */
550550
while ((c=pq_getbyte())!=EOF&&c!='\0')
551551
{
552-
if (len>1)
553-
{
554-
*s++=c;
555-
len--;
556-
}
552+
appendStringInfoChar(s,c);
557553
}
558554

559-
*s='\0';
560-
561555
if (c==EOF)
562556
returnEOF;
563557

‎src/backend/libpq/pqformat.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Copyright (c) 1994, Regents of the University of California
1717
*
18-
*$Id: pqformat.c,v 1.7 1999/07/17 20:17:03 momjian Exp $
18+
*$Id: pqformat.c,v 1.8 1999/08/31 04:26:37 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -290,37 +290,30 @@ pq_getint(int *result, int b)
290290
/* --------------------------------
291291
*pq_getstr - get a null terminated string from connection
292292
*
293-
*FIXME: we ought to usean expansible StringInfo buffer,
294-
*rather than dropping data ifthemessage is too long.
293+
*The return value is placed inan expansible StringInfo.
294+
*Note that space allocation comes fromthecurrent memory context!
295295
*
296296
*returns 0 if OK, EOF if trouble
297297
* --------------------------------
298298
*/
299299
int
300-
pq_getstr(char*s,intmaxlen)
300+
pq_getstr(StringInfos)
301301
{
302302
intc;
303-
304303
#ifdefMULTIBYTE
305304
char*p;
306-
307305
#endif
308306

309-
c=pq_getstring(s,maxlen);
307+
c=pq_getstring(s);
310308

311309
#ifdefMULTIBYTE
312-
p= (char*)pg_client_to_server((unsignedchar*)s,strlen(s));
313-
if (p!=s)/* actual conversion has been done? */
310+
p= (char*)pg_client_to_server((unsignedchar*)s->data,s->len);
311+
if (p!=s->data)/* actual conversion has been done? */
314312
{
315-
intnewlen=strlen(p);
316-
317-
if (newlen<maxlen)
318-
strcpy(s,p);
319-
else
320-
{
321-
strncpy(s,p,maxlen);
322-
s[maxlen-1]='\0';
323-
}
313+
/* reset s to empty, and append the new string p */
314+
s->len=0;
315+
s->data[0]='\0';
316+
appendBinaryStringInfo(s,p,strlen(p));
324317
}
325318
#endif
326319

‎src/backend/tcop/postgres.c

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.127 1999/07/22 02:40:07 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.128 1999/08/31 04:26:40 tgl Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -158,9 +158,9 @@ int_exec_repeat_ = 1;
158158
*decls for routines only used in this file
159159
* ----------------------------------------------------------------
160160
*/
161-
staticintInteractiveBackend(char*inBuf);
162-
staticintSocketBackend(char*inBuf);
163-
staticintReadCommand(char*inBuf);
161+
staticintInteractiveBackend(StringInfoinBuf);
162+
staticintSocketBackend(StringInfoinBuf);
163+
staticintReadCommand(StringInfoinBuf);
164164
staticvoidpg_exec_query(char*query_string);
165165

166166

@@ -178,9 +178,8 @@ static void pg_exec_query(char *query_string);
178178
*/
179179

180180
staticint
181-
InteractiveBackend(char*inBuf)
181+
InteractiveBackend(StringInfoinBuf)
182182
{
183-
char*stuff=inBuf;/* current place in input buffer */
184183
intc;/* character read from getc() */
185184
boolend= false;/* end-of-input flag */
186185
boolbackslashSeen= false;/* have we seen a \ ? */
@@ -192,6 +191,10 @@ InteractiveBackend(char *inBuf)
192191
printf("backend> ");
193192
fflush(stdout);
194193

194+
/* Reset inBuf to empty */
195+
inBuf->len=0;
196+
inBuf->data[0]='\0';
197+
195198
for (;;)
196199
{
197200
if (UseNewLine)
@@ -207,14 +210,15 @@ InteractiveBackend(char *inBuf)
207210
{
208211
if (backslashSeen)
209212
{
210-
stuff--;
213+
/* discard backslash from inBuf */
214+
inBuf->data[--inBuf->len]='\0';
215+
backslashSeen= false;
211216
continue;
212217
}
213218
else
214219
{
215220
/* keep the newline character */
216-
*stuff++='\n';
217-
*stuff++='\0';
221+
appendStringInfoChar(inBuf,'\n');
218222
break;
219223
}
220224
}
@@ -223,7 +227,7 @@ InteractiveBackend(char *inBuf)
223227
else
224228
backslashSeen= false;
225229

226-
*stuff++=(char)c;
230+
appendStringInfoChar(inBuf,(char)c);
227231
}
228232

229233
if (c==EOF)
@@ -236,9 +240,9 @@ InteractiveBackend(char *inBuf)
236240
* ----------------
237241
*/
238242
while ((c=getc(stdin))!=EOF)
239-
*stuff++=(char)c;
243+
appendStringInfoChar(inBuf,(char)c);
240244

241-
if (stuff==inBuf)
245+
if (inBuf->len==0)
242246
end= true;
243247
}
244248

@@ -261,7 +265,7 @@ InteractiveBackend(char *inBuf)
261265
* ----------------
262266
*/
263267
if (EchoQuery)
264-
printf("query: %s\n",inBuf);
268+
printf("query: %s\n",inBuf->data);
265269
fflush(stdout);
266270

267271
return'Q';
@@ -274,15 +278,15 @@ InteractiveBackend(char *inBuf)
274278
*the user is placed in its parameter inBuf.
275279
*
276280
*If the input is a fastpath function call (case 'F') then
277-
*the function call is processed in HandleFunctionRequest().
281+
*the function call is processed in HandleFunctionRequest()
278282
*(now called from PostgresMain()).
279283
*
280284
* EOF is returned if the connection is lost.
281285
* ----------------
282286
*/
283287

284288
staticint
285-
SocketBackend(char*inBuf)
289+
SocketBackend(StringInfoinBuf)
286290
{
287291
charqtype;
288292
charresult='\0';
@@ -302,7 +306,7 @@ SocketBackend(char *inBuf)
302306
* ----------------
303307
*/
304308
case'Q':
305-
if (pq_getstr(inBuf,MAX_PARSE_BUFFER))
309+
if (pq_getstr(inBuf))
306310
returnEOF;
307311
result='Q';
308312
break;
@@ -312,7 +316,7 @@ SocketBackend(char *inBuf)
312316
* ----------------
313317
*/
314318
case'F':
315-
if (pq_getstr(inBuf,MAX_PARSE_BUFFER))
319+
if (pq_getstr(inBuf))
316320
returnEOF;/* ignore "string" at start of F message */
317321
result='F';
318322
break;
@@ -347,12 +351,21 @@ SocketBackend(char *inBuf)
347351
* ----------------
348352
*/
349353
staticint
350-
ReadCommand(char*inBuf)
354+
ReadCommand(StringInfoinBuf)
351355
{
356+
MemoryContextoldcontext;
357+
intresult;
358+
359+
/* Make sure any expansion of inBuf happens in permanent memory context,
360+
* so that we can keep using it for future command cycles.
361+
*/
362+
oldcontext=MemoryContextSwitchTo(TopMemoryContext);
352363
if (IsUnderPostmaster)
353-
returnSocketBackend(inBuf);
364+
result=SocketBackend(inBuf);
354365
else
355-
returnInteractiveBackend(inBuf);
366+
result=InteractiveBackend(inBuf);
367+
MemoryContextSwitchTo(oldcontext);
368+
returnresult;
356369
}
357370

358371
List*
@@ -374,45 +387,7 @@ pg_parse_and_plan(char *query_string,/* string to execute */
374387

375388
if (DebugPrintQuery)
376389
{
377-
if (DebugPrintQuery>3)
378-
{
379-
/* Print the query string as is if query debug level > 3 */
380-
TPRINTF(TRACE_QUERY,"query: %s",query_string);
381-
}
382-
else
383-
{
384-
/* Print condensed query string to fit in one log line */
385-
charbuff[MAX_QUERY_SIZE+1];
386-
charc,
387-
*s,
388-
*d;
389-
intn,
390-
is_space=1;
391-
392-
for (s=query_string,d=buff,n=0; (c=*s)&& (n<MAX_QUERY_SIZE);s++)
393-
{
394-
switch (c)
395-
{
396-
case'\r':
397-
case'\n':
398-
case'\t':
399-
c=' ';
400-
/* fall through */
401-
case' ':
402-
if (is_space)
403-
continue;
404-
is_space=1;
405-
break;
406-
default:
407-
is_space=0;
408-
break;
409-
}
410-
*d++=c;
411-
n++;
412-
}
413-
*d='\0';
414-
TPRINTF(TRACE_QUERY,"query: %s",buff);
415-
}
390+
TPRINTF(TRACE_QUERY,"query: %s",query_string);
416391
}
417392

418393
/* ----------------
@@ -889,7 +864,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
889864
interrs=0;
890865

891866
intfirstchar;
892-
charparser_input[MAX_PARSE_BUFFER];
867+
StringInfoparser_input;
893868
char*userName;
894869

895870
/* Used if verbose is set, must be initialized */
@@ -1452,6 +1427,8 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
14521427

14531428
on_shmem_exit(remove_all_temp_relations,NULL);
14541429

1430+
parser_input=makeStringInfo();/* initialize input buffer */
1431+
14551432
/* ----------------
14561433
*Set up handler for cancel-request signal, and
14571434
*send this backend's cancellation info to the frontend.
@@ -1492,7 +1469,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
14921469
if (!IsUnderPostmaster)
14931470
{
14941471
puts("\nPOSTGRES backend interactive interface ");
1495-
puts("$Revision: 1.127 $ $Date: 1999/07/22 02:40:07 $\n");
1472+
puts("$Revision: 1.128 $ $Date: 1999/08/31 04:26:40 $\n");
14961473
}
14971474

14981475
/* ----------------
@@ -1548,8 +1525,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15481525
* (3) read a command.
15491526
* ----------------
15501527
*/
1551-
MemSet(parser_input,0,MAX_PARSE_BUFFER);
1552-
15531528
firstchar=ReadCommand(parser_input);
15541529

15551530
QueryCancel= false;/* forget any earlier CANCEL signal */
@@ -1592,7 +1567,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
15921567
* ----------------
15931568
*/
15941569
case'Q':
1595-
if (strspn(parser_input," \t\n")==strlen(parser_input))
1570+
if (strspn(parser_input->data," \t\n")==parser_input->len)
15961571
{
15971572
/* ----------------
15981573
*if there is nothing in the input buffer, don't bother
@@ -1616,7 +1591,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
16161591
TPRINTF(TRACE_VERBOSE,"StartTransactionCommand");
16171592
StartTransactionCommand();
16181593

1619-
pg_exec_query(parser_input);
1594+
pg_exec_query(parser_input->data);
16201595

16211596
if (ShowStats)
16221597
ShowUsage();

‎src/include/libpq/libpq.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: libpq.h,v 1.32 1999/07/15 15:21:15 momjian Exp $
9+
* $Id: libpq.h,v 1.33 1999/08/31 04:26:33 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -17,6 +17,7 @@
1717

1818
#include<netinet/in.h>
1919

20+
#include"lib/stringinfo.h"
2021
#include"libpq/libpq-be.h"
2122
#include"tcop/dest.h"
2223
#include"utils/exc.h"
@@ -241,7 +242,7 @@ extern void pq_init(void);
241242
externintpq_getport(void);
242243
externvoidpq_close(void);
243244
externintpq_getbytes(char*s,size_tlen);
244-
externintpq_getstring(char*s,size_tlen);
245+
externintpq_getstring(StringInfos);
245246
externintpq_peekbyte(void);
246247
externintpq_putbytes(constchar*s,size_tlen);
247248
externintpq_flush(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp