dolt_history_$tablename returns misaligned data after column drops
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 108
Description
## Summary
After dropping columns from a table via `ALTER TABLE ... DROP COLUMN`, `dolt_history_$tablename` returns data with positional misalignment for historical rows from before the DDL change, even though column names in the schema are correct.
## Steps to Reproduce **[INCORRECT! WIP]**
**UPDATE: This is NOT a valid minimal test case - please see comment below.**
1. Create a table with columns: `id, a, b, c, d` (where `d` is a datetime)
2. Insert data and commit
3. Drop column `b`: `ALTER TABLE t DROP COLUMN b`
4. Commit
5. Query `SELECT h.d FROM dolt_history_t` — the value returned for `d` from the pre-drop commit is actually the old value of column `c` (positional shift)
## Observed Behavior
- `DESCRIBE dolt_history_t` shows the correct current schema (without column `b`)
- But `SELECT` from it returns data positionally from the old schema for rows at historical commits
- This causes type errors when a string value lands in a datetime column slot (e.g. `Mysql2::Error: Incorrect datetime value: 'published'`)
## Expected Behavior
`dolt_history_$tablename` should return data correctly mapped to the named columns, regardless of schema changes in the commit history. Historical rows should have their values projected into the current column layout by name, not by ordinal position.
## Bisection Details
We bisected the issue by incrementally adding columns to the SELECT:
- Columns 1-12 (up to `seat_number`): OK
- Column 13 (`created_at`, a datetime): FAIL with "Incorrect datetime value: 'published'"
The dropped columns (`algorithm_agrees` boolean and `algorithm_recommendation` varchar) were at positions 10-11 in the old schema. After dropping them, columns from position 10 onward shift, but `dolt_history` returns old positional data for historical commits.
## Workaround
Using `CAST(h.column AS CHAR)` avoids the type error but returns garbled data for shifted columns in pre-migration rows.
## Environment
- Dolt version: latest as of 2026-03-15
- Database: MySQL-compatible mode via `dolt sql-server`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.