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

panic: index out of bounds with DISTINCT and ORDER BY over expr #6021

Closed
philip-stoev opened this issue Mar 8, 2021 · 0 comments · Fixed by #6146
Closed

panic: index out of bounds with DISTINCT and ORDER BY over expr #6021

philip-stoev opened this issue Mar 8, 2021 · 0 comments · Fixed by #6146
Labels
A-sql Area: SQL planning C-bug Category: something is broken

Comments

@philip-stoev
Copy link
Contributor

What version of Materialize are you using?

materialized v0.7.2-dev (148440965)

What was the issue?

DISTINCT does not play well with ORDER BY with an expression:

2021-03-08T09:09:18.216747Z ERROR panic: index out of bounds: the len is 1 but the index is 1
thread: <unnamed>
location: src/sql/src/plan/query.rs:346:33
version: 0.7.2-dev (14844096530f6dc83e56b0f97417861a50c53ad9)
backtrace:
   0: materialized::handle_panic
             at src/materialized/src/bin/materialized/main.rs:618:21
   1: core::ops::function::Fn::call
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/ops/function.rs:70:5
   2: std::panicking::rust_panic_with_hook
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:597:17
   3: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:499:13
   4: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/sys_common/backtrace.rs:141:18
   5: rust_begin_unwind
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:495:5
   6: core::panicking::panic_fmt
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/panicking.rs:92:14
   7: core::panicking::panic_bounds_check
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/panicking.rs:69:5
   8: <usize as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/slice/index.rs:182:10
      core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/slice/index.rs:15:9
      <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/alloc/src/vec.rs:1939:9
      sql::plan::query::try_push_projection_order_by::{{closure}}
             at src/sql/src/plan/query.rs:346:33
      <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::all
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/slice/iter/macros.rs:217:25
      sql::plan::query::try_push_projection_order_by
             at src/sql/src/plan/query.rs:346:8
   9: sql::plan::query::plan_view_select
             at src/sql/src/plan/query.rs:1281:21
  10: sql::plan::query::plan_query
             at src/sql/src/plan/query.rs:763:24
  11: sql::plan::query::plan_root_query
             at src/sql/src/plan/query.rs:299:44
  12: sql::plan::statement::dml::describe_select
             at src/sql/src/plan/statement/dml.rs:105:9
  13: sql::plan::statement::describe
             at src/sql/src/plan/statement.rs:145:36
  14: coord::coord::describe
             at src/coord/src/coord.rs:3603:17
  15: coord::coord::Coordinator::handle_declare
             at src/coord/src/coord.rs:922:20
  16: coord::coord::Coordinator::message_command::{{closure}}
             at src/coord/src/coord.rs:762:30
      <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/future/mod.rs:80:19
      coord::coord::Coordinator::serve::{{closure}}
             at src/coord/src/coord.rs:412:42
  17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/future/mod.rs:80:19
      tokio::park::thread::CachedParkThread::block_on::{{closure}}
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/park/thread.rs:263:54
      tokio::coop::with_budget::{{closure}}
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/coop.rs:121:9
      std::thread::local::LocalKey<T>::try_with
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/thread/local.rs:272:16
      std::thread::local::LocalKey<T>::with
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/thread/local.rs:248:9
      tokio::coop::with_budget
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/coop.rs:114:5
      tokio::coop::budget
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/coop.rs:98:5
      tokio::park::thread::CachedParkThread::block_on
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/park/thread.rs:263:31
  18: tokio::runtime::enter::Enter::block_on
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/runtime/enter.rs:151:13
      tokio::runtime::thread_pool::ThreadPool::block_on
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/runtime/thread_pool/mod.rs:71:9
  19: tokio::runtime::Runtime::block_on
             at /home/pstoev/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/runtime/mod.rs:452:43
  20: coord::coord::serve::{{closure}}::{{closure}}
             at src/coord/src/coord.rs:3470:17
      std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/sys_common/backtrace.rs:125:18
  21: std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/thread/mod.rs:474:17
      <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panic.rs:322:9
      std::panicking::try::do_call
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:381:40
      std::panicking::try
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:345:19
      std::panic::catch_unwind
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panic.rs:396:14
      std::thread::Builder::spawn_unchecked::{{closure}}
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/thread/mod.rs:473:30
      core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/ops/function.rs:227:5
  22: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/alloc/src/boxed.rs:1307:9
      <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/alloc/src/boxed.rs:1307:9
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/sys/unix/thread.rs:71:17
  23: start_thread
  24: clone

Is the issue reproducible? If so, please provide reproduction instructions.

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (f1 INTEGER);
SELECT DISTINCT f1 FROM t1 ORDER BY f1 + 1;
@philip-stoev philip-stoev added the C-bug Category: something is broken label Mar 8, 2021
@benesch benesch added the A-sql Area: SQL planning label Mar 18, 2021
benesch added a commit to benesch/materialize that referenced this issue Mar 18, 2021
philip-stoev pushed a commit to philip-stoev/materialize that referenced this issue Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql Area: SQL planning C-bug Category: something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants