pingcap / pingcap/tidb

[expression] Vectorized ADDTIME can accept a datetime duration and overwrite rows that scalar execution rejects

Open
#70,124 1 comment 0 reactions 0 assignees View on GitHub
affects-7.5 affects-8.1 affects-8.5 component/expression found-by-ai severity/critical type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

**Environment**

TiDB 13282a8bd0; TiKV 730be34f; PD f7db4252; default vector+strict+MDL; real TiKV; no injection

**Steps**

Create a VARCHAR source with base datetime strings and delta strings 2024-01-02 03:04:05, 0000-00-00 01:02:03, and valid 01:02:03. Seed scalar and vector destination copies with NOT NULL DATETIME values and payload markers. Run identical REPLACE INTO dst SELECT id,ADDTIME(base,delta),new with tidb_enable_vectorized_expression OFF and ON in separate sessions.

### 2. What did you expect to see? (Required)

Scalar and vectorized ADDTIME enforce the same pure-duration domain for the second string argument. Both strict writes return 1048 on the first NULL result and preserve every destination preimage.

### 3. What did you see instead? (Required)

Scalar ADDTIME returns NULL for both date-bearing delta strings, so strict REPLACE returns 1048 and preserves all four rows. Default vectorized ADDTIME returns 2024-01-01 03:04:05 and 2024-01-02 01:02:03, reports success with zero warnings, and replaces the two protected rows. The valid duration control is updated in both semantics.

### 4. What is your TiDB version? (Required)

TiDB 13282a8bd0; TiKV 730be34f; PD f7db4252; default vector+strict+MDL; real TiKV; no injection

Likely root cause and fix direction

**Likely root cause**

After ParseDuration succeeds, builtinAddStringAndStringSig.evalString applies a second parser check that rejects number-hyphen-remainder input because it belongs to the datetime domain. The generated vector implementation omits that post-parse classifier and assumes ParseDuration success proves a pure duration. SUBTIME shares the same generated omission.

**Fix direction**

Copy the scalar date-part rejection into the shared AddTime/SubTime vector generation template immediately after string-to-duration parsing. Add scalar/vector parity over date-bearing and pure-duration VARCHAR values plus a strict NOT NULL REPLACE preimage oracle.

Contributor guide

Open the contributing guide

Research direction

Start with builtinAddStringAndStringSig.evalString and the shared AddTime/SubTime vector generation template, then run the minimal scalar/vector ADDTIME reproduction from the issue. Done means date-bearing duration strings have matching scalar and vector behavior, with parity coverage for date-bearing and pure-duration VARCHAR values and the strict NOT NULL REPLACE preimage oracle.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.