Skip to content

JIT compilation changes query result (both are correct) #47787

@qoega

Description

@qoega
CREATE TABLE t2 (c0 Int32, c1 Int32, c2 String) ENGINE = Log() ;
INSERT INTO t2(c1, c0) VALUES (1697596429, 1259570390);
INSERT INTO t2(c1, c2) VALUES (-871444251, 's,');
INSERT INTO t2(c0, c2, c1) VALUES (-943999939, '', 1756486294);

Just changing compile_expressions = 0 in a query changes the result.

SELECT MIN(t2.c0)
FROM t2
GROUP BY log(-(t2.c0 / (t2.c0 - t2.c0)))
HAVING NOT (NOT (-(NOT MIN(t2.c0))))
UNION ALL
SELECT MIN(t2.c0)
FROM t2
GROUP BY log(-(t2.c0 / (t2.c0 - t2.c0)))
HAVING NOT (NOT (NOT (-(NOT MIN(t2.c0)))))
UNION ALL
SELECT MIN(t2.c0)
FROM t2
GROUP BY log(-(t2.c0 / (t2.c0 - t2.c0)))
HAVING (NOT (NOT (-(NOT MIN(t2.c0))))) IS NULL
SETTINGS aggregate_functions_null_for_empty = 1, enable_optimize_predicate_expression = 0, compile_expressions = 1

Query id: 0ff319aa-38b2-4553-87b1-05a533db8e4d

┌─MIN(c0)─┐
│       0 │
└─────────┘

1 row in set. Elapsed: 0.004 sec.

SELECT MIN(t2.c0)
FROM t2
GROUP BY log(-(t2.c0 / (t2.c0 - t2.c0)))
HAVING NOT (NOT (-(NOT MIN(t2.c0))))
UNION ALL
SELECT MIN(t2.c0)
FROM t2
GROUP BY log(-(t2.c0 / (t2.c0 - t2.c0)))
HAVING NOT (NOT (NOT (-(NOT MIN(t2.c0)))))
UNION ALL
SELECT MIN(t2.c0)
FROM t2
GROUP BY log(-(t2.c0 / (t2.c0 - t2.c0)))
HAVING (NOT (NOT (-(NOT MIN(t2.c0))))) IS NULL
SETTINGS aggregate_functions_null_for_empty = 1, enable_optimize_predicate_expression = 0, compile_expressions = 0

Query id: 7ee14624-efb5-44b7-ae09-429a180a2816

┌────MIN(c0)─┐
│ 1259570390 │
└────────────┘
┌─MIN(c0)─┐
│       0 │
└─────────┘

2 rows in set. Elapsed: 0.004 sec.

Metadata

Metadata

Assignees

Labels

fuzzProblem found by one of the fuzzerssqlancerIssue found by SQLancer tool

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions