(Node *) makeInteger(true), -1),
stmt->options);
+ /*
+ * If the table is inherited then use the distribution strategy of the
+ * parent. We must have already checked for multiple parents and raised an
+ * ERROR since Postgres-XL does not support inheriting from multiple
+ * parents.
+ */
+ if (stmt->inhRelations && IS_PGXC_COORDINATOR && autodistribute)
+ {
+ RangeVar *inh = (RangeVar *) linitial(stmt->inhRelations);
+ Relation rel;
+
+ Assert(IsA(inh, RangeVar));
+ rel = heap_openrv(inh, AccessShareLock);
+ if ((rel->rd_rel->relkind != RELKIND_RELATION) &&
+ (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE))
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("inherited relation \"%s\" is not a table",
+ inh->relname)));
+
+ if (stmt->distributeby)
+ {
+ if (!rel->rd_locator_info)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("parent table \"%s\" is not distributed, but "
+ "distribution is specified for the child table \"%s\"",
+ RelationGetRelationName(rel),
+ stmt->relation->relname)));
+ ereport(WARNING,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("Inherited/partition tables inherit"
+ " distribution from the parent"),
+ errdetail("Explicitly specified distribution will be ignored")));
+ }
+ else
+ stmt->distributeby = makeNode(DistributeBy);
+
+
+ if (rel->rd_locator_info)
+ {
+ switch (rel->rd_locator_info->locatorType)
+ {
+ case LOCATOR_TYPE_HASH:
+ stmt->distributeby->disttype = DISTTYPE_HASH;
+ stmt->distributeby->colname =
+ pstrdup(rel->rd_locator_info->partAttrName);
+ break;
+ case LOCATOR_TYPE_MODULO:
+ stmt->distributeby->disttype = DISTTYPE_MODULO;
+ stmt->distributeby->colname =
+ pstrdup(rel->rd_locator_info->partAttrName);
+ break;
+ case LOCATOR_TYPE_REPLICATED:
+ stmt->distributeby->disttype = DISTTYPE_REPLICATION;
+ break;
+ case LOCATOR_TYPE_RROBIN:
+ default:
+ stmt->distributeby->disttype = DISTTYPE_ROUNDROBIN;
+ break;
+ }
+ stmt->subcluster = makeSubCluster(rel->rd_locator_info->rl_nodeList);
+ }
+ heap_close(rel, NoLock);
+ }
+
/*
* transformIndexConstraints wants cxt.alist to contain only index
* statements, so transfer anything we already have into save_alist.
stmt->distributeby->disttype = DISTTYPE_REPLICATION;
stmt->distributeby->colname = NULL;
}
- /*
- * If there are parent tables ingerit distribution of the first parent
- */
- else if (cxt.fallback_source < FBS_UIDX && stmt->inhRelations)
- {
- RangeVar *inh = (RangeVar *) linitial(stmt->inhRelations);
- Relation rel;
-
- Assert(IsA(inh, RangeVar));
- rel = heap_openrv(inh, AccessShareLock);
- if ((rel->rd_rel->relkind != RELKIND_RELATION) &&
- (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE))
- ereport(ERROR,
- (errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("inherited relation \"%s\" is not a table",
- inh->relname)));
-
- if (rel->rd_locator_info)
- {
- switch (rel->rd_locator_info->locatorType)
- {
- case LOCATOR_TYPE_HASH:
- stmt->distributeby->disttype = DISTTYPE_HASH;
- stmt->distributeby->colname =
- pstrdup(rel->rd_locator_info->partAttrName);
- break;
- case LOCATOR_TYPE_MODULO:
- stmt->distributeby->disttype = DISTTYPE_MODULO;
- stmt->distributeby->colname =
- pstrdup(rel->rd_locator_info->partAttrName);
- break;
- case LOCATOR_TYPE_REPLICATED:
- stmt->distributeby->disttype = DISTTYPE_REPLICATION;
- break;
- case LOCATOR_TYPE_RROBIN:
- default:
- stmt->distributeby->disttype = DISTTYPE_ROUNDROBIN;
- break;
- }
- /*
- * Use defined node, if nothing defined get from the parent
- */
- if (stmt->subcluster == NULL)
- stmt->subcluster = makeSubCluster(rel->rd_locator_info->rl_nodeList);
- }
- heap_close(rel, NoLock);
- }
/*
* If there are columns suitable for hash distribution distribute on
* first of them.
-- test inheritance
create table dropColumn (a int, b int, e int) distribute by replication;
create table dropColumnChild (c int) inherits (dropColumn) distribute by replication;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
create table dropColumnAnother (d int) inherits (dropColumnChild);
-- these two should fail
alter table dropColumnchild drop column a;
-- Test corner cases in dropping of inherited columns
create table p1 (f1 int, f2 int) distribute by roundrobin;
create table c1 (f1 int not null) inherits(p1) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
NOTICE: merging column "f1" with inherited definition
-- should be rejected since c1.f1 is inherited
alter table c1 drop column f1;
NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int) distribute by roundrobin;
create table c1 () inherits(p1) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
-- should be rejected since c1.f1 is inherited
alter table c1 drop column f1;
ERROR: cannot drop inherited column "f1"
NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int) distribute by roundrobin;
create table c1 () inherits(p1) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
-- should be rejected since c1.f1 is inherited
alter table c1 drop column f1;
ERROR: cannot drop inherited column "f1"
NOTICE: drop cascades to table c1
create table p1 (f1 int, f2 int) distribute by roundrobin;
create table c1 (f1 int not null) inherits(p1) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
NOTICE: merging column "f1" with inherited definition
-- should be rejected since c1.f1 is inherited
alter table c1 drop column f1;
-- Basic 2 table case: 1 column of matching types.
create table pktable_base (base1 int not null) DISTRIBUTE BY REPLICATION;
create table pktable (ptest1 int, primary key(base1), unique(base1, ptest1)) inherits (pktable_base) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
create table fktable (ftest1 int references pktable(base1));
-- now some ins, upd, del
insert into pktable(base1) values (1);
create table pktable_base(base1 int not null, base2 int) DISTRIBUTE BY REPLICATION;
create table pktable(ptest1 int, ptest2 int, primary key(base1, ptest1), foreign key(base2, ptest2) references
pktable(base1, ptest1)) inherits (pktable_base) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
insert into pktable (base1, ptest1, base2, ptest2) values (1, 1, 1, 1);
insert into pktable (base1, ptest1, base2, ptest2) values (2, 1, 1, 1);
insert into pktable (base1, ptest1, base2, ptest2) values (2, 2, 2, 1);
--
CREATE TABLE a (aa TEXT) distribute by roundrobin;
CREATE TABLE b (bb TEXT) INHERITS (a) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
CREATE TABLE c (cc TEXT) INHERITS (a) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
CREATE TABLE d (dd TEXT) INHERITS (b,c,a) distribute by roundrobin;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
NOTICE: merging multiple inherited definitions of column "aa"
NOTICE: merging multiple inherited definitions of column "aa"
INSERT INTO a(aa) VALUES('aaa');
-- inheritance tests
CREATE TABLE base_tbl_parent (a int) DISTRIBUTE BY REPLICATION;
CREATE TABLE base_tbl_child (CHECK (a > 0)) INHERITS (base_tbl_parent) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
INSERT INTO base_tbl_parent SELECT * FROM generate_series(-8, -1);
INSERT INTO base_tbl_child SELECT * FROM generate_series(1, 8);
CREATE VIEW rw_view1 AS SELECT * FROM base_tbl_parent;
SELECT i,i,'t1' FROM generate_series(1,10) g(i);
ANALYZE t1;
CREATE TABLE t11 (d text) INHERITS (t1) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
CREATE INDEX t11_a_idx ON t11(a);
INSERT INTO t11
SELECT i,i,'t11','t11d' FROM generate_series(1,10) g(i);
ANALYZE t11;
CREATE TABLE t12 (e int[]) INHERITS (t1) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
CREATE INDEX t12_a_idx ON t12(a);
INSERT INTO t12
SELECT i,i,'t12','{1,2}'::int[] FROM generate_series(1,10) g(i);
ANALYZE t12;
CREATE TABLE t111 () INHERITS (t11, t12) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
NOTICE: merging multiple inherited definitions of column "a"
NOTICE: merging multiple inherited definitions of column "b"
NOTICE: merging multiple inherited definitions of column "c"
-- WITH attached to inherited UPDATE or DELETE
CREATE TEMP TABLE parent ( id int, val text ) DISTRIBUTE BY REPLICATION;
CREATE TEMP TABLE child1 ( ) INHERITS ( parent ) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
CREATE TEMP TABLE child2 ( ) INHERITS ( parent ) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
INSERT INTO parent VALUES ( 1, 'p1' );
INSERT INTO child1 VALUES ( 11, 'c11' ),( 12, 'c12' );
INSERT INTO child2 VALUES ( 23, 'c21' ),( 24, 'c22' );
create table t3(val int, val2 int) DISTRIBUTE BY REPLICATION;
create table p1(a int, b int) DISTRIBUTE BY REPLICATION;
create table c1(d int, e int) inherits (p1) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
-- insert some rows in them
insert into t1 values(1,11),(2,11);
insert into t2 values(3,11),(4,11);
create table t3(val int, val2 int) DISTRIBUTE BY REPLICATION;
create table p1(a int, b int) DISTRIBUTE BY REPLICATION;
create table c1(d int, e int) inherits (p1) DISTRIBUTE BY REPLICATION;
+WARNING: Inherited/partition tables inherit distribution from the parent
+DETAIL: Explicitly specified distribution will be ignored
-- insert some rows in them
insert into t1 values(1,11),(2,11);
insert into t2 values(3,11),(4,11);