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

Query using the LN() function does not terminate #518

Closed
mrigger opened this issue Apr 11, 2020 · 2 comments · Fixed by #519
Closed

Query using the LN() function does not terminate #518

mrigger opened this issue Apr 11, 2020 · 2 comments · Fixed by #519

Comments

@mrigger
Copy link
Contributor

mrigger commented Apr 11, 2020

Consider the following statements:

CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT);
INSERT INTO t0(c0) VALUES (0);
INSERT INTO t1(c0) VALUES (0), (0), (1), (-1);
SELECT * FROM t0, t1 WHERE LN(t1.c0) < t0.c0; -- does not terminate

Unexpectedly, the SELECT does not terminate.

I found this bug based on the latest master commit (9795d18).

@Mytherin
Copy link
Collaborator

Very interesting! I wonder what causes this :)

Mytherin added a commit that referenced this issue Apr 11, 2020
…d of potential NaN values, and fix merge join on NaN values (fixes #518)
@Mytherin
Copy link
Collaborator

Fixed in 230785f. The issue was that LN(-1) or LN(0) produced a NaN value, which resulted in an infinite loop in the quick sort step of the merge join. The reason for that is that we had a loop in the form of:

while(i < j) {
    while (data[i] < data[pivot]) {
         i++;
    }
    while (data[pivot] < data[j]) {
        j--;
    }
    if (i < j) {
       swap(data[i], data[j]);
    }
}

However, since NaN always compares false with any other value, this loop became infinite as the conditions to trigger either i++ or j-- were never triggered.

I fixed this case by filtering out NaN values prior to the sort, similar to how NULL values were handled, and also changed the LN, LOG2, LOG10 and SQRT operators to return in a NULL if given invalid input, rather than potentially producing NaN or infinite.

@hannes hannes linked a pull request Apr 12, 2020 that will close this issue
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 a pull request may close this issue.

2 participants