[expression] Vectorized WEEKDAY can silently delete incomplete-date rows
- 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 730be34f9591; real TiKV; default strict DELETE, default vectorization, MDL ON; no injection
**Steps**
Insert 2024-00-15, 2024-01-00, and valid 2024-01-15 into a DATE column under ALLOW_INVALID_DATES, then restore the default strict mode. Join identical scalar and vectorized copies to weekday keys 4 and 6 through WEEKDAY(d), execute DELETE with vectorization OFF and ON, and compare the full surviving primary-key sets.
### 2. What did you expect to see? (Required)
WEEKDAY rejects both all-zero and incomplete DATE values in every execution mode. Default-strict DELETE returns error 1292 and preserves IDs 1,2,3.
### 3. What did you see instead? (Required)
Scalar DELETE returns 1292 and preserves IDs 1,2,3. Default vectorized DELETE succeeds, reports two affected rows, deletes IDs 1 and 2, and leaves only ID 3. ADMIN CHECK remains green because the wrong rows were removed consistently.
### 4. What is your TiDB version? (Required)
TiDB 13282a8bd0; TiKV 730be34f9591; real TiKV; default strict DELETE, default vectorization, MDL ON; no injection
Likely root cause and fix direction
**Likely root cause**
builtinWeekDaySig.evalInt rejects date.IsZero() || date.InvalidZero(). builtinWeekDaySig.vecEvalInt checks only IsZero, so incomplete month or day values reach Weekday() and become ordinary integers. WEEK, WEEKOFYEAR, and YEARWEEK contain the same predicate-strength gap and are blast radius of this week-family root.
**Fix direction**
Make every week-family vectorized guard preserve the scalar invalid-date domain, including InvalidZero, and add scalar/vector terminal parity for incomplete month and day values. Keep the one-guard fixed-binary strict-DML oracle.
Contributor guide
Research direction
Start by locating builtinWeekDaySig.evalInt and vecEvalInt, then compare the corresponding WEEK, WEEKOFYEAR, and YEARWEEK vectorized entry points against scalar invalid-date handling. Re-run the supplied strict-DML reproduction with vectorization OFF and ON; done means incomplete dates consistently raise 1292, preserve IDs 1,2,3, and scalar/vector terminal behavior matches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100