Skip to content

Commit bb34970

Browse files
committed
Use a bitmapset instead of a list for duplicate-column checking in
checkInsertTargets(). Avoids O(N^2) behavior on wide target lists.
1 parent 9e52381 commit bb34970

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/parser/parse_target.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.129 2005/01/13 17:19:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.130 2005/03/26 06:28:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include "postgres.h"
1616

1717
#include "commands/dbcommands.h"
1818
#include "miscadmin.h"
19+
#include "nodes/bitmapset.h"
1920
#include "nodes/makefuncs.h"
2021
#include "parser/parsetree.h"
2122
#include "parser/parse_coerce.h"
@@ -630,7 +631,8 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
630631
/*
631632
* Do initial validation of user-supplied INSERT column list.
632633
*/
633-
List *wholecols = NIL;
634+
Bitmapset *wholecols = NULL;
635+
Bitmapset *partialcols = NULL;
634636
ListCell *tl;
635637

636638
foreach(tl, cols)
@@ -649,21 +651,23 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
649651
if (col->indirection == NIL)
650652
{
651653
/* whole column; must not have any other assignment */
652-
if (list_member_int(*attrnos, attrno))
654+
if (bms_is_member(attrno, wholecols) ||
655+
bms_is_member(attrno, partialcols))
653656
ereport(ERROR,
654657
(errcode(ERRCODE_DUPLICATE_COLUMN),
655658
errmsg("column \"%s\" specified more than once",
656659
name)));
657-
wholecols = lappend_int(wholecols, attrno);
660+
wholecols = bms_add_member(wholecols, attrno);
658661
}
659662
else
660663
{
661664
/* partial column; must not have any whole assignment */
662-
if (list_member_int(wholecols, attrno))
665+
if (bms_is_member(attrno, wholecols))
663666
ereport(ERROR,
664667
(errcode(ERRCODE_DUPLICATE_COLUMN),
665668
errmsg("column \"%s\" specified more than once",
666669
name)));
670+
partialcols = bms_add_member(partialcols, attrno);
667671
}
668672

669673
*attrnos = lappend_int(*attrnos, attrno);

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