Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fuzzer] Subquery error #4562

Closed
Maxxen opened this issue Sep 2, 2022 · 2 comments · Fixed by #4731
Closed

[Fuzzer] Subquery error #4562

Maxxen opened this issue Sep 2, 2022 · 2 comments · Fixed by #4731
Assignees

Comments

@Maxxen
Copy link
Member

Maxxen commented Sep 2, 2022

Originally discovered in #4152

SELECT (VALUES(1 != ALL(SELECT 2)));

Actual:
src/common/types/vector.cpp:94: void duckdb::Vector::Reference(duckdb::Vector &): Assertion `other.GetType() == GetType()' failed.

Expected:
The query should output a single true value.

@Maxxen
Copy link
Member Author

Maxxen commented Sep 2, 2022

@taniabogatsch I think Thijs forwarded this to you after we got stuck on it, so I've assigned you to it for the time being.

@taniabogatsch
Copy link
Contributor

This triggers an assertion in debug mode, namely

src/common/types/vector.cpp:94: void duckdb::Vector::Reference(duckdb::Vector &): Assertion other.GetType() == GetType()' failed.

GetType() is BOOLEAN, other.GetType() is INTEGER.

The query runs fine in release (ofc because no assertions) with the following output.

D SELECT (VALUES(1 != ALL(SELECT 2)));
┌──────────────────────────────────────────────────────────────────┐
│ (SELECT * FROM (VALUES ((NOT 1 = ANY(SELECT 2)))) AS valueslist) │
├──────────────────────────────────────────────────────────────────┤
│ true                                                             │
└──────────────────────────────────────────────────────────────────┘

If we change the query to the rewritten column name, then it runs both in debug and in release.

D (SELECT * FROM (VALUES ((NOT 1 = ANY(SELECT 2)))) AS valueslist);
┌──────┐
│ col0 │
├──────┤
│ true │
└──────┘

From my understanding this implies that the bug happens somewhere during the construction of the plan? The plans (before the optimization step) are different. If we set a breakpoint in client_context.cpp:324 and print p plan->Print(), then we get these.

Failing query.

┌───────────────────────────┐                             
│         PROJECTION        │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│          SUBQUERY         │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│         AGGREGATE         │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│       first(#[8.0])       │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│           LIMIT           │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│         PROJECTION        │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│            col0           │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│       EXPRESSION_GET      │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│      COMPARISON_JOIN      │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│            MARK           ├──────────────┐              
│      (1) = (#[15.0])      │              │              
└─────────────┬─────────────┘              │                                           
┌─────────────┴─────────────┐┌─────────────┴─────────────┐
│         DUMMY_SCAN        ││         PROJECTION        │
│                           ││   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │
│                           ││             2             │
└───────────────────────────┘└─────────────┬─────────────┘                             
                             ┌─────────────┴─────────────┐
                             │         DUMMY_SCAN        │
                             └───────────────────────────┘    

Running query.

┌───────────────────────────┐                             
│         PROJECTION        │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│            col0           │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│         PROJECTION        │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│            col0           │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│       EXPRESSION_GET      │                             
└─────────────┬─────────────┘                                                          
┌─────────────┴─────────────┐                             
│      COMPARISON_JOIN      │                             
│   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │                             
│            MARK           ├──────────────┐              
│      (1) = (#[14.0])      │              │              
└─────────────┬─────────────┘              │                                           
┌─────────────┴─────────────┐┌─────────────┴─────────────┐
│         DUMMY_SCAN        ││         PROJECTION        │
│                           ││   ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─   │
│                           ││             2             │
└───────────────────────────┘└─────────────┬─────────────┘                             
                             ┌─────────────┴─────────────┐
                             │         DUMMY_SCAN        │
                             └───────────────────────────┘

I feel like my knowledge of the Planner is a bit too limited to debug this efficiently. Is this maybe related to the aggregate + limit that we push because of the subquery? I can continue on this, but maybe @Mytherin you have an idea where this originates exactly?

@Tishj also did some initial debugging of this and I am just gonna put the findings here.

The PhysicalExpressionGet has an OperatorExpression of type OPERATOR_NOT
which has a BoundReferenceExpression as child, bound to index 0. The assertion gets triggered because it's trying to reference an INTEGER vector to a BOOLEAN vector.

This expression refers to a data chunk that comes from PhysicalComparisonJoin, which is of JoinType::MARK,
the mark join adds an extra vector of type BOOLEAN.

Mytherin added a commit to Mytherin/duckdb that referenced this issue Sep 15, 2022
Mytherin added a commit that referenced this issue Sep 16, 2022
Fix #4562: generate table index for dummy scan generated from VALUES clause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants