pingcap / pingcap/tidb

[expression] Vectorized TO_DAYS can successfully delete incomplete DATE rows that scalar evaluation rejects

Open
#70,117 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 master 05b396fb66; default vectorized expression; default strict mode during DELETE; MDL ON; one TiDB

**Steps**

Load 2024-00-15, 2024-01-00, and 2024-01-15 into two DATE tables under ALLOW_INVALID_DATES, restore the default strict SQL mode, and create day_keys containing 739234 and 739250. Run DELETE s FROM source s JOIN day_keys k ON TO_DAYS(s.d)=k.day_no once with tidb_enable_vectorized_expression=OFF and once with the default ON. Record the root Projection plan, statement terminal, affected rows, surviving IDs, MDL, and SQL mode.

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

The vectorized evaluator preserves the scalar InvalidZero terminal. Under default strict mode, the DELETE returns error 1292 and all three source rows remain.

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

Scalar evaluation returns error 1292 and leaves IDs 1,2,3. Default vectorized evaluation returns success, reports two affected rows, deletes the incomplete DATE rows with IDs 1 and 2, and leaves only ID 3.

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

TiDB master 05b396fb66; default vectorized expression; default strict mode during DELETE; MDL ON; one TiDB

Likely root cause and fix direction

**Likely root cause**

builtinToDaysSig.evalInt rejects arg.InvalidZero before TimestampDiff. builtinToDaysSig.vecEvalInt omits that guard and turns incomplete DATE values into ordinary day numbers, which become matching root HashJoin keys consumed by DELETE.

**Fix direction**

Copy the scalar InvalidZero guard and terminal mapping into vecEvalInt. Add explicit scalar/vector parity for incomplete DATE values and a strict multi-table DELETE test. Audit every scalar-only validation added by historical fixes across vectorized and remote twins.

Contributor guide

Open the contributing guide

Research direction

Start at builtinToDaysSig.evalInt and builtinToDaysSig.vecEvalInt, then reproduce the stated DELETE with vectorized evaluation both enabled and disabled. Compare the scalar and vectorized terminals for incomplete DATE values; done means InvalidZero behavior matches and a strict multi-table DELETE regression test confirms all three rows remain on error 1292.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
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.