cmu-db / peloton

The Self-Driving Database Management System
http://pelotondb.io
Apache License 2.0
2.03k stars 623 forks source link

prepare_stmt_test fails in codegen #1382

Closed pervazea closed 6 years ago

pervazea commented 6 years ago

Running with:

See below for available data collected:

--- a/src/codegen/query_compiler.cpp
+++ b/src/codegen/query_compiler.cpp
@@ -124,7 +124,6 @@ bool QueryCompiler::IsExpressionSupported(
     const expression::AbstractExpression &expr) {
   switch (expr.GetExpressionType()) {
     case ExpressionType::STAR:
-    case ExpressionType::VALUE_PARAMETER:
       return false;

// test prepare statement                                                    
C.prepare("searchstmt", "SELECT name FROM employee WHERE id=$1;");
// invocation as in variable binding                                         
pqxx::result R = txn2.prepared("searchstmt")(1).exec();

prepare_stmt_test.cpp:41:PrepareStatementTest] INFO - [PrepareStatementTest] Connected to default_database 39: prepare_stmt_test: /home/pakhtar/proj/master_bin/peloton/src/codegen/lang/vectorizedloop.cpp:36: peloton::codegen::lang::VectorizedLoop::~VectorizedLoop(): Assertion `(ended && "You didn't call lang::VectorizedLoop::LoopEnd()!")' failed. 1/1 Test #39: prepare_stmt_test ................***Exception: Other 0.32 sec

0% tests passed, 1 tests failed out of 1

pervazea commented 6 years ago

Re-running after pulling from Master 25 May 18, which provides better diagnostics, courtesy of changes by Matt B.

2018-05-25 14:55:19 [/home/proj/master_bin/peloton/test/network/prepare_stmt_test.cpp:41:PrepareStatementTest] INFO - [PrepareStatementTest] Connected to default_database 2018-05-25 14:55:19 [/home/proj/master_bin/peloton/src/codegen/lang/vectorized_loop.cpp:37:~VectorizedLoop] ERROR - You didn't call lang::VectorizedLoop::LoopEnd()! 2018-05-25 14:55:19 [/home/proj/master_bin/peloton/src/codegen/function_builder.cpp:139:~FunctionBuilder] ERROR - Missing call to FunctionBuilder::ReturnAndFinish() for function '_13_pipeline_0_serialWork_seqscan_output' 2018-05-25 14:55:19 [/home/proj/master_bin/peloton/src/codegen/function_builder.cpp:139:~FunctionBuilder] ERROR - Missing call to FunctionBuilder::ReturnAndFinish() for function '_13_plan' 2018-05-25 14:55:19 [/home/proj/master_bin/peloton/src/executor/plan_executor.cpp:175:ExecutePlan] ERROR - Error thrown during execution: No comparison rule between types: INTEGER and VARCHAR 2018-05-25 14:55:19 [/home/proj/master_bin/peloton/src/network/postgres_protocol_handler.cpp:824:ExecExecuteMessageGetResult] ERROR - Failed to execute: No comparison rule between types: INTEGER and VARCHAR 2018-05-25 14:55:19 [/home/proj/master_bin/peloton/test/network/prepare_stmt_test.cpp:76:PrepareStatementTest] INFO - [PrepareStatementTest] Exception occurred: No comparison rule between types: INTEGER and VARCHAR

/home/pakhtar/proj/master_bin/peloton/test/network/prepare_stmt_test.cpp:77: Failure Value of: false Actual: false Expected: true

pervazea commented 6 years ago

0 peloton::codegen::ComparisonTranslator::DeriveValue (this=0x7fffdc009480,

codegen=..., row=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/expression/comparison_translator.cpp:37

1 0x00007ffff63f337c in peloton::codegen::RowBatch::Row::DeriveValue (

this=0x7fffe8bfc3b0, codegen=..., expr=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/row_batch.cpp:130

2 0x00007ffff64447e2 in peloton::codegen::TableScanTranslator::ScanConsumer::<lambda(peloton::codegen::RowBatch::Row&)>::operator()(peloton::codegen::RowBatch::Row &) const (__closure=0x7fffe8bfc6c0, row=...)

at /home/pakhtar/proj/master_bin/peloton/src/codegen/operator/table_scan_translator.cpp:370

3 0x00007ffff64451cf in std::_Function_handler<void(peloton::codegen::RowBatch::Row&), peloton::codegen::TableScanTranslator::ScanConsumer::FilterRowsByPredicate(peloton::codegen::CodeGen&, const peloton::codegen::TileGroup::TileGroupAccess&, llvm::Value, llvm::Value, peloton::codegen::Vector&) const::<lambda(peloton::codegen::RowBatch::Row&)> >::_M_invoke(const std::_Any_data &, peloton::codegen::RowBatch::Row &) (functor=..., args#0=...)

at /usr/include/c++/5/functional:1871

4 0x00007ffff63f594f in std::function<void (peloton::codegen::RowBatch::Row&)>::operator()(peloton::codegen::RowBatch::Row&) const (this=0x7fffe8bfc6c0,

__args#0=...) at /usr/include/c++/5/functional:2267

5 0x00007ffff63f2c23 in peloton::codegen::(anonymous namespace)::CallbackAdapter::ProcessRow (this=0x7fffe8bfc530, row=...)

at /home/pakhtar/proj/master_bin/peloton/src/codegen/row_batch.cpp:42

6 0x00007ffff63f3eb1 in peloton::codegen::RowBatch::Iterate (

this=0x7fffe8bfc650, codegen=..., cb=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/row_batch.cpp:257

7 0x00007ffff63f4222 in peloton::codegen::RowBatch::Iterate(peloton::codegen::CodeGen&, std::function<void (peloton::codegen::RowBatch::Row&)>) (

this=0x7fffe8bfc650, codegen=..., cb=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/row_batch.cpp:285

8 0x00007ffff6444af1 in peloton::codegen::TableScanTranslator::ScanConsumer::FilterRowsByPredicate (this=0x7fffe8bfcc00, codegen=..., access=...,

tid_start=0x7fffdc00cdd8, tid_end=0x7fffdc011828, selection_vector=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/operator/table_scan_translator.cpp:379

9 0x00007ffff6444336 in peloton::codegen::TableScanTranslator::ScanConsumer::ProcessTuples (this=0x7fffe8bfcc00, codegen=..., tid_start=0x7fffdc00cdd8,

tid_end=0x7fffdc011828, tile_group_access=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/operator/table_scan_translator.cpp:290

10 0x00007ffff64a22fe in peloton::codegen::TileGroup::GenerateTidScan (

this=0x7fffdc00bb48, codegen=..., tile_group_ptr=0x7fffdc00fcf8, 
column_layouts=0x7fffdc00edc8, batch_size=1024, consumer=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/tile_group.cpp:62

11 0x00007ffff64b7a23 in peloton::codegen::Table::GenerateScan (

this=0x7fffdc00bb40, codegen=..., table_ptr=0x7fffdc00e400, 
tilegroup_start=0x0, tilegroup_end=0x0, batch_size=1024, 
predicate_ptr=0x7fffdc00e668, num_predicates=0, consumer=...)
at /home/pakhtar/proj/master_bin/peloton/src/codegen/table.cpp:122

12 0x00007ffff6443a98 in peloton::codegen::TableScanTranslator::<lambda(peloton::codegen::ConsumerContext&)>::operator()(peloton::codegen::ConsumerContext &) const (__closure=0x7fffe8bfd210, ctx=...)

at /home/pakhtar/proj/master_bin/peloton/src/codegen/operator/table_scan_translator.cpp:194

13 0x00007ffff6444e56 in std::_Function_handler<void(peloton::codegen::ConsumerContext&), peloton::codegen::TableScanTranslator::ProduceSerial() const::<lambda(peloton::codegen::ConsumerContext&)> >::_M_invoke(const std::_Any_data &, pelot---Type to continue, or q to quit---

codegen/type/typesystem.h:37 left is (gdb) print left (gdb) print left $17 = { type = { type_id = peloton::type::TypeId::INTEGER, nullable = true, ...

(gdb) print right $19 = { type_ = { type_id = peloton::type::TypeId::VARCHAR, ...

pervazea commented 6 years ago

$21 = (peloton::expression::ComparisonExpression) {

= { = { _vptr.Printable = 0x7ffff7cd7688 }, members of peloton::expression::AbstractExpression: ival_ = 0, expr_name_ = "", alias = "", distinct_ = false, exp_type_ = peloton::ExpressionType::COMPARE_EQUAL, return_value_type_ = peloton::type::TypeId::BOOLEAN, children_ = std::vector of length 2, capacity 2 = { std::unique_ptr containing 0x7ff4 dc0341b0, std::unique_ptr containing 0x7ff4 d
pervazea commented 6 years ago

Possible solutions discussed yesterday.

  1. Doing conversion from VARCHAR (parameter value) to the target type, in codegen. Rejected.
  2. Modifying the planner / optimizer to add a "type conversion node" into the plan, along with suitable support to execute it in the rest of the system. This was the direction.
tli2 commented 6 years ago

As discussed elsewhere, reason for failing is that libpqxx does not fill type fields in prepare message. We are already casting correctly for types that are known in the binding phase in the network code, but do not do type inference to fix the ones that do not specify types.

A workaround would be to use explicit PREPARE with types as SQL in this test case. I have tested that this resolves the issue.

tli2 commented 6 years ago

fixed with #1408