-- Tests that check that our query functionality behaves as expected when the
-- table schema is modified via ALTER statements.
SET citus.next_shard_id TO 620000;
SELECT count(*) FROM customer;
 count
---------------------------------------------------------------------
  1000
(1 row)

SELECT * FROM customer LIMIT 2;
 c_custkey |       c_name       |           c_address            | c_nationkey |     c_phone     | c_acctbal | c_mktsegment |                            c_comment
---------------------------------------------------------------------
         1 | Customer#000000001 | IVhzIApeRb ot,c,E              |          15 | 25-989-741-2988 |    711.56 | BUILDING     | to the even, regular platelets. regular, ironic epitaphs nag e
         2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak |          13 | 23-768-687-3665 |    121.65 | AUTOMOBILE   | l accounts. blithely ironic theodolites integrate boldly: caref
(2 rows)

ALTER TABLE customer ADD COLUMN new_column1 INTEGER;
ALTER TABLE customer ADD COLUMN new_column2 INTEGER;
SELECT count(*) FROM customer;
 count
---------------------------------------------------------------------
  1000
(1 row)

SELECT * FROM customer LIMIT 2;
 c_custkey |       c_name       |           c_address            | c_nationkey |     c_phone     | c_acctbal | c_mktsegment |                            c_comment                            | new_column1 | new_column2
---------------------------------------------------------------------
         1 | Customer#000000001 | IVhzIApeRb ot,c,E              |          15 | 25-989-741-2988 |    711.56 | BUILDING     | to the even, regular platelets. regular, ironic epitaphs nag e  |             |
         2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak |          13 | 23-768-687-3665 |    121.65 | AUTOMOBILE   | l accounts. blithely ironic theodolites integrate boldly: caref |             |
(2 rows)

ALTER TABLE customer DROP COLUMN new_column1;
ALTER TABLE customer DROP COLUMN new_column2;
SELECT count(*) FROM customer;
 count
---------------------------------------------------------------------
  1000
(1 row)

SELECT * FROM customer LIMIT 2;
 c_custkey |       c_name       |           c_address            | c_nationkey |     c_phone     | c_acctbal | c_mktsegment |                            c_comment
---------------------------------------------------------------------
         1 | Customer#000000001 | IVhzIApeRb ot,c,E              |          15 | 25-989-741-2988 |    711.56 | BUILDING     | to the even, regular platelets. regular, ironic epitaphs nag e
         2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak |          13 | 23-768-687-3665 |    121.65 | AUTOMOBILE   | l accounts. blithely ironic theodolites integrate boldly: caref
(2 rows)

-- Verify joins work with dropped columns.
SELECT count(*) FROM customer, orders WHERE c_custkey = o_custkey;
 count
---------------------------------------------------------------------
  1956
(1 row)

-- Test joinExpr aliases by performing an outer-join.
SELECT c_custkey
FROM   (customer LEFT OUTER JOIN orders ON (c_custkey = o_custkey)) AS
       test(c_custkey, c_nationkey)
       INNER JOIN lineitem ON (test.c_custkey = l_orderkey)
ORDER BY 1
LIMIT 10;
 c_custkey
---------------------------------------------------------------------
         1
         1
         1
         1
         1
         1
         1
         1
         1
         1
(10 rows)

