-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support altering column's data type #3517
Comments
Step for modify column
How it works?: #3701 (comment) There is still one issue that has not yet been resolved:When modify column, it need to read all the data in this column of the table and check whether each piece of data can be converted e.g. How do I implement it in |
Validating whether all data are valid is too expensive. We have some other options if we can't cast the value
Maybe we can specify which value to fill in the |
I love this idea and will implement it when PR: apache/datafusion-sqlparser-rs#1216 is merged if you think my steps are feasible |
We can build this feature in a bottom-up pattern. Let's modify the We can also set up a simple rule.
PostgreSQL's syntax is enough so I don't think we must support MySQL's alter syntax. |
Got it, then I will implement it in the reverse order of steps |
We might also add some tests in this file. For example: insert data, change column type, insert data, scan https://github.com/GreptimeTeam/greptimedb/blob/main/src/mito2/src/engine/alter_test.rs |
What problem does the new feature solve?
Sometimes user just want to modify the column's data type.
What does the feature do?
Make column's data type changeable via "alter column" stmt. For example, in mysql:
(see https://dev.mysql.com/doc/refman/8.0/en/alter-table.html). Or in postgresql:
(see https://www.postgresql.org/docs/current/sql-altertable.html).
We might want to go with mysql's "alter column" syntax for the conciseness.
One critical consideration is how to deal with un-convertable data. For example, when you modify the column from string to int, how to deal with the un-convertable data of "a"? In mysql, this results in an error:
In postgresql, it's error, too:
(Interestingly, postgresql has a "hint" to let user specify the data convention method. We might want to do the same.)
So it's clear that we'd better follow their steps and return some errors complaining some data are just not convertable to the target type.
Implementation challenges
The performance is clearly the most challenging part. If we actually change the data's type in the underlying storage, we might need to rewrite all the affected ssts, which can be a lot of work. If we change the reader (so that the data is converted on the fly), it brings extra query cost. Neither is good.
The text was updated successfully, but these errors were encountered: