Skip to content

DuckDB SEGV when running nested PIVOT #14545

Closed
duckdb/duckdb-r
#558
@SteveLeungYL

Description

What happens?

The latest version of the DuckDB (v1.1.3-dev56 39f9863) crashes when running the following SQL statement:

CREATE TABLE v00 (c01 INT);
WITH RECURSIVE ta2205 AS ( SHOW ) PIVOT ( v00 PIVOT ( c01,  FOR IN v00 GROUP BY c01 ) JOIN v00 AS ta2201 USING ( c01 ) ) ON c01;

Here is the stack trace from 39f9863:

(gdb) bt
#0  0x00000000051696ec in duckdb::Transformer::TransformExpressionList (this=0xffffc5afc2e8, list=..., result=...) at /home/duckdb/duckdb/src/parser/transform/expression/transform_expression.cpp:96
#1  0x0000000002c038e0 in duckdb::Transformer::TransformPivotColumn (this=0xffffc5afc2e8, pivot=..., is_pivot=true) at /home/duckdb/duckdb/src/parser/transform/tableref/transform_pivot.cpp:46
#2  0x0000000002c066ac in duckdb::Transformer::TransformPivotList (this=0xffffc5afc2e8, list=..., is_pivot=<optimized out>) at /home/duckdb/duckdb/src/parser/transform/tableref/transform_pivot.cpp:94
#3  0x0000000002c07248 in duckdb::Transformer::TransformPivot (this=0xffffc5afc2e8, root=...) at /home/duckdb/duckdb/src/parser/transform/tableref/transform_pivot.cpp:109
#4  0x0000000002c00e20 in duckdb::Transformer::TransformTableRefNode (this=0xffffc5afc2e8, n=...) at /home/duckdb/duckdb/src/parser/transform/tableref/transform_tableref.cpp:20
#5  0x0000000002bfdb5c in duckdb::Transformer::TransformJoin (this=0xffffc5afc2e8, root=...) at /home/duckdb/duckdb/src/parser/transform/tableref/transform_join.cpp:47
#6  0x0000000002c00f40 in duckdb::Transformer::TransformTableRefNode (this=0xffffc5afc2e8, n=...) at /home/duckdb/duckdb/src/parser/transform/tableref/transform_tableref.cpp:14
#7  0x0000000002ba74f8 in duckdb::Transformer::TransformPivotStatement (this=0xffffc5afc2e8, select=...) at /home/duckdb/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp:138
#8  0x0000000002ba6b48 in duckdb::Transformer::TransformSelectNodeInternal (this=0x34797, select=..., is_select=240) at /home/duckdb/duckdb/src/parser/transform/statement/transform_select.cpp:31
#9  0x0000000002b84ae8 in duckdb::Transformer::TransformSelectStmt (this=0x2048, select=..., is_select=true) at /home/duckdb/duckdb/src/parser/transform/statement/transform_select.cpp:40
#10 0x000000000059adb8 in duckdb::Transformer::TransformStatementInternal (this=0x11, stmt=...) at /home/duckdb/duckdb/src/parser/transformer.cpp:147
#11 0x00000000005992b0 in duckdb::Transformer::TransformStatement (this=0xffffc5afc2e8, stmt=...) at /home/duckdb/duckdb/src/parser/transformer.cpp:59
#12 0x0000000000599ecc in duckdb::Transformer::TransformStatementInternal (this=0x11, stmt=...) at /home/duckdb/duckdb/src/parser/transformer.cpp:139
#13 0x00000000005992b0 in duckdb::Transformer::TransformStatement (this=0xffffc5afc2e8, stmt=...) at /home/duckdb/duckdb/src/parser/transformer.cpp:59
#14 0x000000000057bc94 in duckdb::Transformer::TransformParseTree (this=0xffffc5afc2e8, tree=<optimized out>, statements=...) at /home/duckdb/duckdb/src/parser/transformer.cpp:33
#15 0x0000000000577e60 in duckdb::Parser::ParseQuery (this=0xffffc5afc570, Python Exception <class 'gdb.error'> There is no member named _M_dataplus.: 
query=) at /home/duckdb/duckdb/src/parser/parser.cpp:219
#16 0x00000000004c5e7c in duckdb_shell_sqlite3_prepare_v2 (db=0x16e419b0, zSql=<optimized out>, nByte=<optimized out>, ppStmt=0xffffc5afc698, pzTail=<optimized out>) at ../../tools/sqlite3_api_wrapper/sqlite3_api_wrapper.cpp:176
#17 0x00000000004909c4 in shell_exec (pArg=0xffffc5afc968, 
    zSql=0x16e3b360 "CREATE TABLE v00 (c01 INT);WITH RECURSIVE ta2205 AS ( SHOW ) PIVOT ( v00 PIVOT ( c01,  FOR IN v00 GROUP BY c01 ) JOIN v00 AS ta2201 USING ( c01 ) ) ON c01;", pzErrMsg=<optimized out>)
    at ../../tools/shell/shell.c:12994
#18 0x00000000004b9b94 in runOneSqlLine (p=0xffffc5afc968, 
    zSql=0x16e3b360 "CREATE TABLE v00 (c01 INT);WITH RECURSIVE ta2205 AS ( SHOW ) PIVOT ( v00 PIVOT ( c01,  FOR IN v00 GROUP BY c01 ) JOIN v00 AS ta2201 USING ( c01 ) ) ON c01;", in=<optimized out>, startline=<optimized out>)
    at ../../tools/shell/shell.c:19274
#19 0x0000000000494768 in process_input (p=<optimized out>) at ../../tools/shell/shell.c:19385
#20 0x0000000000475018 in main (argc=<optimized out>, argv=0xffffc5afdd38) at ../../tools/shell/shell.c:20207

To Reproduce

  1. Clone the DuckDB Git from the official repo.
  2. Checkout to either the latest main (39f9863) or release version: 1.1.2 (f680b7d).
  3. Compile the DuckDB binary by using either make reldebug or make debug.
  4. Run the compiled DuckDB and input the following SQL:
CREATE TABLE v00 (c01 INT);
WITH RECURSIVE ta2205 AS ( SHOW ) PIVOT ( v00 PIVOT ( c01,  FOR IN v00 GROUP BY c01 ) JOIN v00 AS ta2201 USING ( c01 ) ) ON c01;

OS:

Ubuntu 20.04 LTS

DuckDB Version:

v1.1.2 f680b7d

DuckDB Client:

cli

Hardware:

No response

Full Name:

Yu Liang

Affiliation:

Pennsylvania State Univerity

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

I have tested with a stable release

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, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions