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
Unexpected result when using trigonomeric functions #3981
Comments
Greetings. Unfortunately, I do not understand your test case. Simplified you execute: select asin(2), 1, asin(2) > 1, True = (asin(2) > 1);
select 1 WHERE (asin(2)) > (1); NaN 1 TRUE TRUE 1 |
There is some weird type conversion somewhere: -- returns 1
SELECT * FROM t1 WHERE (ASIN(2))>(cast(t1.c0 as int));
-- returns 1
SELECT * FROM t1 WHERE (ASIN(2))>(cast(1 as int));
-- returns 1
SELECT * FROM t1 WHERE (ASIN(2))>(1);
-- returns nothing
SELECT * FROM t1 WHERE (ASIN(2))>(t1.c0); I think this issue is legit because it may represent more useful use cases where this goes wrong. |
Interesting! ONLY the private void testRoundingNegative() throws SQLException {
try (
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
) {
stat.execute("CREATE TABLE t1(c0 INT, PRIMARY KEY(c0))");
stat.execute("INSERT INTO t1 VALUES (1);");
try (
ResultSet rs = stat.executeQuery("SELECT * FROM t1 WHERE (ASIN(2))>(t1.c0);");
) {
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
}
}
} I assume, that Primary Key affects/changes the type of the column somehow. (I may be very wrong on this). |
It gets more interesting since it depends how/when the -- Works!
DROP TABLE IF EXISTS PUBLIC.T1;
CREATE TABLE PUBLIC.T1 (
C0 INTEGER NULL
);
INSERT INTO PUBLIC.T1 VALUES (1);
SELECT * FROM t1 WHERE (ASIN(2))>(t1.c0);
-- Works!
DROP TABLE IF EXISTS PUBLIC.T1;
CREATE TABLE PUBLIC.T1 (
C0 INTEGER NOT NULL
);
INSERT INTO PUBLIC.T1 VALUES (1);
ALTER TABLE PUBLIC.T1 ADD PRIMARY KEY (C0);
SELECT * FROM t1 WHERE (ASIN(2))>(t1.c0);
-- Fails!
DROP TABLE IF EXISTS PUBLIC.T1;
CREATE TABLE PUBLIC.T1 (
C0 INTEGER PRIMARY KEY
);
INSERT INTO PUBLIC.T1 VALUES (1);
SELECT * FROM t1 WHERE (ASIN(2))>(t1.c0); |
There are two different problems.
|
I also understand, that comparison of value vs. comparison of index value may run through different code paths, fine. I have checked the column definition according to |
It does matter, because different types of indexes will be used (if column has |
Aha!!!!
|
Maybe I understand what happens: in MVPrimaryIndex won't find anything for @Override
public Cursor find(SessionLocal session, SearchRow first, SearchRow last) {
long min = extractPKFromRow(first, Long.MIN_VALUE);
long max = extractPKFromRow(last, Long.MAX_VALUE);
return find(session, min, max);
} and so does not return a record. Further I assume the solution was to NOT use indexes when Error values are involved. First of all someone needs to decide on he direction here please. I myself would rather fix the comparisons against Error Values. |
@manticore-projects |
Thank you a lot for this explanation @andreitokar. Can we start with saving this snippet above and publish it to the website? |
What makes you to believe that my vague recollection can't be outdated or misleading? 😄 |
Thank you @andreitokar, I fully agree with you that only source is the reliable documentation. |
Consider the following test cases. It is unexpected that the second query return
TRUE
and the third query return an empty result. If it is expected that the second query returnTRUE
, then the third query should return the row in the table.I originally find this by building the latest source version cd09d93. I could also reproduce this in 2.2.224.
Here's how I start H2 Shell:
The text was updated successfully, but these errors were encountered: