matrixorigin / matrixorigin/matrixone

[Compatibility]: MAKEDATE returns VARCHAR instead of DATE

Open
#28,493 0 comments 0 reactions 1 assignee Claimed by @jiangxinmeng1 View on GitHub
area/compatibility kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## Environment

- MatrixOne: latest `main`, commit `f0c31cd4b830be32442cf329e0a3fb08aa9c16c3`
- MySQL comparison: 8.3.0

## Problem

`MAKEDATE(year, dayofyear)` returns an unbounded `VARCHAR` in MatrixOne instead of a `DATE`. The displayed text looks like a date, but the SQL result domain, wire-protocol metadata, derived schema, and downstream type propagation are all wrong.

## Reproduction

```sql
SELECT MAKEDATE(2024, 60) AS d;

CREATE TABLE copied AS
SELECT MAKEDATE(2024, 60) AS d;

SHOW CREATE TABLE copied;
```

MatrixOne reports the scalar as MySQL protocol type 253 (`VAR_STRING`) with length 65535 and creates:

```sql
CREATE TABLE `copied` (
`d` varchar(65535) DEFAULT NULL
)
```

MySQL 8.3 reports protocol type 10 (`DATE`) and creates:

```sql
CREATE TABLE `copied` (
`d` date DEFAULT NULL
)
```

## Downstream effects

The incorrect string domain propagates through other date-capable expressions:

```sql
SELECT MAKEDATE(2024,60) + INTERVAL 1 DAY;
SELECT GREATEST(MAKEDATE(2024,60), CAST('2024-03-01' AS DATE));
SELECT MAKEDATE(2024,60) AS d UNION ALL SELECT CAST('2024-03-01' AS DATE);
```

MatrixOne reports string metadata for each result; MySQL keeps a date result. A view over `MAKEDATE` likewise exposes `VARCHAR(65535)` in `information_schema.columns` instead of `DATE`.

## Coverage

The following paths were repeated three times:

- valid and invalid scalar calls;
- text-protocol result metadata;
- SQL prepared statement execution and metadata;
- date arithmetic, `YEAR`, comparison, `GREATEST`, and `UNION`;
- view metadata and CTAS schema/value persistence.

An explicit `CAST(... AS DATE)` control is reported as protocol type 10 by both systems. The server remains healthy after all runs.

## Code analysis

The `MAKEDATE` registration in `pkg/sql/plan/function/list_builtIn.go` declares:

```go
args: []types.T{types.T_varchar, types.T_varchar},
retType: func(parameters []types.Type) types.Type {
return types.T_varchar.ToType()
},
```

`MakeDateString` in `pkg/sql/plan/function/func_binary.go` formats the date and appends bytes to a varlen result. There is no typed `DATE` result path, so every downstream consumer sees a string rather than a date.

## Duplicate check

#26830 included `MAKEDATE` only as one example of incorrect nullability for NULL-producing functions; it did not cover the function's return domain and is closed. This issue is independent.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.