[MDEV-24824] Can't add non-null column to versioned table Created: 2021-02-09 Updated: 2021-02-12 Resolved: 2021-02-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Versioned Tables |
| Affects Version/s: | 10.5.8 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Remy Fox | Assignee: | Sergei Golubchik |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Evolving applications sometimes add new columns to tables. Sensible values may be added for existing rows in those tables. Versioned tables don't sufficiently support this practice. An error 1265 shows when adding a new, non null column to a versioned table. Example 1:
Example 2:
Interestingly, this does not fail. Example 3:
Example 2 and 3 do the same thing, so this is clearly a bug. In any way, an additional ideal solution would be to allow queries that can alter historical rows, so that the historical nulls can get a sensible value too. |
| Comments |
| Comment by Ian Gilfillan [ 2021-02-10 ] | |||||||
|
In SQL Server, this is handled by setting a DEFAULT value when adding (or altering) a new NOT NULL column, which is then applied to the history. See https://docs.microsoft.com/en-us/sql/relational-databases/tables/changing-the-schema-of-a-system-versioned-temporal-table?view=sql-server-ver15 But this doesn't appear to work in MariaDB. In the meantime I will document this limitation explicitly. | |||||||
| Comment by Sergei Golubchik [ 2021-02-10 ] | |||||||
|
Doesn't look like a bug to me. In the examples 1 and 2 you have a column with (historical) NULL values, and your ALTER converts it to NOT NULL. This causes "1265: Data truncated for column 'b'". Compare with
No system versioning. Same error. In your third example you add a NOT NULL column, so you don't convert NULL values to not null. | |||||||
| Comment by Remy Fox [ 2021-02-10 ] | |||||||
|
@Sergei I see. In your parallel example on normal tables at least I have to option to update rows in between the two ALTER TABLE statements so as to supply sensible values. Has MariaDB planned to enable updating historical rows so as to supply sensible values? | |||||||
| Comment by Sergei Golubchik [ 2021-02-10 ] | |||||||
|
No, so far we only planned to allow INSERT's for mysqldump to work.
this will make NULL-to-empty-string conversion a warning, but not an error. | |||||||
| Comment by Remy Fox [ 2021-02-10 ] | |||||||
|
What should I do if I wanted a more sophisticated historical value in a new column? E.g. a historically valid foreign key or some other sensible expression? It is natural for data models to evolve over time and so is the practice of updating rows for a column that did not exist previously. Example 1: Example 2: You cannot successfully make your historical selections on the historical tables any longer, after these changes. | |||||||
| Comment by Sergei Golubchik [ 2021-02-12 ] | |||||||
|
there's a workaround with two ALTER's. Something like (using your first example}
|