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

feat: support ALTER [TABLE | [MATERIALIZED] VIEW | SOURCE | SINK | CONNECTION | FUNCTION] <name> SET SCHEMA <schema_name> syntax #13341

Merged
merged 27 commits into from
Nov 21, 2023

Conversation

Rossil2012
Copy link
Contributor

@Rossil2012 Rossil2012 commented Nov 9, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Resolve #13159 and #13454

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Support alter relations/connection/function set schema syntax:

ALTER { TABLE t | [MATERIALIZED] VIEW (m)v | SOURCE src | SINK sink | CONNECTION c | FUNCTION f( argument_type [, ...] ) } SET SCHEMA schema_name

@Rossil2012 Rossil2012 changed the title feat: support ALTER [TABLE | [MATERIAL] VIEW | SOURCE | SINK | FUNCTION] <name> SET SCHEMA <schema_name> feat: support ALTER [TABLE | [MATERIAL] VIEW | SOURCE | SINK | FUNCTION] <name> SET SCHEMA <schema_name> syntax Nov 9, 2023
@Rossil2012
Copy link
Contributor Author

As ALTER SET SCHEMA changes the SchemaId, we need to decide how to pass the information from meta to frontend. There are 2 options here:

  1. Overwrite schema_id in proto. And since the old schema_id is absent in the proto, frontend needs to iterate over all schemas in the database and check who owns the [table | view | ...]_id to pin down the original schema.
  2. Add a new field optional uint32 new_schema_id in proto.

Method 1 keeps the proto definition clean but introduce overehead for iteration, but since the no. of schemas in database are generally not huge and the frequencies of calling ALTER SET SCHEMA is relatively low, the overhead might be acceptable.

There is no overhead in Method 2 but introducing a new field may be ugly.

Which way will you suggest here? @yezizp2012

@Rossil2012 Rossil2012 self-assigned this Nov 13, 2023
@Rossil2012 Rossil2012 changed the title feat: support ALTER [TABLE | [MATERIAL] VIEW | SOURCE | SINK | FUNCTION] <name> SET SCHEMA <schema_name> syntax feat: support ALTER [TABLE | [MATERIALIZED] VIEW | SOURCE | SINK | FUNCTION] <name> SET SCHEMA <schema_name> syntax Nov 13, 2023
@yezizp2012
Copy link
Member

As ALTER SET SCHEMA changes the SchemaId, we need to decide how to pass the information from meta to frontend. There are 2 options here:

  1. Overwrite schema_id in proto. And since the old schema_id is absent in the proto, frontend needs to iterate over all schemas in the database and check who owns the [table | view | ...]_id to pin down the original schema.
  2. Add a new field optional uint32 new_schema_id in proto.

Method 1 keeps the proto definition clean but introduce overehead for iteration, but since the no. of schemas in database are generally not huge and the frequencies of calling ALTER SET SCHEMA is relatively low, the overhead might be acceptable.

There is no overhead in Method 2 but introducing a new field may be ugly.

Which way will you suggest here? @yezizp2012

I prefer the first one. There won't be too many schemas and the altering will be very low-frequency.

proto/ddl_service.proto Show resolved Hide resolved
src/frontend/src/catalog/root_catalog.rs Show resolved Hide resolved
src/frontend/src/handler/alter_set_schema.rs Show resolved Hide resolved
src/frontend/src/catalog/root_catalog.rs Show resolved Hide resolved
src/meta/src/manager/catalog/mod.rs Outdated Show resolved Hide resolved
src/meta/src/manager/catalog/mod.rs Show resolved Hide resolved
src/meta/src/manager/catalog/mod.rs Outdated Show resolved Hide resolved
@Rossil2012 Rossil2012 marked this pull request as ready for review November 14, 2023 02:20
Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 682 lines in your changes are missing coverage. Please review.

Comparison is base (942a526) 68.40% compared to head (1e35dac) 68.29%.
Report is 34 commits behind head on main.

Files Patch % Lines
src/meta/src/manager/catalog/mod.rs 0.00% 207 Missing ⚠️
src/frontend/src/catalog/root_catalog.rs 14.17% 115 Missing ⚠️
src/frontend/src/handler/alter_set_schema.rs 45.45% 84 Missing ⚠️
src/frontend/src/handler/mod.rs 12.98% 67 Missing ⚠️
src/sqlparser/src/parser.rs 14.86% 63 Missing ⚠️
src/frontend/src/catalog/schema_catalog.rs 0.00% 48 Missing ⚠️
src/sqlparser/src/ast/ddl.rs 13.04% 20 Missing ⚠️
src/meta/service/src/ddl_service.rs 0.00% 17 Missing ⚠️
src/rpc_client/src/meta_client.rs 0.00% 12 Missing ⚠️
src/frontend/src/catalog/catalog_service.rs 0.00% 11 Missing ⚠️
... and 8 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13341      +/-   ##
==========================================
- Coverage   68.40%   68.29%   -0.12%     
==========================================
  Files        1505     1506       +1     
  Lines      259135   259992     +857     
==========================================
+ Hits       177268   177552     +284     
- Misses      81867    82440     +573     
Flag Coverage Δ
rust 68.29% <16.62%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Rossil2012 Rossil2012 linked an issue Nov 16, 2023 that may be closed by this pull request
@Rossil2012 Rossil2012 changed the title feat: support ALTER [TABLE | [MATERIALIZED] VIEW | SOURCE | SINK | FUNCTION] <name> SET SCHEMA <schema_name> syntax feat: support ALTER [TABLE | [MATERIALIZED] VIEW | SOURCE | SINK | CONNECTION | FUNCTION] <name> SET SCHEMA <schema_name> syntax Nov 16, 2023
e2e_test/ddl/alter_set_schema.slt Outdated Show resolved Hide resolved
e2e_test/udf/alter_function.slt Outdated Show resolved Hide resolved
@yezizp2012
Copy link
Member

Good job! I will review it after my vacation.

Copy link
Member

@yezizp2012 yezizp2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Rest LGTM.

@@ -192,7 +192,7 @@ impl SchemaCatalog {
.unwrap();
entry.get_mut().remove(pos);
}
Vacant(_entry) => unreachable!(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this modification unintentional? I didn't see any reason to ignore it.

Copy link
Contributor Author

@Rossil2012 Rossil2012 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is intentional.
The notification order received by frontend is:

  1. update table
  • create table in the new schema
  • drop table in the old schema (which calls indexes_by_table_id.remove(table_id))
  1. update index
  • create index in the new schema
  • drop index in the old schema (which lookup indexes_by_table_id in the old schema and it is removed in step 1)

By changing the unreachable!() to () and with the designate notification order we can reuse most of code like drop_table/create_table/.... Otherwise we may need to create a new kind of notification for alter set schema and reimplement all the drop and create logic. It might be more robust though since not sharing functions with other statements, but may introduce more duplicate and trivial code. Which option does you prefer, preserve this change or reimplement a new one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Well, let's just ignore it for now and add some comments for it.

src/frontend/src/handler/alter_set_schema.rs Outdated Show resolved Hide resolved
Copy link
Member

@yezizp2012 yezizp2012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!!! LGTM, please add user-facing label for this new syntax and add some brief introduce in the release section.

@Rossil2012 Rossil2012 added the user-facing-changes Contains changes that are visible to users label Nov 21, 2023
@Rossil2012 Rossil2012 added this pull request to the merge queue Nov 21, 2023
Merged via the queue into main with commit 4313a5a Nov 21, 2023
13 of 15 checks passed
@Rossil2012 Rossil2012 deleted the kanzhen/alter-set-schema branch November 21, 2023 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
2 participants