Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: implement table inheritance ( CREATE / ALTER TABLE ... INHERITS ) #22456

Open
trcarden opened this issue Feb 7, 2018 · 4 comments
Open
Labels
A-schema-changes A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community X-anchored-telemetry The issue number is anchored by telemetry references.

Comments

@trcarden
Copy link

trcarden commented Feb 7, 2018

Feature request: Postgresql Table Inheritance

Official Documentation

Table inheritance is typically established when the child table is created, using the INHERITS clause of the CREATE TABLE statement. Alternatively, a table which is already defined in a compatible way can have a new parent relationship added, using the INHERIT variant of ALTER TABLE. To do this the new child table must already include columns with the same names and types as the columns of the parent. It must also include check constraints with the same names and check expressions as those of the parent. Similarly an inheritance link can be removed from a child using the NO INHERIT variant of ALTER TABLE. Dynamically adding and removing inheritance links like this can be useful when the inheritance relationship is being used for table partitioning (see Section 5.9).

https://www.postgresql.org/docs/9.1/static/ddl-inherit.html

Use Case

Through inheritance referencing either all rows of a table or all rows of a table plus all of its descendant tables. This feature is used within Odoo which is an open source accounting and enterprise resource planning tool specifically here and there

Importance

Blocker: if we are to try cockroach with systems that rely on inheritance.

Workaround

None known at this time. That said if anyone has any ideas on how to make this work please share.

Note

Generally Speaking Enterprise resource (ERPs) planning tools where global workloads, consistency (for manufacturing and accounting) seem to be an ideal target for Cockroach Db. Opening up support for open source ERPs could potentially be a good adoption angle for enterprises.

Epic CRDB-8258

Jira issue: CRDB-5856

@jordanlewis jordanlewis added O-community Originated from the community feature A-sql-pgcompat Semantic compatibility with PostgreSQL labels Feb 7, 2018
@jordanlewis jordanlewis added this to the Later milestone Feb 7, 2018
@jordanlewis jordanlewis changed the title Postgresql: Table Inheritance sql: implement table inheritance ( CREATE / ALTER TABLE ... INHERITS ) Feb 7, 2018
@jordanlewis
Copy link
Member

Hi @trcarden,

Thanks for the feature request. We don't have plans to implement table inheritance in the near future. However, I believe there is a relatively simple workaround.

As far as I understand, table inheritance is meant to reduce duplication in schema definition - and that's it. To get around not being able to use INHERITS in a child table, just duplicate the column definitions from the parent table to the child table.

In your first example, the ir_actions table just has a single id column - so you'd duplicate that column definition to all of the tables that inherit it.

It's a little more complicated in the second example, which dynamically creates inherited tables, but you could still do it by introspecting on the parent table and copying the columns to the child.

@knz knz added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) and removed feature labels Apr 24, 2018
@knz knz added this to Backlog in (DEPRECATED) SQL Front-end, Lang & Semantics via automation Apr 24, 2018
@vivekmenezes vivekmenezes added this to Other in Bulk IO Apr 25, 2018
@knz knz moved this from Triage to Feature requests / pie-in-the-skie in (DEPRECATED) SQL Front-end, Lang & Semantics May 3, 2018
@petermattis petermattis removed this from the Later milestone Oct 5, 2018
@jordanlewis jordanlewis moved this from Triage to Lower priority backlog in [DEPRECATED] Old SQLExec board. Don't move stuff here Apr 30, 2019
@jordanlewis jordanlewis removed this from Feature requests / pie-in-the-skie in (DEPRECATED) SQL Front-end, Lang & Semantics Apr 30, 2019
@jordanlewis jordanlewis added this to Triage in Disaster Recovery Backlog via automation Apr 30, 2019
@jordanlewis
Copy link
Member

@vivekmenezes moving to your team.

@SevereOverfl0w
Copy link

I think this is more complicated than schema inheritance.

My understanding of https://www.postgresql.org/docs/9.1/ddl-inherit.html Using inheritance allows you to query cities and that will include results from capitals.

In PostgreSQL, a table can inherit from zero or more other tables, and a query can reference either all rows of a table or all rows of a table plus all of its descendant tables. The latter behavior is the default. For example, the following query finds the names of all cities, including state capitals, that are located at an altitude over 500 feet:

@jordanlewis
Copy link
Member

Oh, neat. So it's like a table with an implicit join on another table. Thanks for clarifying! I think that it's unlikely that we'll get to implementing this any time soon.

@dt dt moved this from Triage to Backlog in Disaster Recovery Backlog May 21, 2019
@dt dt removed this from Backlog in Disaster Recovery Backlog Jul 11, 2019
@jordanlewis jordanlewis moved this from Triage to Lower priority backlog in [DEPRECATED] Old SQLExec board. Don't move stuff here Jul 31, 2019
@mwang1026 mwang1026 added this to Triage in SQL Foundations via automation Jan 27, 2020
@jordanlewis jordanlewis removed this from Triage in SQL Foundations Mar 24, 2020
@asubiotto asubiotto moved this from Lower priority backlog to [TENT] SQL Features in [DEPRECATED] Old SQLExec board. Don't move stuff here Apr 2, 2020
@jordanlewis jordanlewis added the X-anchored-telemetry The issue number is anchored by telemetry references. label Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community X-anchored-telemetry The issue number is anchored by telemetry references.
Projects
No open projects
Development

No branches or pull requests

7 participants