Skip to content

Grouped aggregate output changes from NULL to a numeric value after view materialization. #162

Description

@123lpygithub

Under SQL-equivalent rewriting, the source and mutated queries differ only in extracting the grouped aggregate into a view. The aggregate output changes from NULL to 1.

Version: 8.0.44-alisql-dev

How to repeat:

DROP VIEW IF EXISTS v;
DROP TABLE IF EXISTS t;

CREATE TABLE t (
  c1 TINYINT NOT NULL,
  c6 VARCHAR(1) NOT NULL
);

CREATE UNIQUE INDEX idx_t_c1 ON t (c1);
CREATE INDEX idx_t_c6 ON t (c6);

INSERT INTO t VALUES (1, 'x');

-- Original SQL
SELECT SUM(DISTINCT c1) AS s,
       ROW_NUMBER() OVER () AS r
FROM t
GROUP BY c6;

-- View SQL
CREATE VIEW v AS
SELECT SUM(DISTINCT c1) AS s,
       c6
FROM t
GROUP BY c6;

-- Mutated SQL
SELECT s,
       ROW_NUMBER() OVER () AS r
FROM v;

Observed mismatch:

  • original result:
s r
NULL 1
  • mutated result:
s r
1 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions