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

MERGE_JOIN nil comparison found in operand #5633

Closed
max-hoffman opened this issue Mar 24, 2023 · 1 comment
Closed

MERGE_JOIN nil comparison found in operand #5633

max-hoffman opened this issue Mar 24, 2023 · 1 comment
Labels
analyzer bug Something isn't working sql Issue with SQL

Comments

@max-hoffman
Copy link
Contributor

max-hoffman commented Mar 24, 2023

Triggering query below, better repro soon. This one seems kind of strange, we explicitly check for and handle ErrNilOperand in Equals, RegExp, GreaterThan, GreaterThanOrEqual, LessThan, and LessThanOrEqual. As far as I can tell, there are no unhandled filters in the queries below. The error type check may be failing.

SELECT `ipam_prefix`.`id`, `ipam_prefix`.`created`, `ipam_prefix`.`last_updated`, `ipam_prefix`.`_custom_field_data`, `ipam_prefix`.`status_id`, `ipam_prefix`.`network`, `ipam_prefix`.`broadcast`, `ipam_prefix`.`prefix_length`, `ipam_prefix`.`site_id`, `ipam_prefix`.`location_id`, `ipam_prefix`.`vrf_id`, `ipam_prefix`.`tenant_id`, `ipam_prefix`.`vlan_id`, `ipam_prefix`.`role_id`, `ipam_prefix`.`is_pool`, `ipam_prefix`.`description`
FROM `ipam_prefix`
LEFT OUTER JOIN `ipam_vrf`
ON (`ipam_prefix`.`vrf_id` = `ipam_vrf`.`id`)
WHERE `ipam_prefix`.`prefix_length` = 15
ORDER BY `ipam_vrf`.`name` ASC, `ipam_prefix`.`network` ASC, `ipam_prefix`.`prefix_length` ASC

error: nil comparison found in operand

@max-hoffman max-hoffman transferred this issue from dolthub/go-mysql-server Mar 27, 2023
@timsehn timsehn added sql Issue with SQL analyzer bug Something isn't working labels Mar 27, 2023
@max-hoffman
Copy link
Contributor Author

This is a merge join bug, mergeJoinIter.peekMatch calls Compare without checking for a nil error:

diff --git a/sql/plan/merge_join.go b/sql/plan/merge_join.go
index 9f5910073..84287fa76 100644
--- a/sql/plan/merge_join.go
+++ b/sql/plan/merge_join.go
@@ -458,7 +458,10 @@ func (i *mergeJoinIter) peekMatch(ctx *sql.Context, iter sql.RowIter) (bool, sql
        // check if lookahead valid
        copySubslice(i.fullRow, peek, off)
        res, err := i.cmp.Compare(ctx, i.fullRow)
-       if err != nil {
+       if expression.ErrNilOperand.Is(err) {
+               // revert change to output row if no match
+               copySubslice(i.fullRow, restore, off)
+       } else if err != nil {
                return false, nil, err
        }

peekMatch is only called immediately after we have a merge join match, so reaching this code is not trivial. We need the indexes to have a matching row, and then immediately have a null field.

@max-hoffman max-hoffman changed the title LEFT_OUTER_JOIN nil comparison found in operand MERGE_JOIN nil comparison found in operand Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer bug Something isn't working sql Issue with SQL
Projects
None yet
Development

No branches or pull requests

2 participants