Skip to content

Conversation

Tmonster
Copy link
Contributor

@Tmonster Tmonster commented Nov 11, 2022

This address fuzzer issue 48 in #4978

Originally an INTERNAL ERROR: BINDER ERROR message was thrown, which I don't think is the most informative message to show users. Especially the INTERNAL ERROR

  • Within the (SELECT 0 OFFSET c0) an informative BinderError is produced, but then BindCorrelatedColumns gets called.
  • Eventually a binding is found for c0 to the alias defined in the first select term and the error is ignored.
  • ExtractCorrelatedExpressions, should then extract the correlated column/alias into the binder context but this doesn't happen.
  • The check bound_colref.depth > 0 in ExtractCorrelatedExpressions is false while the depth of the column c0 is very much 1.
  • This is because we are binding a delimiter in a subquery, and a depth of 0 is assumed. See BindDelimiter() in bind_select_node.cpp, which callsexpr_binder.Bind(delimiter); which calls auto error_msg = Bind(&expr, 0, root_expression); in expression_binder.cpp. The 0 is the depth.
  • So since we are in correlated subqueries, we need to make sure the ColumnRef has the proper depth. Now it is set to the depth determined by logic in the correlatedsubquery code.

I'm not sure if this is the best fix though, as it feels like it could mess up other logic that uses the same code path. Maybe a nicer fix would be passing the depth to the BindDelimiter and keep passing it along? Open to other ideas though.

Copy link
Contributor

@lnkuiper lnkuiper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix seems fine to me (if this doesn't break any other tests)

Although, I wonder what happens if you do:

SELECT avg(0) c0, (SELECT 0 OFFSET c0 + 1);

Will your check still trigger? Since the offset is now no longer a BOUND_COLUMN_REF, but rather an expression. Maybe it still triggers because recursively the colref is bound anyway

@Mytherin Mytherin changed the base branch from master to feature November 15, 2022 12:51
Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! A request for more tests below:

statement error
SELECT avg(0) c0, (SELECT 0 OFFSET c0 + 1);
----
Parser Error: Non-constant limit or offset not supported in correlated subquery
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same error happens if we leave out the offset, e.g.:

D select avg(0) AS c0, (SELECT c0);
Error: INTERNAL Error: Failed to bind column reference "c0" [2.0] (bindings: [15.0])

Could you test that that is fixed as well?

Copy link
Contributor Author

@Tmonster Tmonster Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…g as h2oai also makes an https call to github. Maybe the plan_cost_runner doesnt compile duckdb with httpfs?
@Tmonster Tmonster requested a review from Mytherin November 21, 2022 13:54
@Mytherin Mytherin merged commit 907b60b into duckdb:feature Nov 21, 2022
@Mytherin
Copy link
Collaborator

Thanks! LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants