Skip to content

Commit 29a43f3

Browse files
committed
Tweak grammar to use FastAppend rather than lappend when constructing
expr_lists. This appears to be the only remaining O(N^2) bottleneck in processing many-way 'x IN (a,b,c,...)' conditions.
1 parent 92ee252 commit 29a43f3

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/backend/parser/gram.y

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.429 2003/08/17 19:58:05 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.430 2003/08/22 20:34:33 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -108,6 +108,7 @@ static void doNegateFloat(Value *v);
108108
DropBehavior dbehavior;
109109
OnCommitAction oncommit;
110110
List *list;
111+
FastList fastlist;
111112
Node *node;
112113
Value *value;
113114
ColumnRef *columnref;
@@ -6719,8 +6720,18 @@ opt_indirection:
67196720
{ $$ = NIL; }
67206721
;
67216722

6722-
expr_list: a_expr { $$ = makeList1($1); }
6723-
| expr_list ',' a_expr { $$ = lappend($1, $3); }
6723+
expr_list: a_expr
6724+
{
6725+
FastList *dst = (FastList *) &$$;
6726+
makeFastList1(dst, $1);
6727+
}
6728+
| expr_list ',' a_expr
6729+
{
6730+
FastList *dst = (FastList *) &$$;
6731+
FastList *src = (FastList *) &$1;
6732+
*dst = *src;
6733+
FastAppend(dst, $3);
6734+
}
67246735
;
67256736

67266737
extract_list:

src/include/nodes/pg_list.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_list.h,v 1.40 2003/08/08 21:42:48 momjian Exp $
10+
* $Id: pg_list.h,v 1.41 2003/08/22 20:34:33 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -132,6 +132,9 @@ typedef struct List
132132
* FastList is an optimization for building large lists. The conventional
133133
* way to build a list is repeated lappend() operations, but that is O(N^2)
134134
* in the number of list items, which gets tedious for large lists.
135+
*
136+
* Note: there are some hacks in gram.y that rely on the head pointer (the
137+
* value-as-list) being the first field.
135138
*/
136139
typedef struct FastList
137140
{
@@ -144,6 +147,9 @@ typedef struct FastList
144147
( (fl)->head = (l), (fl)->tail = llastnode((fl)->head) )
145148
#define FastListValue(fl) ( (fl)->head )
146149

150+
#define makeFastList1(fl, x1) \
151+
( (fl)->head = (fl)->tail = makeList1(x1) )
152+
147153

148154
/*
149155
* function prototypes in nodes/list.c

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