Skip to content

Commit 30168be

Browse files
committed
Remove plpgsql's special-case code paths for SET/RESET.
In the wake of 84f5c29, 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 b981275. Discussion: https://postgr.es/m/15990-eee2ac466b11293d@postgresql.org
1 parent 9e21537 commit 30168be

File tree

6 files changed

+3
-111
lines changed

6 files changed

+3
-111
lines changed

src/pl/plpgsql/src/expected/plpgsql_transaction.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ END;
497497
$$;
498498
ERROR: SET TRANSACTION ISOLATION LEVEL must be called before any query
499499
CONTEXT: SQL statement "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"
500-
PL/pgSQL function inline_code_block line 3 at SET
500+
PL/pgSQL function inline_code_block line 3 at SQL statement
501501
DO LANGUAGE plpgsql $$
502502
BEGIN
503503
SAVEPOINT foo;

src/pl/plpgsql/src/pl_exec.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ static int exec_stmt_commit(PLpgSQL_execstate *estate,
317317
PLpgSQL_stmt_commit *stmt);
318318
static int exec_stmt_rollback(PLpgSQL_execstate *estate,
319319
PLpgSQL_stmt_rollback *stmt);
320-
static int exec_stmt_set(PLpgSQL_execstate *estate,
321-
PLpgSQL_stmt_set *stmt);
322320

323321
static void plpgsql_estate_setup(PLpgSQL_execstate *estate,
324322
PLpgSQL_function *func,
@@ -2088,10 +2086,6 @@ exec_stmts(PLpgSQL_execstate *estate, List *stmts)
20882086
rc = exec_stmt_rollback(estate, (PLpgSQL_stmt_rollback *) stmt);
20892087
break;
20902088

2091-
case PLPGSQL_STMT_SET:
2092-
rc = exec_stmt_set(estate, (PLpgSQL_stmt_set *) stmt);
2093-
break;
2094-
20952089
default:
20962090
/* point err_stmt to parent, since this one seems corrupt */
20972091
estate->err_stmt = save_estmt;
@@ -4926,37 +4920,6 @@ exec_stmt_rollback(PLpgSQL_execstate *estate, PLpgSQL_stmt_rollback *stmt)
49264920
return PLPGSQL_RC_OK;
49274921
}
49284922

4929-
/*
4930-
* exec_stmt_set
4931-
*
4932-
* Execute SET/RESET statement.
4933-
*
4934-
* We just parse and execute the statement normally, but we have to do it
4935-
* without setting a snapshot, for things like SET TRANSACTION.
4936-
* XXX spi.c now handles this correctly, so we no longer need a special case.
4937-
*/
4938-
static int
4939-
exec_stmt_set(PLpgSQL_execstate *estate, PLpgSQL_stmt_set *stmt)
4940-
{
4941-
PLpgSQL_expr *expr = stmt->expr;
4942-
SPIExecuteOptions options;
4943-
int rc;
4944-
4945-
if (expr->plan == NULL)
4946-
exec_prepare_plan(estate, expr, 0);
4947-
4948-
memset(&options, 0, sizeof(options));
4949-
options.read_only = estate->readonly_func;
4950-
4951-
rc = SPI_execute_plan_extended(expr->plan, &options);
4952-
4953-
if (rc != SPI_OK_UTILITY)
4954-
elog(ERROR, "SPI_execute_plan_extended failed executing query \"%s\": %s",
4955-
expr->query, SPI_result_code_string(rc));
4956-
4957-
return PLPGSQL_RC_OK;
4958-
}
4959-
49604923
/* ----------
49614924
* exec_assign_expr Put an expression's result into a variable.
49624925
* ----------

src/pl/plpgsql/src/pl_funcs.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
288288
return "COMMIT";
289289
case PLPGSQL_STMT_ROLLBACK:
290290
return "ROLLBACK";
291-
case PLPGSQL_STMT_SET:
292-
return "SET";
293291
}
294292

295293
return "unknown";
@@ -370,7 +368,6 @@ static void free_perform(PLpgSQL_stmt_perform *stmt);
370368
static void free_call(PLpgSQL_stmt_call *stmt);
371369
static void free_commit(PLpgSQL_stmt_commit *stmt);
372370
static void free_rollback(PLpgSQL_stmt_rollback *stmt);
373-
static void free_set(PLpgSQL_stmt_set *stmt);
374371
static void free_expr(PLpgSQL_expr *expr);
375372

376373

@@ -460,9 +457,6 @@ free_stmt(PLpgSQL_stmt *stmt)
460457
case PLPGSQL_STMT_ROLLBACK:
461458
free_rollback((PLpgSQL_stmt_rollback *) stmt);
462459
break;
463-
case PLPGSQL_STMT_SET:
464-
free_set((PLpgSQL_stmt_set *) stmt);
465-
break;
466460
default:
467461
elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
468462
break;
@@ -626,12 +620,6 @@ free_rollback(PLpgSQL_stmt_rollback *stmt)
626620
{
627621
}
628622

629-
static void
630-
free_set(PLpgSQL_stmt_set *stmt)
631-
{
632-
free_expr(stmt->expr);
633-
}
634-
635623
static void
636624
free_exit(PLpgSQL_stmt_exit *stmt)
637625
{
@@ -825,7 +813,6 @@ static void dump_perform(PLpgSQL_stmt_perform *stmt);
825813
static void dump_call(PLpgSQL_stmt_call *stmt);
826814
static void dump_commit(PLpgSQL_stmt_commit *stmt);
827815
static void dump_rollback(PLpgSQL_stmt_rollback *stmt);
828-
static void dump_set(PLpgSQL_stmt_set *stmt);
829816
static void dump_expr(PLpgSQL_expr *expr);
830817

831818

@@ -925,9 +912,6 @@ dump_stmt(PLpgSQL_stmt *stmt)
925912
case PLPGSQL_STMT_ROLLBACK:
926913
dump_rollback((PLpgSQL_stmt_rollback *) stmt);
927914
break;
928-
case PLPGSQL_STMT_SET:
929-
dump_set((PLpgSQL_stmt_set *) stmt);
930-
break;
931915
default:
932916
elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
933917
break;
@@ -1329,13 +1313,6 @@ dump_rollback(PLpgSQL_stmt_rollback *stmt)
13291313
printf("ROLLBACK\n");
13301314
}
13311315

1332-
static void
1333-
dump_set(PLpgSQL_stmt_set *stmt)
1334-
{
1335-
dump_ind();
1336-
printf("%s\n", stmt->expr->query);
1337-
}
1338-
13391316
static void
13401317
dump_exit(PLpgSQL_stmt_exit *stmt)
13411318
{

src/pl/plpgsql/src/pl_gram.y

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
197197
%type <stmt> stmt_return stmt_raise stmt_assert stmt_execsql
198198
%type <stmt> stmt_dynexecute stmt_for stmt_perform stmt_call stmt_getdiag
199199
%type <stmt> stmt_open stmt_fetch stmt_move stmt_close stmt_null
200-
%type <stmt> stmt_commit stmt_rollback stmt_set
200+
%type <stmt> stmt_commit stmt_rollback
201201
%type <stmt> stmt_case stmt_foreach_a
202202

203203
%type <list> proc_exceptions
@@ -328,7 +328,6 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
328328
%token <keyword> K_QUERY
329329
%token <keyword> K_RAISE
330330
%token <keyword> K_RELATIVE
331-
%token <keyword> K_RESET
332331
%token <keyword> K_RETURN
333332
%token <keyword> K_RETURNED_SQLSTATE
334333
%token <keyword> K_REVERSE
@@ -338,7 +337,6 @@ static void check_raise_parameters(PLpgSQL_stmt_raise *stmt);
338337
%token <keyword> K_SCHEMA
339338
%token <keyword> K_SCHEMA_NAME
340339
%token <keyword> K_SCROLL
341-
%token <keyword> K_SET
342340
%token <keyword> K_SLICE
343341
%token <keyword> K_SQLSTATE
344342
%token <keyword> K_STACKED
@@ -899,8 +897,6 @@ proc_stmt : pl_block ';'
899897
{ $$ = $1; }
900898
| stmt_rollback
901899
{ $$ = $1; }
902-
| stmt_set
903-
{ $$ = $1; }
904900
;
905901

906902
stmt_perform : K_PERFORM
@@ -2273,34 +2269,6 @@ opt_transaction_chain:
22732269
| /* EMPTY */ { $$ = false; }
22742270
;
22752271

2276-
stmt_set : K_SET
2277-
{
2278-
PLpgSQL_stmt_set *new;
2279-
2280-
new = palloc0(sizeof(PLpgSQL_stmt_set));
2281-
new->cmd_type = PLPGSQL_STMT_SET;
2282-
new->lineno = plpgsql_location_to_lineno(@1);
2283-
new->stmtid = ++plpgsql_curr_compile->nstatements;
2284-
plpgsql_push_back_token(K_SET);
2285-
new->expr = read_sql_stmt();
2286-
2287-
$$ = (PLpgSQL_stmt *)new;
2288-
}
2289-
| K_RESET
2290-
{
2291-
PLpgSQL_stmt_set *new;
2292-
2293-
new = palloc0(sizeof(PLpgSQL_stmt_set));
2294-
new->cmd_type = PLPGSQL_STMT_SET;
2295-
new->lineno = plpgsql_location_to_lineno(@1);
2296-
new->stmtid = ++plpgsql_curr_compile->nstatements;
2297-
plpgsql_push_back_token(K_RESET);
2298-
new->expr = read_sql_stmt();
2299-
2300-
$$ = (PLpgSQL_stmt *)new;
2301-
}
2302-
;
2303-
23042272

23052273
cursor_variable : T_DATUM
23062274
{
@@ -2588,7 +2556,6 @@ unreserved_keyword :
25882556
| K_QUERY
25892557
| K_RAISE
25902558
| K_RELATIVE
2591-
| K_RESET
25922559
| K_RETURN
25932560
| K_RETURNED_SQLSTATE
25942561
| K_REVERSE
@@ -2598,7 +2565,6 @@ unreserved_keyword :
25982565
| K_SCHEMA
25992566
| K_SCHEMA_NAME
26002567
| K_SCROLL
2601-
| K_SET
26022568
| K_SLICE
26032569
| K_SQLSTATE
26042570
| K_STACKED

src/pl/plpgsql/src/pl_unreserved_kwlist.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ PG_KEYWORD("prior", K_PRIOR)
8989
PG_KEYWORD("query", K_QUERY)
9090
PG_KEYWORD("raise", K_RAISE)
9191
PG_KEYWORD("relative", K_RELATIVE)
92-
PG_KEYWORD("reset", K_RESET)
9392
PG_KEYWORD("return", K_RETURN)
9493
PG_KEYWORD("returned_sqlstate", K_RETURNED_SQLSTATE)
9594
PG_KEYWORD("reverse", K_REVERSE)
@@ -99,7 +98,6 @@ PG_KEYWORD("rowtype", K_ROWTYPE)
9998
PG_KEYWORD("schema", K_SCHEMA)
10099
PG_KEYWORD("schema_name", K_SCHEMA_NAME)
101100
PG_KEYWORD("scroll", K_SCROLL)
102-
PG_KEYWORD("set", K_SET)
103101
PG_KEYWORD("slice", K_SLICE)
104102
PG_KEYWORD("sqlstate", K_SQLSTATE)
105103
PG_KEYWORD("stacked", K_STACKED)

src/pl/plpgsql/src/plpgsql.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ typedef enum PLpgSQL_stmt_type
127127
PLPGSQL_STMT_PERFORM,
128128
PLPGSQL_STMT_CALL,
129129
PLPGSQL_STMT_COMMIT,
130-
PLPGSQL_STMT_ROLLBACK,
131-
PLPGSQL_STMT_SET
130+
PLPGSQL_STMT_ROLLBACK
132131
} PLpgSQL_stmt_type;
133132

134133
/*
@@ -566,17 +565,6 @@ typedef struct PLpgSQL_stmt_rollback
566565
bool chain;
567566
} PLpgSQL_stmt_rollback;
568567

569-
/*
570-
* SET statement
571-
*/
572-
typedef struct PLpgSQL_stmt_set
573-
{
574-
PLpgSQL_stmt_type cmd_type;
575-
int lineno;
576-
unsigned int stmtid;
577-
PLpgSQL_expr *expr;
578-
} PLpgSQL_stmt_set;
579-
580568
/*
581569
* GET DIAGNOSTICS item
582570
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy