Prevent dropping distribution keys for MODULO
authorTomas Vondra <tomas@2ndquadrant.com>
Fri, 16 Jun 2017 20:59:48 +0000 (22:59 +0200)
committerTomas Vondra <tomas@2ndquadrant.com>
Sat, 17 Jun 2017 21:28:11 +0000 (23:28 +0200)
commit93656ace7562bf6892764d314311c802fbfdc34f
tree20b32b687ad68885ed968466d91526f5c57d4bdc
parentb11c6ff119ffce5174b221deb7e65c2720da6623
Prevent dropping distribution keys for MODULO

Due to a coding issue in IsDistColumnForRelId() it was possible to drop
columns that were used as modulo distribution keys. A simple example
demonstrates the behavior:

    CREATE TABLE t (a INT, b INT, c INT) DISTRIBUTE BY MODULO (a);
    ALTER TABLE t DROP COLUMN a;

    test=# \d+ t
                              Table "public.t"
     Column |  Type   | Modifiers | Storage | Stats target | Description
    --------+---------+-----------+---------+--------------+-------------
     b      | integer |           | plain   |              |
     c      | integer |           | plain   |              |
    Distribute By: MODULO(........pg.dropped.1........)
    Location Nodes: ALL DATANODES

With this commit, the ALTER TABLE command fails as expected:

    ERROR:  Distribution column cannot be dropped

The commit simplifies the coding a bit, and removes several functions
that were not needed anymore (and unused outside locator.c).
src/backend/pgxc/locator/locator.c
src/include/pgxc/locator.h
src/test/regress/expected/xl_alter_table.out
src/test/regress/sql/xl_alter_table.sql