aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-10-31 14:41:21 +0530
committerRobert Haas <rhaas@postgresql.org>2017-10-31 14:43:05 +0530
commitcf7ab13bfb450dde50c86fa714a92964ce32b537 (patch)
treefea135eb6549f1d217525f262eefac37cd48c536
parent35f059e9bdfb3b14ac9d22a9e159d36ec0ccf804 (diff)
downloadpostgresql-cf7ab13bfb450dde50c86fa714a92964ce32b537.tar.gz
postgresql-cf7ab13bfb450dde50c86fa714a92964ce32b537.zip
Fix code related to partitioning schemes for dropped columns.
The entry in appinfo->translated_vars can be NULL; if so, we must avoid dereferencing it. Ashutosh Bapat Discussion: http://postgr.es/m/CAFjFpReL7+1ien=-21rhjpO3bV7aAm1rQ8XgLVk2csFagSzpZQ@mail.gmail.com
-rw-r--r--src/backend/optimizer/path/allpaths.c12
-rw-r--r--src/test/regress/expected/alter_table.out7
-rw-r--r--src/test/regress/sql/alter_table.sql4
3 files changed, 23 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 4e565b3c000..a6efb4e1d39 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -950,6 +950,18 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
attno - 1);
int child_index;
+ /*
+ * Ignore any column dropped from the parent.
+ * Corresponding Var won't have any translation. It won't
+ * have attr_needed information, since it can not be
+ * referenced in the query.
+ */
+ if (var == NULL)
+ {
+ Assert(attr_needed == NULL);
+ continue;
+ }
+
child_index = var->varattno - childrel->min_attr;
childrel->attr_needed[child_index] = attr_needed;
}
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index d7a084c5b79..ee1f10c8e0a 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -3706,6 +3706,13 @@ ALTER TABLE list_parted2 DROP COLUMN b;
ERROR: cannot drop column named in partition key
ALTER TABLE list_parted2 ALTER COLUMN b TYPE text;
ERROR: cannot alter type of column named in partition key
+-- dropping non-partition key columns should be allowed on the parent table.
+ALTER TABLE list_parted DROP COLUMN b;
+SELECT * FROM list_parted;
+ a
+---
+(0 rows)
+
-- cleanup
DROP TABLE list_parted, list_parted2, range_parted;
DROP TABLE fail_def_part;
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 339d25b5e56..4ae4c2eceea 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -2418,6 +2418,10 @@ ALTER TABLE part_2 INHERIT inh_test;
ALTER TABLE list_parted2 DROP COLUMN b;
ALTER TABLE list_parted2 ALTER COLUMN b TYPE text;
+-- dropping non-partition key columns should be allowed on the parent table.
+ALTER TABLE list_parted DROP COLUMN b;
+SELECT * FROM list_parted;
+
-- cleanup
DROP TABLE list_parted, list_parted2, range_parted;
DROP TABLE fail_def_part;