duckdb / duckdb

DuckDB is an analytical in-process SQL database management system
http://www.duckdb.org
MIT License
22.88k stars 1.82k forks source link

Segmentation fault on `BETWEEN` #6861

Closed DerZc closed 1 year ago

DerZc commented 1 year ago

What happens?

The following program triggers a segmentation fault:

CREATE TABLE t0(c0 TIMESTAMP);

INSERT INTO t0(c0) VALUES ((DATE '1969-12-10')), ((DATE '1969-12-16')), ((DATE '1969-12-07')), ((TIMESTAMP '1969-12-09 10:08:32')), ((DATE '1969-12-30')), ((TIMESTAMP '1969-12-21 00:06:38'));

CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0;

UPDATE t0 SET c0=(NULL);

SELECT t0.c0 FROM t0, v0 WHERE (v0.c0 BETWEEN t0.c0 AND t0.c0);

To Reproduce

I build DuckDB from the last version of source code, just with make command. I can reproduce this bug with CLI.

OS:

ubuntu 22.04

DuckDB Version:

commit version b8cf6a98

DuckDB Client:

CLI

Full Name:

Chi Zhang

Affiliation:

Nanjing University, National University of Singapore

Have you tried this on the latest master branch?

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

Tishj commented 1 year ago

There are other open issues with BETWEEN, which are likely related I'd say Stack trace for this issue:

/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/vector:1572:12: runtime error: reference binding to null pointer of type 'std::unique_ptr<duckdb::SortedBlock>'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/vector:1572:12 in

It's not related to BETWEEN, rewriting it to the verbose version produces the same issue:

statement ok
SELECT
    t0.c0
FROM t0, v0 WHERE (
    v0.c0 >= t0.c0 AND v0.c0 <= t0.c0
);
DerZc commented 1 year ago

Thank you for your confirmation. I'm very sorry that this title misled you.

Tishj commented 1 year ago

Oh that's not it, just investigated a little to see if this was a duplicate of another issue, wanted to post some extra debugging information :)

xuke-hat commented 1 year ago

It is because IEJoin doesn't check for all-null case, I will open a PR for this.