-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
multiregionccl: add unsafe_optimize_system_database #92395
Conversation
@ajwerner this needs more testing before I'm ready to submit it, but can you take a look at let me know what you think of the overall approach? |
ca45ead
to
a2e40c2
Compare
Changing the crdb_region column to an enum type is OK, but the behavior doesn't seem right. Once the type has been changed, we couldn't compare with a string anymore:
On the other hand, for a regular regional by row table, I could still filter by crdb_region, and the DB knows what the possible values are:
|
Yes, this approach is sound |
Andrew and I debugged this. The error is coming from the optimizer. The statistics for the table contain the type of the column and that type is used when planning the query. Regenerating statistics for the table causes the error to go away. Arguably we are breaking an invariant in the optimizer: the type of a column is changing, but the id of the column is not changing. For now we will work around this by clearing stats in the unsafe_optimize_system_database built in. During tenant creation, erasing stats will be a no-op, since stats will not have been generated by the time the tenant is created. |
b3a1cf7
to
9ed141a
Compare
9ed141a
to
337ddc8
Compare
I removed the draft label. This change is ready for review. |
337ddc8
to
d64ac08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 8 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @jaylim-crl)
crdb_internal.unsafe_optimize_system_database optimizes the system database for multi region deployments by configuring latency critical tables as global or regional by row. Tables that are sensitive to read latency were converted to global. Table that are sensitive to write latency were converted to regional by row. system.sqlliveness and system.sql_instances were reworked by (cockroachdb#90408) and (cockroachdb#92010) to have a primary key index that is binary compatible with regional by row tables. The conversion to regional by row is implemented as a built in function because it is not possible to use `ALTER TABLE ... SET LOCALITY REGIONAL BY ROW` to perform the conversion. Using alter table to convert the RBR tables has two challenges: 1. There is no way to convert the crdb_region column from []byte to the region enum type. 2. Changing the locality to RBR always rewrites the primary index. The sqlliveness and sql_instance subsystems use the raw kv API and expect a specific index ID. Rewriting the primary index changes the ID and breaks the subsystems. Release note: None Part of cockroachdb#85736
d64ac08
to
bb388da
Compare
bors r+ |
Build succeeded: |
92588: lease,systemschema: hook up the lease table to regional-by-row partitioning r=ajwerner a=ajwerner This PR extends the `system.lease` table with REGIONAL BY ROW partitioning for use with #92395. The PR is itself freestanding. Epic: CRDB-18596 Release note: None Co-authored-by: Andrew Werner <[email protected]>
crdb_internal.unsafe_optimize_system_database optimizes the system
database for multi region deployments by configuring latency critical
tables as global or regional by row. Tables that are sensitive to read
latency were converted to global. Table that are sensitive to write
latency were converted to regional by row.
system.sqlliveness and system.sql_instances were reworked by (#90408)
and (#92010) to have a primary key index that is binary compatible with
regional by row tables. The conversion to regional by row is
implemented as a built in function because it is not possible to use
ALTER TABLE ... SET LOCALITY REGIONAL BY ROW
to perform the conversion.Using alter table to convert the RBR tables has two challenges:
region enum type.
sqlliveness and sql_instance subsystems use the raw kv API and expect a
specific index ID. Rewriting the primary index changes the ID and breaks
the subsystems.
Release note: None
Part of #85736