diff --git a/src/common/backend/nodes/nodeFuncs.cpp b/src/common/backend/nodes/nodeFuncs.cpp index e50e5aeaf..fc3d82fd0 100644 --- a/src/common/backend/nodes/nodeFuncs.cpp +++ b/src/common/backend/nodes/nodeFuncs.cpp @@ -2828,6 +2828,8 @@ Query* query_tree_mutator(Query* query, Node* (*mutator)(Node*, void*), void* co Query* newquery = NULL; FLATCOPY(newquery, query, Query, true); + if (newquery->resultRelations) + newquery->resultRelations = (List*)copyObject(query->resultRelations); query = newquery; } diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 4a40970f0..dd8fe276c 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -8783,11 +8783,12 @@ key_action: OptInherit: INHERITS '(' qualified_name_list ')' { - const char* message = "CREATE TABLE ... INHERITS is not yet supported."; - InsertErrorMessage(message, u_sess->plsql_cxt.plpgsql_yylloc); - ereport(errstate, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("CREATE TABLE ... INHERITS is not yet supported."))); + if (u_sess->attr.attr_sql.sql_compatibility == B_FORMAT) { + const char* message = "inherits is not support in B-format database, it conflicts with multi-relation update"; + InsertErrorMessage(message, u_sess->plsql_cxt.plpgsql_yylloc); + ereport(errstate, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("inherits is not support in B-format database, it conflicts with multi-relation update"))); + } $$ = $3; } | /*EMPTY*/ { $$ = NIL; } diff --git a/src/common/interfaces/libpq/frontend_parser/gram.y b/src/common/interfaces/libpq/frontend_parser/gram.y index fd4955325..9dff32360 100755 --- a/src/common/interfaces/libpq/frontend_parser/gram.y +++ b/src/common/interfaces/libpq/frontend_parser/gram.y @@ -6367,7 +6367,6 @@ key_action: OptInherit: INHERITS '(' qualified_name_list ')' { - feparser_printf("CREATE TABLE ... INHERITS is not yet supported.\n"); $$ = $3; } | /*EMPTY*/ { $$ = NIL; } diff --git a/src/gausskernel/optimizer/commands/analyze.cpp b/src/gausskernel/optimizer/commands/analyze.cpp index 81ce2d222..918c7ce56 100755 --- a/src/gausskernel/optimizer/commands/analyze.cpp +++ b/src/gausskernel/optimizer/commands/analyze.cpp @@ -622,6 +622,12 @@ static void analyze_rel_internal(Relation onerel, VacuumStmt* vacstmt, BufferAcc * Do the normal non-recursive ANALYZE. */ do_analyze_rel(onerel, vacstmt, relpages, false, elevel, analyzemode); + + /* + * If there are child tables, do recursive ANALYZE. + */ + if (onerel->rd_rel->relhassubclass) + do_analyze_rel(onerel, vacstmt, relpages, true, elevel, analyzemode); /* * Close source relation now, but keep lock so that no one deletes it diff --git a/src/gausskernel/optimizer/path/allpaths.cpp b/src/gausskernel/optimizer/path/allpaths.cpp index e63f1a67b..ae1c18b6a 100755 --- a/src/gausskernel/optimizer/path/allpaths.cpp +++ b/src/gausskernel/optimizer/path/allpaths.cpp @@ -1536,8 +1536,8 @@ static void set_append_rel_size(PlannerInfo* root, RelOptInfo* rel, Index rti, R parent_rows += RELOPTINFO_LOCAL_FIELD(root, childrel, rows); parent_global_rows += childrel->rows; - parent_tuples += RELOPTINFO_LOCAL_FIELD(root, childrel, tuples); - parent_global_tuples += childrel->tuples; + parent_tuples += RELOPTINFO_LOCAL_FIELD(root, childrel, rows); + parent_global_tuples += childrel->rows; parent_size += childrel->reltarget->width * RELOPTINFO_LOCAL_FIELD(root, childrel, rows); /* diff --git a/src/gausskernel/optimizer/path/equivclass.cpp b/src/gausskernel/optimizer/path/equivclass.cpp index 23c699ae0..9d57b912a 100644 --- a/src/gausskernel/optimizer/path/equivclass.cpp +++ b/src/gausskernel/optimizer/path/equivclass.cpp @@ -1899,6 +1899,7 @@ void add_child_rel_equivalences( PlannerInfo* root, AppendRelInfo* appinfo, RelOptInfo* parent_rel, RelOptInfo* child_rel) { ListCell* lc1 = NULL; + Relids top_parent_relids = child_rel->top_parent_relids ? child_rel->top_parent_relids: parent_rel->relids; foreach (lc1, root->eq_classes) { EquivalenceClass* cur_ec = (EquivalenceClass*)lfirst(lc1); @@ -1913,7 +1914,7 @@ void add_child_rel_equivalences( continue; /* No point in searching if parent rel not mentioned in eclass */ - if (!bms_is_subset(parent_rel->relids, cur_ec->ec_relids)) + if (!bms_is_subset(top_parent_relids, cur_ec->ec_relids)) continue; foreach (lc2, cur_ec->ec_members) { @@ -1923,13 +1924,18 @@ void add_child_rel_equivalences( continue; /* ignore consts and children here */ /* Does it reference parent_rel? */ - if (bms_overlap(cur_em->em_relids, parent_rel->relids)) { + if (bms_overlap(cur_em->em_relids, top_parent_relids)) { /* Yes, generate transformed child version */ Expr* child_expr = NULL; Relids new_relids; Relids new_nullable_relids; - child_expr = (Expr*)adjust_appendrel_attrs(root, (Node*)cur_em->em_expr, appinfo); + if (parent_rel->reloptkind != RELOPT_OTHER_MEMBER_REL) { + child_expr = (Expr*)adjust_appendrel_attrs(root, (Node*)cur_em->em_expr, appinfo); + } else { + child_expr = (Expr *)adjust_appendrel_attrs_multilevel(root, (Node *)cur_em->em_expr, + child_rel->relids, top_parent_relids); + } /* * Transform em_relids to match. Note we do *not* do @@ -1937,7 +1943,7 @@ void add_child_rel_equivalences( * transformation might have substituted a constant, but we * don't want the child member to be marked as constant. */ - new_relids = bms_difference(cur_em->em_relids, parent_rel->relids); + new_relids = bms_difference(cur_em->em_relids, top_parent_relids); new_relids = bms_add_members(new_relids, child_rel->relids); /* @@ -1945,8 +1951,8 @@ void add_child_rel_equivalences( * parent and child relids are singletons. */ new_nullable_relids = cur_em->em_nullable_relids; - if (bms_overlap(new_nullable_relids, parent_rel->relids)) { - new_nullable_relids = bms_difference(new_nullable_relids, parent_rel->relids); + if (bms_overlap(new_nullable_relids, top_parent_relids)) { + new_nullable_relids = bms_difference(new_nullable_relids, top_parent_relids); new_nullable_relids = bms_add_members(new_nullable_relids, child_rel->relids); } diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index cbf3c2dd5..45920c5a0 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -1359,7 +1359,7 @@ static Plan* create_merge_append_plan(PlannerInfo* root, MergeAppendPath* best_p (void)prepare_sort_from_pathkeys(root, plan, pathkeys, - NULL, + best_path->path.parent->relids, NULL, true, &node->numCols, diff --git a/src/gausskernel/optimizer/plan/planner.cpp b/src/gausskernel/optimizer/plan/planner.cpp index 17e83f8bf..f46f5c433 100755 --- a/src/gausskernel/optimizer/plan/planner.cpp +++ b/src/gausskernel/optimizer/plan/planner.cpp @@ -1915,8 +1915,10 @@ Plan* subquery_planner(PlannerGlobal* glob, Query* parse, PlannerInfo* parent_ro */ if (parse->resultRelations && parse->commandType != CMD_INSERT && rt_fetch(linitial_int(parse->resultRelations), parse->rtable)->inh) + { plan = inheritance_planner(root); - else { + plan->isinherit = true; + } else { plan = grouping_planner(root, tuple_fraction); /* * Make sure the topmost plan node's targetlist exposes the original diff --git a/src/gausskernel/optimizer/prep/prepunion.cpp b/src/gausskernel/optimizer/prep/prepunion.cpp index 18b7bb761..44feb4f97 100644 --- a/src/gausskernel/optimizer/prep/prepunion.cpp +++ b/src/gausskernel/optimizer/prep/prepunion.cpp @@ -1768,6 +1768,67 @@ Bitmapset* translate_col_privs(const Bitmapset* parent_privs, List* translated_v return child_privs; } +/* + * find_appinfos_by_relids + * Find AppendRelInfo structures for all relations specified by relids. + * + * The AppendRelInfos are returned in an array, which can be pfree'd by the + * caller. *nappinfos is set to the number of entries in the array. + */ +AppendRelInfo **find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos) +{ + AppendRelInfo **appinfos; + int cnt = 0; + int i; + + *nappinfos = bms_num_members(relids); + appinfos = (AppendRelInfo **) palloc(sizeof(AppendRelInfo *) * *nappinfos); + + i = -1; + while ((i = bms_next_member(relids, i)) >= 0) { + AppendRelInfo *appinfo = root->append_rel_array[i]; + if (!appinfo) + elog(ERROR, "child rel %d not found in append_rel_array", i); + appinfos[cnt++] = appinfo; + } + return appinfos; +} + +/* + * adjust_appendrel_attrs_multilevel + * Apply Var translations from a toplevel appendrel parent down to a child. + * + * In some cases we need to translate expressions referencing a parent relation + * to reference an appendrel child that's multiple levels removed from it. + */ +Node *adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids) +{ + AppendRelInfo **appinfos; + AppendRelInfo *appinfo; + Bitmapset *parent_relids = NULL; + int nappinfos; + int cnt; + + Assert(bms_num_members(child_relids) == bms_num_members(top_parent_relids)); + appinfos = find_appinfos_by_relids(root, child_relids, &nappinfos); + + /* Construct relids set for the immediate parent of given child. */ + for (cnt = 0; cnt < nappinfos; cnt++) { + appinfo = appinfos[cnt]; + parent_relids = bms_add_member(parent_relids, appinfo->parent_relid); + } + + /* Recurse if immediate parent is not the top parent. */ + if (!bms_equal(parent_relids, top_parent_relids)) + node = adjust_appendrel_attrs_multilevel(root, node, parent_relids, + top_parent_relids); + + /* Now translate for this child */ + node = adjust_appendrel_attrs(root, node, appinfo); + pfree(appinfos); + return node; +} + /* * adjust_appendrel_attrs * Copy the specified query or expression and translate Vars referring diff --git a/src/gausskernel/optimizer/util/relnode.cpp b/src/gausskernel/optimizer/util/relnode.cpp index 450f5e816..4ce26b212 100755 --- a/src/gausskernel/optimizer/util/relnode.cpp +++ b/src/gausskernel/optimizer/util/relnode.cpp @@ -135,16 +135,41 @@ void setup_simple_rel_arrays(PlannerInfo* root) rti = 1; foreach (lc, root->parse->rtable) { RangeTblEntry* rte = (RangeTblEntry*)lfirst(lc); - root->simple_rte_array[rti++] = rte; } + + /* append_rel_array is not needed if there are no AppendRelInfos */ + if (root->append_rel_list == NIL) { + root->append_rel_array = NULL; + return; + } + + root->append_rel_array = (AppendRelInfo **) + palloc0(root->simple_rel_array_size * sizeof(AppendRelInfo *)); + + /* + * append_rel_array is filled with any already-existing AppendRelInfos, + * which currently could only come from UNION ALL flattening. We might + * add more later during inheritance expansion, but it's the + * responsibility of the expansion code to update the array properly. + */ + foreach(lc, root->append_rel_list) { + AppendRelInfo *appinfo = lfirst_node(AppendRelInfo, lc); + int child_relid = appinfo->child_relid; + + /* Sanity check */ + Assert(child_relid < root->simple_rel_array_size); + if (root->append_rel_array[child_relid]) + elog(ERROR, "child relation already exists"); + root->append_rel_array[child_relid] = appinfo; + } } /* * build_simple_rel * Construct a new RelOptInfo for a base relation or 'other' relation. */ -RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind) +RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind, Bitmapset *parent) { RelOptInfo* rel = NULL; RangeTblEntry* rte = NULL; @@ -279,6 +304,22 @@ RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind rel->locator_type = LOCATOR_TYPE_NONE; #endif + /* + * Pass assorted information down the inheritance hierarchy. + */ + + /* + * Each direct or indirect child wants to know the relids of its + * topmost parent. + */ + + if (parent) { + rel->top_parent_relids = bms_copy(parent); + } else { + rel->top_parent_relids = bms_copy(rel->relids); + parent = bms_copy(rel->top_parent_relids); + } + /* Check type of rtable entry */ switch (rte->rtekind) { case RTE_RELATION: @@ -350,7 +391,7 @@ RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind if (appinfo->parent_relid != (unsigned int)relid) continue; - (void)build_simple_rel(root, appinfo->child_relid, RELOPT_OTHER_MEMBER_REL); + (void)build_simple_rel(root, appinfo->child_relid, RELOPT_OTHER_MEMBER_REL, parent); } } diff --git a/src/gausskernel/runtime/executor/execJunk.cpp b/src/gausskernel/runtime/executor/execJunk.cpp index 4f99056ca..f7a9a9722 100644 --- a/src/gausskernel/runtime/executor/execJunk.cpp +++ b/src/gausskernel/runtime/executor/execJunk.cpp @@ -95,15 +95,16 @@ JunkFilter* ExecInitJunkFilter(List* targetList, bool hasoid, TupleTableSlot* sl cleanLength = cleanTupType->natts; if (cleanLength > 0) { cleanMap = (AttrNumber*)palloc(cleanLength * sizeof(AttrNumber)); - cleanResno = 1; + cleanResno = 0; foreach (t, targetList) { TargetEntry* tle = (TargetEntry*)lfirst(t); if (!tle->resjunk) { - cleanMap[cleanResno - 1] = tle->resno; + cleanMap[cleanResno] = tle->resno; cleanResno++; } } + Assert(cleanResno == cleanLength); } else { cleanMap = NULL; } diff --git a/src/gausskernel/runtime/executor/execMain.cpp b/src/gausskernel/runtime/executor/execMain.cpp index 1fb6069db..8e6875997 100755 --- a/src/gausskernel/runtime/executor/execMain.cpp +++ b/src/gausskernel/runtime/executor/execMain.cpp @@ -176,22 +176,23 @@ static void report_iud_time(QueryDesc *query) } PlannedStmt *plannedstmt = query->plannedstmt; - - foreach (lc, (List*)linitial(plannedstmt->resultRelations)) { - Index idx = lfirst_int(lc); - rid = getrelid(idx, plannedstmt->rtable); - if (OidIsValid(rid) == false || rid < FirstNormalObjectId) { - continue; - } - Relation rel = NULL; - rel = heap_open(rid, AccessShareLock); - if (rel->rd_rel->relkind == RELKIND_RELATION) { - if (rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT || - rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) { - pgstat_report_data_changed(rid, STATFLG_RELATION, rel->rd_rel->relisshared); + if (plannedstmt->resultRelations) { + foreach (lc, (List*)linitial(plannedstmt->resultRelations)) { + Index idx = lfirst_int(lc); + rid = getrelid(idx, plannedstmt->rtable); + if (OidIsValid(rid) == false || rid < FirstNormalObjectId) { + continue; } + Relation rel = NULL; + rel = heap_open(rid, AccessShareLock); + if (rel->rd_rel->relkind == RELKIND_RELATION) { + if (rel->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT || + rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) { + pgstat_report_data_changed(rid, STATFLG_RELATION, rel->rd_rel->relisshared); + } + } + heap_close(rel, AccessShareLock); } - heap_close(rel, AccessShareLock); } } @@ -3950,11 +3951,11 @@ void EvalPlanQualEnd(EPQState *epqstate) epqstate->origslot = NULL; } -TupleTableSlot* FetchPlanSlot(PlanState* subPlanState, ProjectionInfo** projInfos) +TupleTableSlot* FetchPlanSlot(PlanState* subPlanState, ProjectionInfo** projInfos, bool isinherit) { int result_rel_index = subPlanState->state->result_rel_index; - if (result_rel_index > 0) { + if (result_rel_index > 0 && !isinherit) { return ExecProject(projInfos[result_rel_index], NULL); } else { return ExecProcNode(subPlanState); diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index fc7f932c8..a0f697420 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -3408,8 +3408,9 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) bool is_first_modified = true; int2 bucketid = InvalidBktId; List *partition_list = NIL; - int resultRelationNum = node->mt_ResultTupleSlots ? list_length(node->mt_ResultTupleSlots) : 1; + int resultRelationNum = node->mt_ResultTupleSlots ? list_length(node->mt_ResultTupleSlots): node->mt_nplans; + CHECK_FOR_INTERRUPTS(); /* @@ -3518,7 +3519,9 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) result_rel_info = node->resultRelInfo + estate->result_rel_index; estate->es_result_relation_info = result_rel_info; junk_filter = result_rel_info->ri_junkFilter; - partExprKeyStr = node->partExprKeyStrArray[estate->result_rel_index]; + if (!node->isinherit) { + partExprKeyStr = node->partExprKeyStrArray[estate->result_rel_index]; + } if (estate->deleteLimitCount != 0 && estate->es_processed == estate->deleteLimitCount) { break; } @@ -3530,7 +3533,7 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) */ ResetPerTupleExprContext(estate); t_thrd.xact_cxt.ActiveLobRelid = result_rel_info->ri_RelationDesc->rd_id; - plan_slot = FetchPlanSlot(subPlanState, node->mt_ProjInfos); + plan_slot = FetchPlanSlot(subPlanState, node->mt_ProjInfos, node->isinherit); t_thrd.xact_cxt.ActiveLobRelid = InvalidOid; if (TupIsNull(plan_slot)) { record_first_time(); @@ -3541,8 +3544,18 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) /* advance to next subplan if any */ node->mt_whichplan++; - Assert(estate->result_rel_index == 0); + if (!node->isinherit) { + Assert(estate->result_rel_index == 0); + } if (node->mt_whichplan < node->mt_nplans) { + if (node->isinherit) { + if (estate->result_rel_index == resultRelationNum - 1) { + estate->result_rel_index = 0; + } else { + estate->result_rel_index++; + } + result_rel_info = node->resultRelInfo + estate->result_rel_index; + } subPlanState = node->mt_plans[node->mt_whichplan]; #ifdef ENABLE_MULTIPLE_NODES /* Move to next remote plan */ @@ -3569,7 +3582,6 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) LockRelFileNode(estate->es_result_relation_info->ri_RelationDesc->rd_node, RowExclusiveLock); } } - continue; } else { if (use_heap_multi_insert) { @@ -3699,8 +3711,10 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) /* * apply the junk_filter if needed. */ - if (operation != CMD_DELETE) + if (operation != CMD_DELETE) { slot = ExecFilterJunk(junk_filter, slot); + slot->tts_tam_ops = result_rel_info->ri_RelationDesc->rd_tam_ops; + } } #ifdef ENABLE_MULTIPLE_NODES @@ -3745,11 +3759,19 @@ static TupleTableSlot* ExecModifyTable(PlanState* state) } record_first_time(); - - if (estate->result_rel_index == resultRelationNum - 1) { - estate->result_rel_index = 0; - } else { - estate->result_rel_index++; + + /* + * Switching the result_relation_info here will cause the inheritance function error, + * but if don't switch the result_relation_info here, + * openGauss will not be compatible with the multi-table update and deletion of 'B' database + * ensure result_relation_info must be switched here when perform the multi-table update and deletion + */ + if (!node->isinherit) { + if (estate->result_rel_index == resultRelationNum - 1) { + estate->result_rel_index = 0; + } else { + estate->result_rel_index++; + } } /* @@ -3796,7 +3818,7 @@ static void InitMultipleModify(ModifyTableState* node, PlanState* subnode, uint3 List* targetlists = ((ModifyTable*)(node->ps.plan))->targetlists; EState* estate = node->ps.state; - if (resultRelationNum == 1) { + if (resultRelationNum == 1 || node->isinherit) { return; } @@ -3849,13 +3871,12 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl UpsertState* upsertState = NULL; ListCell* l = NULL; int i; + int resultRelationNum; #ifdef PGXC #ifdef ENABLE_MULTIPLE_NDOES PlanState* saved_remote_rel_info = NULL; #endif #endif - int resultRelationNum = list_length((List*)linitial(node->resultRelations)); - /* check for unsupported flags */ Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK))); @@ -3868,7 +3889,13 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl mt_state = makeNode(ModifyTableState); estate->deleteLimitCount = 0; - + + mt_state->isinherit = node->plan.isinherit; + if (mt_state->isinherit) + resultRelationNum = list_length(node->resultRelations); + else + resultRelationNum = list_length((List*)linitial(node->resultRelations)); + if (node->cacheEnt != NULL) { ErrorCacheEntry* entry = node->cacheEnt; @@ -4312,29 +4339,60 @@ ModifyTableState* ExecInitModifyTable(ModifyTable* node, EState* estate, int efl } if (junk_filter_needed) { - result_rel_info = mt_state->resultRelInfo; - for (i = 0; i < nplans; i++) { - sub_plan = mt_state->mt_plans[i]->plan; - if (resultRelationNum > 1) { - foreach (l, node->targetlists) { - List* targetlist = (List*)lfirst(l); - if (operation == CMD_UPDATE) { - ExecCheckPlanOutput(result_rel_info->ri_RelationDesc, targetlist); + if (mt_state->isinherit) { + result_rel_info = mt_state->resultRelInfo; + for (i = 0; i < nplans; i++) { + JunkFilter *j; + sub_plan = mt_state->mt_plans[i]->plan; + if (operation == CMD_INSERT || operation == CMD_UPDATE) + ExecCheckPlanOutput(result_rel_info->ri_RelationDesc, sub_plan->targetlist); + + j = ExecInitJunkFilter(sub_plan->targetlist, + result_rel_info->ri_RelationDesc->rd_att->tdhasoid, + ExecInitExtraTupleSlot(estate, NULL), TableAmHeap); + + if (operation == CMD_UPDATE || operation == CMD_DELETE) { + /* For UPDATE/DELETE, find the appropriate junk attr now */ + char relkind = result_rel_info->ri_RelationDesc->rd_rel->relkind; + if (relkind == RELKIND_RELATION || + relkind == RELKIND_MATVIEW || + relkind == PARTTYPE_PARTITIONED_RELATION) { + j->jf_junkAttNo = ExecFindJunkAttribute(j, "ctid"); + if (!AttributeNumberIsValid(j->jf_junkAttNo)) + elog(ERROR, "could not find junk ctid column"); + } else { + j->jf_junkAttNo = ExecFindJunkAttribute(j, "wholerow"); + if (!AttributeNumberIsValid(j->jf_junkAttNo)) + elog(ERROR, "could not find junk wholerow column"); } - ExecInitJunkAttr(estate, operation, targetlist, result_rel_info); - result_rel_info++; } - } else { - if (operation == CMD_UPDATE) { - CheckPlanOutput(sub_plan, result_rel_info->ri_RelationDesc); + result_rel_info->ri_junkFilter = j; + result_rel_info++; + } + } else { + result_rel_info = mt_state->resultRelInfo; + for (i = 0; i < nplans; i++) { + sub_plan = mt_state->mt_plans[i]->plan; + if (resultRelationNum > 1) { + foreach (l, node->targetlists) { + List* targetlist = (List*)lfirst(l); + if (operation == CMD_UPDATE) { + ExecCheckPlanOutput(result_rel_info->ri_RelationDesc, targetlist); + } + ExecInitJunkAttr(estate, operation, targetlist, result_rel_info); + result_rel_info++; + } + } else { + if (operation == CMD_UPDATE) { + CheckPlanOutput(sub_plan, result_rel_info->ri_RelationDesc); + } + ExecInitJunkAttr(estate, operation, sub_plan->targetlist, result_rel_info); } - ExecInitJunkAttr(estate, operation, sub_plan->targetlist, result_rel_info); } } } else { - if (operation == CMD_INSERT) { + if (operation == CMD_INSERT) CheckPlanOutput(sub_plan, mt_state->resultRelInfo->ri_RelationDesc); - } } } diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index ec08b0244..92dfc1e88 100755 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -255,7 +255,7 @@ extern PlanState* ExecInitNode(Plan* node, EState* estate, int eflags); extern Node* MultiExecProcNode(PlanState* node); extern void ExecEndNode(PlanState* node); extern bool NeedStubExecution(Plan* plan); -extern TupleTableSlot* FetchPlanSlot(PlanState* subPlanState, ProjectionInfo** projInfos); +extern TupleTableSlot* FetchPlanSlot(PlanState* subPlanState, ProjectionInfo** projInfos, bool isinherit); extern long ExecGetPlanMemCost(Plan* node); diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 3d70b0a06..2b61f8bb6 100755 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -1505,6 +1505,7 @@ typedef struct ModifyTableState { bool mt_done; /* are we done? */ bool isReplace; bool isConflict; + bool isinherit; PlanState** mt_plans; /* subplans (one per target rel) */ #ifdef PGXC PlanState** mt_remoterels; /* per-target remote query node */ diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 7fba1981e..d5da7fb38 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -293,6 +293,8 @@ typedef struct Plan { /* flag to indicate if it is controller plan node */ bool recursive_union_controller; + + bool isinherit; /* plan node id of Controller plan node, 0 for not in control */ int control_plan_nodeid; diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index b24120376..c97b0664f 100755 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -338,6 +338,14 @@ typedef struct PlannerInfo { */ RangeTblEntry** simple_rte_array; /* rangetable as an array */ + /* + * append_rel_array is the same length as the above arrays, and holds + * pointers to the corresponding AppendRelInfo entry indexed by + * child_relid, or NULL if the rel is not an appendrel child. The array + * itself is not allocated if append_rel_list is empty. + */ + struct AppendRelInfo **append_rel_array; + /* * all_baserels is a Relids set of all base relids (but not "other" * relids) in the query; that is, the Relids identifier of the final join @@ -829,6 +837,7 @@ typedef struct RelOptInfo { List* joininfo; /* RestrictInfo structures for join clauses * involving this rel */ bool has_eclass_joins; /* T means joininfo is incomplete */ + Relids top_parent_relids; /* Relids of topmost parents (if "other"* rel) */ RelOrientation orientation; /* the store type of base rel */ RelstoreType relStoreLocation; /* the relation store location. */ char locator_type; /* the location type of base rel */ diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index 8cce2273a..c9e5af177 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -114,7 +114,7 @@ extern Path* reparameterize_path(PlannerInfo* root, Path* path, Relids required_ * prototypes for relnode.c */ extern void setup_simple_rel_arrays(PlannerInfo* root); -extern RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind); +extern RelOptInfo* build_simple_rel(PlannerInfo* root, int relid, RelOptKind reloptkind, Bitmapset *parent = NULL); extern RelOptInfo* find_base_rel(PlannerInfo* root, int relid); extern RelOptInfo* find_join_rel(PlannerInfo* root, Relids relids); extern void remove_join_rel(PlannerInfo *root, RelOptInfo *rel); diff --git a/src/include/optimizer/prep.h b/src/include/optimizer/prep.h index 5ae677c24..d98e6eda2 100755 --- a/src/include/optimizer/prep.h +++ b/src/include/optimizer/prep.h @@ -104,7 +104,9 @@ extern void make_inh_translation_list( extern Bitmapset* translate_col_privs(const Bitmapset* parent_privs, List* translated_vars); extern Node* adjust_appendrel_attrs(PlannerInfo* root, Node* node, AppendRelInfo* appinfo); - +extern Node* adjust_appendrel_attrs_multilevel( + PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids); +extern AppendRelInfo **find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos); extern void mark_parent_child_pushdown_flag(Query *parent, Query *child); extern bool check_base_rel_in_fromlist(Query *parse, Node *jtnode); extern UNIONALL_SHIPPING_TYPE precheck_shipping_union_all(Query *subquery, Node *setOp); diff --git a/src/test/regress/expected/alter_table_002.out b/src/test/regress/expected/alter_table_002.out index e2186356e..50f98e2c6 100644 --- a/src/test/regress/expected/alter_table_002.out +++ b/src/test/regress/expected/alter_table_002.out @@ -50,7 +50,6 @@ drop table atacc1; create table atacc1 (test int); create table atacc2 (test2 int); create table atacc3 (test3 int) inherits (atacc1, atacc2); -ERROR: CREATE TABLE ... INHERITS is not yet supported. alter table atacc2 add constraint foo check (test2>0); -- fail and then succeed on atacc2 insert into atacc2 (test2) values (-3); @@ -59,32 +58,22 @@ DETAIL: N/A insert into atacc2 (test2) values (3); -- fail and then succeed on atacc3 insert into atacc3 (test2) values (-3); -ERROR: relation "atacc3" does not exist on datanode1 -LINE 1: insert into atacc3 (test2) values (-3); - ^ +ERROR: new row for relation "atacc3" violates check constraint "foo" +DETAIL: N/A insert into atacc3 (test2) values (3); -ERROR: relation "atacc3" does not exist on datanode1 -LINE 1: insert into atacc3 (test2) values (3); - ^ drop table atacc3; -ERROR: table "atacc3" does not exist drop table atacc2; drop table atacc1; -- same things with one created with INHERIT create table atacc1 (test int); create table atacc2 (test2 int); create table atacc3 (test3 int) inherits (atacc1, atacc2); -ERROR: CREATE TABLE ... INHERITS is not yet supported. alter table atacc3 no inherit atacc2; -ERROR: relation "atacc3" does not exist -- fail alter table atacc3 no inherit atacc2; -ERROR: relation "atacc3" does not exist +ERROR: relation "atacc2" is not a parent of relation "atacc3" -- make sure it really isn't a child insert into atacc3 (test2) values (3); -ERROR: relation "atacc3" does not exist on datanode1 -LINE 1: insert into atacc3 (test2) values (3); - ^ select test2 from atacc2; test2 ------- @@ -93,35 +82,27 @@ select test2 from atacc2; -- fail due to missing constraint alter table atacc2 add constraint foo check (test2>0); alter table atacc3 inherit atacc2; -ERROR: relation "atacc3" does not exist +ERROR: child table is missing constraint "foo" -- fail due to missing column alter table atacc3 rename test2 to testx; -ERROR: relation "atacc3" does not exist alter table atacc3 inherit atacc2; -ERROR: relation "atacc3" does not exist +ERROR: child table is missing column "test2" -- fail due to mismatched data type alter table atacc3 add test2 bool; -ERROR: relation "atacc3" does not exist alter table atacc3 inherit atacc2; -ERROR: relation "atacc3" does not exist +ERROR: child table "atacc3" has different type for column "test2" alter table atacc3 drop test2; -ERROR: relation "atacc3" does not exist -- succeed alter table atacc3 add test2 int; -ERROR: relation "atacc3" does not exist update atacc3 set test2 = 4 where test2 is null; -ERROR: relation "atacc3" does not exist on datanode1 -LINE 1: update atacc3 set test2 = 4 where test2 is null; - ^ alter table atacc3 add constraint foo check (test2>0); -ERROR: relation "atacc3" does not exist alter table atacc3 inherit atacc2; -ERROR: relation "atacc3" does not exist -- fail due to duplicates and circular inheritance alter table atacc3 inherit atacc2; -ERROR: relation "atacc3" does not exist +ERROR: relation "atacc2" would be inherited from more than once alter table atacc2 inherit atacc3; -ERROR: relation "atacc3" does not exist +ERROR: circular inheritance not allowed +DETAIL: "atacc3" is already a child of "atacc2". alter table atacc2 inherit atacc2; ERROR: circular inheritance not allowed DETAIL: "atacc2" is already a child of "atacc2". @@ -129,21 +110,19 @@ DETAIL: "atacc2" is already a child of "atacc2". select test2 from atacc2; test2 ------- -(0 rows) + 4 +(1 row) drop table atacc2 cascade; +NOTICE: drop cascades to table atacc3 drop table atacc1; -- adding only to a parent is allowed as of 9.2 create table atacc1 (test int); create table atacc2 (test2 int) inherits (atacc1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. -- ok: alter table atacc1 add constraint foo check (test>0) no inherit; -- check constraint is not there on child insert into atacc2 (test) values (-3); -ERROR: relation "atacc2" does not exist on datanode1 -LINE 1: insert into atacc2 (test) values (-3); - ^ -- check constraint is there on parent insert into atacc1 (test) values (-3); ERROR: new row for relation "atacc1" violates check constraint "foo" @@ -151,9 +130,8 @@ DETAIL: N/A insert into atacc1 (test) values (3); -- fail, violating row: alter table atacc2 add constraint foo check (test>0) no inherit; -ERROR: relation "atacc2" does not exist +ERROR: check constraint "foo" is violated by some row drop table atacc2; -ERROR: table "atacc2" does not exist drop table atacc1; -- test unique constraint adding create table atacc1 ( test int ) with oids; @@ -408,48 +386,35 @@ ERROR: table "atacc1" does not exist -- test inheritance create table parent (a int); create table child (b varchar(255)) inherits (parent); -ERROR: CREATE TABLE ... INHERITS is not yet supported. alter table parent alter a set not null; insert into parent values (NULL); ERROR: null value in column "a" violates not-null constraint DETAIL: Failing row contains (null). insert into child (a, b) values (NULL, 'foo'); -ERROR: relation "child" does not exist on datanode1 -LINE 1: insert into child (a, b) values (NULL, 'foo'); - ^ +ERROR: null value in column "a" violates not-null constraint +DETAIL: Failing row contains (null, foo). alter table parent alter a drop not null; insert into parent values (NULL); insert into child (a, b) values (NULL, 'foo'); -ERROR: relation "child" does not exist on datanode1 -LINE 1: insert into child (a, b) values (NULL, 'foo'); - ^ alter table only parent alter a set not null; ERROR: column "a" contains null values alter table child alter a set not null; -ERROR: relation "child" does not exist +ERROR: column "a" contains null values delete from parent; alter table only parent alter a set not null; insert into parent values (NULL); ERROR: null value in column "a" violates not-null constraint DETAIL: Failing row contains (null). alter table child alter a set not null; -ERROR: relation "child" does not exist insert into child (a, b) values (NULL, 'foo'); -ERROR: relation "child" does not exist on datanode1 -LINE 1: insert into child (a, b) values (NULL, 'foo'); - ^ +ERROR: null value in column "a" violates not-null constraint +DETAIL: Failing row contains (null, foo). delete from child; -ERROR: relation "child" does not exist on datanode1 -LINE 1: delete from child; - ^ alter table child alter a set not null; -ERROR: relation "child" does not exist insert into child (a, b) values (NULL, 'foo'); -ERROR: relation "child" does not exist on datanode1 -LINE 1: insert into child (a, b) values (NULL, 'foo'); - ^ +ERROR: null value in column "a" violates not-null constraint +DETAIL: Failing row contains (null, foo). drop table child; -ERROR: table "child" does not exist drop table parent; -- test setting and removing default values create table def_test ( @@ -835,34 +800,35 @@ create table parent (a int, b int, c int); insert into parent values (1, 2, 3); alter table parent drop a; create table child (d varchar(255)) inherits (parent); -ERROR: CREATE TABLE ... INHERITS is not yet supported. insert into child values (12, 13, 'testing'); -ERROR: relation "child" does not exist on datanode1 -LINE 1: insert into child values (12, 13, 'testing'); - ^ select * from parent order by b; - b | c ----+--- - 2 | 3 -(1 row) + b | c +----+---- + 2 | 3 + 12 | 13 +(2 rows) select * from child; -ERROR: relation "child" does not exist on datanode1 -LINE 1: select * from child; - ^ + b | c | d +----+----+--------- + 12 | 13 | testing +(1 row) + alter table parent drop c; select * from parent order by b; - b ---- - 2 -(1 row) + b +---- + 2 + 12 +(2 rows) select * from child; -ERROR: relation "child" does not exist on datanode1 -LINE 1: select * from child; - ^ + b | d +----+--------- + 12 | testing +(1 row) + drop table child; -ERROR: table "child" does not exist drop table parent; -- test copy in/out create table test (a int4, b int4, c int4); diff --git a/src/test/regress/expected/alter_table_003.out b/src/test/regress/expected/alter_table_003.out index ebad1a500..515572d59 100644 --- a/src/test/regress/expected/alter_table_003.out +++ b/src/test/regress/expected/alter_table_003.out @@ -4,35 +4,29 @@ -- test inheritance create table dropColumn (a int, b int, e int); create table dropColumnChild (c int) inherits (dropColumn); -ERROR: CREATE TABLE ... INHERITS is not yet supported. create table dropColumnAnother (d int) inherits (dropColumnChild); -ERROR: CREATE TABLE ... INHERITS is not yet supported. -- these two should fail alter table dropColumnchild drop column a; -ERROR: relation "dropcolumnchild" does not exist +ERROR: cannot drop inherited column "a" alter table only dropColumnChild drop column b; -ERROR: relation "dropcolumnchild" does not exist +ERROR: cannot drop inherited column "b" -- these three should work alter table only dropColumn drop column e; alter table dropColumnChild drop column c; -ERROR: relation "dropcolumnchild" does not exist alter table dropColumn drop column a; create table renameColumn (a int); create table renameColumnChild (b int) inherits (renameColumn); -ERROR: CREATE TABLE ... INHERITS is not yet supported. create table renameColumnAnother (c int) inherits (renameColumnChild); -ERROR: CREATE TABLE ... INHERITS is not yet supported. -- these three should fail alter table renameColumnChild rename column a to d; -ERROR: relation "renamecolumnchild" does not exist +ERROR: cannot rename inherited column "a" alter table only renameColumnChild rename column a to d; -ERROR: relation "renamecolumnchild" does not exist +ERROR: inherited column "a" must be renamed in child tables too alter table only renameColumn rename column a to d; +ERROR: inherited column "a" must be renamed in child tables too -- these should work alter table renameColumn rename column a to d; -ERROR: column "a" does not exist alter table renameColumnChild rename column b to a; -ERROR: relation "renamecolumnchild" does not exist -- these should work alter table if exists doesnt_exist_tab rename column a to d; NOTICE: relation "doesnt_exist_tab" does not exist, skipping @@ -42,80 +36,92 @@ NOTICE: relation "doesnt_exist_tab" does not exist, skipping alter table renameColumn add column w int; -- this should fail alter table only renameColumn add column x int; +ERROR: column must be added to child tables too -- Test corner cases in dropping of inherited columns create table p1 (f1 int, f2 int); create table c1 (f1 int not null) inherits(p1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: merging column "f1" with inherited definition -- should be rejected since c1.f1 is inherited alter table c1 drop column f1; -ERROR: relation "c1" does not exist +ERROR: cannot drop inherited column "f1" -- should work alter table p1 drop column f1; -- c1.f1 is still there, but no longer inherited select f1 from c1; -ERROR: relation "c1" does not exist on datanode1 -LINE 1: select f1 from c1; - ^ + f1 +---- +(0 rows) + alter table c1 drop column f1; -ERROR: relation "c1" does not exist select f1 from c1; -ERROR: relation "c1" does not exist on datanode1 +ERROR: column "f1" does not exist LINE 1: select f1 from c1; - ^ + ^ +CONTEXT: referenced column: f1 drop table p1 cascade; +NOTICE: drop cascades to table c1 create table p1 (f1 int, f2 int); create table c1 () inherits(p1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. -- should be rejected since c1.f1 is inherited alter table c1 drop column f1; -ERROR: relation "c1" does not exist +ERROR: cannot drop inherited column "f1" alter table p1 drop column f1; -- c1.f1 is dropped now, since there is no local definition for it select f1 from c1; -ERROR: relation "c1" does not exist on datanode1 +ERROR: column "f1" does not exist LINE 1: select f1 from c1; - ^ + ^ +CONTEXT: referenced column: f1 drop table p1 cascade; +NOTICE: drop cascades to table c1 create table p1 (f1 int, f2 int); create table c1 () inherits(p1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. -- should be rejected since c1.f1 is inherited alter table c1 drop column f1; -ERROR: relation "c1" does not exist +ERROR: cannot drop inherited column "f1" alter table only p1 drop column f1; -- c1.f1 is NOT dropped, but must now be considered non-inherited alter table c1 drop column f1; -ERROR: relation "c1" does not exist drop table p1 cascade; +NOTICE: drop cascades to table c1 create table p1 (f1 int, f2 int); create table c1 (f1 int not null) inherits(p1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: merging column "f1" with inherited definition -- should be rejected since c1.f1 is inherited alter table c1 drop column f1; -ERROR: relation "c1" does not exist +ERROR: cannot drop inherited column "f1" alter table only p1 drop column f1; -- c1.f1 is still there, but no longer inherited alter table c1 drop column f1; -ERROR: relation "c1" does not exist drop table p1 cascade; +NOTICE: drop cascades to table c1 create table p1(id int, name text); create table p2(id2 int, name text, height int); create table c1(age int) inherits(p1,p2); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: merging multiple inherited definitions of column "name" create table gc1() inherits (c1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. select relname, attname, attinhcount, attislocal from pg_class join pg_attribute on (pg_class.oid = pg_attribute.attrelid) where relname in ('p1','p2','c1','gc1') and attnum > 0 and not attisdropped order by relname, attnum; relname | attname | attinhcount | attislocal ---------+---------+-------------+------------ + c1 | id | 1 | f + c1 | name | 2 | f + c1 | id2 | 1 | f + c1 | height | 1 | f + c1 | age | 0 | t + gc1 | id | 1 | f + gc1 | name | 1 | f + gc1 | id2 | 1 | f + gc1 | height | 1 | f + gc1 | age | 1 | f p1 | id | 0 | t p1 | name | 0 | t p2 | id2 | 0 | t p2 | name | 0 | t p2 | height | 0 | t -(5 rows) +(15 rows) -- should work alter table only p1 drop column name; @@ -123,13 +129,12 @@ alter table only p1 drop column name; alter table p2 drop column name; -- should be rejected since its inherited alter table gc1 drop column name; -ERROR: relation "gc1" does not exist +ERROR: cannot drop inherited column "name" -- should work, and drop gc1.name along alter table c1 drop column name; -ERROR: relation "c1" does not exist -- should fail: column does not exist alter table gc1 drop column name; -ERROR: relation "gc1" does not exist +ERROR: column "name" of relation "gc1" does not exist -- should work and drop the attribute in all tables alter table p2 drop column height; select relname, attname, attinhcount, attislocal @@ -138,11 +143,20 @@ where relname in ('p1','p2','c1','gc1') and attnum > 0 and not attisdropped order by relname, attnum; relname | attname | attinhcount | attislocal ---------+---------+-------------+------------ + c1 | id | 1 | f + c1 | id2 | 1 | f + c1 | age | 0 | t + gc1 | id | 1 | f + gc1 | id2 | 1 | f + gc1 | age | 1 | f p1 | id | 0 | t p2 | id2 | 0 | t -(2 rows) +(8 rows) drop table p1, p2 cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table c1 +drop cascades to table gc1 -- -- Test the ALTER TABLE SET WITH/WITHOUT OIDS command -- @@ -179,7 +193,7 @@ create table altwithoid (col integer) with oids; ERROR: CREATE TABLE ... WITH OIDS is not yet supported. -- Inherits parents oid column anyway create table altinhoid () inherits (altwithoid) without oids; -ERROR: CREATE TABLE ... INHERITS is not yet supported. +ERROR: relation "altwithoid" does not exist insert into altinhoid values (1); ERROR: relation "altinhoid" does not exist on datanode1 LINE 1: insert into altinhoid values (1); @@ -225,7 +239,7 @@ ERROR: table "altwithoid" does not exist create table altwithoid (col integer) without oids; -- child can have local oid column create table altinhoid () inherits (altwithoid) with oids; -ERROR: CREATE TABLE ... INHERITS is not yet supported. +ERROR: CREATE TABLE ... WITH OIDS is not yet supported. insert into altinhoid values (1); ERROR: relation "altinhoid" does not exist on datanode1 LINE 1: insert into altinhoid values (1); @@ -265,32 +279,31 @@ drop table altwithoid cascade; -- test renumbering of child-table columns in inherited operations create table p1 (f1 int); create table c1 (f2 text, f3 int) inherits (p1); -ERROR: CREATE TABLE ... INHERITS is not yet supported. alter table p1 add column a1 int check (a1 > 0); alter table p1 add column f2 text; +NOTICE: merging definition of column "f2" for child "c1" insert into p1 values (1,2,'abc'); insert into c1 values(11,'xyz',33,0); -- should fail -ERROR: relation "c1" does not exist on datanode1 -LINE 1: insert into c1 values(11,'xyz',33,0); - ^ +ERROR: new row for relation "c1" violates check constraint "p1_a1_check" +DETAIL: N/A insert into c1 values(11,'xyz',33,22); -ERROR: relation "c1" does not exist on datanode1 -LINE 1: insert into c1 values(11,'xyz',33,22); - ^ select * from p1 order by f1; f1 | a1 | f2 ----+----+----- 1 | 2 | abc -(1 row) + 11 | 22 | xyz +(2 rows) update p1 set a1 = a1 + 1, f2 = upper(f2); select * from p1 order by f1; f1 | a1 | f2 ----+----+----- 1 | 3 | ABC -(1 row) + 11 | 23 | XYZ +(2 rows) drop table p1 cascade; +NOTICE: drop cascades to table c1 -- test that operations with a dropped column do not try to reference -- its datatype --create domain mytype as text; @@ -440,7 +453,6 @@ where oid = 'test_storage'::regclass; -- ALTER TYPE with a check constraint and a child table (bug before Nov 2012) CREATE TABLE test_inh_check (a float check (a > 10.2)); CREATE TABLE test_inh_check_child() INHERITS(test_inh_check); -ERROR: CREATE TABLE ... INHERITS is not yet supported. ALTER TABLE test_inh_check ALTER COLUMN a TYPE numeric; \d test_inh_check Table "public.test_inh_check" @@ -449,8 +461,17 @@ Table "public.test_inh_check" a | numeric | Check constraints: "test_inh_check_a_check" CHECK (a::double precision > 10.2::double precision) +Number of child tables: 1 (Use \d+ to list them.) \d test_inh_check_child +Table "public.test_inh_check_child" + Column | Type | Modifiers +--------+---------+----------- + a | numeric | +Check constraints: + "test_inh_check_a_check" CHECK (a::double precision > 10.2::double precision) +Inherits: test_inh_check + -- -- lock levels -- @@ -770,7 +791,6 @@ ERROR: cannot alter type "test_type1" because column "test_tbl1.y" uses it CREATE TYPE test_type2 AS (a int, b text); CREATE TABLE test_tbl2 OF test_type2; CREATE TABLE test_tbl2_subclass () INHERITS (test_tbl2); -ERROR: CREATE TABLE ... INHERITS is not yet supported. \d test_type2 Composite type "public.test_type2" Column | Type | Modifiers @@ -784,6 +804,7 @@ Composite type "public.test_type2" --------+---------+----------- a | integer | b | text | +Number of child tables: 1 (Use \d+ to list them.) Typed table of type: test_type2 ALTER TYPE test_type2 ADD ATTRIBUTE c text; -- fails @@ -805,6 +826,7 @@ Composite type "public.test_type2" a | integer | b | text | c | text | +Number of child tables: 1 (Use \d+ to list them.) Typed table of type: test_type2 ALTER TYPE test_type2 ALTER ATTRIBUTE b TYPE varchar; -- fails @@ -826,6 +848,7 @@ ALTER TYPE test_type2 ALTER ATTRIBUTE b TYPE varchar CASCADE; a | integer | b | character varying | c | text | +Number of child tables: 1 (Use \d+ to list them.) Typed table of type: test_type2 ALTER TYPE test_type2 DROP ATTRIBUTE b; -- fails @@ -845,6 +868,7 @@ Composite type "public.test_type2" --------+---------+----------- a | integer | c | text | +Number of child tables: 1 (Use \d+ to list them.) Typed table of type: test_type2 ALTER TYPE test_type2 RENAME ATTRIBUTE a TO aa; -- fails @@ -864,11 +888,18 @@ Composite type "public.test_type2" --------+---------+----------- aa | integer | c | text | +Number of child tables: 1 (Use \d+ to list them.) Typed table of type: test_type2 \d test_tbl2_subclass +Table "public.test_tbl2_subclass" + Column | Type | Modifiers +--------+---------+----------- + aa | integer | + c | text | +Inherits: test_tbl2 + DROP TABLE test_tbl2_subclass; -ERROR: table "test_tbl2_subclass" does not exist -- This test isn't that interesting on its own, but the purpose is to leave -- behind a table to test pg_upgrade with. The table has a composite type -- column in it, and the composite type has a dropped attribute. @@ -889,7 +920,6 @@ CREATE TABLE tt3 (y numeric(8,2), x int); -- wrong column order CREATE TABLE tt4 (x int); -- too few columns CREATE TABLE tt5 (x int, y numeric(8,2), z int); -- too few columns CREATE TABLE tt6 () INHERITS (tt0); -- can't have a parent -ERROR: CREATE TABLE ... INHERITS is not yet supported. CREATE TABLE tt7 (x int, q text, y numeric(8,2)) WITH OIDS; ERROR: CREATE TABLE ... WITH OIDS is not yet supported. ALTER TABLE tt7 DROP q; -- OK @@ -906,7 +936,7 @@ ERROR: table is missing column "y" ALTER TABLE tt5 OF tt_t0; ERROR: table has extra column "z" ALTER TABLE tt6 OF tt_t0; -ERROR: relation "tt6" does not exist +ERROR: typed tables cannot inherit ALTER TABLE tt7 OF tt_t0; ERROR: relation "tt7" does not exist CREATE TYPE tt_t1 AS (x int, y numeric(8,2)); @@ -918,14 +948,13 @@ ERROR: relation "tt7" does not exist -- make sure we can drop a constraint on the parent but it remains on the child CREATE TABLE test_drop_constr_parent (c text CHECK (c IS NOT NULL)); CREATE TABLE test_drop_constr_child () INHERITS (test_drop_constr_parent); -ERROR: CREATE TABLE ... INHERITS is not yet supported. ALTER TABLE ONLY test_drop_constr_parent DROP CONSTRAINT "test_drop_constr_parent_c_check"; -- should fail INSERT INTO test_drop_constr_child (c) VALUES (NULL); -ERROR: relation "test_drop_constr_child" does not exist on datanode1 -LINE 1: INSERT INTO test_drop_constr_child (c) VALUES (NULL); - ^ +ERROR: new row for relation "test_drop_constr_child" violates check constraint "test_drop_constr_parent_c_check" +DETAIL: N/A DROP TABLE test_drop_constr_parent CASCADE; +NOTICE: drop cascades to table test_drop_constr_child -- -- IF EXISTS test -- diff --git a/src/test/regress/expected/dml.out b/src/test/regress/expected/dml.out index 2dfbb33f2..41261b3de 100644 --- a/src/test/regress/expected/dml.out +++ b/src/test/regress/expected/dml.out @@ -746,11 +746,10 @@ explain (verbose on, costs off) insert into pg_description select * from tmp_description; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- - [Bypass] Insert on pg_catalog.pg_description -> Seq Scan on distribute_dml.tmp_description Output: tmp_description.objoid, tmp_description.classoid, tmp_description.objsubid, tmp_description.description -(4 rows) +(3 rows) drop table tmp_description; --data distribute skew functions and view diff --git a/src/test/regress/expected/gpi_create_constraint.out b/src/test/regress/expected/gpi_create_constraint.out index befb7bde8..36d0bb68c 100644 --- a/src/test/regress/expected/gpi_create_constraint.out +++ b/src/test/regress/expected/gpi_create_constraint.out @@ -134,7 +134,8 @@ Partition By RANGE(c1) Number of partitions: 4 (View pg_partition to check each partition range.) create table gpi_table2_inherits (c4 int) INHERITS (gpi_table2); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +ERROR: inherited relation "gpi_table2" is a partitioned table +DETAIL: can not inherit from partitioned table -- error alter table gpi_table2 set (wait_clean_gpi=y); ERROR: Un-support feature diff --git a/src/test/regress/expected/gtt_function.out b/src/test/regress/expected/gtt_function.out index cecceafac..46b405790 100644 --- a/src/test/regress/expected/gtt_function.out +++ b/src/test/regress/expected/gtt_function.out @@ -155,16 +155,17 @@ d date not null )on commit delete rows; -- ERROR create global temp table tbl_inherits_partition() inherits (tbl_inherits_parent); -ERROR: CREATE TABLE ... INHERITS is not yet supported. -- ERROR create global temp table tbl_inherits_partition() inherits (tbl_inherits_parent_global_temp) on commit delete rows; -ERROR: CREATE TABLE ... INHERITS is not yet supported. +ERROR: relation "tbl_inherits_partition" already exists in schema "gtt_function" +DETAIL: creating new table with existing name in the same schema select relname ,relkind, relpersistence, reloptions from pg_class where relname like 'p_table0%' or relname like 'tbl_inherits%' order by relname; - relname | relkind | relpersistence | reloptions ----------------------------------+---------+----------------+------------------------------------------------------------- + relname | relkind | relpersistence | reloptions +---------------------------------+---------+----------------+-------------------------------------------------------------- tbl_inherits_parent | r | p | {orientation=row,compression=no} tbl_inherits_parent_global_temp | r | g | {orientation=row,compression=no,on_commit_delete_rows=true} -(2 rows) + tbl_inherits_partition | r | g | {orientation=row,compression=no,on_commit_delete_rows=false} +(3 rows) -- ERROR create global temp table gtt3(a int primary key, b text) on commit drop; @@ -565,13 +566,14 @@ ERROR: duplicate key value violates unique constraint "gtt_test12_c0_c1_key" DETAIL: Key (c0, c1)=(1, t) already exists. reset search_path; drop schema gtt_function cascade; -NOTICE: drop cascades to 37 other objects +NOTICE: drop cascades to 38 other objects DETAIL: drop cascades to table gtt_function.gtt1 drop cascades to table gtt_function.gtt2 drop cascades to table gtt_function.gtt3 drop cascades to table gtt_function.gtt6 drop cascades to table gtt_function.tbl_inherits_parent drop cascades to table gtt_function.tbl_inherits_parent_global_temp +drop cascades to table gtt_function.tbl_inherits_partition drop cascades to table gtt_function.gtt10 drop cascades to table gtt_function.gtt4 drop cascades to table gtt_function.gtt5 diff --git a/src/test/regress/expected/inherits01.out b/src/test/regress/expected/inherits01.out new file mode 100644 index 000000000..0715ef1a3 --- /dev/null +++ b/src/test/regress/expected/inherits01.out @@ -0,0 +1,4027 @@ +-- inherit +CREATE DATABASE inherit_base; +\c inherit_base; +--analyze +CREATE TABLE dep AS SELECT mod(i,10000) a, + mod(i,10000) b + FROM generate_series(1,100000) s(i); +CREATE TABLE dep_son() inherits(dep); +INSERT INTO dep_son(a,b) SELECT (10000 * random())::int a, + (10000 * random())::int b + FROM generate_series(1,100000) s(i); +analyze; +EXPLAIN ANALYZE SELECT a FROM dep WHERE b < 5000 GROUP BY a; +--?.* +--?.* +--?.* + Group By Key: public.dep.a +--?.* +--?.* + Filter: (b < 5000) + Rows Removed by Filter: 50000 +--?.* + Filter: (b < 5000) +--?.* +--?.* +(10 rows) + +EXPLAIN ANALYZE SELECT a FROM ONLY dep WHERE b < 5000 GROUP BY a; +--?.* +--?.* +--?.* + Group By Key: a +--?.* + Filter: (b < 5000) +--?.* +--?.* +(6 rows) + +drop table dep cascade; +NOTICE: drop cascades to table dep_son +-- iud view +create table grandfather +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "grandfather_pkey" for table "grandfather" +insert into grandfather +(id, grandfather1_name)values +(0,'A0'); +create table father +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather); +insert into father +(id, grandfather1_name, father1_name)values +(1,'A1','B1'), +(2,'A2','B2'); +CREATE VIEW g_v AS select * from grandfather; +CREATE VIEW f_v AS select * from father; +select * from g_v; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A2 | 80 +(3 rows) + +select * from f_v; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A2 | 80 | B2 | 60 +(2 rows) + +insert into f_v +(id, grandfather1_name, father1_name)values +(3,'A3','B3'); +select * from g_v; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A2 | 80 + 3 | A3 | 80 +(4 rows) + +select * from f_v; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A2 | 80 | B2 | 60 + 3 | A3 | 80 | B3 | 60 +(3 rows) + +delete from g_v where id=3; +select * from g_v; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A2 | 80 +(3 rows) + +select * from f_v; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A2 | 80 | B2 | 60 +(2 rows) + +update g_v set grandfather1_name='A9' where id=2; +select * from g_v; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A9 | 80 +(3 rows) + +select * from f_v; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A9 | 80 | B2 | 60 +(2 rows) + +DROP VIEW g_v; +DROP VIEW f_v; +DROP TABLE grandfather CASCADE; +NOTICE: drop cascades to table father +-- column +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +) WITH (ORIENTATION = COLUMN); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "grandfather1_pkey" for table "grandfather1" +insert into grandfather1 +(id, grandfather1_name)values +(0,'A0'); +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1) WITH (ORIENTATION = COLUMN);-- error +ERROR: Unsupport feature +DETAIL: cstore/timeseries don't support relation defination with inheritance. +DROP TABLE grandfather1 CASCADE; +-- normal table inherit temporary +create temporary table tmp1(col1 int, col2 int); +create table normal(col3 int)inherits(tmp1);-- error +ERROR: cannot inherit from temporary relation "tmp1" +drop table tmp1; +-- temporary table inherit normal +create table normal(col1 int); +create temporary table tmp1(col1 int, col2 int)inherits(normal); +NOTICE: merging column "col1" with inherited definition +create temporary table tmp2(col0 int)inherits(tmp1); +create temporary table tmp3()inherits(normal, tmp1); +NOTICE: merging multiple inherited definitions of column "col1" +\d tmp1 +--?.* + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + col2 | integer | +Inherits: normal +Number of child tables: 2 (Use \d+ to list them.) + +\d normal + Table "public.normal" + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | +Number of child tables: 2 (Use \d+ to list them.) + +alter table normal add column sex Boolean; +NOTICE: merging definition of column "sex" for child "tmp3" +\d tmp1 +--?.* + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + col2 | integer | + sex | boolean | +Inherits: normal +Number of child tables: 2 (Use \d+ to list them.) + +\d normal + Table "public.normal" + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + sex | boolean | +Number of child tables: 2 (Use \d+ to list them.) + +alter table tmp2 add constraint test_pkey primary key(col0); +NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "test_pkey" for table "tmp2" +\d tmp2 +--?.* + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + col2 | integer | + col0 | integer | not null + sex | boolean | +Indexes: + "test_pkey" PRIMARY KEY, btree (col0) TABLESPACE pg_default +Inherits: tmp1 + +\d normal + Table "public.normal" + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + sex | boolean | +Number of child tables: 2 (Use \d+ to list them.) + +alter table normal add constraint test2_pkey primary key(col1); +NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "test2_pkey" for table "normal" +\d tmp1 +--?.* + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + col2 | integer | + sex | boolean | +Inherits: normal +Number of child tables: 2 (Use \d+ to list them.) + +\d tmp2 +--?.* + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | + col2 | integer | + col0 | integer | not null + sex | boolean | +Indexes: + "test_pkey" PRIMARY KEY, btree (col0) TABLESPACE pg_default +Inherits: tmp1 + +\d normal + Table "public.normal" + Column | Type | Modifiers +--------+---------+----------- + col1 | integer | not null + sex | boolean | +Indexes: + "test2_pkey" PRIMARY KEY, btree (col1) TABLESPACE pg_default +Number of child tables: 2 (Use \d+ to list them.) + +drop table tmp3; +drop table tmp2; +drop table tmp1; +drop table normal; +-- partition +CREATE TABLE plt_father1 +( id int not null, + primary key(id) +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "plt_father1_pkey" for table "plt_father1" +CREATE TABLE plt( + id serial primary key, + col1 varchar(8)) inherits(plt_father1) + partition by range(id) + ( + partition p1 values less than(10), + partition p2 values less than(20), + partition p3 values less than(30), + partition p4 values less than(maxvalue) + );-- error +NOTICE: CREATE TABLE will create implicit sequence "plt_id_seq" for serial column "plt.id" +ERROR: unsupport inherits clause for partitioned table +DROP TABLE plt_father1 CASCADE; +CREATE TABLE plt( + id serial primary key, + col1 varchar(8)) + partition by range(id) + ( + partition p1 values less than(10), + partition p2 values less than(20), + partition p3 values less than(30), + partition p4 values less than(maxvalue) + ); +NOTICE: CREATE TABLE will create implicit sequence "plt_id_seq" for serial column "plt.id" +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "plt_pkey" for table "plt" +CREATE TABLE plt_son +( id int not null, + primary key(id) +) inherits(plt);-- error +ERROR: inherited relation "plt" is a partitioned table +DETAIL: can not inherit from partitioned table +DROP TABLE plt CASCADE; +-- origin +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "grandfather1_pkey" for table "grandfather1" +INSERT INTO grandfather1 +(id, grandfather1_name) VALUES +(0,'A0'); +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1); +INSERT INTO father1 +(id, grandfather1_name, father1_name) VALUES +(1,'A1','B1'), +(2,'A2','B2'); +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A2 | 80 +(3 rows) + +SELECT * FROM father1; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A2 | 80 | B2 | 60 +(2 rows) + +DELETE FROM grandfather1 WHERE ID=2; +SELECT * FROM father1; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 +(1 row) + +UPDATE grandfather1 SET grandfather1_name='A100' WHERE ID=0; +UPDATE grandfather1 SET father1_name='B100' WHERE ID=0;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B100' WHERE ID=0; + ^ +UPDATE grandfather1 SET grandfather1_name='A99' WHERE ID=1; +UPDATE grandfather1 SET father1_name='B99' WHERE ID=1;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B99' WHERE ID=1; + ^ +UPDATE father1 SET father1_name='B99' WHERE ID=1; +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 +(2 rows) + +CREATE TABLE son1 +( son1_name varchar(64), + s_age int DEFAULT 30 +)inherits(father1); +INSERT INTO son1 +(id, grandfather1_name, father1_name, son1_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A3 | 80 + 4 | A4 | 80 +(4 rows) + +SELECT * FROM son1; + id | grandfather1_name | g_age | father1_name | f_age | son1_name | s_age +----+-------------------+-------+--------------+-------+-----------+------- + 3 | A3 | 80 | B3 | 60 | C3 | 30 + 4 | A4 | 80 | B4 | 60 | C4 | 30 +(2 rows) + +DELETE FROM grandfather1 WHERE ID=4; +SELECT * FROM son1; + id | grandfather1_name | g_age | father1_name | f_age | son1_name | s_age +----+-------------------+-------+--------------+-------+-----------+------- + 3 | A3 | 80 | B3 | 60 | C3 | 30 +(1 row) + +UPDATE grandfather1 SET grandfather1_name='A300' WHERE ID=3; +UPDATE grandfather1 SET father1_name='B300' WHERE ID=3;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B300' WHERE ID=3; + ^ +UPDATE grandfather1 SET son1_name='C300' WHERE ID=3;-- error +ERROR: column "son1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET son1_name='C300' WHERE ID=3; + ^ +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +ALTER TABLE grandfather1 RENAME TO grandfather0; +ALTER TABLE grandfather0 DROP COLUMN s_age CASCADE;-- error +ERROR: column "s_age" of relation "grandfather0" does not exist +ALTER TABLE grandfather0 rename COLUMN f_age TO father_age;-- error +ERROR: column "f_age" does not exist +ALTER TABLE grandfather0 rename COLUMN g_age TO grandfather_age; +SELECT * FROM son1; + id | grandfather1_name | grandfather_age | father1_name | f_age | son1_name | s_age +----+-------------------+-----------------+--------------+-------+-----------+------- + 3 | A300 | 80 | B3 | 60 | C3 | 30 +(1 row) + +SELECT * FROM grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +ALTER TABLE ONLY grandfather0 rename COLUMN grandfather_age TO grand_age;-- error +ERROR: inherited column "grandfather_age" must be renamed in child tables too +SELECT * FROM son1; + id | grandfather1_name | grandfather_age | father1_name | f_age | son1_name | s_age +----+-------------------+-----------------+--------------+-------+-----------+------- + 3 | A300 | 80 | B3 | 60 | C3 | 30 +(1 row) + +SELECT * FROM grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +SELECT * FROM only grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 +(1 row) + +DROP TABLE grandfather0 cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table father1 +drop cascades to table son1 +CREATE TABLE father2 +( id int not null, + father2_name varchar(64), + f2_age int DEFAULT 60 +); +CREATE TABLE father3 +( id int not null, + father3_name varchar(64), + f3_age int DEFAULT 60 +); +CREATE TABLE son2 +( son2_name varchar(64), + s_age int DEFAULT 30 +)inherits(father2,father3); +NOTICE: merging multiple inherited definitions of column "id" +INSERT INTO son2 +(id, father2_name, father3_name, son2_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM son2; + id | father2_name | f2_age | father3_name | f3_age | son2_name | s_age +----+--------------+--------+--------------+--------+-----------+------- + 3 | A3 | 60 | B3 | 60 | C3 | 30 + 4 | A4 | 60 | B4 | 60 | C4 | 30 +(2 rows) + +SELECT * FROM father2; + id | father2_name | f2_age +----+--------------+-------- + 3 | A3 | 60 + 4 | A4 | 60 +(2 rows) + +SELECT * FROM father3; + id | father3_name | f3_age +----+--------------+-------- + 3 | B3 | 60 + 4 | B4 | 60 +(2 rows) + +ALTER TABLE father2 DROP COLUMN id CASCADE; +SELECT * FROM son2; + id | father2_name | f2_age | father3_name | f3_age | son2_name | s_age +----+--------------+--------+--------------+--------+-----------+------- + 3 | A3 | 60 | B3 | 60 | C3 | 30 + 4 | A4 | 60 | B4 | 60 | C4 | 30 +(2 rows) + +SELECT * FROM father2; + father2_name | f2_age +--------------+-------- + A3 | 60 + A4 | 60 +(2 rows) + +SELECT * FROM father3; + id | father3_name | f3_age +----+--------------+-------- + 3 | B3 | 60 + 4 | B4 | 60 +(2 rows) + +DELETE FROM father3 WHERE son2_name='C4';-- error +ERROR: column "son2_name" does not exist +LINE 1: DELETE FROM father3 WHERE son2_name='C4'; + ^ +DELETE FROM father3 WHERE id=3; +SELECT * FROM father2; + father2_name | f2_age +--------------+-------- + A4 | 60 +(1 row) + +DROP TABLE IF EXISTS son2 cascade; +DROP TABLE IF EXISTS father2 cascade; +DROP TABLE IF EXISTS father3 cascade; +SET enable_indexonlyscan = off; +CREATE TABLE events (event_id int primary key); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "events_pkey" for table "events" +CREATE TABLE other_events (event_id int primary key); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "other_events_pkey" for table "other_events" +CREATE TABLE events_child1 () inherits (events); +INSERT INTO events_child1 (event_id) VALUES (5); +INSERT INTO events_child1 (event_id) VALUES (1); +INSERT INTO events (event_id) VALUES (2); +INSERT INTO other_events(event_id) VALUES (3); +-- order by +SELECT event_id + FROM (SELECT event_id FROM events + union all + SELECT event_id FROM other_events) ss + order by event_id; + event_id +---------- + 1 + 2 + 3 + 5 +(4 rows) + +DROP TABLE events_child1, events, other_events; +RESET enable_indexonlyscan; +-- inherit multi tables +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father_z82rgvsefn PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father_z82rgvsefn" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2_z82rgvsefn PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2_z82rgvsefn" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3_z82rgvsefn PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3_z82rgvsefn" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2022() inherits(father,father2,father3); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021(like father2 including all) inherits(father,father2,father3); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "kid_2021_pkey" for table "kid_2021" +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "kid_2021_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +DROP TABLE father CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table kid_2022 +drop cascades to table kid_2021 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +-- like father and including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2020() inherits(father,father2,father3); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021(like father) inherits(father); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +CREATE TABLE kid_2022(like father including all) inherits(father); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +NOTICE: merging constraint "father_salary_check" with inherited definition +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "kid_2022_pkey" for table "kid_2022" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "kid_2022_md_attr_key" for table "kid_2022" +CREATE TABLE kid_2023(like father) inherits(father); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "kid_2022_pkey" PRIMARY KEY, btree (id) TABLESPACE pg_default + "kid_2022_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; + count +------- + 7 +(1 row) + +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | + 502 | 31 | 2 | 2 | + 504 | 20 | 3 | 2 | + 505 | 22 | 1 | 2 | + 503 | 52 | 2 | 2 | + 506 | 23 | 1 | 2 | + 507 | 23 | 2 | 2 | +(7 rows) + +SELECT id, md_attr FROM father* WHERE id>500; + id | md_attr +-----+--------- + 501 | 21 + 502 | 31 + 504 | 20 + 505 | 22 + 503 | 52 + 506 | 23 + 507 | 23 +(7 rows) + +update father SET salary =90; +SELECT * FROM kid_2021; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | 90 + 502 | 31 | 2 | 2 | 90 + 504 | 20 | 3 | 2 | 90 +(3 rows) + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ERROR: cannot drop inherited constraint "father_salary_check" of relation "kid_2022" +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +ERROR: cannot rename inherited constraint "father_salary_check" +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ERROR: cannot alter inherited column "md_attr" +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ERROR: cannot rename inherited column "num" +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk; +ALTER TABLE father RENAME COlUMN md_attr TO new; +ERROR: cannot rename inherited column "md_attr" +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "new_constraint_namepk" PRIMARY KEY, btree (id) TABLESPACE pg_default + "kid_2022_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +ERROR: column "new" of relation "kid_2020" does not exist +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child have num +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2023 no inherit father; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "new_constraint_namepk" PRIMARY KEY, btree (id) TABLESPACE pg_default + "kid_2022_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE father ALTER COLUMN id TYPE int; +ERROR: syntax error at or near "ALTER" +LINE 2: ALTER TABLE father ALTER COLUMN id TYPE int; + ^ +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "new_constraint_namepk" PRIMARY KEY, btree (id) TABLESPACE pg_default + "kid_2022_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk"; +DROP TABLE father CASCADE; +NOTICE: drop cascades to 3 other objects +DETAIL: drop cascades to table kid_2020 +drop cascades to table kid_2021 +drop cascades to table kid_2022 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +DROP TABLESPACE example1; +-- not like father not including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2020() inherits(father,father2,father3); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021() inherits(father); +CREATE TABLE kid_2022() inherits(father); +CREATE TABLE kid_2023() inherits(father); +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; + count +------- + 7 +(1 row) + +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | + 502 | 31 | 2 | 2 | + 504 | 20 | 3 | 2 | + 505 | 22 | 1 | 2 | + 503 | 52 | 2 | 2 | + 506 | 23 | 1 | 2 | + 507 | 23 | 2 | 2 | +(7 rows) + +SELECT id, md_attr FROM father* WHERE id>500; + id | md_attr +-----+--------- + 501 | 21 + 502 | 31 + 504 | 20 + 505 | 22 + 503 | 52 + 506 | 23 + 507 | 23 +(7 rows) + +update father SET salary =90; +SELECT * FROM kid_2021; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | 90 + 502 | 31 | 2 | 2 | 90 + 504 | 20 | 3 | 2 | 90 +(3 rows) + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ERROR: cannot drop inherited constraint "father_salary_check" of relation "kid_2022" +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +ERROR: cannot rename inherited constraint "father_salary_check" +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ERROR: cannot alter inherited column "md_attr" +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ERROR: cannot rename inherited column "num" +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk;-- error +ERROR: constraint "kid_2022_pkey" for table "kid_2022" does not exist +ALTER TABLE father RENAME COlUMN md_attr TO new; +ERROR: cannot rename inherited column "md_attr" +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +ERROR: column "new" of relation "kid_2020" does not exist +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child without num +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2023 no inherit father; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE father ALTER COLUMN id TYPE int; +ERROR: syntax error at or near "ALTER" +LINE 2: ALTER TABLE father ALTER COLUMN id TYPE int; + ^ +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error +ERROR: constraint "new_constraint_namepk" of relation "kid_2022" does not exist +DROP TABLE father CASCADE; +NOTICE: drop cascades to 3 other objects +DETAIL: drop cascades to table kid_2020 +drop cascades to table kid_2021 +drop cascades to table kid_2022 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +DROP TABLESPACE example1; +\c regression +DROP DATABASE inherit_base; +-- ustore +CREATE DATABASE inherit_ustore; +\c inherit_ustore; +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "grandfather1_pkey" for table "grandfather1" +INSERT INTO grandfather1 +(id, grandfather1_name) VALUES +(0,'A0'); +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1) WITH (storage_type=ustore); +INSERT INTO father1 +(id, grandfather1_name, father1_name) VALUES +(1,'A1','B1'), +(2,'A2','B2'); +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A2 | 80 +(3 rows) + +SELECT * FROM father1; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A2 | 80 | B2 | 60 +(2 rows) + +DELETE FROM grandfather1 WHERE ID=2; +SELECT * FROM father1; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 +(1 row) + +UPDATE grandfather1 SET grandfather1_name='A100' WHERE ID=0; +UPDATE grandfather1 SET father1_name='B100' WHERE ID=0;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B100' WHERE ID=0; + ^ +UPDATE grandfather1 SET grandfather1_name='A99' WHERE ID=1; +UPDATE grandfather1 SET father1_name='B99' WHERE ID=1;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B99' WHERE ID=1; + ^ +UPDATE father1 SET father1_name='B99' WHERE ID=1; +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 +(2 rows) + +CREATE TABLE son1 +( son1_name varchar(64), + s_age int DEFAULT 30 +)inherits(father1) WITH (storage_type=ustore); +INSERT INTO son1 +(id, grandfather1_name, father1_name, son1_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A3 | 80 + 4 | A4 | 80 +(4 rows) + +SELECT * FROM son1; + id | grandfather1_name | g_age | father1_name | f_age | son1_name | s_age +----+-------------------+-------+--------------+-------+-----------+------- + 3 | A3 | 80 | B3 | 60 | C3 | 30 + 4 | A4 | 80 | B4 | 60 | C4 | 30 +(2 rows) + +DELETE FROM grandfather1 WHERE ID=4; +SELECT * FROM son1; + id | grandfather1_name | g_age | father1_name | f_age | son1_name | s_age +----+-------------------+-------+--------------+-------+-----------+------- + 3 | A3 | 80 | B3 | 60 | C3 | 30 +(1 row) + +UPDATE grandfather1 SET grandfather1_name='A300' WHERE ID=3; +UPDATE grandfather1 SET father1_name='B300' WHERE ID=3;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B300' WHERE ID=3; + ^ +UPDATE grandfather1 SET son1_name='C300' WHERE ID=3;-- error +ERROR: column "son1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET son1_name='C300' WHERE ID=3; + ^ +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +ALTER TABLE grandfather1 RENAME TO grandfather0; +ALTER TABLE grandfather0 DROP COLUMN s_age CASCADE;-- error +ERROR: column "s_age" of relation "grandfather0" does not exist +ALTER TABLE grandfather0 rename COLUMN f_age TO father_age;-- error +ERROR: column "f_age" does not exist +ALTER TABLE grandfather0 rename COLUMN g_age TO grandfather_age; +SELECT * FROM son1; + id | grandfather1_name | grandfather_age | father1_name | f_age | son1_name | s_age +----+-------------------+-----------------+--------------+-------+-----------+------- + 3 | A300 | 80 | B3 | 60 | C3 | 30 +(1 row) + +SELECT * FROM grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +ALTER TABLE ONLY grandfather0 rename COLUMN grandfather_age TO grand_age;-- error +ERROR: inherited column "grandfather_age" must be renamed in child tables too +SELECT * FROM son1; + id | grandfather1_name | grandfather_age | father1_name | f_age | son1_name | s_age +----+-------------------+-----------------+--------------+-------+-----------+------- + 3 | A300 | 80 | B3 | 60 | C3 | 30 +(1 row) + +SELECT * FROM grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +SELECT * FROM only grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 +(1 row) + +DROP TABLE grandfather0 cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table father1 +drop cascades to table son1 +CREATE TABLE father2 +( id int not null, + father2_name varchar(64), + f2_age int DEFAULT 60 +) WITH (storage_type=ustore); +CREATE TABLE father3 +( id int not null, + father3_name varchar(64), + f3_age int DEFAULT 60 +) WITH (storage_type=ustore); +CREATE TABLE son2 +( son2_name varchar(64), + s_age int DEFAULT 30 +)inherits(father2,father3) WITH (storage_type=ustore); +NOTICE: merging multiple inherited definitions of column "id" +INSERT INTO son2 +(id, father2_name, father3_name, son2_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM son2; + id | father2_name | f2_age | father3_name | f3_age | son2_name | s_age +----+--------------+--------+--------------+--------+-----------+------- + 3 | A3 | 60 | B3 | 60 | C3 | 30 + 4 | A4 | 60 | B4 | 60 | C4 | 30 +(2 rows) + +SELECT * FROM father2; + id | father2_name | f2_age +----+--------------+-------- + 3 | A3 | 60 + 4 | A4 | 60 +(2 rows) + +SELECT * FROM father3; + id | father3_name | f3_age +----+--------------+-------- + 3 | B3 | 60 + 4 | B4 | 60 +(2 rows) + +ALTER TABLE father2 DROP COLUMN id CASCADE; +SELECT * FROM son2; + id | father2_name | f2_age | father3_name | f3_age | son2_name | s_age +----+--------------+--------+--------------+--------+-----------+------- + 3 | A3 | 60 | B3 | 60 | C3 | 30 + 4 | A4 | 60 | B4 | 60 | C4 | 30 +(2 rows) + +SELECT * FROM father2; + father2_name | f2_age +--------------+-------- + A3 | 60 + A4 | 60 +(2 rows) + +SELECT * FROM father3; + id | father3_name | f3_age +----+--------------+-------- + 3 | B3 | 60 + 4 | B4 | 60 +(2 rows) + +DELETE FROM father3 WHERE son2_name='C4';-- error +ERROR: column "son2_name" does not exist +LINE 1: DELETE FROM father3 WHERE son2_name='C4'; + ^ +DELETE FROM father3 WHERE id=3; +SELECT * FROM father2; + father2_name | f2_age +--------------+-------- + A4 | 60 +(1 row) + +DROP TABLE IF EXISTS son2 cascade; +DROP TABLE IF EXISTS father2 cascade; +DROP TABLE IF EXISTS father3 cascade; +SET enable_indexonlyscan = off; +CREATE TABLE events (event_id int primary key); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "events_pkey" for table "events" +CREATE TABLE other_events (event_id int primary key); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "other_events_pkey" for table "other_events" +CREATE TABLE events_child1 () inherits (events); +INSERT INTO events_child1 (event_id) VALUES (5); +INSERT INTO events_child1 (event_id) VALUES (1); +INSERT INTO events (event_id) VALUES (2); +INSERT INTO other_events(event_id) VALUES (3); +-- order by +SELECT event_id + FROM (SELECT event_id FROM events + union all + SELECT event_id FROM other_events) ss + order by event_id; + event_id +---------- + 1 + 2 + 3 + 5 +(4 rows) + +DROP TABLE events_child1, events, other_events; +RESET enable_indexonlyscan; +-- inherit multi tables +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (storage_type=ustore); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father_z82rgvsefn PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father_z82rgvsefn" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2_z82rgvsefn PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2_z82rgvsefn" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3_z82rgvsefn PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3_z82rgvsefn" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2022() inherits(father,father2,father3) WITH (storage_type=ustore); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021(like father2 including all) inherits(father,father2,father3) WITH (storage_type=ustore);-- error +ERROR: unsupport "like clause including reloptions" together with "with" +DETAIL: use either "like clause including reloptions" or "with" clause +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +\d kid_2021 +DROP TABLE father CASCADE; +NOTICE: drop cascades to table kid_2022 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +-- ustore like father and including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (storage_type=ustore); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (storage_type=ustore); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021(like father) inherits(father) WITH (storage_type=ustore); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +CREATE TABLE kid_2022(like father including all) inherits(father) WITH (storage_type=ustore);-- error +ERROR: unsupport "like clause including reloptions" together with "with" +DETAIL: use either "like clause including reloptions" or "with" clause +CREATE TABLE kid_2023(like father) inherits(father) WITH (storage_type=ustore); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2);-- error +ERROR: relation "kid_2022" does not exist on datanode1 +LINE 1: INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); + ^ +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | + 502 | 31 | 2 | 2 | + 504 | 20 | 3 | 2 | + 506 | 23 | 1 | 2 | + 507 | 23 | 2 | 2 | +(5 rows) + +SELECT id, md_attr FROM father* WHERE id>500; + id | md_attr +-----+--------- + 501 | 21 + 502 | 31 + 504 | 20 + 506 | 23 + 507 | 23 +(5 rows) + +update father SET salary =90; +SELECT * FROM kid_2021; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | 90 + 502 | 31 | 2 | 2 | 90 + 504 | 20 | 3 | 2 | 90 +(3 rows) + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ERROR: relation "kid_2022" does not exist +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +ERROR: relation "kid_2022" does not exist +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ERROR: cannot alter inherited column "md_attr" +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ERROR: cannot rename inherited column "num" +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk; +ERROR: relation "kid_2022" does not exist +ALTER TABLE father RENAME COlUMN md_attr TO new; +ERROR: cannot rename inherited column "md_attr" +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +ERROR: column "new" of relation "kid_2020" does not exist +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child have num +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2023 no inherit father; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 2 (Use \d+ to list them.) + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 2 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE father ALTER COLUMN id TYPE int; +ERROR: syntax error at or near "ALTER" +LINE 2: ALTER TABLE father ALTER COLUMN id TYPE int; + ^ +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 2 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error +ERROR: relation "kid_2022" does not exist +DROP TABLE father CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table kid_2020 +drop cascades to table kid_2021 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +DROP TABLESPACE example1; +-- ustore not like father not including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (storage_type=ustore); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (storage_type=ustore); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021() inherits(father) WITH (storage_type=ustore); +CREATE TABLE kid_2022() inherits(father) WITH (storage_type=ustore); +CREATE TABLE kid_2023() inherits(father) WITH (storage_type=ustore); +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; + count +------- + 7 +(1 row) + +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | + 502 | 31 | 2 | 2 | + 504 | 20 | 3 | 2 | + 505 | 22 | 1 | 2 | + 503 | 52 | 2 | 2 | + 506 | 23 | 1 | 2 | + 507 | 23 | 2 | 2 | +(7 rows) + +SELECT id, md_attr FROM father* WHERE id>500; + id | md_attr +-----+--------- + 501 | 21 + 502 | 31 + 504 | 20 + 505 | 22 + 503 | 52 + 506 | 23 + 507 | 23 +(7 rows) + +update father SET salary =90; +SELECT * FROM kid_2021; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | 90 + 502 | 31 | 2 | 2 | 90 + 504 | 20 | 3 | 2 | 90 +(3 rows) + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ERROR: cannot drop inherited constraint "father_salary_check" of relation "kid_2022" +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +ERROR: cannot rename inherited constraint "father_salary_check" +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ERROR: cannot alter inherited column "md_attr" +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ERROR: cannot rename inherited column "num" +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk;-- error +ERROR: constraint "kid_2022_pkey" for table "kid_2022" does not exist +ALTER TABLE father RENAME COlUMN md_attr TO new; +ERROR: cannot rename inherited column "md_attr" +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +ERROR: column "new" of relation "kid_2020" does not exist +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child without num +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2023 no inherit father; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE father ALTER COLUMN id TYPE int; +ERROR: syntax error at or near "ALTER" +LINE 2: ALTER TABLE father ALTER COLUMN id TYPE int; + ^ +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, ubtree (id) WITH (storage_type=USTORE) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, ubtree (md_attr) WITH (storage_type=USTORE) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error +ERROR: constraint "new_constraint_namepk" of relation "kid_2022" does not exist +DROP TABLE father CASCADE; +NOTICE: drop cascades to 3 other objects +DETAIL: drop cascades to table kid_2020 +drop cascades to table kid_2021 +drop cascades to table kid_2022 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +DROP TABLESPACE example1; +\c regression +DROP DATABASE inherit_ustore; +-- segment +CREATE DATABASE inherit_segment; +\c inherit_segment; +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "grandfather1_pkey" for table "grandfather1" +INSERT INTO grandfather1 +(id, grandfather1_name) VALUES +(0,'A0'); +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1) WITH (segment=on); +INSERT INTO father1 +(id, grandfather1_name, father1_name) VALUES +(1,'A1','B1'), +(2,'A2','B2'); +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A0 | 80 + 1 | A1 | 80 + 2 | A2 | 80 +(3 rows) + +SELECT * FROM father1; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 + 2 | A2 | 80 | B2 | 60 +(2 rows) + +DELETE FROM grandfather1 WHERE ID=2; +SELECT * FROM father1; + id | grandfather1_name | g_age | father1_name | f_age +----+-------------------+-------+--------------+------- + 1 | A1 | 80 | B1 | 60 +(1 row) + +UPDATE grandfather1 SET grandfather1_name='A100' WHERE ID=0; +UPDATE grandfather1 SET father1_name='B100' WHERE ID=0;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B100' WHERE ID=0; + ^ +UPDATE grandfather1 SET grandfather1_name='A99' WHERE ID=1; +UPDATE grandfather1 SET father1_name='B99' WHERE ID=1;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B99' WHERE ID=1; + ^ +UPDATE father1 SET father1_name='B99' WHERE ID=1; +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 +(2 rows) + +CREATE TABLE son1 +( son1_name varchar(64), + s_age int DEFAULT 30 +)inherits(father1) WITH (segment=on); +INSERT INTO son1 +(id, grandfather1_name, father1_name, son1_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A3 | 80 + 4 | A4 | 80 +(4 rows) + +SELECT * FROM son1; + id | grandfather1_name | g_age | father1_name | f_age | son1_name | s_age +----+-------------------+-------+--------------+-------+-----------+------- + 3 | A3 | 80 | B3 | 60 | C3 | 30 + 4 | A4 | 80 | B4 | 60 | C4 | 30 +(2 rows) + +DELETE FROM grandfather1 WHERE ID=4; +SELECT * FROM son1; + id | grandfather1_name | g_age | father1_name | f_age | son1_name | s_age +----+-------------------+-------+--------------+-------+-----------+------- + 3 | A3 | 80 | B3 | 60 | C3 | 30 +(1 row) + +UPDATE grandfather1 SET grandfather1_name='A300' WHERE ID=3; +UPDATE grandfather1 SET father1_name='B300' WHERE ID=3;-- error +ERROR: column "father1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET father1_name='B300' WHERE ID=3; + ^ +UPDATE grandfather1 SET son1_name='C300' WHERE ID=3;-- error +ERROR: column "son1_name" of relation "grandfather1" does not exist +LINE 1: UPDATE grandfather1 SET son1_name='C300' WHERE ID=3; + ^ +SELECT * FROM grandfather1; + id | grandfather1_name | g_age +----+-------------------+------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +ALTER TABLE grandfather1 RENAME TO grandfather0; +ALTER TABLE grandfather0 DROP COLUMN s_age CASCADE;-- error +ERROR: column "s_age" of relation "grandfather0" does not exist +ALTER TABLE grandfather0 rename COLUMN f_age TO father_age;-- error +ERROR: column "f_age" does not exist +ALTER TABLE grandfather0 rename COLUMN g_age TO grandfather_age; +SELECT * FROM son1; + id | grandfather1_name | grandfather_age | father1_name | f_age | son1_name | s_age +----+-------------------+-----------------+--------------+-------+-----------+------- + 3 | A300 | 80 | B3 | 60 | C3 | 30 +(1 row) + +SELECT * FROM grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +ALTER TABLE ONLY grandfather0 rename COLUMN grandfather_age TO grand_age;-- error +ERROR: inherited column "grandfather_age" must be renamed in child tables too +SELECT * FROM son1; + id | grandfather1_name | grandfather_age | father1_name | f_age | son1_name | s_age +----+-------------------+-----------------+--------------+-------+-----------+------- + 3 | A300 | 80 | B3 | 60 | C3 | 30 +(1 row) + +SELECT * FROM grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 + 1 | A99 | 80 + 3 | A300 | 80 +(3 rows) + +SELECT * FROM only grandfather0; + id | grandfather1_name | grandfather_age +----+-------------------+----------------- + 0 | A100 | 80 +(1 row) + +DROP TABLE grandfather0 cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table father1 +drop cascades to table son1 +CREATE TABLE father2 +( id int not null, + father2_name varchar(64), + f2_age int DEFAULT 60 +) WITH (segment=on); +CREATE TABLE father3 +( id int not null, + father3_name varchar(64), + f3_age int DEFAULT 60 +) WITH (segment=on); +CREATE TABLE son2 +( son2_name varchar(64), + s_age int DEFAULT 30 +)inherits(father2,father3) WITH (segment=on); +NOTICE: merging multiple inherited definitions of column "id" +INSERT INTO son2 +(id, father2_name, father3_name, son2_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM son2; + id | father2_name | f2_age | father3_name | f3_age | son2_name | s_age +----+--------------+--------+--------------+--------+-----------+------- + 3 | A3 | 60 | B3 | 60 | C3 | 30 + 4 | A4 | 60 | B4 | 60 | C4 | 30 +(2 rows) + +SELECT * FROM father2; + id | father2_name | f2_age +----+--------------+-------- + 3 | A3 | 60 + 4 | A4 | 60 +(2 rows) + +SELECT * FROM father3; + id | father3_name | f3_age +----+--------------+-------- + 3 | B3 | 60 + 4 | B4 | 60 +(2 rows) + +ALTER TABLE father2 DROP COLUMN id CASCADE; +SELECT * FROM son2; + id | father2_name | f2_age | father3_name | f3_age | son2_name | s_age +----+--------------+--------+--------------+--------+-----------+------- + 3 | A3 | 60 | B3 | 60 | C3 | 30 + 4 | A4 | 60 | B4 | 60 | C4 | 30 +(2 rows) + +SELECT * FROM father2; + father2_name | f2_age +--------------+-------- + A3 | 60 + A4 | 60 +(2 rows) + +SELECT * FROM father3; + id | father3_name | f3_age +----+--------------+-------- + 3 | B3 | 60 + 4 | B4 | 60 +(2 rows) + +DELETE FROM father3 WHERE son2_name='C4';-- error +ERROR: column "son2_name" does not exist +LINE 1: DELETE FROM father3 WHERE son2_name='C4'; + ^ +DELETE FROM father3 WHERE id=3; +SELECT * FROM father2; + father2_name | f2_age +--------------+-------- + A4 | 60 +(1 row) + +DROP TABLE IF EXISTS son2 cascade; +DROP TABLE IF EXISTS father2 cascade; +DROP TABLE IF EXISTS father3 cascade; +SET enable_indexonlyscan = off; +CREATE TABLE events (event_id int primary key) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "events_pkey" for table "events" +CREATE TABLE other_events (event_id int primary key) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "other_events_pkey" for table "other_events" +CREATE TABLE events_child1 () inherits (events) WITH (segment=on); +INSERT INTO events_child1 (event_id) VALUES (5); +INSERT INTO events_child1 (event_id) VALUES (1); +INSERT INTO events (event_id) VALUES (2); +INSERT INTO other_events(event_id) VALUES (3); +-- order by +SELECT event_id + FROM (SELECT event_id FROM events + union all + SELECT event_id FROM other_events) ss + order by event_id; + event_id +---------- + 1 + 2 + 3 + 5 +(4 rows) + +DROP TABLE events_child1, events, other_events; +RESET enable_indexonlyscan; +-- inherit multi tables +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (segment=on); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father_z82rgvsefn PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father_z82rgvsefn" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2_z82rgvsefn PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2_z82rgvsefn" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3_z82rgvsefn PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3_z82rgvsefn" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2022() inherits(father,father2,father3) WITH (segment=on); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021(like father2 including all) inherits(father,father2,father3) WITH (segment=on);-- error +ERROR: unsupport "like clause including reloptions" together with "with" +DETAIL: use either "like clause including reloptions" or "with" clause +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +\d kid_2021 +DROP TABLE father CASCADE; +NOTICE: drop cascades to table kid_2022 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +-- segment like father and including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (segment=on); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (segment=on); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021(like father) inherits(father) WITH (segment=on); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +CREATE TABLE kid_2022(like father including all) inherits(father) WITH (segment=on);-- error +ERROR: unsupport "like clause including reloptions" together with "with" +DETAIL: use either "like clause including reloptions" or "with" clause +CREATE TABLE kid_2023(like father) inherits(father) WITH (segment=on); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "md_attr" with inherited definition +NOTICE: merging column "wai_id" with inherited definition +NOTICE: merging column "num" with inherited definition +NOTICE: merging column "salary" with inherited definition +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2);-- error +ERROR: relation "kid_2022" does not exist on datanode1 +LINE 1: INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); + ^ +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | + 502 | 31 | 2 | 2 | + 504 | 20 | 3 | 2 | + 506 | 23 | 1 | 2 | + 507 | 23 | 2 | 2 | +(5 rows) + +SELECT id, md_attr FROM father* WHERE id>500; + id | md_attr +-----+--------- + 501 | 21 + 502 | 31 + 504 | 20 + 506 | 23 + 507 | 23 +(5 rows) + +update father SET salary =90; +SELECT * FROM kid_2021; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | 90 + 502 | 31 | 2 | 2 | 90 + 504 | 20 | 3 | 2 | 90 +(3 rows) + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ERROR: relation "kid_2022" does not exist +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +ERROR: relation "kid_2022" does not exist +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ERROR: cannot alter inherited column "md_attr" +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ERROR: cannot rename inherited column "num" +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk; +ERROR: relation "kid_2022" does not exist +ALTER TABLE father RENAME COlUMN md_attr TO new; +ERROR: cannot rename inherited column "md_attr" +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +ERROR: column "new" of relation "kid_2020" does not exist +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child have num +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2023 no inherit father; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 2 (Use \d+ to list them.) + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 2 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE father ALTER COLUMN id TYPE int; +ERROR: syntax error at or near "ALTER" +LINE 2: ALTER TABLE father ALTER COLUMN id TYPE int; + ^ +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 2 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error +ERROR: relation "kid_2022" does not exist +DROP TABLE father CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table kid_2020 +drop cascades to table kid_2021 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +DROP TABLESPACE example1; +-- segment not like father not including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fa_wai_pkey" for table "fa_wai" +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (segment=on); +NOTICE: merging column "id" with inherited definition +NOTICE: merging column "name" with inherited definition +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father" for table "father" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father_md_attr_key" for table "father" +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father2" for table "father2" +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (segment=on); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pk_father3" for table "father3" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "father3_md_attr_key" for table "father3" +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (segment=on); +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +NOTICE: merging multiple inherited definitions of column "id" +NOTICE: merging multiple inherited definitions of column "md_attr" +CREATE TABLE kid_2021() inherits(father) WITH (segment=on); +CREATE TABLE kid_2022() inherits(father) WITH (segment=on); +CREATE TABLE kid_2023() inherits(father) WITH (segment=on); +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; + count +------- + 5 +(1 row) + +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; + count +------- + 7 +(1 row) + +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | + 502 | 31 | 2 | 2 | + 504 | 20 | 3 | 2 | + 505 | 22 | 1 | 2 | + 503 | 52 | 2 | 2 | + 506 | 23 | 1 | 2 | + 507 | 23 | 2 | 2 | +(7 rows) + +SELECT id, md_attr FROM father* WHERE id>500; + id | md_attr +-----+--------- + 501 | 21 + 502 | 31 + 504 | 20 + 505 | 22 + 503 | 52 + 506 | 23 + 507 | 23 +(7 rows) + +update father SET salary =90; +SELECT * FROM kid_2021; + id | md_attr | wai_id | num | salary +-----+---------+--------+-----+-------- + 501 | 21 | 1 | 2 | 90 + 502 | 31 | 2 | 2 | 90 + 504 | 20 | 3 | 2 | 90 +(3 rows) + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ERROR: cannot drop inherited constraint "father_salary_check" of relation "kid_2022" +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +ERROR: cannot rename inherited constraint "father_salary_check" +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ERROR: cannot alter inherited column "md_attr" +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ERROR: cannot rename inherited column "num" +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk;-- error +ERROR: constraint "kid_2022_pkey" for table "kid_2022" does not exist +ALTER TABLE father RENAME COlUMN md_attr TO new; +ERROR: cannot rename inherited column "md_attr" +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +ERROR: column "new" of relation "kid_2020" does not exist +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + num | integer | default 2 + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + num | integer | default 1 + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child without num +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 4 (Use \d+ to list them.) + +\d kid_2020 + Table "public.kid_2020" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | + md_attr | character varying(32) | not null + wai_id | integer | + salary | real | +Check constraints: + "father3_id_check" CHECK (id > 3) + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father, + father2, + father3 + +ALTER TABLE kid_2023 no inherit father; +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "pk_father" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE father ALTER COLUMN id TYPE int; +ERROR: syntax error at or near "ALTER" +LINE 2: ALTER TABLE father ALTER COLUMN id TYPE int; + ^ +\d father + Table "public.father" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Indexes: + "new_index_name" PRIMARY KEY, btree (id) TABLESPACE example1 + "father_md_attr_key" UNIQUE CONSTRAINT, btree (md_attr) TABLESPACE pg_default +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Foreign-key constraints: + "father_wai_id_fkey" FOREIGN KEY (wai_id) REFERENCES fa_wai(id) +Number of child tables: 3 (Use \d+ to list them.) + +\d kid_2021 + Table "public.kid_2021" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2022 + Table "public.kid_2022" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) +Inherits: father + +\d kid_2023 + Table "public.kid_2023" + Column | Type | Modifiers +---------+-----------------------+----------- + id | integer | not null + md_attr | character varying(32) | + wai_id | integer | + salary | real | +Check constraints: + "father_salary_check" CHECK (salary > 0::double precision) + +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error +ERROR: constraint "new_constraint_namepk" of relation "kid_2022" does not exist +DROP TABLE father CASCADE; +NOTICE: drop cascades to 3 other objects +DETAIL: drop cascades to table kid_2020 +drop cascades to table kid_2021 +drop cascades to table kid_2022 +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +NOTICE: drop cascades to table kid_wai +DROP TABLESPACE example1; +\c regression +DROP DATABASE inherit_segment; +-- multi_update +CREATE DATABASE inherit_multi_update DBCOMPATIBILITY = 'B'; +\c inherit_multi_update; +-- five relation +DROP TABLE IF EXISTS t_t_mutil_t1; +NOTICE: table "t_t_mutil_t1" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t2; +NOTICE: table "t_t_mutil_t2" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t3; +NOTICE: table "t_t_mutil_t3" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t4; +NOTICE: table "t_t_mutil_t4" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t5; +NOTICE: table "t_t_mutil_t5" does not exist, skipping +CREATE TABLE t_t_mutil_t1(col1 int,col2 int); +CREATE TABLE t_t_mutil_t2(col1 int,col2 int); +CREATE TABLE t_t_mutil_t3 () INHERITS(t_t_mutil_t1); +--?.* +CREATE TABLE t_t_mutil_t4 () INHERITS(t_t_mutil_t3); +--?.* +CREATE TABLE t_t_mutil_t5(col1 int,col2 int); +INSERT INTO t_t_mutil_t1 VALUES(1,1),(1,1); +INSERT INTO t_t_mutil_t2 VALUES(1,1),(1,2); +INSERT INTO t_t_mutil_t3 VALUES(1,1),(1,3); +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: INSERT INTO t_t_mutil_t3 VALUES(1,1),(1,3); + ^ +INSERT INTO t_t_mutil_t4 VALUES(1,1),(1,4); +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: INSERT INTO t_t_mutil_t4 VALUES(1,1),(1,4); + ^ +INSERT INTO t_t_mutil_t5 VALUES(1,1),(1,5); +-- single inherits multi update +update t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.col2=5,a.col2=4,c.col2=6 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +update t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.col2=3,a.col2=2,c.col2=5 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: update t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.co... + ^ +update t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.col2=2,a.col2=1,c.col2=4 WHERE a.col1=b.col1 and b.col1=c.col1; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: update t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.co... + ^ +SELECT * FROM t_t_mutil_t2; + col1 | col2 +------+------ + 1 | 5 + 1 | 5 +(2 rows) + +SELECT * FROM t_t_mutil_t4; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: SELECT * FROM t_t_mutil_t4; + ^ +SELECT * FROM t_t_mutil_t5; + col1 | col2 +------+------ + 1 | 6 + 1 | 6 +(2 rows) + +update t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t3 c SET b.col2=2,a.col2=1,c.col2=3 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: update t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t3 c SET b.co... + ^ +update t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t4 c SET b.col2=1,a.col2=11,c.col2=2 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: update t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t4 c SET b.co... + ^ +update t_t_mutil_t1 a,t_t_mutil_t2 b SET a.col2=7,b.col2=8 WHERE a.col1=b.col1;-- error +update t_t_mutil_t3 a,t_t_mutil_t2 b SET a.col2=6,b.col2=5 WHERE a.col1=b.col1;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: update t_t_mutil_t3 a,t_t_mutil_t2 b SET a.col2=6,b.col2=5 W... + ^ +update t_t_mutil_t4 a,t_t_mutil_t2 b SET a.col2=5,b.col2=4 WHERE a.col1=b.col1; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: update t_t_mutil_t4 a,t_t_mutil_t2 b SET a.col2=5,b.col2=4 W... + ^ +SELECT * FROM t_t_mutil_t2; + col1 | col2 +------+------ + 1 | 8 + 1 | 8 +(2 rows) + +SELECT * FROM t_t_mutil_t4; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: SELECT * FROM t_t_mutil_t4; + ^ +update t_t_mutil_t4 a,t_t_mutil_t3 b SET a.col2=3,b.col2=2 WHERE a.col1=b.col1;-- error +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: update t_t_mutil_t4 a,t_t_mutil_t3 b SET a.col2=3,b.col2=2 W... + ^ +update t_t_mutil_t3 a,t_t_mutil_t4 b SET a.col2=2,b.col2=1 WHERE a.col1=b.col1;-- error; +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: update t_t_mutil_t3 a,t_t_mutil_t4 b SET a.col2=2,b.col2=1 W... + ^ +\c regression +DROP DATABASE inherit_multi_update; +CREATE DATABASE inherit_multi_delete DBCOMPATIBILITY = 'B'; +\c inherit_multi_delete; +-- five relation +DROP TABLE IF EXISTS t_t_mutil_t1; +NOTICE: table "t_t_mutil_t1" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t2; +NOTICE: table "t_t_mutil_t2" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t3; +NOTICE: table "t_t_mutil_t3" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t4; +NOTICE: table "t_t_mutil_t4" does not exist, skipping +DROP TABLE IF EXISTS t_t_mutil_t5; +NOTICE: table "t_t_mutil_t5" does not exist, skipping +CREATE TABLE t_t_mutil_t1(col1 int,col2 int); +CREATE TABLE t_t_mutil_t2(col1 int,col2 int); +CREATE TABLE t_t_mutil_t3 () INHERITS(t_t_mutil_t1); +--?.* +CREATE TABLE t_t_mutil_t4 () INHERITS(t_t_mutil_t3); +--?.* +CREATE TABLE t_t_mutil_t5(col1 int,col2 int); +INSERT INTO t_t_mutil_t1 VALUES(1,1),(1,1); +INSERT INTO t_t_mutil_t2 VALUES(1,1),(1,2); +INSERT INTO t_t_mutil_t3 VALUES(1,1),(1,3); +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: INSERT INTO t_t_mutil_t3 VALUES(1,1),(1,3); + ^ +INSERT INTO t_t_mutil_t4 VALUES(1,1),(1,4); +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: INSERT INTO t_t_mutil_t4 VALUES(1,1),(1,4); + ^ +INSERT INTO t_t_mutil_t5 VALUES(1,1),(1,5); +delete FROM t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHE... + ^ +begin; +delete FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHE... + ^ +SELECT * FROM t_t_mutil_t2; +ERROR: current transaction is aborted, commands ignored until end of transaction block, firstChar[Q] +SELECT * FROM t_t_mutil_t4; +ERROR: current transaction is aborted, commands ignored until end of transaction block, firstChar[Q] +SELECT * FROM t_t_mutil_t5; +ERROR: current transaction is aborted, commands ignored until end of transaction block, firstChar[Q] +rollback; +-- delete xx FROM xxx; +delete t_t_mutil_t1 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete t_t_mutil_t3 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete t_t_mutil_t3 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHE... + ^ +begin; +delete t_t_mutil_t4 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete t_t_mutil_t4 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHE... + ^ +rollback; +delete a FROM t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete a FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete a FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c W... + ^ +begin; +delete a FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete a FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c W... + ^ +rollback; +delete t_t_mutil_t1 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete t_t_mutil_t3 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete t_t_mutil_t3 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHE... + ^ +begin; +delete t_t_mutil_t4 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete t_t_mutil_t4 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHE... + ^ +rollback; +delete a,b FROM t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete a,b FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete a,b FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c... + ^ +begin; +delete a,b FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete a,b FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c... + ^ +rollback; +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2;-- error +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.c... + ^ +begin; +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.c... + ^ +rollback; +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +ERROR: syntax error at or near "limit" +LINE 1: ...util_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; + ^ +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error +ERROR: syntax error at or near "order" +LINE 1: ...il_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a... + ^ +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error +ERROR: syntax error at or near "returning" +LINE 1: ...il_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 returning ... + ^ +delete t_t_mutil_t1 a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +ERROR: syntax error at or near "limit" +LINE 1: ...util_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; + ^ +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +ERROR: syntax error at or near "limit" +LINE 1: ...util_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; + ^ +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error +ERROR: syntax error at or near "order" +LINE 1: ...il_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a... + ^ +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error +ERROR: syntax error at or near "returning" +LINE 1: ...il_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 returning ... + ^ +delete t_t_mutil_t3 a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +ERROR: syntax error at or near "limit" +LINE 1: ...util_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; + ^ +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +ERROR: syntax error at or near "limit" +LINE 1: ...util_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; + ^ +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error +ERROR: syntax error at or near "order" +LINE 1: ...il_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a... + ^ +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error +ERROR: syntax error at or near "returning" +LINE 1: ...il_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 returning ... + ^ +delete t_t_mutil_t4 a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +ERROR: syntax error at or near "limit" +LINE 1: ...util_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; + ^ +-- condition is false +delete FROM t_t_mutil_t1 a,t_t_mutil_t2 b WHERE a.col1 = 1 and a.col1=2;-- error +delete FROM t_t_mutil_t3 a,t_t_mutil_t2 b WHERE a.col1 = 1 and a.col1=2;-- error +ERROR: relation "t_t_mutil_t3" does not exist on datanode1 +LINE 1: delete FROM t_t_mutil_t3 a,t_t_mutil_t2 b WHERE a.col1 = 1 a... + ^ +delete FROM t_t_mutil_t4 a,t_t_mutil_t2 b WHERE a.col1 = 1 and a.col1=2; +ERROR: relation "t_t_mutil_t4" does not exist on datanode1 +LINE 1: delete FROM t_t_mutil_t4 a,t_t_mutil_t2 b WHERE a.col1 = 1 a... + ^ +\c regression +DROP DATABASE inherit_multi_delete; diff --git a/src/test/regress/expected/single_node_foreign_key.out b/src/test/regress/expected/single_node_foreign_key.out index 599bead5f..3b2890256 100644 --- a/src/test/regress/expected/single_node_foreign_key.out +++ b/src/test/regress/expected/single_node_foreign_key.out @@ -865,194 +865,135 @@ DETAIL: Key columns "ptest4" and "ptest1" are of incompatible types: inet and i -- Basic 2 table case: 1 column of matching types. create table pktable_base (base1 int not null); create table pktable (ptest1 int, primary key(base1), unique(base1, ptest1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" +NOTICE: CREATE TABLE / UNIQUE will create implicit index "pktable_base1_ptest1_key" for table "pktable" create table fktable (ftest1 int references pktable(base1)); -ERROR: relation "pktable" does not exist -- now some ins, upd, del insert into pktable(base1) values (1); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable(base1) values (1); - ^ insert into pktable(base1) values (2); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable(base1) values (2); - ^ -- let's insert a non-existent fktable value insert into fktable(ftest1) values (3); -ERROR: relation "fktable" does not exist on datanode1 -LINE 1: insert into fktable(ftest1) values (3); - ^ +ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_ftest1_fkey" +DETAIL: Key (ftest1)=(3) is not present in table "pktable". -- let's make a valid row for that insert into pktable(base1) values (3); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable(base1) values (3); - ^ insert into fktable(ftest1) values (3); -ERROR: relation "fktable" does not exist on datanode1 -LINE 1: insert into fktable(ftest1) values (3); - ^ -- let's try removing a row that should fail from pktable delete from pktable where base1>2; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base1>2; - ^ +ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_fkey" on table "fktable" +DETAIL: Key (base1)=(3) is still referenced from table "fktable". -- okay, let's try updating all of the base1 values to *4 -- which should fail. update pktable set base1=base1*4; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: update pktable set base1=base1*4; - ^ +ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_fkey" on table "fktable" +DETAIL: Key (base1)=(3) is still referenced from table "fktable". -- okay, let's try an update that should work. update pktable set base1=base1*4 where base1<3; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: update pktable set base1=base1*4 where base1<3; - ^ -- and a delete that should work delete from pktable where base1>3; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base1>3; - ^ -- cleanup drop table fktable; -ERROR: table "fktable" does not exist delete from pktable; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable; - ^ -- Now 2 columns 2 tables, matching types create table fktable (ftest1 int, ftest2 int, foreign key(ftest1, ftest2) references pktable(base1, ptest1)); -ERROR: relation "pktable" does not exist -- now some ins, upd, del insert into pktable(base1, ptest1) values (1, 1); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable(base1, ptest1) values (1, 1); - ^ insert into pktable(base1, ptest1) values (2, 2); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable(base1, ptest1) values (2, 2); - ^ -- let's insert a non-existent fktable value insert into fktable(ftest1, ftest2) values (3, 1); -ERROR: relation "fktable" does not exist on datanode1 -LINE 1: insert into fktable(ftest1, ftest2) values (3, 1); - ^ +ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_ftest1_fkey" +DETAIL: Key (ftest1, ftest2)=(3, 1) is not present in table "pktable". -- let's make a valid row for that insert into pktable(base1,ptest1) values (3, 1); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable(base1,ptest1) values (3, 1); - ^ insert into fktable(ftest1, ftest2) values (3, 1); -ERROR: relation "fktable" does not exist on datanode1 -LINE 1: insert into fktable(ftest1, ftest2) values (3, 1); - ^ -- let's try removing a row that should fail from pktable delete from pktable where base1>2; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base1>2; - ^ +ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_fkey" on table "fktable" +DETAIL: Key (base1, ptest1)=(3, 1) is still referenced from table "fktable". -- okay, let's try updating all of the base1 values to *4 -- which should fail. update pktable set base1=base1*4; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: update pktable set base1=base1*4; - ^ +ERROR: update or delete on table "pktable" violates foreign key constraint "fktable_ftest1_fkey" on table "fktable" +DETAIL: Key (base1, ptest1)=(3, 1) is still referenced from table "fktable". -- okay, let's try an update that should work. update pktable set base1=base1*4 where base1<3; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: update pktable set base1=base1*4 where base1<3; - ^ -- and a delete that should work delete from pktable where base1>3; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base1>3; - ^ -- cleanup drop table fktable; -ERROR: table "fktable" does not exist drop table pktable; -ERROR: table "pktable" does not exist drop table pktable_base; -- Now we'll do one all in 1 table with 2 columns of matching types create table pktable_base(base1 int not null, base2 int); create table pktable(ptest1 int, ptest2 int, primary key(base1, ptest1), foreign key(base2, ptest2) references pktable(base1, ptest1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" insert into pktable (base1, ptest1, base2, ptest2) values (1, 1, 1, 1); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable (base1, ptest1, base2, ptest2) values (1... - ^ insert into pktable (base1, ptest1, base2, ptest2) values (2, 1, 1, 1); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable (base1, ptest1, base2, ptest2) values (2... - ^ insert into pktable (base1, ptest1, base2, ptest2) values (2, 2, 2, 1); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable (base1, ptest1, base2, ptest2) values (2... - ^ insert into pktable (base1, ptest1, base2, ptest2) values (1, 3, 2, 2); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable (base1, ptest1, base2, ptest2) values (1... - ^ -- fails (3,2) isn't in base1, ptest1 insert into pktable (base1, ptest1, base2, ptest2) values (2, 3, 3, 2); -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: insert into pktable (base1, ptest1, base2, ptest2) values (2... - ^ +ERROR: insert or update on table "pktable" violates foreign key constraint "pktable_base2_fkey" +DETAIL: Key (base2, ptest2)=(3, 2) is not present in table "pktable". -- fails (2,2) is being referenced delete from pktable where base1=2; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base1=2; - ^ +ERROR: update or delete on table "pktable" violates foreign key constraint "pktable_base2_fkey" on table "pktable" +DETAIL: Key (base1, ptest1)=(2, 2) is still referenced from table "pktable". -- fails (1,1) is being referenced (twice) update pktable set base1=3 where base1=1; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: update pktable set base1=3 where base1=1; - ^ +ERROR: update or delete on table "pktable" violates foreign key constraint "pktable_base2_fkey" on table "pktable" +DETAIL: Key (base1, ptest1)=(1, 1) is still referenced from table "pktable". -- this sequence of two deletes will work, since after the first there will be no (2,*) references delete from pktable where base2=2; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base2=2; - ^ delete from pktable where base1=2; -ERROR: relation "pktable" does not exist on datanode1 -LINE 1: delete from pktable where base1=2; - ^ drop table pktable; -ERROR: table "pktable" does not exist drop table pktable_base; -- 2 columns (2 tables), mismatched types create table pktable_base(base1 int not null); create table pktable(ptest1 inet, primary key(base1, ptest1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" -- just generally bad types (with and without column references on the referenced table) create table fktable(ftest1 cidr, ftest2 int[], foreign key (ftest1, ftest2) references pktable); -ERROR: relation "pktable" does not exist +ERROR: foreign key constraint "fktable_ftest1_fkey" cannot be implemented +DETAIL: Key columns "ftest1" and "base1" are of incompatible types: cidr and integer. create table fktable(ftest1 cidr, ftest2 int[], foreign key (ftest1, ftest2) references pktable(base1, ptest1)); -ERROR: relation "pktable" does not exist +ERROR: foreign key constraint "fktable_ftest1_fkey" cannot be implemented +DETAIL: Key columns "ftest1" and "base1" are of incompatible types: cidr and integer. -- let's mix up which columns reference which create table fktable(ftest1 int, ftest2 inet, foreign key(ftest2, ftest1) references pktable); -ERROR: relation "pktable" does not exist +ERROR: foreign key constraint "fktable_ftest2_fkey" cannot be implemented +DETAIL: Key columns "ftest2" and "base1" are of incompatible types: inet and integer. create table fktable(ftest1 int, ftest2 inet, foreign key(ftest2, ftest1) references pktable(base1, ptest1)); -ERROR: relation "pktable" does not exist +ERROR: foreign key constraint "fktable_ftest2_fkey" cannot be implemented +DETAIL: Key columns "ftest2" and "base1" are of incompatible types: inet and integer. create table fktable(ftest1 int, ftest2 inet, foreign key(ftest1, ftest2) references pktable(ptest1, base1)); -ERROR: relation "pktable" does not exist +ERROR: foreign key constraint "fktable_ftest1_fkey" cannot be implemented +DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: integer and inet. drop table pktable; -ERROR: table "pktable" does not exist drop table pktable_base; -- 2 columns (1 table), mismatched types create table pktable_base(base1 int not null, base2 int); create table pktable(ptest1 inet, ptest2 inet[], primary key(base1, ptest1), foreign key(base2, ptest2) references pktable(base1, ptest1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" +ERROR: foreign key constraint "pktable_base2_fkey" cannot be implemented +DETAIL: Key columns "ptest2" and "ptest1" are of incompatible types: inet[] and inet. create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(base2, ptest2) references pktable(ptest1, base1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" +ERROR: foreign key constraint "pktable_base2_fkey" cannot be implemented +DETAIL: Key columns "base2" and "ptest1" are of incompatible types: integer and inet. create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(ptest2, base2) references pktable(base1, ptest1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" +ERROR: foreign key constraint "pktable_ptest2_fkey" cannot be implemented +DETAIL: Key columns "ptest2" and "base1" are of incompatible types: inet and integer. create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(ptest2, base2) references pktable(base1, ptest1)) inherits (pktable_base); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable" +ERROR: foreign key constraint "pktable_ptest2_fkey" cannot be implemented +DETAIL: Key columns "ptest2" and "base1" are of incompatible types: inet and integer. drop table pktable; ERROR: table "pktable" does not exist drop table pktable_base; @@ -1130,7 +1071,7 @@ SET CONSTRAINTS ALL IMMEDIATE; ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_fk_fkey" DETAIL: Key (fk)=(2000) is not present in table "pktable". INSERT INTO pktable VALUES (2000, 3); -- too late ---?ERROR: current transaction is aborted, commands ignored until end of transaction block.* +ERROR: current transaction is aborted, commands ignored until end of transaction block, firstChar[Q] COMMIT; DROP TABLE fktable, pktable; -- deferrable, initially deferred diff --git a/src/test/regress/expected/single_node_union.out b/src/test/regress/expected/single_node_union.out index ffec33a15..5cd4e6dd8 100644 --- a/src/test/regress/expected/single_node_union.out +++ b/src/test/regress/expected/single_node_union.out @@ -625,7 +625,6 @@ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "events_pkey" for create table other_events (event_id int primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "other_events_pkey" for table "other_events" create table events_child () inherits (events); -ERROR: CREATE TABLE ... INHERITS is not yet supported. explain (costs off) select event_id from (select event_id from events @@ -636,13 +635,17 @@ select event_id ---------------------------------------------------------------- Result -> Merge Append - Sort Key: events.event_id - -> Index Scan using events_pkey on events + Sort Key: public.events.event_id + -> Merge Append + Sort Key: public.events.event_id + -> Index Scan using events_pkey on events + -> Sort + Sort Key: public.events.event_id + -> Seq Scan on events_child events -> Index Scan using other_events_pkey on other_events -(5 rows) +(10 rows) drop table events_child, events, other_events; -ERROR: table "events_child" does not exist reset enable_indexonlyscan; -- Test constraint exclusion of UNION ALL subqueries explain (costs off) diff --git a/src/test/regress/expected/xc_dml.out b/src/test/regress/expected/xc_dml.out index a5aad51e8..b97da6e5b 100644 --- a/src/test/regress/expected/xc_dml.out +++ b/src/test/regress/expected/xc_dml.out @@ -2,71 +2,85 @@ CREATE SCHEMA FVT_DBSYSTEM_MANAGE; CREATE TABLE FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TAB_013(ID INT,ID2 INT); COMMENT ON TABLE FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TAB_013 IS 'PG_DESCRIPTION_TAB_013'; CREATE TABLE FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020(DESCRIPTION TEXT) INHERITS (PG_DESCRIPTION); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +NOTICE: merging column "description" with inherited definition INSERT INTO FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SELECT * FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: INSERT INTO FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SEL... - ^ SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_T... - ^ -SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; description ------------------------ PG_DESCRIPTION_TAB_013 (1 row) +SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; + description +------------------------ + PG_DESCRIPTION_TAB_013 + PG_DESCRIPTION_TAB_013 +(2 rows) + EXPLAIN (VERBOSE ON, COSTS OFF) UPDATE FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SET DESCRIPTION = 'PG_DESCRIPTION_TAB_013_0' WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: EXPLAIN (VERBOSE ON, COSTS OFF) UPDATE FVT_DBSYSTEM_MANAGE.P... - ^ + QUERY PLAN +------------------------------------------------------------------------------------------- + Update on fvt_dbsystem_manage.pg_description_table_020 + -> Seq Scan on fvt_dbsystem_manage.pg_description_table_020 + Output: objoid, classoid, objsubid, 'PG_DESCRIPTION_TAB_013_0'::text, ctid + Filter: (pg_description_table_020.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) +(4 rows) + UPDATE FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SET DESCRIPTION = 'PG_DESCRIPTION_TAB_013_0' WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: UPDATE FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SET DESC... - ^ SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_T... - ^ -SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; - description ------------------------- - PG_DESCRIPTION_TAB_013 + description +-------------------------- + PG_DESCRIPTION_TAB_013_0 (1 row) +SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; + description +-------------------------- + PG_DESCRIPTION_TAB_013 + PG_DESCRIPTION_TAB_013_0 +(2 rows) + EXPLAIN (VERBOSE ON, COSTS OFF) UPDATE PG_DESCRIPTION SET DESCRIPTION = 'PG_DESCRIPTION_TAB_013_1' WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; - QUERY PLAN ------------------------------------------------------------------------------------- + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Update on pg_catalog.pg_description -> Seq Scan on pg_catalog.pg_description - Output: objoid, classoid, objsubid, 'PG_DESCRIPTION_TAB_013_1'::text, ctid - Filter: (pg_description.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) -(4 rows) + Output: pg_catalog.pg_description.objoid, pg_catalog.pg_description.classoid, pg_catalog.pg_description.objsubid, 'PG_DESCRIPTION_TAB_013_1'::text, pg_catalog.pg_description.ctid + Filter: (pg_catalog.pg_description.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) + -> Seq Scan on fvt_dbsystem_manage.pg_description_table_020 pg_description + Output: fvt_dbsystem_manage.pg_description.objoid, fvt_dbsystem_manage.pg_description.classoid, fvt_dbsystem_manage.pg_description.objsubid, 'PG_DESCRIPTION_TAB_013_1'::text, fvt_dbsystem_manage.pg_description.ctid + Filter: (fvt_dbsystem_manage.pg_description.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) +(7 rows) UPDATE PG_DESCRIPTION SET DESCRIPTION = 'PG_DESCRIPTION_TAB_013_1' WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_T... - ^ -SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; description -------------------------- PG_DESCRIPTION_TAB_013_1 (1 row) +SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; + description +-------------------------- + PG_DESCRIPTION_TAB_013_1 + PG_DESCRIPTION_TAB_013_1 +(2 rows) + EXPLAIN (VERBOSE ON, COSTS OFF) DELETE FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: EXPLAIN (VERBOSE ON, COSTS OFF) DELETE FROM FVT_DBSYSTEM_MAN... - ^ + QUERY PLAN +------------------------------------------------------------------------------------------- + Delete on fvt_dbsystem_manage.pg_description_table_020 + -> Seq Scan on fvt_dbsystem_manage.pg_description_table_020 + Output: ctid + Filter: (pg_description_table_020.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) +(4 rows) + DELETE FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: DELETE FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHE... - ^ SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_T... - ^ + description +------------- +(0 rows) + SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; description -------------------------- @@ -74,30 +88,33 @@ SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TA (1 row) INSERT INTO FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SELECT * FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: INSERT INTO FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 SEL... - ^ EXPLAIN (VERBOSE ON, COSTS OFF) DELETE FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; - QUERY PLAN ---------------------------------------------------------------------------------- + QUERY PLAN +----------------------------------------------------------------------------------------------------- Delete on pg_catalog.pg_description -> Seq Scan on pg_catalog.pg_description - Output: ctid - Filter: (pg_description.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) -(4 rows) + Output: pg_catalog.pg_description.ctid + Filter: (pg_catalog.pg_description.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) + -> Seq Scan on fvt_dbsystem_manage.pg_description_table_020 pg_description + Output: fvt_dbsystem_manage.pg_description.ctid + Filter: (fvt_dbsystem_manage.pg_description.description ~~ 'PG_DESCRIPTION_TAB_013%'::text) +(7 rows) DELETE FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%'; SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_TABLE_020 WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; -ERROR: relation "fvt_dbsystem_manage.pg_description_table_020" does not exist on datanode1 -LINE 1: SELECT description FROM FVT_DBSYSTEM_MANAGE.PG_DESCRIPTION_T... - ^ + description +------------- +(0 rows) + SELECT description FROM PG_DESCRIPTION WHERE DESCRIPTION LIKE 'PG_DESCRIPTION_TAB_013%' ORDER BY 1; description ------------- (0 rows) DROP SCHEMA FVT_DBSYSTEM_MANAGE CASCADE; -NOTICE: drop cascades to table fvt_dbsystem_manage.pg_description_tab_013 +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to table fvt_dbsystem_manage.pg_description_tab_013 +drop cascades to table fvt_dbsystem_manage.pg_description_table_020 CREATE TABLE DELETE_XC_C(C1 INT, C2 DATE, C3 INT); CREATE TABLE DELETE_XC_D(D1 INT, D2 DATE, D3 INT); INSERT INTO DELETE_XC_C SELECT GENERATE_SERIES(1,100),NOW(), 1; @@ -1678,64 +1695,57 @@ ALTER TABLE parent_replica_table ADD PRIMARY KEY (A, B); NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "parent_replica_table_pkey" for table "parent_replica_table" INSERT INTO parent_replica_table VALUES(1, 2, 3, 'sadfadsgdsf'); CREATE TABLE son_hash_table() INHERITS (parent_replica_table); -ERROR: CREATE TABLE ... INHERITS is not yet supported. INSERT INTO son_hash_table VALUES(1, 2, 3, 'sadfadsgdsf'); -ERROR: relation "son_hash_table" does not exist on datanode1 -LINE 1: INSERT INTO son_hash_table VALUES(1, 2, 3, 'sadfadsgdsf'); - ^ INSERT INTO son_hash_table VALUES(1, 1, 1, 'sadfadsgdsf'); -ERROR: relation "son_hash_table" does not exist on datanode1 -LINE 1: INSERT INTO son_hash_table VALUES(1, 1, 1, 'sadfadsgdsf'); - ^ EXPLAIN (VERBOSE TRUE, COSTS FALSE) DELETE FROM parent_replica_table; - QUERY PLAN ------------------------------------------------ + QUERY PLAN +-------------------------------------------------------------- Delete on public.parent_replica_table -> Seq Scan on public.parent_replica_table - Output: ctid -(3 rows) + Output: public.parent_replica_table.ctid + -> Seq Scan on public.son_hash_table parent_replica_table + Output: public.parent_replica_table.ctid +(5 rows) DELETE FROM parent_replica_table WHERE A = 1 AND B = 1 AND C = 1; EXPLAIN (VERBOSE TRUE, COSTS FALSE) UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0; - QUERY PLAN ---------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Update on public.parent_replica_table - -> Bitmap Heap Scan on public.parent_replica_table - Output: a, b, c, 'AAAAA'::character varying(20), ctid - Recheck Cond: (parent_replica_table.a > 0) - -> Bitmap Index Scan on parent_replica_table_pkey - Index Cond: (parent_replica_table.a > 0) -(6 rows) + -> Seq Scan on public.parent_replica_table + Output: public.parent_replica_table.a, public.parent_replica_table.b, public.parent_replica_table.c, 'AAAAA'::character varying(20), public.parent_replica_table.ctid + Filter: (public.parent_replica_table.a > 0) + -> Seq Scan on public.son_hash_table parent_replica_table + Output: public.parent_replica_table.a, public.parent_replica_table.b, public.parent_replica_table.c, 'AAAAA'::character varying(20), public.parent_replica_table.ctid + Filter: (public.parent_replica_table.a > 0) +(7 rows) UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0; UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0 AND B > 0; UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0 AND B > 0 AND C > 0; DROP TABLE son_hash_table; -ERROR: table "son_hash_table" does not exist CREATE TABLE son_replica_table() INHERITS (parent_replica_table); -ERROR: CREATE TABLE ... INHERITS is not yet supported. ALTER TABLE son_replica_table ADD PRIMARY KEY (A, B); -ERROR: relation "son_replica_table" does not exist +NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "son_replica_table_pkey" for table "son_replica_table" INSERT INTO son_replica_table VALUES(1, 2, 3, 'sadfadsgdsf'); -ERROR: relation "son_replica_table" does not exist on datanode1 -LINE 1: INSERT INTO son_replica_table VALUES(1, 2, 3, 'sadfadsgdsf')... - ^ EXPLAIN (VERBOSE TRUE, COSTS FALSE) UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0; - QUERY PLAN ---------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Update on public.parent_replica_table - -> Bitmap Heap Scan on public.parent_replica_table - Output: a, b, c, 'AAAAA'::character varying(20), ctid - Recheck Cond: (parent_replica_table.a > 0) - -> Bitmap Index Scan on parent_replica_table_pkey - Index Cond: (parent_replica_table.a > 0) -(6 rows) + -> Seq Scan on public.parent_replica_table + Output: public.parent_replica_table.a, public.parent_replica_table.b, public.parent_replica_table.c, 'AAAAA'::character varying(20), public.parent_replica_table.ctid + Filter: (public.parent_replica_table.a > 0) + -> Bitmap Heap Scan on public.son_replica_table parent_replica_table + Output: public.parent_replica_table.a, public.parent_replica_table.b, public.parent_replica_table.c, 'AAAAA'::character varying(20), public.parent_replica_table.ctid + Recheck Cond: (public.parent_replica_table.a > 0) + -> Bitmap Index Scan on son_replica_table_pkey + Index Cond: (public.parent_replica_table.a > 0) +(9 rows) UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0; UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0 AND B > 0; UPDATE parent_replica_table SET D='AAAAA' WHERE A > 0 AND B > 0 AND C > 0; DROP TABLE son_replica_table; -ERROR: table "son_replica_table" does not exist DROP TABLE parent_replica_table; -- ---- CLEAN UP diff --git a/src/test/regress/output/cstore_unsupported_feature.source b/src/test/regress/output/cstore_unsupported_feature.source index 404320245..1ebf7e00f 100644 --- a/src/test/regress/output/cstore_unsupported_feature.source +++ b/src/test/regress/output/cstore_unsupported_feature.source @@ -8,7 +8,8 @@ DROP TYPE cstore_person_type; -- feature 2: inheritance CREATE TABLE cstore_parent_tbl( a1 int, a2 bool, a3 bigint); CREATE TABLE cstore_child_tbl( b1 bool, b2 bool, b3 bigint) INHERITS ( cstore_parent_tbl ) with (ORIENTATION = COLUMN ); -ERROR: CREATE TABLE ... INHERITS is not yet supported. +ERROR: Unsupport feature +DETAIL: cstore/timeseries don't support relation defination with inheritance. DROP TABLE cstore_parent_tbl; -- feature 3: unchange some storage parameter CREATE TABLE cstore_coltbl( a1 int, a2 int ) with (orientation = column); diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 07fee81f6..de3420762 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -1082,6 +1082,9 @@ test: optimizing_index_scan_ustore # row_count() test: row_count_function +# test for inherit table +test: inherits01 + # show_warnings test: show_warnings prevent_table_in_sys_schema create_tbl_init_td_check diff --git a/src/test/regress/parallel_schedule0B b/src/test/regress/parallel_schedule0B index ff19cf471..29d8fb6f6 100644 --- a/src/test/regress/parallel_schedule0B +++ b/src/test/regress/parallel_schedule0B @@ -315,6 +315,9 @@ test: hw_datatype_2 hw_datatype_3 test: hw_datatype hw_datatype_set test: test_regex llt_atc +# test for inherit table +test: inherits01 + # ---------- # test for set operations # ---------- diff --git a/src/test/regress/sql/inherits01.sql b/src/test/regress/sql/inherits01.sql new file mode 100644 index 000000000..91a7abd09 --- /dev/null +++ b/src/test/regress/sql/inherits01.sql @@ -0,0 +1,1242 @@ +-- inherit +CREATE DATABASE inherit_base; +\c inherit_base; + +--analyze +CREATE TABLE dep AS SELECT mod(i,10000) a, + mod(i,10000) b + FROM generate_series(1,100000) s(i); + +CREATE TABLE dep_son() inherits(dep); +INSERT INTO dep_son(a,b) SELECT (10000 * random())::int a, + (10000 * random())::int b + FROM generate_series(1,100000) s(i); +analyze; +EXPLAIN ANALYZE SELECT a FROM dep WHERE b < 5000 GROUP BY a; +EXPLAIN ANALYZE SELECT a FROM ONLY dep WHERE b < 5000 GROUP BY a; +drop table dep cascade; + +-- iud view +create table grandfather +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +); +insert into grandfather +(id, grandfather1_name)values +(0,'A0'); + +create table father +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather); +insert into father +(id, grandfather1_name, father1_name)values +(1,'A1','B1'), +(2,'A2','B2'); + +CREATE VIEW g_v AS select * from grandfather; +CREATE VIEW f_v AS select * from father; +select * from g_v; +select * from f_v; + +insert into f_v +(id, grandfather1_name, father1_name)values +(3,'A3','B3'); +select * from g_v; +select * from f_v; + +delete from g_v where id=3; +select * from g_v; +select * from f_v; + +update g_v set grandfather1_name='A9' where id=2; +select * from g_v; +select * from f_v; + +DROP VIEW g_v; +DROP VIEW f_v; +DROP TABLE grandfather CASCADE; + +-- column +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +) WITH (ORIENTATION = COLUMN); +insert into grandfather1 +(id, grandfather1_name)values +(0,'A0'); +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1) WITH (ORIENTATION = COLUMN);-- error +DROP TABLE grandfather1 CASCADE; + +-- normal table inherit temporary +create temporary table tmp1(col1 int, col2 int); +create table normal(col3 int)inherits(tmp1);-- error +drop table tmp1; + +-- temporary table inherit normal +create table normal(col1 int); +create temporary table tmp1(col1 int, col2 int)inherits(normal); +create temporary table tmp2(col0 int)inherits(tmp1); +create temporary table tmp3()inherits(normal, tmp1); +\d tmp1 +\d normal +alter table normal add column sex Boolean; +\d tmp1 +\d normal +alter table tmp2 add constraint test_pkey primary key(col0); +\d tmp2 +\d normal +alter table normal add constraint test2_pkey primary key(col1); +\d tmp1 +\d tmp2 +\d normal +drop table tmp3; +drop table tmp2; +drop table tmp1; +drop table normal; + +-- partition +CREATE TABLE plt_father1 +( id int not null, + primary key(id) +); +CREATE TABLE plt( + id serial primary key, + col1 varchar(8)) inherits(plt_father1) + partition by range(id) + ( + partition p1 values less than(10), + partition p2 values less than(20), + partition p3 values less than(30), + partition p4 values less than(maxvalue) + );-- error +DROP TABLE plt_father1 CASCADE; + +CREATE TABLE plt( + id serial primary key, + col1 varchar(8)) + partition by range(id) + ( + partition p1 values less than(10), + partition p2 values less than(20), + partition p3 values less than(30), + partition p4 values less than(maxvalue) + ); +CREATE TABLE plt_son +( id int not null, + primary key(id) +) inherits(plt);-- error +DROP TABLE plt CASCADE; + +-- origin +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +); +INSERT INTO grandfather1 +(id, grandfather1_name) VALUES +(0,'A0'); + +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1); + +INSERT INTO father1 +(id, grandfather1_name, father1_name) VALUES +(1,'A1','B1'), +(2,'A2','B2'); +SELECT * FROM grandfather1; +SELECT * FROM father1; +DELETE FROM grandfather1 WHERE ID=2; +SELECT * FROM father1; +UPDATE grandfather1 SET grandfather1_name='A100' WHERE ID=0; +UPDATE grandfather1 SET father1_name='B100' WHERE ID=0;-- error +UPDATE grandfather1 SET grandfather1_name='A99' WHERE ID=1; +UPDATE grandfather1 SET father1_name='B99' WHERE ID=1;-- error +UPDATE father1 SET father1_name='B99' WHERE ID=1; +SELECT * FROM grandfather1; + +CREATE TABLE son1 +( son1_name varchar(64), + s_age int DEFAULT 30 +)inherits(father1); + +INSERT INTO son1 +(id, grandfather1_name, father1_name, son1_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM grandfather1; +SELECT * FROM son1; +DELETE FROM grandfather1 WHERE ID=4; +SELECT * FROM son1; +UPDATE grandfather1 SET grandfather1_name='A300' WHERE ID=3; +UPDATE grandfather1 SET father1_name='B300' WHERE ID=3;-- error +UPDATE grandfather1 SET son1_name='C300' WHERE ID=3;-- error +SELECT * FROM grandfather1; + +ALTER TABLE grandfather1 RENAME TO grandfather0; +ALTER TABLE grandfather0 DROP COLUMN s_age CASCADE;-- error +ALTER TABLE grandfather0 rename COLUMN f_age TO father_age;-- error +ALTER TABLE grandfather0 rename COLUMN g_age TO grandfather_age; +SELECT * FROM son1; +SELECT * FROM grandfather0; +ALTER TABLE ONLY grandfather0 rename COLUMN grandfather_age TO grand_age;-- error +SELECT * FROM son1; +SELECT * FROM grandfather0; +SELECT * FROM only grandfather0; +DROP TABLE grandfather0 cascade; + +CREATE TABLE father2 +( id int not null, + father2_name varchar(64), + f2_age int DEFAULT 60 +); +CREATE TABLE father3 +( id int not null, + father3_name varchar(64), + f3_age int DEFAULT 60 +); +CREATE TABLE son2 +( son2_name varchar(64), + s_age int DEFAULT 30 +)inherits(father2,father3); + +INSERT INTO son2 +(id, father2_name, father3_name, son2_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); + +SELECT * FROM son2; +SELECT * FROM father2; +SELECT * FROM father3; +ALTER TABLE father2 DROP COLUMN id CASCADE; +SELECT * FROM son2; +SELECT * FROM father2; +SELECT * FROM father3; +DELETE FROM father3 WHERE son2_name='C4';-- error +DELETE FROM father3 WHERE id=3; +SELECT * FROM father2; + +DROP TABLE IF EXISTS son2 cascade; +DROP TABLE IF EXISTS father2 cascade; +DROP TABLE IF EXISTS father3 cascade; + +SET enable_indexonlyscan = off; +CREATE TABLE events (event_id int primary key); +CREATE TABLE other_events (event_id int primary key); +CREATE TABLE events_child1 () inherits (events); +INSERT INTO events_child1 (event_id) VALUES (5); +INSERT INTO events_child1 (event_id) VALUES (1); +INSERT INTO events (event_id) VALUES (2); +INSERT INTO other_events(event_id) VALUES (3); + +-- order by +SELECT event_id + FROM (SELECT event_id FROM events + union all + SELECT event_id FROM other_events) ss + order by event_id; + +DROP TABLE events_child1, events, other_events; +RESET enable_indexonlyscan; + +-- inherit multi tables +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father_z82rgvsefn PRIMARY KEY (id) + ); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2_z82rgvsefn PRIMARY KEY (id) + ); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3_z82rgvsefn PRIMARY KEY (id) + ); +CREATE TABLE kid_2022() inherits(father,father2,father3); +CREATE TABLE kid_2021(like father2 including all) inherits(father,father2,father3); +\d kid_2022 +\d kid_2021 +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE fa_wai CASCADE; + +-- like father and including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ); +CREATE TABLE kid_2020() inherits(father,father2,father3); +CREATE TABLE kid_2021(like father) inherits(father); +CREATE TABLE kid_2022(like father including all) inherits(father); +CREATE TABLE kid_2023(like father) inherits(father); +\d kid_2021 +\d kid_2022 + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; +SELECT id, md_attr FROM father* WHERE id>500; +update father SET salary =90; +SELECT * FROM kid_2021; + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk; +ALTER TABLE father RENAME COlUMN md_attr TO new; +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father +\d kid_2020 +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +\d kid_2020 +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father +\d kid_2020 +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child have num +\d father +\d kid_2020 +ALTER TABLE kid_2023 no inherit father; +\d father +\d kid_2023 +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE father ALTER COLUMN id TYPE int; +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk"; + +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +DROP TABLESPACE example1; + +-- not like father not including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ); +CREATE TABLE kid_2020() inherits(father,father2,father3); +CREATE TABLE kid_2021() inherits(father); +CREATE TABLE kid_2022() inherits(father); +CREATE TABLE kid_2023() inherits(father); +\d kid_2021 +\d kid_2022 + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; +SELECT id, md_attr FROM father* WHERE id>500; +update father SET salary =90; +SELECT * FROM kid_2021; + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk;-- error +ALTER TABLE father RENAME COlUMN md_attr TO new; +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father +\d kid_2020 +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +\d kid_2020 +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father +\d kid_2020 +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child without num +\d father +\d kid_2020 +ALTER TABLE kid_2023 no inherit father; +\d father +\d kid_2023 +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE father ALTER COLUMN id TYPE int; +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error + +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +DROP TABLESPACE example1; + +\c regression +DROP DATABASE inherit_base; + +-- ustore +CREATE DATABASE inherit_ustore; +\c inherit_ustore; +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +) WITH (storage_type=ustore); +INSERT INTO grandfather1 +(id, grandfather1_name) VALUES +(0,'A0'); + +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1) WITH (storage_type=ustore); + +INSERT INTO father1 +(id, grandfather1_name, father1_name) VALUES +(1,'A1','B1'), +(2,'A2','B2'); +SELECT * FROM grandfather1; +SELECT * FROM father1; +DELETE FROM grandfather1 WHERE ID=2; +SELECT * FROM father1; +UPDATE grandfather1 SET grandfather1_name='A100' WHERE ID=0; +UPDATE grandfather1 SET father1_name='B100' WHERE ID=0;-- error +UPDATE grandfather1 SET grandfather1_name='A99' WHERE ID=1; +UPDATE grandfather1 SET father1_name='B99' WHERE ID=1;-- error +UPDATE father1 SET father1_name='B99' WHERE ID=1; +SELECT * FROM grandfather1; + +CREATE TABLE son1 +( son1_name varchar(64), + s_age int DEFAULT 30 +)inherits(father1) WITH (storage_type=ustore); + +INSERT INTO son1 +(id, grandfather1_name, father1_name, son1_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM grandfather1; +SELECT * FROM son1; +DELETE FROM grandfather1 WHERE ID=4; +SELECT * FROM son1; +UPDATE grandfather1 SET grandfather1_name='A300' WHERE ID=3; +UPDATE grandfather1 SET father1_name='B300' WHERE ID=3;-- error +UPDATE grandfather1 SET son1_name='C300' WHERE ID=3;-- error +SELECT * FROM grandfather1; + +ALTER TABLE grandfather1 RENAME TO grandfather0; +ALTER TABLE grandfather0 DROP COLUMN s_age CASCADE;-- error +ALTER TABLE grandfather0 rename COLUMN f_age TO father_age;-- error +ALTER TABLE grandfather0 rename COLUMN g_age TO grandfather_age; +SELECT * FROM son1; +SELECT * FROM grandfather0; +ALTER TABLE ONLY grandfather0 rename COLUMN grandfather_age TO grand_age;-- error +SELECT * FROM son1; +SELECT * FROM grandfather0; +SELECT * FROM only grandfather0; +DROP TABLE grandfather0 cascade; + +CREATE TABLE father2 +( id int not null, + father2_name varchar(64), + f2_age int DEFAULT 60 +) WITH (storage_type=ustore); +CREATE TABLE father3 +( id int not null, + father3_name varchar(64), + f3_age int DEFAULT 60 +) WITH (storage_type=ustore); +CREATE TABLE son2 +( son2_name varchar(64), + s_age int DEFAULT 30 +)inherits(father2,father3) WITH (storage_type=ustore); + +INSERT INTO son2 +(id, father2_name, father3_name, son2_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); + +SELECT * FROM son2; +SELECT * FROM father2; +SELECT * FROM father3; +ALTER TABLE father2 DROP COLUMN id CASCADE; +SELECT * FROM son2; +SELECT * FROM father2; +SELECT * FROM father3; +DELETE FROM father3 WHERE son2_name='C4';-- error +DELETE FROM father3 WHERE id=3; +SELECT * FROM father2; + +DROP TABLE IF EXISTS son2 cascade; +DROP TABLE IF EXISTS father2 cascade; +DROP TABLE IF EXISTS father3 cascade; + +SET enable_indexonlyscan = off; +CREATE TABLE events (event_id int primary key); +CREATE TABLE other_events (event_id int primary key); +CREATE TABLE events_child1 () inherits (events); +INSERT INTO events_child1 (event_id) VALUES (5); +INSERT INTO events_child1 (event_id) VALUES (1); +INSERT INTO events (event_id) VALUES (2); +INSERT INTO other_events(event_id) VALUES (3); +-- order by +SELECT event_id + FROM (SELECT event_id FROM events + union all + SELECT event_id FROM other_events) ss + order by event_id; + +DROP TABLE events_child1, events, other_events; +RESET enable_indexonlyscan; + +-- inherit multi tables +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (storage_type=ustore); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (storage_type=ustore); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father_z82rgvsefn PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2_z82rgvsefn PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3_z82rgvsefn PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE kid_2022() inherits(father,father2,father3) WITH (storage_type=ustore); +CREATE TABLE kid_2021(like father2 including all) inherits(father,father2,father3) WITH (storage_type=ustore);-- error +\d kid_2022 +\d kid_2021 +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE fa_wai CASCADE; + +-- ustore like father and including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (storage_type=ustore); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (storage_type=ustore); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (storage_type=ustore); +CREATE TABLE kid_2021(like father) inherits(father) WITH (storage_type=ustore); +CREATE TABLE kid_2022(like father including all) inherits(father) WITH (storage_type=ustore);-- error +CREATE TABLE kid_2023(like father) inherits(father) WITH (storage_type=ustore); +\d kid_2021 +\d kid_2022 + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2);-- error +SELECT count(*) FROM father; +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; +SELECT id, md_attr FROM father* WHERE id>500; +update father SET salary =90; +SELECT * FROM kid_2021; + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk; +ALTER TABLE father RENAME COlUMN md_attr TO new; +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father +\d kid_2020 +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +\d kid_2020 +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father +\d kid_2020 +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child have num +\d father +\d kid_2020 +ALTER TABLE kid_2023 no inherit father; +\d father +\d kid_2023 +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE father ALTER COLUMN id TYPE int; +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error + +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +DROP TABLESPACE example1; + +-- ustore not like father not including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (storage_type=ustore); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (storage_type=ustore); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (storage_type=ustore); +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (storage_type=ustore); +CREATE TABLE kid_2021() inherits(father) WITH (storage_type=ustore); +CREATE TABLE kid_2022() inherits(father) WITH (storage_type=ustore); +CREATE TABLE kid_2023() inherits(father) WITH (storage_type=ustore); +\d kid_2021 +\d kid_2022 + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; +SELECT id, md_attr FROM father* WHERE id>500; +update father SET salary =90; +SELECT * FROM kid_2021; + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk;-- error +ALTER TABLE father RENAME COlUMN md_attr TO new; +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father +\d kid_2020 +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +\d kid_2020 +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father +\d kid_2020 +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child without num +\d father +\d kid_2020 +ALTER TABLE kid_2023 no inherit father; +\d father +\d kid_2023 +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE father ALTER COLUMN id TYPE int; +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error + +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +DROP TABLESPACE example1; + +\c regression +DROP DATABASE inherit_ustore; + +-- segment +CREATE DATABASE inherit_segment; +\c inherit_segment; +CREATE TABLE grandfather1 +( id int not null, + grandfather1_name varchar(64), + g_age int DEFAULT 80, + primary key(id) +) WITH (segment=on); +INSERT INTO grandfather1 +(id, grandfather1_name) VALUES +(0,'A0'); + +CREATE TABLE father1 +( father1_name varchar(64), + f_age int DEFAULT 60 +)inherits(grandfather1) WITH (segment=on); + +INSERT INTO father1 +(id, grandfather1_name, father1_name) VALUES +(1,'A1','B1'), +(2,'A2','B2'); +SELECT * FROM grandfather1; +SELECT * FROM father1; +DELETE FROM grandfather1 WHERE ID=2; +SELECT * FROM father1; +UPDATE grandfather1 SET grandfather1_name='A100' WHERE ID=0; +UPDATE grandfather1 SET father1_name='B100' WHERE ID=0;-- error +UPDATE grandfather1 SET grandfather1_name='A99' WHERE ID=1; +UPDATE grandfather1 SET father1_name='B99' WHERE ID=1;-- error +UPDATE father1 SET father1_name='B99' WHERE ID=1; +SELECT * FROM grandfather1; + +CREATE TABLE son1 +( son1_name varchar(64), + s_age int DEFAULT 30 +)inherits(father1) WITH (segment=on); + +INSERT INTO son1 +(id, grandfather1_name, father1_name, son1_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); +SELECT * FROM grandfather1; +SELECT * FROM son1; +DELETE FROM grandfather1 WHERE ID=4; +SELECT * FROM son1; +UPDATE grandfather1 SET grandfather1_name='A300' WHERE ID=3; +UPDATE grandfather1 SET father1_name='B300' WHERE ID=3;-- error +UPDATE grandfather1 SET son1_name='C300' WHERE ID=3;-- error +SELECT * FROM grandfather1; + +ALTER TABLE grandfather1 RENAME TO grandfather0; +ALTER TABLE grandfather0 DROP COLUMN s_age CASCADE;-- error +ALTER TABLE grandfather0 rename COLUMN f_age TO father_age;-- error +ALTER TABLE grandfather0 rename COLUMN g_age TO grandfather_age; +SELECT * FROM son1; +SELECT * FROM grandfather0; +ALTER TABLE ONLY grandfather0 rename COLUMN grandfather_age TO grand_age;-- error +SELECT * FROM son1; +SELECT * FROM grandfather0; +SELECT * FROM only grandfather0; +DROP TABLE grandfather0 cascade; + +CREATE TABLE father2 +( id int not null, + father2_name varchar(64), + f2_age int DEFAULT 60 +) WITH (segment=on); +CREATE TABLE father3 +( id int not null, + father3_name varchar(64), + f3_age int DEFAULT 60 +) WITH (segment=on); +CREATE TABLE son2 +( son2_name varchar(64), + s_age int DEFAULT 30 +)inherits(father2,father3) WITH (segment=on); + +INSERT INTO son2 +(id, father2_name, father3_name, son2_name) VALUES +(3,'A3','B3','C3'), +(4,'A4','B4','C4'); + +SELECT * FROM son2; +SELECT * FROM father2; +SELECT * FROM father3; +ALTER TABLE father2 DROP COLUMN id CASCADE; +SELECT * FROM son2; +SELECT * FROM father2; +SELECT * FROM father3; +DELETE FROM father3 WHERE son2_name='C4';-- error +DELETE FROM father3 WHERE id=3; +SELECT * FROM father2; + +DROP TABLE IF EXISTS son2 cascade; +DROP TABLE IF EXISTS father2 cascade; +DROP TABLE IF EXISTS father3 cascade; + +SET enable_indexonlyscan = off; +CREATE TABLE events (event_id int primary key) WITH (segment=on); +CREATE TABLE other_events (event_id int primary key) WITH (segment=on); +CREATE TABLE events_child1 () inherits (events) WITH (segment=on); +INSERT INTO events_child1 (event_id) VALUES (5); +INSERT INTO events_child1 (event_id) VALUES (1); +INSERT INTO events (event_id) VALUES (2); +INSERT INTO other_events(event_id) VALUES (3); +-- order by +SELECT event_id + FROM (SELECT event_id FROM events + union all + SELECT event_id FROM other_events) ss + order by event_id; + +DROP TABLE events_child1, events, other_events; +RESET enable_indexonlyscan; +-- inherit multi tables +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (segment=on); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (segment=on); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father_z82rgvsefn PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2_z82rgvsefn PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3_z82rgvsefn PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE kid_2022() inherits(father,father2,father3) WITH (segment=on); +CREATE TABLE kid_2021(like father2 including all) inherits(father,father2,father3) WITH (segment=on);-- error +\d kid_2022 +\d kid_2021 +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE fa_wai CASCADE; + +-- segment like father and including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (segment=on); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (segment=on); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (segment=on); +CREATE TABLE kid_2021(like father) inherits(father) WITH (segment=on); +CREATE TABLE kid_2022(like father including all) inherits(father) WITH (segment=on);-- error +CREATE TABLE kid_2023(like father) inherits(father) WITH (segment=on); +\d kid_2021 +\d kid_2022 + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2);-- error +SELECT count(*) FROM father; +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; +SELECT id, md_attr FROM father* WHERE id>500; +update father SET salary =90; +SELECT * FROM kid_2021; + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk; +ALTER TABLE father RENAME COlUMN md_attr TO new; +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father +\d kid_2020 +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +\d kid_2020 +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father +\d kid_2020 +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child have num +\d father +\d kid_2020 +ALTER TABLE kid_2023 no inherit father; +\d father +\d kid_2023 +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE father ALTER COLUMN id TYPE int; +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error + +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +DROP TABLESPACE example1; + +-- segment not like father not including all +CREATE TABLE fa_wai( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL +) WITH (segment=on); +CREATE TABLE kid_wai(like fa_wai) inherits(fa_wai) WITH (segment=on); +CREATE TABLE father( + id int NOT NULL, + md_attr CHARACTER VARYING(32) UNIQUE, + wai_id int references fa_wai(ID), + num int DEFAULT 2, + SALARY REAL CHECK(SALARY > 0), + CONSTRAINT pk_father PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE father2( + id int UNIQUE, + md_attr CHARACTER VARYING(32) not null, + CONSTRAINT pk_father2 PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE father3( + id int CHECK(id > 3), + md_attr CHARACTER VARYING(32) UNIQUE, + CONSTRAINT pk_father3 PRIMARY KEY (id) + ) WITH (segment=on); +CREATE TABLE kid_2020() inherits(father,father2,father3) WITH (segment=on); +CREATE TABLE kid_2021() inherits(father) WITH (segment=on); +CREATE TABLE kid_2022() inherits(father) WITH (segment=on); +CREATE TABLE kid_2023() inherits(father) WITH (segment=on); +\d kid_2021 +\d kid_2022 + +INSERT INTO fa_wai VALUES(1,'a'),(2,'b'); +INSERT INTO kid_wai VALUES(3,'c'),(4,'d'); +INSERT INTO father VALUES(1,20,1),(2,30,2); +INSERT INTO kid_2021 VALUES(501,21,1),(502,31,2); +INSERT INTO kid_2021 VALUES(504,20,3); +SELECT count(*) FROM father; +INSERT INTO kid_2022 VALUES(505,22,1),(503,52,2); +SELECT count(*) FROM father; +INSERT INTO kid_2023 VALUES(506,23,1),(507,23,2); +SELECT * FROM father WHERE id>10; +SELECT id, md_attr FROM father* WHERE id>500; +update father SET salary =90; +SELECT * FROM kid_2021; + +ALTER TABLE kid_2022 DROP CONSTRAINT "father_salary_check";-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check TO new_constraint_check;-- error +CREATE TABLESPACE example1 RELATIVE LOCATION 'tablespace22/tablespace_22'; +ALTER INDEX pk_father SET TABLESPACE example1; --child index won't change +ALTER TABLE kid_2020 ALTER COLUMN md_attr TYPE int;-- error +ALTER TABLE kid_2020 RENAME COlUMN num TO new1;-- error +ALTER TABLE kid_2022 RENAME CONSTRAINT kid_2022_pkey TO new_constraint_namepk;-- error +ALTER TABLE father RENAME COlUMN md_attr TO new; +\d kid_2022 +ALTER TABLE kid_2020 ALTER COLUMN num SET DEFAULT 1; +\d father +\d kid_2020 +ALTER TABLE kid_2020 ALTER COLUMN new SET not NULL; +\d kid_2020 +ALTER TABLE kid_2020 ALTER id DROP not null; +\d father +\d kid_2020 +ALTER TABLE father DROP COLUMN IF EXISTS num;-- father without num, child without num +\d father +\d kid_2020 +ALTER TABLE kid_2023 no inherit father; +\d father +\d kid_2023 +ALTER INDEX IF EXISTS pk_father rename to new_index_name; +ALTER TABLE kid_2022 RENAME CONSTRAINT father_salary_check to new_salary_check +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE father ALTER COLUMN id TYPE int; +\d father +\d kid_2021 +\d kid_2022 +\d kid_2023 +ALTER TABLE kid_2022 DROP CONSTRAINT "new_constraint_namepk";-- error + +DROP TABLE father CASCADE; +DROP TABLE father2 CASCADE; +DROP TABLE father3 CASCADE; +DROP TABLE kid_2023 CASCADE; +DROP TABLE fa_wai CASCADE; +DROP TABLESPACE example1; + +\c regression +DROP DATABASE inherit_segment; + +-- multi_update +CREATE DATABASE inherit_multi_update DBCOMPATIBILITY = 'B'; +\c inherit_multi_update; + +-- five relation +DROP TABLE IF EXISTS t_t_mutil_t1; +DROP TABLE IF EXISTS t_t_mutil_t2; +DROP TABLE IF EXISTS t_t_mutil_t3; +DROP TABLE IF EXISTS t_t_mutil_t4; +DROP TABLE IF EXISTS t_t_mutil_t5; +CREATE TABLE t_t_mutil_t1(col1 int,col2 int); +CREATE TABLE t_t_mutil_t2(col1 int,col2 int); +CREATE TABLE t_t_mutil_t3 () INHERITS(t_t_mutil_t1); +CREATE TABLE t_t_mutil_t4 () INHERITS(t_t_mutil_t3); +CREATE TABLE t_t_mutil_t5(col1 int,col2 int); +INSERT INTO t_t_mutil_t1 VALUES(1,1),(1,1); +INSERT INTO t_t_mutil_t2 VALUES(1,1),(1,2); +INSERT INTO t_t_mutil_t3 VALUES(1,1),(1,3); +INSERT INTO t_t_mutil_t4 VALUES(1,1),(1,4); +INSERT INTO t_t_mutil_t5 VALUES(1,1),(1,5); + +-- single inherits multi update +update t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.col2=5,a.col2=4,c.col2=6 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +update t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.col2=3,a.col2=2,c.col2=5 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +update t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c SET b.col2=2,a.col2=1,c.col2=4 WHERE a.col1=b.col1 and b.col1=c.col1; +SELECT * FROM t_t_mutil_t2; +SELECT * FROM t_t_mutil_t4; +SELECT * FROM t_t_mutil_t5; +update t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t3 c SET b.col2=2,a.col2=1,c.col2=3 WHERE a.col1=b.col1 and b.col1=c.col1;-- error +update t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t4 c SET b.col2=1,a.col2=11,c.col2=2 WHERE a.col1=b.col1 and b.col1=c.col1;-- error + +update t_t_mutil_t1 a,t_t_mutil_t2 b SET a.col2=7,b.col2=8 WHERE a.col1=b.col1;-- error +update t_t_mutil_t3 a,t_t_mutil_t2 b SET a.col2=6,b.col2=5 WHERE a.col1=b.col1;-- error +update t_t_mutil_t4 a,t_t_mutil_t2 b SET a.col2=5,b.col2=4 WHERE a.col1=b.col1; +SELECT * FROM t_t_mutil_t2; +SELECT * FROM t_t_mutil_t4; +update t_t_mutil_t4 a,t_t_mutil_t3 b SET a.col2=3,b.col2=2 WHERE a.col1=b.col1;-- error +update t_t_mutil_t3 a,t_t_mutil_t4 b SET a.col2=2,b.col2=1 WHERE a.col1=b.col1;-- error; + +\c regression +DROP DATABASE inherit_multi_update; +CREATE DATABASE inherit_multi_delete DBCOMPATIBILITY = 'B'; +\c inherit_multi_delete; + +-- five relation +DROP TABLE IF EXISTS t_t_mutil_t1; +DROP TABLE IF EXISTS t_t_mutil_t2; +DROP TABLE IF EXISTS t_t_mutil_t3; +DROP TABLE IF EXISTS t_t_mutil_t4; +DROP TABLE IF EXISTS t_t_mutil_t5; +CREATE TABLE t_t_mutil_t1(col1 int,col2 int); +CREATE TABLE t_t_mutil_t2(col1 int,col2 int); +CREATE TABLE t_t_mutil_t3 () INHERITS(t_t_mutil_t1); +CREATE TABLE t_t_mutil_t4 () INHERITS(t_t_mutil_t3); +CREATE TABLE t_t_mutil_t5(col1 int,col2 int); +INSERT INTO t_t_mutil_t1 VALUES(1,1),(1,1); +INSERT INTO t_t_mutil_t2 VALUES(1,1),(1,2); +INSERT INTO t_t_mutil_t3 VALUES(1,1),(1,3); +INSERT INTO t_t_mutil_t4 VALUES(1,1),(1,4); +INSERT INTO t_t_mutil_t5 VALUES(1,1),(1,5); + +delete FROM t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +begin; +delete FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +SELECT * FROM t_t_mutil_t2; +SELECT * FROM t_t_mutil_t4; +SELECT * FROM t_t_mutil_t5; +rollback; + +-- delete xx FROM xxx; +delete t_t_mutil_t1 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete t_t_mutil_t3 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +begin; +delete t_t_mutil_t4 a FROM t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +rollback; + +delete a FROM t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete a FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +begin; +delete a FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +rollback; + +delete t_t_mutil_t1 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete t_t_mutil_t3 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +begin; +delete t_t_mutil_t4 a,t_t_mutil_t2 b FROM t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +rollback; + +delete a,b FROM t_t_mutil_t1 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +delete a,b FROM t_t_mutil_t3 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2;-- error +begin; +delete a,b FROM t_t_mutil_t4 a,t_t_mutil_t2 b,t_t_mutil_t5 c WHERE a.col2=b.col2 and b.col2=c.col2; +rollback; + +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2;-- error +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2;-- error +begin; +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2; +rollback; + +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error +delete a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error +delete t_t_mutil_t1 a FROM t_t_mutil_t1 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error + +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error +delete a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error +delete t_t_mutil_t3 a FROM t_t_mutil_t3 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error + +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 order by a.col2; -- error +delete a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 returning *; -- error +delete t_t_mutil_t4 a FROM t_t_mutil_t4 a left join t_t_mutil_t2 b on a.col2=b.col2 limit 1; -- error + +-- condition is false +delete FROM t_t_mutil_t1 a,t_t_mutil_t2 b WHERE a.col1 = 1 and a.col1=2;-- error +delete FROM t_t_mutil_t3 a,t_t_mutil_t2 b WHERE a.col1 = 1 and a.col1=2;-- error +delete FROM t_t_mutil_t4 a,t_t_mutil_t2 b WHERE a.col1 = 1 and a.col1=2; + +\c regression +DROP DATABASE inherit_multi_delete;