]> granicus.if.org Git - postgresql/commitdiff
Fix EXPLAIN and EXECUTE commands to pass portal parameters through to
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 29 Nov 2005 01:25:50 +0000 (01:25 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 29 Nov 2005 01:25:50 +0000 (01:25 +0000)
the executor.  This allows, for example, JDBC clients to use '?' bound
parameters in these commands.  Per gripe from Virag Saksena.

src/backend/commands/explain.c
src/backend/commands/prepare.c
src/backend/tcop/utility.c
src/include/commands/explain.h
src/include/commands/prepare.h

index f60fff36c4c7534a167dcbeefab543adf04720c1..bd4e575dbae1284aec51e341fa2a700ac019c8f6 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994-5, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.141 2005/11/26 22:14:56 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.142 2005/11/29 01:25:49 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -45,7 +45,7 @@ typedef struct ExplainState
 } ExplainState;
 
 static void ExplainOneQuery(Query *query, ExplainStmt *stmt,
-                               TupOutputState *tstate);
+                                                       ParamListInfo params, TupOutputState *tstate);
 static double elapsed_time(instr_time *starttime);
 static void explain_outNode(StringInfo str,
                                Plan *plan, PlanState *planstate,
@@ -67,7 +67,7 @@ static void show_sort_keys(List *tlist, int nkeys, AttrNumber *keycols,
  *       execute an EXPLAIN command
  */
 void
-ExplainQuery(ExplainStmt *stmt, DestReceiver *dest)
+ExplainQuery(ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest)
 {
        Query      *query = stmt->query;
        TupOutputState *tstate;
@@ -91,9 +91,9 @@ ExplainQuery(ExplainStmt *stmt, DestReceiver *dest)
        {
                /* Rewriter will not cope with utility statements */
                if (query->utilityStmt && IsA(query->utilityStmt, DeclareCursorStmt))
-                       ExplainOneQuery(query, stmt, tstate);
+                       ExplainOneQuery(query, stmt, params, tstate);
                else if (query->utilityStmt && IsA(query->utilityStmt, ExecuteStmt))
-                       ExplainExecuteQuery(stmt, tstate);
+                       ExplainExecuteQuery(stmt, params, tstate);
                else
                        do_text_output_oneline(tstate, "Utility statements have no plan structure");
        }
@@ -118,7 +118,7 @@ ExplainQuery(ExplainStmt *stmt, DestReceiver *dest)
                        /* Explain every plan */
                        foreach(l, rewritten)
                        {
-                               ExplainOneQuery(lfirst(l), stmt, tstate);
+                               ExplainOneQuery(lfirst(l), stmt, params, tstate);
                                /* put a blank line between plans */
                                if (lnext(l) != NULL)
                                        do_text_output_oneline(tstate, "");
@@ -150,7 +150,8 @@ ExplainResultDesc(ExplainStmt *stmt)
  *       print out the execution plan for one query
  */
 static void
-ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
+ExplainOneQuery(Query *query, ExplainStmt *stmt, ParamListInfo params,
+                               TupOutputState *tstate)
 {
        Plan       *plan;
        QueryDesc  *queryDesc;
@@ -208,7 +209,7 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate)
        /* Create a QueryDesc requesting no output */
        queryDesc = CreateQueryDesc(query, plan,
                                                                ActiveSnapshot, InvalidSnapshot,
-                                                               None_Receiver, NULL,
+                                                               None_Receiver, params,
                                                                stmt->analyze);
 
        ExplainOnePlan(queryDesc, stmt, tstate);
index 7932f838fee93c13d8cb5e428219a68b1bdf2b76..dc84f57506a3650c64a08dab56590fa1b0db22fb 100644 (file)
@@ -10,7 +10,7 @@
  * Copyright (c) 2002-2005, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.42 2005/10/21 16:43:33 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.43 2005/11/29 01:25:49 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -121,7 +121,8 @@ PrepareQuery(PrepareStmt *stmt)
  * Implements the 'EXECUTE' utility statement.
  */
 void
-ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag)
+ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params,
+                        DestReceiver *dest, char *completionTag)
 {
        PreparedStatement *entry;
        char       *query_string;
@@ -150,6 +151,7 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag)
                 * of query, in case parameters are pass-by-reference.
                 */
                estate = CreateExecutorState();
+               estate->es_param_list_info = params;
                paramLI = EvaluateParams(estate, stmt->params, entry->argtype_list);
        }
 
@@ -538,7 +540,8 @@ DropPreparedStatement(const char *stmt_name, bool showError)
  * Implements the 'EXPLAIN EXECUTE' utility statement.
  */
 void
-ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate)
+ExplainExecuteQuery(ExplainStmt *stmt, ParamListInfo params,
+                                       TupOutputState *tstate)
 {
        ExecuteStmt *execstmt = (ExecuteStmt *) stmt->query->utilityStmt;
        PreparedStatement *entry;
@@ -568,6 +571,7 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate)
                 * of query, in case parameters are pass-by-reference.
                 */
                estate = CreateExecutorState();
+               estate->es_param_list_info = params;
                paramLI = EvaluateParams(estate, execstmt->params,
                                                                 entry->argtype_list);
        }
index e8f6379b9298a649b2b8cb534512b9605e4e6665..85b81fd14b53f3fbda01b19508c72b00247d3b18 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.249 2005/11/22 18:17:22 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.250 2005/11/29 01:25:49 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -365,7 +365,7 @@ check_xact_readonly(Node *parsetree)
  *             general utility function invoker
  *
  *     parsetree: the parse tree for the utility statement
- *     params: parameters to use during execution (currently only used by DECLARE)
+ *     params: parameters to use during execution
  *     dest: where to send results
  *     completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
  *             in which to store a command completion status string.
@@ -648,7 +648,8 @@ ProcessUtility(Node *parsetree,
                        break;
 
                case T_ExecuteStmt:
-                       ExecuteQuery((ExecuteStmt *) parsetree, dest, completionTag);
+                       ExecuteQuery((ExecuteStmt *) parsetree, params,
+                                                dest, completionTag);
                        break;
 
                case T_DeallocateStmt:
@@ -891,7 +892,7 @@ ProcessUtility(Node *parsetree,
                        break;
 
                case T_ExplainStmt:
-                       ExplainQuery((ExplainStmt *) parsetree, dest);
+                       ExplainQuery((ExplainStmt *) parsetree, params, dest);
                        break;
 
                case T_VariableSetStmt:
index 58cff3cdc083b61ed876ac727220fe778fe4920c..8fb2721c437a5fd308c1df078c7f9b599b6d8aaf 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994-5, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.24 2004/12/31 22:03:28 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.25 2005/11/29 01:25:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,7 +18,8 @@
 #include "tcop/dest.h"
 
 
-extern void ExplainQuery(ExplainStmt *stmt, DestReceiver *dest);
+extern void ExplainQuery(ExplainStmt *stmt, ParamListInfo params,
+                                                DestReceiver *dest);
 
 extern TupleDesc ExplainResultDesc(ExplainStmt *stmt);
 
index b6c315bd42de8a60c9d0001007f866ba31f43f3b..4eafb91480412b198773dc8e2302b0d42f97e65f 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 2002-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.14 2005/06/22 17:45:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.15 2005/11/29 01:25:50 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -42,10 +42,11 @@ typedef struct
 
 /* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */
 extern void PrepareQuery(PrepareStmt *stmt);
-extern void ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest,
-                        char *completionTag);
+extern void ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params,
+                                                DestReceiver *dest, char *completionTag);
 extern void DeallocateQuery(DeallocateStmt *stmt);
-extern void ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate);
+extern void ExplainExecuteQuery(ExplainStmt *stmt, ParamListInfo params,
+                                                               TupOutputState *tstate);
 
 /* Low-level access to stored prepared statements */
 extern void StorePreparedStatement(const char *stmt_name,