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

bug: panic when adding to a table a column as the primary key #19609

Open
lmatz opened this issue Nov 29, 2024 · 3 comments
Open

bug: panic when adding to a table a column as the primary key #19609

lmatz opened this issue Nov 29, 2024 · 3 comments
Labels
type/bug Something isn't working
Milestone

Comments

@lmatz
Copy link
Contributor

lmatz commented Nov 29, 2024

Describe the bug

dev=> create table t(v1 int, v2 int);
CREATE_TABLE

dev=> drop table tmp2;
DROP_TABLE

dev=> create table tmp2 as select * except (v1) from t;
INSERT 0 0

dev=> alter table tmp2 add column employee_id int primary key;
ERROR:  Panicked when handling the request: called `Result::unwrap()` on an `Err` value: []
This is a bug. We would appreciate a bug report at:
  https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Fbug&template=bug_report.yml
SSL connection has been closed unexpectedly

Error message/log

2024-11-29 10:56:04.860	
thread 'rw-standalone-frontend' panicked at src/frontend/src/handler/alter_table_column.rs:322:10:
2024-11-29 10:56:04.860	
called `Result::unwrap()` on an `Err` value: []
2024-11-29 10:56:04.860	
stack backtrace:
2024-11-29 10:56:04.978	
   0:     0xaaaad2dc7c74 - std::backtrace_rs::backtrace::libunwind::trace::h22abe6941b6c364e
2024-11-29 10:56:04.978	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
2024-11-29 10:56:04.978	
   1:     0xaaaad2dc7c74 - std::backtrace_rs::backtrace::trace_unsynchronized::h09825ba824b25c03
2024-11-29 10:56:04.978	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2024-11-29 10:56:04.978	
   2:     0xaaaad2dc7c74 - std::sys_common::backtrace::_print_fmt::h8edb2ed98e6d043e
2024-11-29 10:56:04.978	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys_common/backtrace.rs:68:5
2024-11-29 10:56:04.978	
   3:     0xaaaad2dc7c74 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h59fe19f00e808c0f
2024-11-29 10:56:04.978	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys_common/backtrace.rs:44:22
2024-11-29 10:56:04.979	
   4:     0xaaaac82db660 - core::fmt::rt::Argument::fmt::h97fcedd5c989dd8e
2024-11-29 10:56:04.979	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/core/src/fmt/rt.rs:165:63
2024-11-29 10:56:04.979	
   5:     0xaaaac82db660 - core::fmt::write::h2ab4a0f6cb1c47e2
2024-11-29 10:56:04.979	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/core/src/fmt/mod.rs:1168:21
2024-11-29 10:56:04.979	
   6:     0xaaaad2dc135c - std::io::Write::write_fmt::h92c5bdbd600095f4
2024-11-29 10:56:04.979	
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/io/mod.rs:1835:15
2024-11-29 10:56:04.979	
   7:     0xaaaad2dc7abc - std::sys_common::backtrace::_print::ha084ca3dc112f7ce

To Reproduce

Please use the SQL statements above

Expected behavior

No response

How did you deploy RisingWave?

No response

The version of RisingWave

No response

Additional context

This pattern is useful when we want to create a table with a primary key but without manually specifying the schema.

@lmatz lmatz added the type/bug Something isn't working label Nov 29, 2024
@github-actions github-actions bot added this to the release-2.2 milestone Nov 29, 2024
@BugenZhao
Copy link
Member

BugenZhao commented Nov 29, 2024

I believe this issue arises because you're performing a schema change on a CREATE TABLE AS (CTAS). The table's definition isn't properly maintained, which is necessary for replacing the table plan.

Similar issue: #15334 (comment). Covered by #17472 (comment).

Adding a primary key to a normal table should be rejected gracefully.

@lmatz
Copy link
Contributor Author

lmatz commented Nov 29, 2024

Always reject or reject under some conditions?

The doc includes "primary key" clause in the syntax:
https://docs.risingwave.com/sql/commands/sql-alter-table#clauses
but does not mention under what condition it can be used

@BugenZhao
Copy link
Member

Always reject or reject under some conditions?

Always rejected. Primary key affects the physical distribution of the table data thus cannot be changed with instant schema change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants