Skip to content

Commit cf7ab13

Browse files
committed
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
1 parent 35f059e commit cf7ab13

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,18 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
950950
attno - 1);
951951
int child_index;
952952

953+
/*
954+
* Ignore any column dropped from the parent.
955+
* Corresponding Var won't have any translation. It won't
956+
* have attr_needed information, since it can not be
957+
* referenced in the query.
958+
*/
959+
if (var == NULL)
960+
{
961+
Assert(attr_needed == NULL);
962+
continue;
963+
}
964+
953965
child_index = var->varattno - childrel->min_attr;
954966
childrel->attr_needed[child_index] = attr_needed;
955967
}

src/test/regress/expected/alter_table.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,6 +3706,13 @@ ALTER TABLE list_parted2 DROP COLUMN b;
37063706
ERROR: cannot drop column named in partition key
37073707
ALTER TABLE list_parted2 ALTER COLUMN b TYPE text;
37083708
ERROR: cannot alter type of column named in partition key
3709+
-- dropping non-partition key columns should be allowed on the parent table.
3710+
ALTER TABLE list_parted DROP COLUMN b;
3711+
SELECT * FROM list_parted;
3712+
a
3713+
---
3714+
(0 rows)
3715+
37093716
-- cleanup
37103717
DROP TABLE list_parted, list_parted2, range_parted;
37113718
DROP TABLE fail_def_part;

src/test/regress/sql/alter_table.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,10 @@ ALTER TABLE part_2 INHERIT inh_test;
24182418
ALTER TABLE list_parted2 DROP COLUMN b;
24192419
ALTER TABLE list_parted2 ALTER COLUMN b TYPE text;
24202420

2421+
-- dropping non-partition key columns should be allowed on the parent table.
2422+
ALTER TABLE list_parted DROP COLUMN b;
2423+
SELECT * FROM list_parted;
2424+
24212425
-- cleanup
24222426
DROP TABLE list_parted, list_parted2, range_parted;
24232427
DROP TABLE fail_def_part;

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