8000 Add keywords to implement Vadim's transaction isolation · postgrespro/postgres_cluster@bcb5aac · GitHub
[go: up one dir, main page]

Skip to content < 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/keyboard-shortcuts-dialog-b3dd4b1cb532.js" defer="defer">

Commit bcb5aac

Browse files
author
Thomas G. Lockhart
committed
Add keywords to implement Vadim's transaction isolation
and lock syntax as fully parsed tokens. Two keywords for isolation are non-reserved SQL92 (COMMITTED, SERIALIZABLE). All other new keywords are non-reserved Postgres (not SQL92) (ACCESS, EXCLUSIVE, MODE, SHARE). Add syntax to allow CREATE [GLOBAL|LOCAL] TEMPORARY TABLE, throwing an error if GLOBAL is specified.
1 parent 3ce054b commit bcb5aac

File tree

2 files changed

+70
-92
lines changed

2 files changed

+70
-92
lines changed

src/backend/parser/gram.y

Lines changed: 62 additions & 89 deletions
< A3E2 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.73 1999/05/11 03:28:42 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.74 1999/05/12 07:22:51 thomas Exp $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -136,16 +136,17 @@ Oid param_type(int t); /* used in parse_expr.c */
136136
ClusterStmt, ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
137137
CreateUserStmt, AlterUserStmt, DropUserStmt, RuleActionStmt
138138

139-
%type <str> opt_database1, opt_database2, location, encoding
139+
%type <str> opt_database1, opt_database2, location, encoding
140140

141-
%type <str> opt_lmode
141+
%type <ival> opt_lock, lock_type
142+
%type <boolean> opt_lmode
142143

143144
%type <pboolean> user_createdb_clause, user_createuser_clause
144-
%type <str> user_passwd_clause
145-
%type <str> user_valid_clause
146-
%type <list> user_group_list, user_group_clause
145+
%type <str> user_passwd_clause
146+
%type <str> user_valid_clause
147+
%type <list> user_group_list, user_group_clause
147148

148-
%type <boolean> TriggerActionTime, TriggerForSpec, PLangTrusted
149+
%type <boolean> TriggerActionTime, TriggerForSpec, PLangTrusted
149150

150151
%type <str> TriggerEvents, TriggerFuncArg
151152

@@ -157,6 +158,7 @@ Oid param_type(int t); /* used in parse_expr.c */
157158
all_Op, MathOp, opt_name, opt_unique,
158159
OptUseOp, opt_class, SpecialRuleRelation
159160

161+
%type <str> opt_level
160162
%type <str> privileges, operation_commalist, grantee
161163
%type <chr> operation, TriggerOneEvent
162164

@@ -175,7 +177,7 @@ Oid param_type(int t); /* used in parse_expr.c */
175177
%type <node> func_return
176178
%type <boolean> set_opt
177179

178-
%type <boolean> TriggerForOpt, TriggerForType, OptTemp
180+
%type <boolean> TriggerForOpt, TriggerForType, OptTemp, OptTempType, OptTempScope
179181

180182
%type <list> for_update_clause, update_list
181183
%type <boolean> opt_union
@@ -274,13 +276,13 @@ Oid param_type(int t); /* used in parse_expr.c */
274276
%token ABSOLUTE, ACTION, ADD, ALL, ALTER, AND, ANY, AS, ASC,
275277
BEGIN_TRANS, BETWEEN, BOTH, BY,
276278
CASCADE, CASE, CAST, CHAR, CHARACTER, CHECK, CLOSE,
277-
COALESCE, COLLATE, COLUMN, COMMIT,
279+
COALESCE, COLLATE, COLUMN, COMMIT,
278280
CONSTRAINT, CREATE, CROSS, CURRENT, CURRENT_DATE, CURRENT_TIME,
279281
CURRENT_TIMESTAMP, CURRENT_USER, CURSOR,
280282
DAY_P, DECIMAL, DECLARE, DEFAULT, DELETE, DESC, DISTINCT, DOUBLE, DROP,
281283
ELSE, END_TRANS, EXCEPT, EXECUTE, EXISTS, EXTRACT,
282284
FALSE_P, FETCH, FLOAT, FOR, FOREIGN, FROM, FULL,
283-
GRANT, GROUP, HAVING, HOUR_P,
285+
GLOBAL, GRANT, GROUP, HAVING, HOUR_P,
284286
IN, INNER_P, INSENSITIVE, INSERT, INTERSECT, INTERVAL, INTO, IS,
285287
ISOLATION, JOIN, KEY, LANGUAGE, LEADING, LEFT, LEVEL, LIKE, LOCAL,
286288
MATCH, MINUTE_P, MONTH_P, NAMES,
@@ -299,25 +301,28 @@ Oid param_type(int t); /* used in parse_expr.c */
299301
%token TRIGGER
300302

301303
/* Keywords (in SQL92 non-reserved words) */
302-
%token TYPE_P
304+
%token COMMITTED, SERIALIZABLE, TYPE_P
303305

304306
/* Keywords for Postgres support (not in SQL92 reserved words)
305307
*
306308
* The CREATEDB and CREATEUSER tokens should go away
307309
* when some sort of pg_privileges relation is introduced.
308310
* - Todd A. Brandys 1998-01-01?
309311
*/
310-
%token ABORT_TRANS, AFTER, AGGREGATE, ANALYZE, BACKWARD, BEFORE, BINARY,
312+
%token ABORT_TRANS, ACCESS, AFTER, AGGREGATE, ANALYZE,
313+
BACKWARD, BEFORE, BINARY,
311314
CACHE, CLUSTER, COPY, CREATEDB, CREATEUSER, CYCLE,
312-
DATABASE, DELIMITERS, DO, EACH, ENCODING, EXPLAIN, EXTEND,
315+
DATABASE, DELIMITERS, DO,
316+
EACH, ENCODING, EXCLUSIVE, EXPLAIN, EXTEND,
313317
FORWARD, FUNCTION, HANDLER,
314318
INCREMENT, INDEX, INHERITS, INSTEAD, ISNULL,
315319
LANCOMPILER, LIMIT, LISTEN, LOAD, LOCATION, LOCK_P,
316-
MAXVALUE, MINVALUE, MOVE,
320+
MAXVALUE, MINVALUE, MODE, MOVE,
317321
NEW, NOCREATEDB, NOCREATEUSER, NONE, NOTHING, NOTIFY, NOTNULL,
318322
OFFSET, OIDS, OPERATOR, PASSWORD, PROCEDURAL,
319323
RENAME, RESET, RETURNS, ROW, RULE,
320-
SEQUENCE, SERIAL, SETOF, SHOW, START, STATEMENT, STDIN, STDOUT, TRUSTED,
324+
SEQUENCE, SERIAL, SETOF, SHARE, SHOW, START, STATEMENT, STDIN, STDOUT,
325+
TRUSTED,
321326
UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION
322327

323328
/* Special keywords, not in the query language - see the "lex" file */
@@ -557,22 +562,11 @@ VariableSetStmt: SET ColId TO var_value
557562
n->value = $4;
558563
$$ = (Node *) n;
559564
}
560-
| SET TRANSACTION ISOLATION LEVEL READ ColId
561-
{
562-
VariableSetStmt *n = makeNode(VariableSetStmt);
563-
n->name = "XactIsoLevel";
564-
n->value = $6;
565-
if (strcasecmp(n->value, "COMMITTED"))
566-
elog(ERROR,"parser: syntax error at or near \"%s\"", n->value);
567-
$$ = (Node *) n;
568-
}
569-
| SET TRANSACTION ISOLATION LEVEL ColId
565+
| SET TRANSACTION ISOLATION LEVEL opt_level
570566
{
571567
VariableSetStmt *n = makeNode(VariableSetStmt);
572568
n->name = "XactIsoLevel";
573569
n->value = $5;
574-
if (strcasecmp(n->value, "SERIALIZABLE"))
575-
elog(ERROR,"parser: syntax error at or near \"%s\"", n->value);
576570
$$ = (Node *) n;
577571
}
578572
| SET NAMES encoding
@@ -588,6 +582,10 @@ VariableSetStmt: SET ColId TO var_value
588582
}
589583
;
590584

585+
opt_level: READ COMMITTED { $$ = "committed"; }
586+
| SERIALIZABLE { $$ = "serializable"; }
587+
;
588+
591589
var_value: Sconst { $$ = $1; }
592590
| DEFAULT { $$ = NULL; }
593591
;
@@ -767,12 +765,26 @@ CreateStmt: CREATE OptTemp TABLE relation_name '(' OptTableElementList ')'
767765
}
768766
;
769767

770-
OptTemp:
771-
TEMP { $$ = TRUE; }
768+
OptTemp: OptTempType { $$ = $1; }
769+
| OptTempScope OptTempType { $$ = $2; }
770+
;
771+
772+
OptTempType: TEMP { $$ = TRUE; }
772773
| TEMPORARY { $$ = TRUE; }
773774
| /*EMPTY*/ { $$ = FALSE; }
774775
;
775776

777+
OptTempScope: GLOBAL
778+
{
779+
elog(ERROR, "GLOBAL TEMPORARY TABLE is not currently supported");
780+
$$ = TRUE;
781+
}
782+
| LOCAL
783+
{
784+
$$ = FALSE;
785+
}
786+
;
787+
776788
OptTableElementList: OptTableElementList ',' OptTableElement
777789
{
778790
if ($3 != NULL)
@@ -2580,78 +2592,31 @@ DeleteStmt: DELETE FROM relation_name
25802592
}
25812593
;
25822594

2583-
LockStmt: LOCK_P opt_table relation_name
2595+
LockStmt: LOCK_P opt_table relation_name opt_lock
25842596
{
25852597
LockStmt *n = makeNode(LockStmt);
25862598

25872599
n->relname = $3;
2588-
n->mode = AccessExclusiveLock;
2600+
n->mode = $4;
25892601
$$ = (Node *)n;
25902602
}
2591-
| LOCK_P opt_table relation_name IN opt_lmode ROW IDENT IDENT
2592-
{
2593-
LockStmt *n = makeNode(LockStmt);
2594-
2595-
n->relname = $3;
2596-
if (strcasecmp($8, "MODE"))
2597-
elog(ERROR,"parser: syntax error at or near \"%s\"", $8);
2598-
if ($5 != NULL)
2599-
{
2600-
if (strcasecmp($5, "SHARE"))
2601-
elog(ERROR,"parser: syntax error at or near \"%s\"", $5);
2602-
if (strcasecmp($7, "EXCLUSIVE"))
2603-
elog(ERROR,"parser: syntax error at or near \"%s\"", $7);
2604-
n->mode = ShareRowExclusiveLock;
2605-
}
2606-
else
2607-
{
2608-
if (strcasecmp($7, "SHARE") == 0)
2609-
n->mode = RowShareLock;
2610-
else if (strcasecmp($7, "EXCLUSIVE") == 0)
2611-
n->mode = RowExclusiveLock;
2612-
else
2613-
elog(ERROR,"parser: syntax error at or near \"%s\"", $7);
2614-
}
2615-
$$ = (Node *)n;
2616-
}
2617-
| LOCK_P opt_table relation_name IN IDENT IDENT IDENT
2618-
{
2619-
LockStmt *n = makeNode(LockStmt);
2603+
;
26202604

2621-
n->relname = $3;
2622-
if (strcasecmp($7, "MODE"))
2623-
elog(ERROR,"parser: syntax error at or near \"%s\"", $7);
2624-
if (strcasecmp($5, "ACCESS"))
2625-
elog(ERROR,"parser: syntax error at or near \"%s\"", $5);
2626-
if (strcasecmp($6, "SHARE") == 0)
2627-
n->mode = AccessShareLock;
2628-
else if (strcasecmp($6, "EXCLUSIVE") == 0)
2629-
n->mode = AccessExclusiveLock;
2630-
else
2631-
elog(ERROR,"parser: syntax error at or near \"%s\"", $6);
2632-
$$ = (Node *)n;
2633-
}
2634-
| LOCK_P opt_table relation_name IN IDENT IDENT
2635-
{
2636-
LockStmt *n = makeNode(LockStmt);
2605+
opt_lock: lock_type MODE { $$ = $1; }
2606+
| /*EMPTY*/ { $$ = AccessExclusiveLock; }
2607+
;
26372608

2638-
n->relname = $3;
2639-
if (strcasecmp($6, "MODE"))
2640-
elog(ERROR,"parser: syntax error at or near \"%s\"", $6);
2641-
if (strcasecmp($5, "SHARE") == 0)
2642-
n->mode = ShareLock;
2643-
else if (strcasecmp($5, "EXCLUSIVE") == 0)
2644-
n->mode = ExclusiveLock;
2645-
else
2646-
elog(ERROR,"parser: syntax error at or near \"%s\"", $5);
2647-
$$ = (Node *)n;
2648-
}
2609+
lock_type: SHARE ROW EXCLUSIVE { $$ = ShareRowExclusiveLock; }
2610+
| ROW opt_lmode { $$ = ($2? RowShareLock: RowExclusiveLock); }
2611+
| ACCESS opt_lmode { $$ = ($2? AccessShareLock: AccessExclusiveLock); }
2612+
| opt_lmode { $$ = ($1? ShareLock: ExclusiveLock); }
26492613
;
26502614

2651-
opt_lmode: IDENT { $$ = $1; }
2652-
| /*EMPTY*/ { $$ = NULL; }
2615+
opt_lmode: SHARE { $$ = TRUE; }
2616+
| EXCLUSIVE { $$ = FALSE; }
26532617
;
26542618

2619+
26552620
/*****************************************************************************
26562621
*
26572622
* QUERY:
@@ -5173,12 +5138,14 @@ TypeId: ColId
51735138
ColId: IDENT { $$ = $1; }
51745139
| datetime { $$ = $1; }
51755140
| ABSOLUTE { $$ = "absolute"; }
5141+
| ACCESS { $$ = "access"; }
51765142
| ACTION { $$ = "action"; }
51775143
| AFTER { $$ = "after"; }
51785144
| AGGREGATE { $$ = "aggregate"; }
51795145
| BACKWARD { $$ = "backward"; }
51805146
| BEFORE { $$ = "before"; }
51815147
| CACHE { $$ = "cache"; }
5148+
| COMMITTED { $$ = "committed"; }
51825149
| CREATEDB { $$ = "createdb"; }
51835150
| CREATEUSER { $$ = "createuser"; }
51845151
| CYCLE { $$ = "cycle"; }
@@ -5187,6 +5154,7 @@ ColId: IDENT { $$ = $1; }
51875154
| DOUBLE { $$ = "double"; }
51885155
| EACH { $$ = "each"; }
51895156
| ENCODING { $$ = "encoding"; }
5157+
| EXCLUSIVE { $$ = "exclusive"; }
51905158
| FORWARD { $$ = "forward"; }
51915159
| FUNCTION { $$ = "function"; }
51925160
| HANDLER { $$ = "handler"; }
@@ -5203,6 +5171,7 @@ ColId: IDENT { $$ = $1; }
52035171
| MATCH { $$ = "match"; }
52045172
| MAXVALUE { $$ = "maxvalue"; }
52055173
| MINVALUE { $$ = "minvalue"; }
5174+
| MODE { $$ = "mode"; }
52065175
| NEXT { $$ = "next"; }
52075176
| NOCREATEDB { $$ = "nocreatedb"; }
52085177
| NOCREATEUSER { $$ = "nocreateuser"; }
@@ -5226,6 +5195,8 @@ ColId: IDENT { $$ = $1; }
52265195
| SCROLL { $$ = "scroll"; }
52275196
| SEQUENCE { $$ = "sequence"; }
52285197
| SERIAL { $$ = "serial"; }
5198+
| SERIALIZABLE { $$ = "serializable"; }
5199+
| SHARE { $$ = "share"; }
52295200
| START { $$ = "start"; }
52305201
| STATEMENT { $$ = "statement"; }
52315202
| STDIN { $$ = "stdin"; }
@@ -5269,9 +5240,11 @@ ColLabel: ColId { $$ = $1; }
52695240
| EXTEND { $$ = "extend"; }
52705241
| FALSE_P { $$ = "false"; }
52715242
| FOREIGN { $$ = "foreign"; }
5243+
| GLOBAL { $$ = "global"; }
52725244
| GROUP { $$ = "group"; }
52735245
| LISTEN { $$ = "listen"; }
52745246
| LOAD { $$ = "load"; }
5247+
| LOCAL { $$ = "local"; }
52755248
| LOCK_P { $$ = "lock"; }
52765249
| MOVE { $$ = "move"; }
52775250
| NEW { $$ = "new"; }

src/backend/parser/keywords.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.56 1999/04/19 16:00:18 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.57 1999/05/12 07:22:52 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,6 +31,7 @@ static ScanKeyword ScanKeywords[] = {
3131
/* name, value */
3232
{"abort", ABORT_TRANS},
3333
{"absolute", ABSOLUTE},
34+
{"access", ACCESS},
3435
{"action", ACTION},
3536
{"add", ADD},
3637
{"after", AFTER},
@@ -62,6 +63,7 @@ static ScanKeyword ScanKeywords[] = {
6263
{"collate", COLLATE},
6364
{"column", COLUMN},
6465
{"commit", COMMIT},
66+
{"committed", COMMITTED},
6567
{"constraint", CONSTRAINT},
6668
{"copy", COPY},
6769
{"create", CREATE},
@@ -92,7 +94,7 @@ static ScanKeyword ScanKeywords[] = {
9294
{"end", END_TRANS},
9395
/***S*I***/
9496
{"except", EXCEPT},
95-
97+
{"exclusive", EXCLUSIVE},
9698
{"execute", EXECUTE},
9799
{"exists", EXISTS},
98100
{"explain", EXPLAIN},
@@ -107,6 +109,7 @@ static ScanKeyword ScanKeywords[] = {
107109
{"from", FROM},
108110
{"full", FULL},
109111
{"function", FUNCTION},
112+
{"global", GLOBAL},
110113
{"grant", GRANT},
111114
{"group", GROUP},
112115
{"handler", HANDLER},
@@ -122,7 +125,6 @@ static ScanKeyword ScanKeywords[] = {
122125
{"instead", INSTEAD},
123126
/***S*I***/
124127
{"intersect", INTERSECT},
125-
126128
{"interval", INTERVAL},
127129
{"into", INTO},
128130
{"is", IS},
@@ -146,6 +148,7 @@ static ScanKeyword ScanKeywords[] = {
146148
{"maxvalue", MAXVALUE},
147149
{"minute", MINUTE_P},
148150
{"minvalue", MINVALUE},
151+
{"mode", MODE},
149152
{"month", MONTH_P},
150153
{"move", MOVE},
151154
{"names", NAMES},
@@ -202,8 +205,10 @@ static ScanKeyword ScanKeywords[] = {
202205
{"select", SELECT},
203206
{"sequence", SEQUENCE},
204207
{"serial", SERIAL},
208+
{"serializable", SERIALIZABLE},
205209
{"set", SET},
206210
{"setof", SETOF},
211+
{"share", SHARE},
207212
{"show", SHOW},
208213
{"start", START},
209214
{"statement", STATEMENT},

0 commit comments

Comments
 (0)
0