cmu-db / noisepage

Self-Driving Database Management System from Carnegie Mellon University
https://noise.page
MIT License
1.74k stars 502 forks source link

SELECT NULL fails #1020

Closed apavlo closed 3 years ago

apavlo commented 4 years ago

If you have NULL in the output list of a SELECT statement, then the server crashes. It doesn't matter whether you have a FROM clause or not:

Client

terrier=# CREATE TABLE xxx (val int);
CREATE TABLE
terrier=# INSERT INTO xxx VALUES (1);
INSERT 0 1
terrier=# SELECT NULL FROM xxx;
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

Server

terrier: /home/pavlo/Documents/Peloton/Github/terrier/src/include/planner/plannodes/output_schema.h:40:
 terrier::planner::OutputSchema::Column::Column(std::__cxx11::string, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression>): Assertion `(type_ != type::TypeId::INVALID) && ("Attribute type cannot be INVALID.")' failed.
Aborted (core dumped)
apavlo commented 4 years ago

This is still broken. We are now dying in the network layer:

terrier: /home/pavlo/Documents/Peloton/Github/terrier/src/include/planner/plannodes/output_schema.h:41:
 terrier::planner::OutputSchema::Column::Column(std::__cxx11::string, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression>): 
Assertion `(type_ != type::TypeId::INVALID) && ("Attribute type cannot be INVALID.")' failed.

Full stacktrace:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff52308b1 in __GI_abort () at abort.c:79
#2  0x00007ffff522042a in __assert_fail_base (fmt=0x7ffff53a7a38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x5555590b5ac0 "(type_ != type::TypeId::INVALID) && (\"Attribute type cannot be INVALID.\")", 
    file=file@entry=0x5555590b70a0 "/home/pavlo/Documents/Peloton/Github/terrier/src/include/planner/plannodes/output_schema.h", line=line@entry=41, 
    function=function@entry=0x5555590bc4e0 <terrier::planner::OutputSchema::Column::Column(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression, std::default_delete<terrier::parser::AbstractExpression> >)::__PRETTY_FUNCTION__> "terrier::planner::OutputSchema::Column::Column(std::__cxx11::string, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression>)") at assert.c:92
#3  0x00007ffff52204a2 in __GI___assert_fail (assertion=0x5555590b5ac0 "(type_ != type::TypeId::INVALID) && (\"Attribute type cannot be INVALID.\")", 
    file=0x5555590b70a0 "/home/pavlo/Documents/Peloton/Github/terrier/src/include/planner/plannodes/output_schema.h", line=41, 
    function=0x5555590bc4e0 <terrier::planner::OutputSchema::Column::Column(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression, std::default_delete<terrier::parser::AbstractExpression> >)::__PRETTY_FUNCTION__> "terrier::planner::OutputSchema::Column::Column(std::__cxx11::string, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression>)") at assert.c:101
#4  0x0000555556ceed89 in terrier::planner::OutputSchema::Column::Column (this=0x60400002ac10, name="", type=terrier::type::TypeId::INVALID, 
    expr=std::unique_ptr<terrier::parser::AbstractExpression> = {...}) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/planner/plannodes/output_schema.h:41
#5  0x0000555556d2ab76 in __gnu_cxx::new_allocator<terrier::planner::OutputSchema::Column>::construct<terrier::planner::OutputSchema::Column, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression, std::default_delete<terrier::parser::AbstractExpression> > > (this=0x7fff6dca6700, 
    __p=0x60400002ac10) at /usr/include/c++/7/ext/new_allocator.h:136
#6  0x0000555556d1c89f in std::allocator_traits<std::allocator<terrier::planner::OutputSchema::Column> >::construct<terrier::planner::OutputSchema::Column, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression, std::default_delete<terrier::parser::AbstractExpression> > > (
    __a=..., __p=0x60400002ac10) at /usr/include/c++/7/bits/alloc_traits.h:475
#7  0x0000555556d1ca7d in std::vector<terrier::planner::OutputSchema::Column, std::allocator<terrier::planner::OutputSchema::Column> >::_M_realloc_insert<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression, std::default_delete<terrier::parser::AbstractExpression> > > (
    this=0x7fff6dca6700, __position=non-dereferenceable iterator for std::vector) at /usr/include/c++/7/bits/vector.tcc:415
#8  0x0000555556d0c069 in std::vector<terrier::planner::OutputSchema::Column, std::allocator<terrier::planner::OutputSchema::Column> >::emplace_back<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, terrier::type::TypeId, std::unique_ptr<terrier::parser::AbstractExpression, std::default_delete<terrier::parser::AbstractExpression> > > (
    this=0x7fff6dca6700) at /usr/include/c++/7/bits/vector.tcc:105
#9  0x0000555556cd6a63 in terrier::optimizer::PlanGenerator::CorrectOutputPlanWithProjection (this=0x7fff6dca6e80)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/optimizer/plan_generator.cpp:106
#10 0x0000555556cd5c5b in terrier::optimizer::PlanGenerator::ConvertOpNode (this=0x7fff6dca6e80, txn=0x60d000016de0, accessor=0x60600001a900, op=0x60400002ab50, required_props=0x7fff6dca7760, 
    required_cols=std::vector of length 1, capacity 1 = {...}, output_cols=std::vector of length 0, capacity 0, children_plans=..., children_expr_map=...)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/optimizer/plan_generator.cpp:74
#11 0x0000555556c65b58 in terrier::optimizer::Optimizer::ChooseBestPlan (this=0x7fff6dca7960, txn=0x60d000016de0, accessor=0x60600001a900, id=..., required_props=0x7fff6dca7760, 
    required_cols=std::vector of length 1, capacity 1 = {...}) at /home/pavlo/Documents/Peloton/Github/terrier/src/optimizer/optimizer.cpp:112
#12 0x0000555556c6470c in terrier::optimizer::Optimizer::BuildPlanTree (this=0x7fff6dca7960, txn=0x60d000016de0, accessor=0x60600001a900, storage=0x606000010f40, query_info=..., 
    op_tree=std::unique_ptr<terrier::optimizer::AbstractOptimizerNode> = {...}) at /home/pavlo/Documents/Peloton/Github/terrier/src/optimizer/optimizer.cpp:55
#13 0x000055555656b09d in terrier::trafficcop::TrafficCopUtil::Optimize (txn=..., accessor=..., query=..., db_oid=..., stats_storage=..., 
    cost_model=std::unique_ptr<terrier::optimizer::AbstractCostModel> = {...}, optimizer_timeout=5000) at /home/pavlo/Documents/Peloton/Github/terrier/src/traffic_cop/traffic_cop_util.cpp:68
#14 0x000055555653c344 in terrier::trafficcop::TrafficCop::OptimizeBoundQuery (this=0x606000011540, connection_ctx=..., query=...)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/traffic_cop/traffic_cop.cpp:143
#15 0x000055555612c42b in terrier::network::SimpleQueryCommand::Exec (this=0x60400002a210, interpreter=..., out=..., t_cop=..., connection=...)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/network/postgres/postgres_network_commands.cpp:147
#16 0x000055555619d4c1 in terrier::network::PostgresProtocolInterpreter::Process (this=0x611000039fc0, in=..., out=..., t_cop=..., context=...)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/network/postgres/postgres_protocol_interpreter.cpp:45
#17 0x0000555557b34174 in terrier::network::ConnectionHandle::Process (this=0x61300001ff50) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/network/connection_handle.h:121
#18 0x0000555557b30086 in terrier::network::ConnectionHandle::StateMachine::<lambda(terrier::common::ManagedPointer<terrier::network::ConnectionHandle>)>::operator()(terrier::common::ManagedPointer<terrier::network::ConnectionHandle>) const (__closure=0x0, w=...) at /home/pavlo/Documents/Peloton/Github/terrier/src/network/connection_handle.cpp:105
#19 0x0000555557b300a5 in terrier::network::ConnectionHandle::StateMachine::<lambda(terrier::common::ManagedPointer<terrier::network::ConnectionHandle>)>::_FUN(terrier::common::ManagedPointer<terrier::network::ConnectionHandle>) () at /home/pavlo/Documents/Peloton/Github/terrier/src/network/connection_handle.cpp:105
#20 0x0000555557b31edc in terrier::network::ConnectionHandle::StateMachine::Accept (this=0x61300001ff70, action=terrier::network::Transition::WAKEUP, connection=...)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/network/connection_handle.cpp:155
#21 0x0000555556c1c21b in terrier::network::ConnectionHandle::HandleEvent (this=0x61300001ff50, fd=124, flags=2)
    at /home/pavlo/Documents/Peloton/Github/terrier/src/include/network/connection_handle.h:96
#22 0x0000555557b34204 in terrier::network::ConnectionHandle::UpdateEventFlags(short, int)::{lambda(int, short, void*)#1}::operator()(int, short, void*) const (__closure=0x0, fd=124, flags=2, 
    arg=0x61300001ff50) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/network/connection_handle.h:152
#23 0x0000555557b34233 in terrier::network::ConnectionHandle::UpdateEventFlags(short, int)::{lambda(int, short, void*)#1}::_FUN(int, short, void*) ()
    at /home/pavlo/Documents/Peloton/Github/terrier/src/include/network/connection_handle.h:152
#24 0x00007ffff69c88f8 in ?? () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#25 0x00007ffff69c933f in event_base_loop () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#26 0x0000555556c049a2 in terrier::EventUtil::EventBaseDispatch (base=0x617000010000) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/common/event_util.h:92
#27 0x0000555556c04a3d in terrier::common::NotifiableTask::EventLoop (this=0x610000008040) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/common/notifiable_task.h:159
#28 0x0000555556c1bd34 in terrier::common::NotifiableTask::RunTask (this=0x610000008040) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/common/notifiable_task.h:166
#29 0x0000555556c04e92 in terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}::operator()() const (__closure=0x6030000449e8) at /home/pavlo/Documents/Peloton/Github/terrier/src/include/common/dedicated_thread_registry.h:83
#30 0x0000555556c0667f in std::__invoke_impl<void, terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}>(std::__invoke_other, terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}&&) (__f=...) at /usr/include/c++/7/bits/invoke.h:60
#31 0x0000555556c05b30 in std::__invoke<terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}>(terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}&&) (__fn=...) at /usr/include/c++/7/bits/invoke.h:95
#32 0x0000555556c07aea in std::thread::_Invoker<std::tuple<terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) (this=0x6030000449e8) at /usr/include/c++/7/thread:234
#33 0x0000555556c07abb in std::thread::_Invoker<std::tuple<terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}> >::operator()() (this=0x6030000449e8) at /usr/include/c++/7/thread:243
#34 0x0000555556c07a9a in std::thread::_State_impl<std::thread::_Invoker<std::tuple<terrier::common::ManagedPointer<terrier::network::ConnectionHandlerTask> terrier::common::DedicatedThreadRegistry::RegisterDedicatedThread<terrier::network::ConnectionHandlerTask, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory> >(terrier::common::DedicatedThreadOwner*, int, terrier::common::ManagedPointer<terrier::network::ConnectionHandleFactory>)::{lambda()#1}> > >::_M_run() (this=0x6030000449e0) at /usr/include/c++/7/thread:186
#35 0x00007ffff5c546df in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#36 0x00007ffff6c026db in start_thread (arg=0x7fff6dca9700) at pthread_create.c:463
#37 0x00007ffff5311a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
mbutrovich commented 4 years ago

Looks like the same failure as before, not in the network layer. I suspect it's triggering an assertion on constructing the OutputSchema because NULLs come in from the parser with an invalid type and the binder doesn't know what type to assign the expression. It dies all the way at the optimizer trying to generate the physical plan and the output schema.

lmwnshn commented 3 years ago

As of today, it still dies. Postgres seems to return the null as a string.

postgres=# select null;
 ?column? 
----------

(1 row)

postgres=# \gdesc
  Column  | Type 
----------+------
 ?column? | text
(1 row)

postgres=# select null,null,1;
 ?column? | ?column? | ?column? 
----------+----------+----------
          |          |        1
(1 row)

postgres=# \gdesc
  Column  |  Type   
----------+---------
 ?column? | text
 ?column? | text
 ?column? | integer
(3 rows)