Skip to content

sql: invalid argument to asin(), acosd(), and asind() results in NaN instead of error #168595

@dddddddcoconut

Description

@dddddddcoconut

Describe the problem

The query returns duplicated rows and repeated columns when using SELECT DISTINCT together with GROUP BY on a single column, while also containing an ANY predicate involving ASIND().

Although only one grouping key (t0.c0) is used, the result set contains repeated identical columns and multiple rows that appear to be derived solely from a cross join with t59, even though t59 does not contribute to projection.

This suggests incorrect interaction between:

  • DISTINCT
  • GROUP BY
  • ANY subquery expression
  • ASIND() function rewrite or evaluation

To Reproduce

DROP TABLE IF EXISTS t0;
DROP TABLE IF EXISTS t59;

CREATE TABLE t0 (
c0 TIMESTAMP,
c1 FLOAT
);

CREATE TABLE t59 ( x INT);

INSERT INTO t0 VALUES
('1969-12-24 01:54:36+08', 0.18),
('1969-12-13 01:19:22+08', NULL),
('1970-01-01 00:00:00+08', 1.2), -- out of domain
('1970-01-02 00:00:00+08', -1.2); -- out of domain

INSERT INTO t59 VALUES (1);

SELECT DISTINCT t0.c0, t0.c0, t0.c0
FROM t0, t59
WHERE (0.18064210411325599 > ANY (t0.c1, ASIND(t0.c1)))
GROUP BY t0.c0
LIMIT 10;

Expected behavior
Each t0.c0 value should appear at most once due to GROUP BY t0.c0 and DISTINCT.
Output columns should not be duplicated (c0, c0, c0 should be normalized or collapsed).
The presence of t59 (which is not referenced in projection or filter logically affecting grouping) should not affect result multiplicity.
The ANY condition involving ASIND(t0.c1) should not introduce unintended row multiplication or rewrite inconsistencies.

Expected result should be logically equivalent to:

c0 c0 c0
1969-12-24 01:54:36.000000 1969-12-24 01:54:36.000000 1969-12-24 01:54:36.000000
1970-01-02 00:00:00.000000 1970-01-02 00:00:00.000000 1970-01-02 00:00:00.000000

Additional data / screenshots
Actual output:

c0 c0 c0
1969-12-24 01:54:36.000000 1969-12-24 01:54:36.000000 1969-12-24 01:54:36.000000
1970-01-01 00:00:00.000000 1970-01-01 00:00:00.000000 1970-01-01 00:00:00.000000
1970-01-02 00:00:00.000000 1970-01-02 00:00:00.000000 1970-01-02 00:00:00.000000

Environment:
Impact:

  • Potential incorrect query rewrite or optimization involving scalar functions (ASIND) inside ANY
  • Possible interaction bug between:
    scalar function evaluation
    join planning (FROM t0, t59)
    aggregation (GROUP BY)
    DISTINCT projection normalization

This may lead to incorrect result shaping and unexpected column duplication in query output, which is especially problematic for ORM / JDBC clients relying on stable schema inference.

Jira issue: CRDB-63031

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the communityT-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)X-blathers-triagedblathers was able to find an ownertarget-release-26.3.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions