diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index a9fe412..c2b7e35 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -70,7 +70,7 @@ static BufferAccessStrategy vac_strategy; /* non-export function prototypes */ static void get_rel_oids(List **vacrels); -static void check_columns_exist(List *relations); +static void check_column_lists(List *relations); static void vac_truncate_clog(TransactionId frozenXID, MultiXactId minMulti, TransactionId lastSaneFrozenXid, @@ -265,8 +265,11 @@ vacuum(int options, List *relations, VacuumParams *params, * Check that all specified columns exist so that we can fast-fail * commands with multiple tables. If the column disappears before we * actually process it, we will emit a WARNING and skip it later on. + * + * Also verify that there are no duplicate columns specified in any of + * the column lists. */ - check_columns_exist(relations); + check_column_lists(relations); /* * Decide whether we need to start/commit our own transactions. @@ -550,16 +553,20 @@ get_rel_oids(List **vacrels) } /* - * Check that all specified columns for the relations exist. + * Check that all specified columns for the relations exist and that there are + * no duplicate columns specified in each list. * * This function emits an ERROR if the relation or the columns specified for * a relation cannot be found. This is used to pre-validate any column lists * specified in VACUUM/ANALYZE commands. If any columns disappear between * calling this function and when we actually get to processing them, we will * emit a WARNING and skip it at that time. + * + * This function also emits an ERROR if any column list contains duplicate + * entries, as ANALYZE will fail in that case. */ static void -check_columns_exist(List *relations) +check_column_lists(List *relations) { ListCell *relation_lc; foreach(relation_lc, relations) @@ -567,6 +574,7 @@ check_columns_exist(List *relations) VacuumRelation *relation = lfirst_node(VacuumRelation, relation_lc); Relation rel; ListCell *column_lc; + List *unique_columns; if (relation->va_cols == NIL) /* nothing to check */ return; @@ -593,6 +601,24 @@ check_columns_exist(List *relations) relation->relation->relname))); } + /* verify that there are no duplicate columns specified */ + unique_columns = list_concat_unique(NIL, relation->va_cols); + if (list_length(unique_columns) != list_length(relation->va_cols)) + { + if (relation->relation->schemaname) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("column lists cannot have duplicate entries"), + errhint("the column list specified for relation \"%s.%s\" contains duplicates", + relation->relation->schemaname, relation->relation->relname))); + else + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("column lists cannot have duplicate entries"), + errhint("the column list specified for relation \"%s\" contains duplicates", + relation->relation->relname))); + } + foreach(column_lc, relation->va_cols) { char *col = strVal(lfirst(column_lc)); diff --git a/src/test/regress/expected/vacuum.out b/src/test/regress/expected/vacuum.out index d29dd8f..cb377ab 100644 --- a/src/test/regress/expected/vacuum.out +++ b/src/test/regress/expected/vacuum.out @@ -97,6 +97,8 @@ VACUUM (FREEZE) vaccluster, does_not_exist; ERROR: relation "does_not_exist" does not exist VACUUM (FREEZE, ANALYZE) vactst (i); VACUUM (FREEZE, ANALYZE) vactst (i, i, i); +ERROR: column lists cannot have duplicate entries +HINT: the column list specified for relation "vactst" contains duplicates VACUUM (FREEZE, ANALYZE) vactst, vacparted (a); VACUUM (FREEZE, ANALYZE) vacparted, vactst (i), vacparted; VACUUM (FREEZE, ANALYZE) vactst (i), vacparted (a, b), vaccluster (i); @@ -120,6 +122,9 @@ ANALYZE VERBOSE vactst (i), vacparted (does_not_exist); ERROR: column "does_not_exist" of relation "vacparted" does not exist ANALYZE vactst, vactst, vactst; ANALYZE vacparted (a), vacparted (b), vacparted; +ANALYZE vactst (i, i), vacparted (a), vactst (i), vacparted (a, b, a); +ERROR: column lists cannot have duplicate entries +HINT: the column list specified for relation "vactst" contains duplicates DROP TABLE vaccluster; DROP TABLE vactst; DROP TABLE vacparted; diff --git a/src/test/regress/sql/vacuum.sql b/src/test/regress/sql/vacuum.sql index 991bea7..1134a58 100644 --- a/src/test/regress/sql/vacuum.sql +++ b/src/test/regress/sql/vacuum.sql @@ -93,6 +93,7 @@ ANALYZE vacparted (b), vactst; ANALYZE VERBOSE vactst (i), vacparted (does_not_exist); ANALYZE vactst, vactst, vactst; ANALYZE vacparted (a), vacparted (b), vacparted; +ANALYZE vactst (i, i), vacparted (a), vactst (i), vacparted (a, b, a); DROP TABLE vaccluster; DROP TABLE vactst;