Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c00b309

Browse files
committed
Alter string format used for integer and OID lists in stored rules.
This simplifies and speeds up the reader by letting it get the representation right the first time, rather than correcting it after-the-fact. Also, after int and OID lists become separate node types per Neil's pending patch, this will let us treat these lists as just plain Nodes instead of requiring separate read/write macros the way we have now.
1 parent 4af3421 commit c00b309

File tree

5 files changed

+91
-74
lines changed

5 files changed

+91
-74
lines changed

src/backend/nodes/outfuncs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.234 2004/05/06 14:01:33 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.235 2004/05/08 21:21:18 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -155,6 +155,7 @@ _outIntList(StringInfo str, List *list)
155155
List *l;
156156

157157
appendStringInfoChar(str, '(');
158+
appendStringInfoChar(str, 'i');
158159
foreach(l, list)
159160
appendStringInfo(str, " %d", lfirsti(l));
160161
appendStringInfoChar(str, ')');
@@ -170,6 +171,7 @@ _outOidList(StringInfo str, List *list)
170171
List *l;
171172

172173
appendStringInfoChar(str, '(');
174+
appendStringInfoChar(str, 'o');
173175
foreach(l, list)
174176
appendStringInfo(str, " %u", lfirsto(l));
175177
appendStringInfoChar(str, ')');
@@ -179,8 +181,9 @@ _outOidList(StringInfo str, List *list)
179181
* _outBitmapset -
180182
* converts a bitmap set of integers
181183
*
182-
* Note: for historical reasons, the output is formatted exactly like
183-
* an integer List would be.
184+
* Note: the output format is "(b int int ...)", similar to an integer List.
185+
* Currently bitmapsets do not appear in any node type that is stored in
186+
* rules, so there is no support in readfuncs.c for reading this format.
184187
*/
185188
static void
186189
_outBitmapset(StringInfo str, Bitmapset *bms)
@@ -189,6 +192,7 @@ _outBitmapset(StringInfo str, Bitmapset *bms)
189192
int x;
190193

191194
appendStringInfoChar(str, '(');
195+
appendStringInfoChar(str, 'b');
192196
tmpset = bms_copy(bms);
193197
while ((x = bms_first_member(tmpset)) >= 0)
194198
appendStringInfo(str, " %d", x);

src/backend/nodes/print.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/print.c,v 1.65 2003/11/29 19:51:49 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/print.c,v 1.66 2004/05/08 21:21:18 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHOR DATE MAJOR EVENT
@@ -194,12 +194,20 @@ pretty_format_node_dump(const char *dump)
194194
}
195195
j = indentDist - 1;
196196
/* j will equal indentDist on next loop iteration */
197+
/* suppress whitespace just after } */
198+
while (dump[i+1] == ' ')
199+
i++;
197200
break;
198201
case ')':
199-
/* force line break after ')' */
200-
line[j + 1] = '\0';
201-
appendStringInfo(&str, "%s\n", line);
202-
j = indentDist - 1;
202+
/* force line break after ), unless another ) follows */
203+
if (dump[i+1] != ')')
204+
{
205+
line[j + 1] = '\0';
206+
appendStringInfo(&str, "%s\n", line);
207+
j = indentDist - 1;
208+
while (dump[i+1] == ' ')
209+
i++;
210+
}
203211
break;
204212
case '{':
205213
/* force line break before { */

src/backend/nodes/read.c

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.40 2004/05/06 14:01:33 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/nodes/read.c,v 1.41 2004/05/08 21:21:18 tgl Exp $
1313
*
1414
* HISTORY
1515
* AUTHOR DATE MAJOR EVENT
@@ -261,7 +261,8 @@ nodeTokenType(char *token, int length)
261261
* lexical tokenizer pg_strtok(). It can read
262262
* * Value token nodes (integers, floats, or strings);
263263
* * General nodes (via parseNodeString() from readfuncs.c);
264-
* * Lists of the above.
264+
* * Lists of the above;
265+
* * Lists of integers or OIDs.
265266
* The return value is declared void *, not Node *, to avoid having to
266267
* cast it explicitly in callers that assign to fields of different types.
267268
*
@@ -300,14 +301,68 @@ nodeRead(char *token, int tok_len)
300301
{
301302
List *l = NIL;
302303

303-
for (;;)
304+
/*----------
305+
* Could be an integer list: (i int int ...)
306+
* or an OID list: (o int int ...)
307+
* or a list of nodes/values: (node node ...)
308+
*----------
309+
*/
310+
token = pg_strtok(&tok_len);
311+
if (token == NULL)
312+
elog(ERROR, "unterminated List structure");
313+
if (tok_len == 1 && token[0] == 'i')
304314
{
305-
token = pg_strtok(&tok_len);
306-
if (token == NULL)
307-
elog(ERROR, "unterminated List structure");
308-
if (token[0] == ')')
309-
break;
310-
l = lappend(l, nodeRead(token, tok_len));
315+
/* List of integers */
316+
for (;;)
317+
{
318+
int val;
319+
char *endptr;
320+
321+
token = pg_strtok(&tok_len);
322+
if (token == NULL)
323+
elog(ERROR, "unterminated List structure");
324+
if (token[0] == ')')
325+
break;
326+
val = (int) strtol(token, &endptr, 10);
327+
if (endptr != token + tok_len)
328+
elog(ERROR, "unrecognized integer: \"%.*s\"",
329+
tok_len, token);
330+
l = lappendi(l, val);
331+
}
332+
}
333+
else if (tok_len == 1 && token[0] == 'o')
334+
{
335+
/* List of OIDs */
336+
for (;;)
337+
{
338+
Oid val;
339+
char *endptr;
340+
341+
token = pg_strtok(&tok_len);
342+
if (token == NULL)
343+
elog(ERROR, "unterminated List structure");
344+
if (token[0] == ')')
345+
break;
346+
val = (Oid) strtoul(token, &endptr, 10);
347+
if (endptr != token + tok_len)
348+
elog(ERROR, "unrecognized OID: \"%.*s\"",
349+
tok_len, token);
350+
l = lappendo(l, val);
351+
}
352+
}
353+
else
354+
{
355+
/* List of other node types */
356+
for (;;)
357+
{
358+
/* We have already scanned next token... */
359+
if (token[0] == ')')
360+
break;
361+
l = lappend(l, nodeRead(token, tok_len));
362+
token = pg_strtok(&tok_len);
363+
if (token == NULL)
364+
elog(ERROR, "unterminated List structure");
365+
}
311366
}
312367
result = (Node *) l;
313368
break;

src/backend/nodes/readfuncs.c

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.167 2004/05/06 14:01:33 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.168 2004/05/08 21:21:18 tgl Exp $
1212
*
1313
* NOTES
1414
* Path and Plan nodes do not have any readfuncs support, because we
@@ -101,15 +101,15 @@
101101
token = pg_strtok(&length); /* skip :fldname */ \
102102
local_node->fldname = nodeRead(NULL, 0)
103103

104-
/* Read an integer-list field */
104+
/* Read an integer-list field (XXX combine me with READ_NODE_FIELD) */
105105
#define READ_INTLIST_FIELD(fldname) \
106106
token = pg_strtok(&length); /* skip :fldname */ \
107-
local_node->fldname = toIntList(nodeRead(NULL, 0))
107+
local_node->fldname = nodeRead(NULL, 0)
108108

109-
/* Read an OID-list field */
109+
/* Read an OID-list field (XXX combine me with READ_NODE_FIELD) */
110110
#define READ_OIDLIST_FIELD(fldname) \
111111
token = pg_strtok(&length); /* skip :fldname */ \
112-
local_node->fldname = toOidList(nodeRead(NULL, 0))
112+
local_node->fldname = nodeRead(NULL, 0)
113113

114114
/* Routine exit */
115115
#define READ_DONE() \
@@ -135,56 +135,6 @@
135135
static Datum readDatum(bool typbyval);
136136

137137

138-
/* Convert Value list returned by nodeRead into list of integers */
139-
static List *
140-
toIntList(List *list)
141-
{
142-
List *l;
143-
144-
foreach(l, list)
145-
{
146-
Value *v = (Value *) lfirst(l);
147-
148-
if (!IsA(v, Integer))
149-
elog(ERROR, "unexpected node type: %d", (int) nodeTag(v));
150-
lfirsti(l) = intVal(v);
151-
pfree(v);
152-
}
153-
return list;
154-
}
155-
156-
/* Convert Value list returned by nodeRead into list of OIDs */
157-
static List *
158-
toOidList(List *list)
159-
{
160-
List *l;
161-
162-
foreach(l, list)
163-
{
164-
Value *v = (Value *) lfirst(l);
165-
166-
/*
167-
* This is a bit tricky because OID is unsigned, and so nodeRead
168-
* might have concluded the value doesn't fit in an integer. Must
169-
* cope with T_Float as well.
170-
*/
171-
if (IsA(v, Integer))
172-
{
173-
lfirsto(l) = (Oid) intVal(v);
174-
pfree(v);
175-
}
176-
else if (IsA(v, Float))
177-
{
178-
lfirsto(l) = atooid(strVal(v));
179-
pfree(strVal(v));
180-
pfree(v);
181-
}
182-
else
183-
elog(ERROR, "unexpected node type: %d", (int) nodeTag(v));
184-
}
185-
return list;
186-
}
187-
188138
/*
189139
* _readQuery
190140
*/

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.227 2004/05/02 13:39:51 momjian Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.228 2004/05/08 21:21:18 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200405020
56+
#define CATALOG_VERSION_NO 200405081
5757

5858
#endif

0 commit comments

Comments
 (0)