pg_duckdb icon indicating copy to clipboard operation
pg_duckdb copied to clipboard

duckdb leaves stack trace when executing query SELECT MIN(test_value) FROM test_table;

Open saygoodbyye opened this issue 6 months ago • 2 comments

What happens?

PostgreSQL configuration:

CFLAGS='-Og' ./configure --enable-tap-tests  --enable-debug --with-openssl --enable-cassert --with-icu --with-lz4 --with-libxml --quiet --prefix="$PGPREFIX"

To Reproduce

postgresql.conf:

shared_preload_libraries='pg_duckdb'
duckdb.force_execution = true
duckdb.postgres_role = 'duckdb_group'
log_temp_files = -1

test.sql:

CREATE EXTENSION pg_duckdb;
CREATE TABLE num_data (id int4, val numeric(210,10));
SELECT MIN(val) FROM num_data;

result:

test=# CREATE EXTENSION pg_duckdb;
CREATE TABLE num_data (id int4, val numeric(210,10));
SELECT MIN(val) FROM num_data;
CREATE EXTENSION
CREATE TABLE
WARNING:  (PGDuckDB/CreatePlan) Prepared query returned an error: 'INTERNAL Error: Unimplemented type for min/max aggregate

Stack Trace:

/tmp/pgsql/lib/libduckdb.so(duckdb::Exception::ToJSON(duckdb::ExceptionType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)+0x240) [0x7fae649b1120]
/tmp/pgsql/lib/libduckdb.so(duckdb::Exception::ToJSON(duckdb::ExceptionType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x56) [0x7fae649b1426]
/tmp/pgsql/lib/libduckdb.so(duckdb::Exception::Exception(duckdb::ExceptionType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x14) [0x7fae649b14e4]
/tmp/pgsql/lib/libduckdb.so(duckdb::InternalException::InternalException(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x11) [0x7fae649b3511]
/tmp/pgsql/lib/libduckdb.so(duckdb::unique_ptr<duckdb::FunctionData, std::default_delete<duckdb::FunctionData>, true> duckdb::BindMinMax<duckdb::MinOperation, duckdb::MinOperationString, duckdb::MinOperationVector>(duckdb::ClientContext&, duckdb::AggregateFunction&, duckdb::vector<duckdb::unique_ptr<duckdb::Expression, std::default_delete<duckdb::Expression>, true>, true>&)+0x156d) [0x7fae6430161d]
/tmp/pgsql/lib/libduckdb.so(duckdb::FunctionBinder::BindAggregateFunction(duckdb::AggregateFunction, duckdb::vector<duckdb::unique_ptr<duckdb::Expression, std::default_delete<duckdb::Expression>, true>, true>, duckdb::unique_ptr<duckdb::Expression, std::default_delete<duckdb::Expression>, true>, duckdb::AggregateType)+0x44) [0x7fae6468fed4]
/tmp/pgsql/lib/libduckdb.so(duckdb::BaseSelectBinder::BindAggregate(duckdb::FunctionExpression&, duckdb::AggregateFunctionCatalogEntry&, unsigned long)+0x1228) [0x7fae64164988]
/tmp/pgsql/lib/libduckdb.so(duckdb::ExpressionBinder::BindExpression(duckdb::FunctionExpression&, unsigned long, duckdb::unique_ptr<duckdb::ParsedExpression, std::default_delete<duckdb::ParsedExpression>, true>&)+0x17d) [0x7fae6416a73d]
/tmp/pgsql/lib/libduckdb.so(duckdb::ExpressionBinder::BindExpression(duckdb::unique_ptr<duckdb::ParsedExpression, std::default_delete<duckdb::ParsedExpression>, true>&, unsigned long, bool)+0x314) [0x7fae6421dbb4]
/tmp/pgsql/lib/libduckdb.so(duckdb::BaseSelectBinder::BindExpression(duckdb::unique_ptr<duckdb::ParsedExpression, std::default_delete<duckdb::ParsedExpression>, true>&, unsigned long, bool)+0x64) [0x7fae641ebca4]
/tmp/pgsql/lib/libduckdb.so(duckdb::ExpressionBinder::Bind(duckdb::unique_ptr<duckdb::ParsedExpression, std::default_delete<duckdb::ParsedExpression>, true>&, unsigned long, bool)+0xa0) [0x7fae64217db0]
/tmp/pgsql/lib/libduckdb.so(duckdb::ExpressionBinder::Bind(duckdb::unique_ptr<duckdb::ParsedExpression, std::default_delete<duckdb::ParsedExpression>, true>&, duckdb::optional_ptr<duckdb::LogicalType, true>, bool)+0x30) [0x7fae6422eb10]
/tmp/pgsql/lib/libduckdb.so(duckdb::Binder::BindSelectNode(duckdb::SelectNode&, duckdb::unique_ptr<duckdb::BoundTableRef, std::default_delete<duckdb::BoundTableRef>, true>)+0x1a6a) [0x7fae6418772a]
/tmp/pgsql/lib/libduckdb.so(duckdb::Binder::BindNode(duckdb::SelectNode&)+0x61) [0x7fae64188761]
/tmp/pgsql/lib/libduckdb.so(duckdb::Binder::BindNode(duckdb::QueryNode&)+0xc5) [0x7fae64224d15]
/tmp/pgsql/lib/libduckdb.so(duckdb::Binder::Bind(duckdb::QueryNode&)+0x54) [0x7fae64225524]
/tmp/pgsql/lib/libduckdb.so(duckdb::Binder::Bind(duckdb::SelectStatement&)+0x3a) [0x7fae641924da]
/tmp/pgsql/lib/libduckdb.so(duckdb::Binder::Bind(duckdb::SQLStatement&)+0x215) [0x7fae64225f25]
/tmp/pgsql/lib/libduckdb.so(duckdb::Planner::CreatePlan(duckdb::SQLStatement&)+0xa5) [0x7fae64230f45]
/tmp/pgsql/lib/libduckdb.so(duckdb::ClientContext::CreatePreparedStatementInternal(duckdb::ClientContextLock&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, duckdb::unique_ptr<duckdb::SQLStatement, std::default_delete<duckdb::SQLStatement>, true>, duckdb::optional_ptr<std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, duckdb::BoundParameterData, duckdb::CaseInsensitiveStringHashFunction, duckdb::CaseInsensitiveStringEquality, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, duckdb::BoundParameterData> > >, true>)+0x2e8) [0x7fae64db57f8]
/tmp/pgsql/lib/libduckdb.so(duckdb::ClientContext::CreatePreparedStatement(duckdb::ClientContextLock&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, duckdb::unique_ptr<duckdb::SQLStatement, std::default_delete<duckdb::SQLStatement>, true>, duckdb::optional_ptr<std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, duckdb::BoundParameterData, duckdb::CaseInsensitiveStringHashFunction, duckdb::CaseInsensitiveStringEquality, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, duckdb::BoundParameterData> > >, true>, duckdb::PreparedStatementMode)+0x2f2) [0x7fae64db6382]
/tmp/pgsql/lib/libduckdb.so(+0x17b65cc) [0x7fae64db65cc]
/tmp/pgsql/lib/libduckdb.so(duckdb::ClientContext::RunFunctionInTransactionInternal(duckdb::ClientContextLock&, std::function<void ()> const&, bool)+0x6c) [0x7fae64da1c0c]
/tmp/pgsql/lib/libduckdb.so(duckdb::ClientContext::PrepareInternal(duckdb::ClientContextLock&, duckdb::unique_ptr<duckdb::SQLStatement, std::default_delete<duckdb::SQLStatement>, true>)+0x17d) [0x7fae64da1fbd]
/tmp/pgsql/lib/libduckdb.so(duckdb::ClientContext::Prepare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0xc3) [0x7fae64dc10d3]
/tmp/pgsql/lib/pg_duckdb.so(+0x2f2486) [0x7fae66cf2486]
/tmp/pgsql/lib/pg_duckdb.so(+0x2f27e6) [0x7fae66cf27e6]
/tmp/pgsql/lib/pg_duckdb.so(+0x2f33b1) [0x7fae66cf33b1]
/tmp/pgsql/lib/pg_duckdb.so(+0x2c6fab) [0x7fae66cc6fab]
/tmp/pgsql/lib/pg_duckdb.so(+0x2c7159) [0x7fae66cc7159]
postgres: test test [local] SELECT(pg_plan_query+0xc8) [0x561157542f88]
postgres: test test [local] SELECT(pg_plan_queries+0x127) [0x561157543237]
postgres: test test [local] SELECT(+0x2efad43) [0x561157543d43]
postgres: test test [local] SELECT(PostgresMain+0x2e11) [0x561157547751]
postgres: test test [local] SELECT(BackendMain+0x156) [0x5611575397f6]
postgres: test test [local] SELECT(postmaster_child_launch+0x201) [0x5611572cab61]
postgres: test test [local] SELECT(+0x2c8a1f1) [0x5611572d31f1]
postgres: test test [local] SELECT(PostmasterMain+0x19bf) [0x5611572d6b0f]
postgres: test test [local] SELECT(main+0x2ac) [0x561156509cec]
/lib/x86_64-linux-gnu/libc.so.6(+0x2724a) [0x7fae6aa4624a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x7fae6aa46305]
postgres: test test [local] SELECT(_start+0x21) [0x56115650f861]

This error signals an assertion failure within DuckDB. This usually occurs due to unexpected conditions or errors in the program's logic.
For more information, see https://duckdb.org/docs/dev/internal_errors
 min
-----

(1 row)

OS:

Debian-12

pg_duckdb Version (if built from source use commit hash):

49cd67618e683a15404f9edd78e2b4e79b401547

Postgres Version (if built from source use commit hash):

002938f15c63a52bfb191dce9496486a4bbfb757

Hardware:

No response

Full Name:

Egor Chindyaskin

Affiliation:

Postgres Professional

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • [ ] Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • [ ] Yes, I have

saygoodbyye avatar Jun 05 '25 13:06 saygoodbyye

The exception comes from DuckDB. I guess we could remove it but it might be useful to have it handy in some cases. @JelteF wdyt? Should we keep it under a compilation flag?

Y-- avatar Jun 05 '25 13:06 Y--

I'd say the stack trace is fine. But the fact that we get this error is a problem.

JelteF avatar Jun 11 '25 11:06 JelteF