Commit 982430f8 authored by Tom Lane's avatar Tom Lane

Put back encoding-conversion step in processing of incoming queries;

I had inadvertently omitted it while rearranging things to support
length-counted incoming messages.  Also, change the parser's API back
to accepting a 'char *' query string instead of 'StringInfo', as the
latter wasn't buying us anything except overhead.  (I think when I put
it in I had some notion of making the parser API 8-bit-clean, but
seeing that flex depends on null-terminated input, that's not really
ever gonna happen.)
parent 351372e5
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.90 2003/04/24 21:16:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.91 2003/04/27 20:09:43 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -967,7 +967,6 @@ spi_printtup(HeapTuple tuple, TupleDesc tupdesc, DestReceiver *self) ...@@ -967,7 +967,6 @@ spi_printtup(HeapTuple tuple, TupleDesc tupdesc, DestReceiver *self)
static int static int
_SPI_execute(const char *src, int tcount, _SPI_plan *plan) _SPI_execute(const char *src, int tcount, _SPI_plan *plan)
{ {
StringInfoData stri;
List *raw_parsetree_list; List *raw_parsetree_list;
List *query_list_list; List *query_list_list;
List *plan_list; List *plan_list;
...@@ -994,10 +993,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan) ...@@ -994,10 +993,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan)
/* /*
* Parse the request string into a list of raw parse trees. * Parse the request string into a list of raw parse trees.
*/ */
initStringInfo(&stri); raw_parsetree_list = pg_parse_query(src, argtypes, nargs);
appendStringInfoString(&stri, src);
raw_parsetree_list = pg_parse_query(&stri, argtypes, nargs);
/* /*
* Do parse analysis and rule rewrite for each raw parsetree. * Do parse analysis and rule rewrite for each raw parsetree.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.134 2003/04/08 23:20:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.135 2003/04/27 20:09:44 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -1692,7 +1692,6 @@ inline_function(Oid funcid, Oid result_type, List *args, ...@@ -1692,7 +1692,6 @@ inline_function(Oid funcid, Oid result_type, List *args,
bool isNull; bool isNull;
MemoryContext oldcxt; MemoryContext oldcxt;
MemoryContext mycxt; MemoryContext mycxt;
StringInfoData stri;
List *raw_parsetree_list; List *raw_parsetree_list;
List *querytree_list; List *querytree_list;
Query *querytree; Query *querytree;
...@@ -1752,10 +1751,7 @@ inline_function(Oid funcid, Oid result_type, List *args, ...@@ -1752,10 +1751,7 @@ inline_function(Oid funcid, Oid result_type, List *args,
* we care about. Also, we can punt as soon as we detect more than * we care about. Also, we can punt as soon as we detect more than
* one command in the function body. * one command in the function body.
*/ */
initStringInfo(&stri); raw_parsetree_list = pg_parse_query(src,
appendStringInfo(&stri, "%s", src);
raw_parsetree_list = pg_parse_query(&stri,
funcform->proargtypes, funcform->proargtypes,
funcform->pronargs); funcform->pronargs);
if (length(raw_parsetree_list) != 1) if (length(raw_parsetree_list) != 1)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.55 2003/04/24 21:16:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.56 2003/04/27 20:09:44 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -437,7 +437,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod) ...@@ -437,7 +437,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod)
initStringInfo(&buf); initStringInfo(&buf);
appendStringInfo(&buf, "SELECT (NULL::%s)", str); appendStringInfo(&buf, "SELECT (NULL::%s)", str);
raw_parsetree_list = parser(&buf, NULL, 0); raw_parsetree_list = parser(buf.data, NULL, 0);
/* /*
* Make sure we got back exactly what we expected and no more; * Make sure we got back exactly what we expected and no more;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.55 2002/09/04 20:31:24 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.56 2003/04/27 20:09:44 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -45,7 +45,7 @@ static bool have_lookahead; /* lookahead_token set? */ ...@@ -45,7 +45,7 @@ static bool have_lookahead; /* lookahead_token set? */
* Returns a list of raw (un-analyzed) parse trees. * Returns a list of raw (un-analyzed) parse trees.
*/ */
List * List *
parser(StringInfo str, Oid *typev, int nargs) parser(const char *str, Oid *typev, int nargs)
{ {
int yyresult; int yyresult;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.104 2003/04/24 21:16:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.105 2003/04/27 20:09:44 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -595,18 +595,23 @@ yyerror(const char *message) ...@@ -595,18 +595,23 @@ yyerror(const char *message)
* Called before any actual parsing is done * Called before any actual parsing is done
*/ */
void void
scanner_init(StringInfo str) scanner_init(const char *str)
{ {
Size slen = strlen(str);
/* /*
* Might be left over after ereport() * Might be left over after ereport()
*/ */
if (YY_CURRENT_BUFFER) if (YY_CURRENT_BUFFER)
yy_delete_buffer(YY_CURRENT_BUFFER); yy_delete_buffer(YY_CURRENT_BUFFER);
scanbuf = palloc(str->len + 2); /*
memcpy(scanbuf, str->data, str->len); * Make a scan buffer with special termination needed by flex.
scanbuf[str->len] = scanbuf[str->len + 1] = YY_END_OF_BUFFER_CHAR; */
scanbufhandle = yy_scan_buffer(scanbuf, str->len + 2); scanbuf = palloc(slen + 2);
memcpy(scanbuf, str, slen);
scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
scanbufhandle = yy_scan_buffer(scanbuf, slen + 2);
/* initialize literal buffer to a reasonable but expansible size */ /* initialize literal buffer to a reasonable but expansible size */
literalalloc = 128; literalalloc = 128;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2003, PostgreSQL Global Development Group * Copyright (c) 2001-2003, PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.34 2003/04/26 02:57:14 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.35 2003/04/27 20:09:44 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -446,7 +446,7 @@ pgstat_bestart(void) ...@@ -446,7 +446,7 @@ pgstat_bestart(void)
* ---------- * ----------
*/ */
void void
pgstat_report_activity(char *what) pgstat_report_activity(const char *what)
{ {
PgStat_MsgActivity msg; PgStat_MsgActivity msg;
int len; int len;
...@@ -455,7 +455,8 @@ pgstat_report_activity(char *what) ...@@ -455,7 +455,8 @@ pgstat_report_activity(char *what)
return; return;
len = strlen(what); 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); memcpy(msg.m_what, what, len);
msg.m_what[len] = '\0'; msg.m_what[len] = '\0';
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.324 2003/04/24 21:16:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.325 2003/04/27 20:09:44 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -60,16 +60,15 @@ ...@@ -60,16 +60,15 @@
#include "pgstat.h" #include "pgstat.h"
extern int optind;
extern char *optarg;
/* ---------------- /* ----------------
* global variables * global variables
* ---------------- * ----------------
*/ */
const char *debug_query_string; /* for pgmonitor and
extern int optind;
extern char *optarg;
char *debug_query_string; /* for pgmonitor and
* log_min_error_statement */ * log_min_error_statement */
/* Note: whereToSendOutput is initialized for the bootstrap/standalone case */ /* Note: whereToSendOutput is initialized for the bootstrap/standalone case */
...@@ -339,22 +338,18 @@ ReadCommand(StringInfo inBuf) ...@@ -339,22 +338,18 @@ ReadCommand(StringInfo inBuf)
* but it is still needed for parsing of SQL function bodies. * but it is still needed for parsing of SQL function bodies.
*/ */
List * List *
pg_parse_and_rewrite(char *query_string, /* string to execute */ pg_parse_and_rewrite(const char *query_string, /* string to execute */
Oid *typev, /* parameter types */ Oid *typev, /* parameter types */
int nargs) /* number of parameters */ int nargs) /* number of parameters */
{ {
List *raw_parsetree_list; List *raw_parsetree_list;
List *querytree_list; List *querytree_list;
List *list_item; List *list_item;
StringInfoData stri;
initStringInfo(&stri);
appendStringInfoString(&stri, query_string);
/* /*
* (1) parse the request string into a list of raw parse trees. * (1) parse the request string into a list of raw parse trees.
*/ */
raw_parsetree_list = pg_parse_query(&stri, typev, nargs); raw_parsetree_list = pg_parse_query(query_string, typev, nargs);
/* /*
* (2) Do parse analysis and rule rewrite. * (2) Do parse analysis and rule rewrite.
...@@ -385,12 +380,12 @@ pg_parse_and_rewrite(char *query_string, /* string to execute */ ...@@ -385,12 +380,12 @@ pg_parse_and_rewrite(char *query_string, /* string to execute */
* commands are not processed any further than the raw parse stage. * commands are not processed any further than the raw parse stage.
*/ */
List * List *
pg_parse_query(StringInfo query_string, Oid *typev, int nargs) pg_parse_query(const char *query_string, Oid *typev, int nargs)
{ {
List *raw_parsetree_list; List *raw_parsetree_list;
if (log_statement) if (log_statement)
elog(LOG, "query: %s", query_string->data); elog(LOG, "query: %s", query_string);
if (log_parser_stats) if (log_parser_stats)
ResetUsage(); ResetUsage();
...@@ -569,7 +564,7 @@ pg_plan_query(Query *querytree) ...@@ -569,7 +564,7 @@ pg_plan_query(Query *querytree)
*/ */
void void
pg_exec_query_string(StringInfo query_string, /* string to execute */ pg_exec_query_string(const char *query_string, /* string to execute */
CommandDest dest, /* where results should go */ CommandDest dest, /* where results should go */
MemoryContext parse_context) /* context for MemoryContext parse_context) /* context for
* parsetrees */ * parsetrees */
...@@ -582,7 +577,7 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */ ...@@ -582,7 +577,7 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
stop_t; stop_t;
bool save_log_duration = log_duration; bool save_log_duration = log_duration;
debug_query_string = query_string->data; debug_query_string = query_string;
/* /*
* We use save_log_duration so "SET log_duration = true" doesn't * We use save_log_duration so "SET log_duration = true" doesn't
...@@ -1248,7 +1243,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1248,7 +1243,7 @@ PostgresMain(int argc, char *argv[], const char *username)
GucSource gucsource; GucSource gucsource;
char *tmp; char *tmp;
int firstchar; int firstchar;
StringInfo parser_input; StringInfo input_message;
bool send_rfq; bool send_rfq;
/* /*
...@@ -1831,7 +1826,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1831,7 +1826,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.324 $ $Date: 2003/04/24 21:16:43 $\n"); puts("$Revision: 1.325 $ $Date: 2003/04/27 20:09:44 $\n");
} }
/* /*
...@@ -1933,7 +1928,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1933,7 +1928,7 @@ PostgresMain(int argc, char *argv[], const char *username)
MemoryContextSwitchTo(QueryContext); MemoryContextSwitchTo(QueryContext);
MemoryContextResetAndDeleteChildren(QueryContext); MemoryContextResetAndDeleteChildren(QueryContext);
parser_input = makeStringInfo(); input_message = makeStringInfo();
/* /*
* (1) tell the frontend we're ready for a new query. * (1) tell the frontend we're ready for a new query.
...@@ -1983,7 +1978,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1983,7 +1978,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/* /*
* (3) read a command (loop blocks here) * (3) read a command (loop blocks here)
*/ */
firstchar = ReadCommand(parser_input); firstchar = ReadCommand(input_message);
/* /*
* (4) disable async signal conditions again. * (4) disable async signal conditions again.
...@@ -2009,18 +2004,21 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -2009,18 +2004,21 @@ PostgresMain(int argc, char *argv[], const char *username)
switch (firstchar) switch (firstchar)
{ {
case 'Q': /* simple query */ case 'Q': /* simple query */
{
/* /*
* Process the query string. * Process the query string.
* *
* Note: transaction command start/end is now done within * Note: transaction command start/end is now done within
* pg_exec_query_string(), not here. * pg_exec_query_string(), not here.
*/ */
const char *query_string = pq_getmsgstring(input_message);
if (log_statement_stats) if (log_statement_stats)
ResetUsage(); ResetUsage();
pgstat_report_activity(parser_input->data); pgstat_report_activity(query_string);
pg_exec_query_string(parser_input, pg_exec_query_string(query_string,
whereToSendOutput, whereToSendOutput,
QueryContext); QueryContext);
...@@ -2028,6 +2026,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -2028,6 +2026,7 @@ PostgresMain(int argc, char *argv[], const char *username)
ShowUsage("QUERY STATISTICS"); ShowUsage("QUERY STATISTICS");
send_rfq = true; send_rfq = true;
}
break; break;
case 'F': /* fastpath function call */ case 'F': /* fastpath function call */
...@@ -2037,7 +2036,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -2037,7 +2036,7 @@ PostgresMain(int argc, char *argv[], const char *username)
/* start an xact for this function invocation */ /* start an xact for this function invocation */
start_xact_command(); start_xact_command();
if (HandleFunctionRequest(parser_input) == EOF) if (HandleFunctionRequest(input_message) == EOF)
{ {
/* lost frontend connection during F message input */ /* lost frontend connection during F message input */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: gramparse.h,v 1.25 2002/09/04 20:31:45 momjian Exp $ * $Id: gramparse.h,v 1.26 2003/04/27 20:09:44 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#ifndef GRAMPARSE_H #ifndef GRAMPARSE_H
#define GRAMPARSE_H #define GRAMPARSE_H
#include "lib/stringinfo.h"
#include "nodes/parsenodes.h" #include "nodes/parsenodes.h"
/* from parser.c */ /* from parser.c */
...@@ -24,7 +23,7 @@ extern Oid param_type(int t); ...@@ -24,7 +23,7 @@ extern Oid param_type(int t);
extern int yylex(void); extern int yylex(void);
/* from scan.l */ /* from scan.l */
extern void scanner_init(StringInfo str); extern void scanner_init(const char *str);
extern void scanner_finish(void); extern void scanner_finish(void);
extern int base_yylex(void); extern int base_yylex(void);
extern void yyerror(const char *message); extern void yyerror(const char *message);
......
...@@ -7,16 +7,15 @@ ...@@ -7,16 +7,15 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parser.h,v 1.13 2002/06/20 20:29:52 momjian Exp $ * $Id: parser.h,v 1.14 2003/04/27 20:09:44 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PARSER_H #ifndef PARSER_H
#define PARSER_H #define PARSER_H
#include "lib/stringinfo.h"
#include "parser/parse_node.h" #include "parser/parse_node.h"
extern List *parser(StringInfo str, Oid *typev, int nargs); extern List *parser(const char *str, Oid *typev, int nargs);
#endif /* PARSER_H */ #endif /* PARSER_H */
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 2001-2003, PostgreSQL Global Development Group * Copyright (c) 2001-2003, PostgreSQL Global Development Group
* *
* $Id: pgstat.h,v 1.14 2003/04/26 02:57:14 tgl Exp $ * $Id: pgstat.h,v 1.15 2003/04/27 20:09:44 tgl Exp $
* ---------- * ----------
*/ */
#ifndef PGSTAT_H #ifndef PGSTAT_H
...@@ -359,7 +359,7 @@ extern void pgstat_beterm(int pid); ...@@ -359,7 +359,7 @@ extern void pgstat_beterm(int pid);
extern void pgstat_bestart(void); extern void pgstat_bestart(void);
extern void pgstat_ping(void); extern void pgstat_ping(void);
extern void pgstat_report_activity(char *what); extern void pgstat_report_activity(const char *what);
extern void pgstat_report_tabstat(void); extern void pgstat_report_tabstat(void);
extern int pgstat_vacuum_tabstat(void); extern int pgstat_vacuum_tabstat(void);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: tcopprot.h,v 1.53 2002/11/15 01:57:28 momjian Exp $ * $Id: tcopprot.h,v 1.54 2003/04/27 20:09:44 tgl Exp $
* *
* OLD COMMENTS * OLD COMMENTS
* This file was created so that other c files could get the two * This file was created so that other c files could get the two
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <setjmp.h> #include <setjmp.h>
#include "executor/execdesc.h" #include "executor/execdesc.h"
#include "lib/stringinfo.h"
#include "tcop/dest.h" #include "tcop/dest.h"
...@@ -32,16 +31,16 @@ extern bool InError; ...@@ -32,16 +31,16 @@ extern bool InError;
extern CommandDest whereToSendOutput; extern CommandDest whereToSendOutput;
extern bool log_hostname; extern bool log_hostname;
extern bool LogSourcePort; extern bool LogSourcePort;
extern DLLIMPORT char* debug_query_string; extern DLLIMPORT const char *debug_query_string;
#ifndef BOOTSTRAP_INCLUDE #ifndef BOOTSTRAP_INCLUDE
extern List *pg_parse_query(StringInfo query_string, Oid *typev, int nargs); extern List *pg_parse_query(const char *query_string, Oid *typev, int nargs);
extern List *pg_analyze_and_rewrite(Node *parsetree); extern List *pg_analyze_and_rewrite(Node *parsetree);
extern List *pg_parse_and_rewrite(char *query_string, extern List *pg_parse_and_rewrite(const char *query_string,
Oid *typev, int nargs); Oid *typev, int nargs);
extern Plan *pg_plan_query(Query *querytree); extern Plan *pg_plan_query(Query *querytree);
extern void pg_exec_query_string(StringInfo query_string, extern void pg_exec_query_string(const char *query_string,
CommandDest dest, CommandDest dest,
MemoryContext parse_context); MemoryContext parse_context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment