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: facilitate applying zone configs to same-named partitions #39357

Closed
solongordon opened this issue Aug 6, 2019 · 6 comments
Closed

sql: facilitate applying zone configs to same-named partitions #39357

solongordon opened this issue Aug 6, 2019 · 6 comments
Assignees
Labels
A-partitioning C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@solongordon
Copy link
Contributor

Once #20880 is closed, it will be possible to use the same name for related partitions on a table and its indexes. Then it would be great to make it easy for users to apply a zone config to all partitions with the same name in a single statement. We could make this the default behavior for ALTER PARTITION north_america OF TABLE .... Or we could make the syntax more explicit, like ALTER ALL PARTITIONS north_america OF TABLE ....

@solongordon solongordon added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-partitioning labels Aug 6, 2019
@solongordon solongordon self-assigned this Aug 6, 2019
@awoods187
Copy link
Contributor

cc @andreimatei bc he was interested

@andreimatei
Copy link
Contributor

I think a key thing here is to somehow tie together all the "north_america" partitions of different tables and have all of them point to a single "zone config". As it stands, zone configs are defined by a start and end key, so there's no such thing as different tables or partitions pointing to the same zone config. But there should be.
One has to be able to edit the constraints/attributes of all north_america partitions at once, and code that deals with zone (e.g. reporting) should be able to report only one zone for all the north_americas.

solongordon added a commit to solongordon/cockroach that referenced this issue Aug 19, 2019
`ALTER ALL PARTITIONS ... OF TABLE` applies a zone configuration to
all the partitions of a table and its indexes which have the specified
name.

Refers cockroachdb#39357

Release note (sql change): Added the `ALTER ALL PARTITIONS ... OF TABLE`
command, which allows applying a zone configuration to all the
partitions of a table and its indexes with the specified name.
solongordon added a commit to solongordon/cockroach that referenced this issue Aug 26, 2019
`ALTER PARTITION ... OF INDEX` now allows a user to specify all indexes
of a table via `tbl@*` syntax. This means that every partition with the
specified name across all of a table's indexes should be affected.

Refers cockroachdb#39357

Release note (sql change): The `ALTER PARTITION` statement now supports
applying a zone configuration to all the partitions of a table and its
indexes that share the same partition name. The syntax for this is `ALTER
PARTITION <partition name> OF INDEX <table name>@*`.
solongordon added a commit to solongordon/cockroach that referenced this issue Aug 26, 2019
`ALTER PARTITION ... OF INDEX` now allows a user to specify all indexes
of a table via `tbl@*` syntax. This means that every partition with the
specified name across all of a table's indexes should be affected.

Refers cockroachdb#39357

Release note (sql change): The `ALTER PARTITION` statement now supports
applying a zone configuration to all the partitions of a table and its
indexes that share the same partition name. The syntax for this is `ALTER
PARTITION <partition name> OF INDEX <table name>@*`.
craig bot pushed a commit that referenced this issue Aug 26, 2019
39750: sql: support wildcard in ALTER PARTITION OF INDEX r=solongordon a=solongordon

sql: support wildcard in ALTER PARTITION OF INDEX

`ALTER PARTITION ... OF INDEX` now allows a user to specify all indexes
of a table via `tbl@*` syntax. This means that every partition with the
specified name across all of a table's indexes should be affected.

Refers #39357

Release note (sql change): The `ALTER PARTITION` statement now supports
applying a zone configuration to all the partitions of a table and its
indexes that share the same partition name. The syntax for this is `ALTER
PARTITION <partition name> OF INDEX <table name>@*`.

Co-authored-by: Solon Gordon <solon@cockroachlabs.com>
@awoods187
Copy link
Contributor

@solongordon so with #39750 this now applies to all indexes. Where we thinking this could apply to the entire table + indexes in this issue with another pr? or is that now a separate issue?

@solongordon
Copy link
Contributor Author

The terminology is slightly confusing but "all indexes" includes the primary index, so this already applies to the entire table plus indexes.

I didn't close this issue because this doesn't address @andreimatei's concerns about how to tie together analogous partitions across multiple tables, but that is a broader issue so perhaps it could use a fresh issue.

@awoods187
Copy link
Contributor

Ah I see. I was able to do that via:

ALTER TABLE rides PARTITION BY LIST (city) ( PARTITION new_york VALUES IN ('new york'), PARTITION chicago VALUES IN ('chicago'), PARTITION seattle VALUES IN ('seattle') );
ALTER INDEX rides_auto_index_fk_city_ref_users PARTITION BY LIST (city) ( PARTITION new_york VALUES IN ('new york'), PARTITION chicago VALUES IN ('chicago'), PARTITION seattle VALUES IN ('seattle') );
ALTER INDEX rides_auto_index_fk_vehicle_city_ref_vehicles PARTITION BY LIST (vehicle_city) ( PARTITION new_york VALUES IN ('new york'), PARTITION chicago VALUES IN ('chicago'), PARTITION seattle VALUES IN ('seattle') );

Then:

show partitions from table rides;

  database_name | table_name | partition_name | parent_partition | column_names |                     index_name                      | partition_value | zone_config
+---------------+------------+----------------+------------------+--------------+-----------------------------------------------------+-----------------+-------------+
  movr          | rides      | new_york       | NULL             | city         | rides@primary                                       | ('new york')    | NULL
  movr          | rides      | chicago        | NULL             | city         | rides@primary                                       | ('chicago')     | NULL
  movr          | rides      | seattle        | NULL             | city         | rides@primary                                       | ('seattle')     | NULL
  movr          | rides      | new_york       | NULL             | city         | rides@rides_auto_index_fk_city_ref_users            | ('new york')    | NULL
  movr          | rides      | chicago        | NULL             | city         | rides@rides_auto_index_fk_city_ref_users            | ('chicago')     | NULL
  movr          | rides      | seattle        | NULL             | city         | rides@rides_auto_index_fk_city_ref_users            | ('seattle')     | NULL
  movr          | rides      | new_york       | NULL             | vehicle_city | rides@rides_auto_index_fk_vehicle_city_ref_vehicles | ('new york')    | NULL
  movr          | rides      | chicago        | NULL             | vehicle_city | rides@rides_auto_index_fk_vehicle_city_ref_vehicles | ('chicago')     | NULL
  movr          | rides      | seattle        | NULL             | vehicle_city | rides@rides_auto_index_fk_vehicle_city_ref_vehicles | ('seattle')     | NULL
(9 rows)

Using the new command:

ALTER PARTITION new_york OF INDEX movr.rides@* CONFIGURE ZONE USING constraints='[+region=us-east,+az=1]'; ALTER PARTITION chicago OF INDEX rides@* CONFIGURE ZONE USING constraints='[+region=us-central,+az=1]'; ALTER PARTITION seattle OF INDEX movr.rides@* CONFIGURE ZONE USING constraints='[+region=us-west,+az=2]';

And finally we can see that it works:

show partitions from table rides;
  database_name | table_name | partition_name | parent_partition | column_names |                     index_name                      | partition_value |                 zone_config
+---------------+------------+----------------+------------------+--------------+-----------------------------------------------------+-----------------+---------------------------------------------+
  movr          | rides      | new_york       | NULL             | city         | rides@primary                                       | ('new york')    | constraints = '[+region=us-east, +az=1]'
  movr          | rides      | chicago        | NULL             | city         | rides@primary                                       | ('chicago')     | constraints = '[+region=us-central, +az=1]'
  movr          | rides      | seattle        | NULL             | city         | rides@primary                                       | ('seattle')     | constraints = '[+region=us-west, +az=2]'
  movr          | rides      | new_york       | NULL             | city         | rides@rides_auto_index_fk_city_ref_users            | ('new york')    | constraints = '[+region=us-east, +az=1]'
  movr          | rides      | chicago        | NULL             | city         | rides@rides_auto_index_fk_city_ref_users            | ('chicago')     | constraints = '[+region=us-central, +az=1]'
  movr          | rides      | seattle        | NULL             | city         | rides@rides_auto_index_fk_city_ref_users            | ('seattle')     | constraints = '[+region=us-west, +az=2]'
  movr          | rides      | new_york       | NULL             | vehicle_city | rides@rides_auto_index_fk_vehicle_city_ref_vehicles | ('new york')    | constraints = '[+region=us-east, +az=1]'
  movr          | rides      | chicago        | NULL             | vehicle_city | rides@rides_auto_index_fk_vehicle_city_ref_vehicles | ('chicago')     | constraints = '[+region=us-central, +az=1]'
  movr          | rides      | seattle        | NULL             | vehicle_city | rides@rides_auto_index_fk_vehicle_city_ref_vehicles | ('seattle')     | constraints = '[+region=us-west, +az=2]'
(9 rows)

Time: 13.992ms

I think we should close this issue as addressed and open a new one on @andreimatei 's idea. Does that work for you?

@solongordon
Copy link
Contributor Author

Created #40703 to track @andreimatei's suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-partitioning C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

No branches or pull requests

3 participants