Remove plpgsql's special-case code paths for SET/RESET.
authorTom Lane
Sat, 22 May 2021 14:25:36 +0000 (10:25 -0400)
committerTom Lane
Sat, 22 May 2021 14:25:36 +0000 (10:25 -0400)
In the wake of 84f5c2908, it's no longer necessary for plpgsql to
handle SET/RESET specially.  The point of that was just to avoid
taking a new transaction snapshot prematurely, which the regular code
path through _SPI_execute_plan() now does just fine (in fact better,
since it now does the right thing for LOCK too).  Hence, rip out a
few lines of code, going back to the old way of treating SET/RESET
as a generic SQL command.  This essentially reverts all but the
test cases from b981275b6.

Discussion: https://postgr.es/m/15990-eee2ac466b11293d@postgresql.org

src/pl/plpgsql/src/expected/plpgsql_transaction.out
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_funcs.c
src/pl/plpgsql/src/pl_gram.y
src/pl/plpgsql/src/pl_unreserved_kwlist.h
src/pl/plpgsql/src/plpgsql.h

index e205a1e00227c9aa778da7bd9d5774af51ab191a..8fceb88c9bb14e03be738a5bcec786e9ffec1e2b 100644 (file)
@@ -497,7 +497,7 @@ END;
 $$;
 ERROR:  SET TRANSACTION ISOLATION LEVEL must be called before any query
 CONTEXT:  SQL statement "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"
-PL/pgSQL function inline_code_block line 3 at SET
+PL/pgSQL function inline_code_block line 3 at SQL statement
 DO LANGUAGE plpgsql $$
 BEGIN
     SAVEPOINT foo;
index 4e705c162ac0b4bc9390e56afc962b998b68dce6..78b593d12c7ce2862fc2744f171439f06667bcdb 100644 (file)
@@ -317,8 +317,6 @@ static int  exec_stmt_commit(PLpgSQL_execstate *estate,
                             PLpgSQL_stmt_commit *stmt);
 static int exec_stmt_rollback(PLpgSQL_execstate *estate,
                               PLpgSQL_stmt_rollback *stmt);
-static int exec_stmt_set(PLpgSQL_execstate *estate,
-                         PLpgSQL_stmt_set *stmt);
 
 static void plpgsql_estate_setup(PLpgSQL_execstate *estate,
                                 PLpgSQL_function *func,
@@ -2088,10 +2086,6 @@ exec_stmts(PLpgSQL_execstate *estate, List *stmts)
                rc = exec_stmt_rollback(estate, (PLpgSQL_stmt_rollback *) stmt);
                break;
 
-           case PLPGSQL_STMT_SET:
-               rc = exec_stmt_set(estate, (PLpgSQL_stmt_set *) stmt);
-               break;
-
            default:
                /* point err_stmt to parent, since this one seems corrupt */
                estate->err_stmt = save_estmt;
@@ -4926,37 +4920,6 @@ exec_stmt_rollback(PLpgSQL_execstate *estate, PLpgSQL_stmt_rollback *stmt)
    return PLPGSQL_RC_OK;
 }
 
-/*
- * exec_stmt_set
- *
- * Execute SET/RESET statement.
- *
- * We just parse and execute the statement normally, but we have to do it
- * without setting a snapshot, for things like SET TRANSACTION.
- * XXX spi.c now handles this correctly, so we no longer need a special case.
- */
-static int
-exec_stmt_set(PLpgSQL_execstate *estate, PLpgSQL_stmt_set *stmt)
-{
-   PLpgSQL_expr *expr = stmt->expr;
-   SPIExecuteOptions options;
-   int         rc;
-
-   if (expr->plan == NULL)
-       exec_prepare_plan(estate, expr, 0);
-
-   memset(&options, 0, sizeof(options));
-   options.read_only = estate->readonly_func;
-
-   rc = SPI_execute_plan_extended(expr->plan, &options);
-
-   if (rc != SPI_OK_UTILITY)
-       elog(ERROR, "SPI_execute_plan_extended failed executing query \"%s\": %s",
-            expr->query, SPI_result_code_string(rc));
-
-   return PLPGSQL_RC_OK;
-}
-
 /* ----------
  * exec_assign_expr            Put an expression's result into a variable.
  * ----------
index 919b968826c04bf360baa560c35db5e22150a203..e0863acb3d1f300b15e7ae17bca67eee77aec57d 100644 (file)
@@ -288,8 +288,6 @@ plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
            return "COMMIT";
        case PLPGSQL_STMT_ROLLBACK:
            return "ROLLBACK";
-       case PLPGSQL_STMT_SET:
-           return "SET";
    }
 
    return "unknown";
@@ -370,7 +368,6 @@ static void free_perform(PLpgSQL_stmt_perform *stmt);
 static void free_call(PLpgSQL_stmt_call *stmt);
 static void free_commit(PLpgSQL_stmt_commit *stmt);
 static void free_rollback(PLpgSQL_stmt_rollback *stmt);
-static void free_set(PLpgSQL_stmt_set *stmt);
 static void free_expr(PLpgSQL_expr *expr);
 
 
@@ -460,9 +457,6 @@ free_stmt(PLpgSQL_stmt *stmt)
        case PLPGSQL_STMT_ROLLBACK:
            free_rollback((PLpgSQL_stmt_rollback *) stmt);
            break;
-       case PLPGSQL_STMT_SET:
-           free_set((PLpgSQL_stmt_set *) stmt);
-           break;
        default:
            elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
            break;
@@ -626,12 +620,6 @@ free_rollback(PLpgSQL_stmt_rollback *stmt)
 {
 }
 
-static void
-free_set(PLpgSQL_stmt_set *stmt)
-{
-   free_expr(stmt->expr);
-}
-
 static void
 free_exit(PLpgSQL_stmt_exit *stmt)
 {
@@ -825,7 +813,6 @@ static void dump_perform(PLpgSQL_stmt_perform *stmt);
 static void dump_call(PLpgSQL_stmt_call *stmt);
 static void dump_commit(PLpgSQL_stmt_commit *stmt);
 static void dump_rollback(PLpgSQL_stmt_rollback *stmt);
-static void dump_set(PLpgSQL_stmt_set *stmt);
 static void dump_expr(PLpgSQL_expr *expr);
 
 
@@ -925,9 +912,6 @@ dump_stmt(PLpgSQL_stmt *stmt)
        case PLPGSQL_STMT_ROLLBACK:
            dump_rollback((PLpgSQL_stmt_rollback *) stmt);
            break;
-       case PLPGSQL_STMT_SET:
-           dump_set((PLpgSQL_stmt_set *) stmt);
-           break;
        default:
            elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
            break;
@@ -1329,13 +1313,6 @@ dump_rollback(PLpgSQL_stmt_rollback *stmt)
        printf("ROLLBACK\n");
 }
 
-static void
-dump_set(PLpgSQL_stmt_set *stmt)
-{
-   dump_ind();
-   printf("%s\n", stmt->expr->query);
-}
-
 static void
 dump_exit(PLpgSQL_stmt_exit *stmt)
 {
index 34e0520719fea280fa03dab03458ce8ff3ff0f37..3fcca43b904ec5b215cc6f8449d40f5faff69e64 100644 (file)
@@ -197,7 +197,7 @@ static  void            check_raise_parameters(PLpgSQL_stmt_raise *stmt);
 %type    stmt_return stmt_raise stmt_assert stmt_execsql
 %type    stmt_dynexecute stmt_for stmt_perform stmt_call stmt_getdiag
 %type    stmt_open stmt_fetch stmt_move stmt_close stmt_null
-%type    stmt_commit stmt_rollback stmt_set
+%type    stmt_commit stmt_rollback
 %type    stmt_case stmt_foreach_a
 
 %type    proc_exceptions
@@ -328,7 +328,6 @@ static  void            check_raise_parameters(PLpgSQL_stmt_raise *stmt);
 %token    K_QUERY
 %token    K_RAISE
 %token    K_RELATIVE
-%token    K_RESET
 %token    K_RETURN
 %token    K_RETURNED_SQLSTATE
 %token    K_REVERSE
@@ -338,7 +337,6 @@ static  void            check_raise_parameters(PLpgSQL_stmt_raise *stmt);
 %token    K_SCHEMA
 %token    K_SCHEMA_NAME
 %token    K_SCROLL
-%token    K_SET
 %token    K_SLICE
 %token    K_SQLSTATE
 %token    K_STACKED
@@ -899,8 +897,6 @@ proc_stmt       : pl_block ';'
                        { $$ = $1; }
                | stmt_rollback
                        { $$ = $1; }
-               | stmt_set
-                       { $$ = $1; }
                ;
 
 stmt_perform   : K_PERFORM
@@ -2273,34 +2269,6 @@ opt_transaction_chain:
            | /* EMPTY */           { $$ = false; }
                ;
 
-stmt_set   : K_SET
-                   {
-                       PLpgSQL_stmt_set *new;
-
-                       new = palloc0(sizeof(PLpgSQL_stmt_set));
-                       new->cmd_type = PLPGSQL_STMT_SET;
-                       new->lineno = plpgsql_location_to_lineno(@1);
-                       new->stmtid = ++plpgsql_curr_compile->nstatements;
-                       plpgsql_push_back_token(K_SET);
-                       new->expr = read_sql_stmt();
-
-                       $$ = (PLpgSQL_stmt *)new;
-                   }
-           | K_RESET
-                   {
-                       PLpgSQL_stmt_set *new;
-
-                       new = palloc0(sizeof(PLpgSQL_stmt_set));
-                       new->cmd_type = PLPGSQL_STMT_SET;
-                       new->lineno = plpgsql_location_to_lineno(@1);
-                       new->stmtid = ++plpgsql_curr_compile->nstatements;
-                       plpgsql_push_back_token(K_RESET);
-                       new->expr = read_sql_stmt();
-
-                       $$ = (PLpgSQL_stmt *)new;
-                   }
-           ;
-
 
 cursor_variable    : T_DATUM
                    {
@@ -2588,7 +2556,6 @@ unreserved_keyword    :
                | K_QUERY
                | K_RAISE
                | K_RELATIVE
-               | K_RESET
                | K_RETURN
                | K_RETURNED_SQLSTATE
                | K_REVERSE
@@ -2598,7 +2565,6 @@ unreserved_keyword    :
                | K_SCHEMA
                | K_SCHEMA_NAME
                | K_SCROLL
-               | K_SET
                | K_SLICE
                | K_SQLSTATE
                | K_STACKED
index 44c8b68bfbc4b964ad4114f46d5d9c3d22425c52..fcb34f7c7fbca6816a4622383118201bdc8df62f 100644 (file)
@@ -89,7 +89,6 @@ PG_KEYWORD("prior", K_PRIOR)
 PG_KEYWORD("query", K_QUERY)
 PG_KEYWORD("raise", K_RAISE)
 PG_KEYWORD("relative", K_RELATIVE)
-PG_KEYWORD("reset", K_RESET)
 PG_KEYWORD("return", K_RETURN)
 PG_KEYWORD("returned_sqlstate", K_RETURNED_SQLSTATE)
 PG_KEYWORD("reverse", K_REVERSE)
@@ -99,7 +98,6 @@ PG_KEYWORD("rowtype", K_ROWTYPE)
 PG_KEYWORD("schema", K_SCHEMA)
 PG_KEYWORD("schema_name", K_SCHEMA_NAME)
 PG_KEYWORD("scroll", K_SCROLL)
-PG_KEYWORD("set", K_SET)
 PG_KEYWORD("slice", K_SLICE)
 PG_KEYWORD("sqlstate", K_SQLSTATE)
 PG_KEYWORD("stacked", K_STACKED)
index d5010862a5035c0314af9119db24f011d3f8bde6..fcbfcd678b161762873d0440c64dc9d20ac7b4a1 100644 (file)
@@ -127,8 +127,7 @@ typedef enum PLpgSQL_stmt_type
    PLPGSQL_STMT_PERFORM,
    PLPGSQL_STMT_CALL,
    PLPGSQL_STMT_COMMIT,
-   PLPGSQL_STMT_ROLLBACK,
-   PLPGSQL_STMT_SET
+   PLPGSQL_STMT_ROLLBACK
 } PLpgSQL_stmt_type;
 
 /*
@@ -566,17 +565,6 @@ typedef struct PLpgSQL_stmt_rollback
    bool        chain;
 } PLpgSQL_stmt_rollback;
 
-/*
- * SET statement
- */
-typedef struct PLpgSQL_stmt_set
-{
-   PLpgSQL_stmt_type cmd_type;
-   int         lineno;
-   unsigned int stmtid;
-   PLpgSQL_expr *expr;
-} PLpgSQL_stmt_set;
-
 /*
  * GET DIAGNOSTICS item
  */