TIME Type Precision Support in Foreign Key Constraints
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 120
Description
Two tests in the time with foreign keys script are failing because our current implementation doesn't properly support TIME precision in foreign key constraints (dolthub/dolt#9544)
All TIME types in the codebase are normalized to TIME(6) internally, as confirmed in `/workspace/go-mysql-server/sql/types/time.go`. This can't distinguish between TIME(0) and TIME(6) at runtime, causing inconsistent behavior with foreign key constraints.
MySQL Behavior
```sql
-- Parent tables
CREATE TABLE parent_t0 (t TIME PRIMARY KEY);
CREATE TABLE parent_t6 (t TIME(6) PRIMARY KEY);
INSERT INTO parent_t0 VALUES ('12:34:56'); -- Stored as '12:34:56'
INSERT INTO parent_t6 VALUES ('12:34:56'); -- Stored as '12:34:56.000000'
-- Child tables with foreign keys
CREATE TABLE child_t0_p6 (t TIME, FOREIGN KEY (t) REFERENCES parent_t6(t));
CREATE TABLE child_t6_p0 (t TIME(6), FOREIGN KEY (t) REFERENCES parent_t0(t));
-- These inserts fail with foreign key violations
INSERT INTO child_t0_p6 VALUES ('12:34:56'); -- TIME(0) → TIME(6) - Fails
INSERT INTO child_t6_p0 VALUES ('12:34:56'); -- TIME(6) → TIME(0) - Fails
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading /workspace/go-mysql-server/sql/types/time.go and running the two failing tests in the time with foreign keys script. Trace how TIME precision is represented during foreign-key checks; done means the TIME(0)/TIME(6) cases match the documented MySQL behavior without breaking existing foreign-key tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, mysql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100