SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

sql join causing panic (None.unwrap) when selecting columns from multiple tables

Open leonardpauli opened this issue 9 months ago • 2 comments

Just followed the server https://spacetimedb.com/docs/modules/rust/quickstart, and got the where you could query with sql. Working fine until I do (replicable):

spacetime sql quickstart-chat "select m.text, u.online from message m join user u on u.identity = m.sender"

Then the server crashes.

/Users/runner/work/SpacetimeDB/SpacetimeDB/crates/client-api/src/routes/database.rs:382: auth: AuthCtx { owner: Identity(...), caller: Identity(...) }
thread 'tokio-runtime-worker' panicked at crates/execution/src/lib.rs:169:18:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

then with RUST_BACKTRACE=full spacetime start:

thread 'tokio-runtime-worker' panicked at crates/execution/src/lib.rs:169:18:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: <spacetimedb_execution::Tuple as spacetimedb_physical_plan::plan::ProjectField>::project
   5: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
   6: spacetimedb_execution::pipelined::ProjectListExecutor::execute::{{closure}}
   7: spacetimedb_execution::pipelined::PipelinedIxJoin::execute::{{closure}}
   8: spacetimedb_execution::pipelined::PipelinedExecutor::execute
   9: spacetimedb_execution::pipelined::PipelinedExecutor::execute
  10: spacetimedb_execution::pipelined::ProjectListExecutor::execute
  11: spacetimedb::sql::execute::run
  12: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  13: tokio::runtime::task::core::Core<T,S>::poll
  14: tokio::runtime::task::harness::Harness<T,S>::poll
  15: tokio::runtime::blocking::pool::Inner::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Expected: The server not to crash, and instead just not return the rows where no user for the default identity exists. A query should never crash the server.

leonardpauli avatar Mar 25 '25 11:03 leonardpauli

Actually:

# works
spacetime sql quickstart-chat "select u.identity from user u join message m on m.sender = u.identity"
# works
spacetime sql quickstart-chat "select m.sender from user u join message m on m.sender = u.identity"
# works: multiple fields same table
spacetime sql quickstart-chat "select u.identity, u.online from user u join message m on m.sender = u.identity"
# works "Error: Duplicate name `text`", no server crash
spacetime sql quickstart-chat "select m.text, m.text from user u join message m on m.sender = u.identity"

# FAILS! server crash! fields from different entities
spacetime sql quickstart-chat "select u.identity, m.sender from user u join message m on m.sender = u.identity"

leonardpauli avatar Mar 25 '25 11:03 leonardpauli

Thanks for the report! @joshua-spacetime is on it 🏃

bfops avatar Apr 02 '25 17:04 bfops