-
Notifications
You must be signed in to change notification settings - Fork 161
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
Exclude optional fields from database schema #1923
Comments
In the case that we do not fill in the optional column, we usually fill in
The Effect of NULL in PostgreSQLIn PostgreSQL, table row is physically represented as specified in the manual:
The per-row null bitmap is present only if the row contains least one In effect, there is no storage overhead for tables with 8 columns or less (because 8 bits equals the padding of one byte). Otherwise, the per-row overhead will most likely use 8 bytes (enough for up to 64 columns). SolutionsWait for Persistent v3There is a proposed redesign that would solve this. It would generate separate, extensible types for inserting. Unfortunately, there has been no update for at least 4 years. Course Grained Schema VariantsAnother approach, which is already in use, is to define the schema in small pieces, and then stitch them together at runtime. This works quite well in practice, but it may be a bit heavyhanded for dealing with one or two columns. Common fields have to be duplicated across each variant. This also means combining options will be difficult. Write NULLsThe easiest solution would be to ignore all the problems above and continue to write Consider the case Custom BackendYet another option would be extend the PostgreSQL backend, to override its |
The current persistent way to exclude columns from inserts is to define separate entities, very similar to our schema variants. I propose we use a combination of our existing strategies:
Schema variants could be useful when dealing with whole tables or a large number of fields (say, three or more). When dealing with one or two columns, we can live with nulls. If we find we are accumulating a lot of them, we can group them and create configuration options. |
We have several optional database columns, which we may not fill in, depending on the configuration. Currently, we have 2 mechanisms to deal with that:
null
.We should explore more general ways to solve this.
The text was updated successfully, but these errors were encountered: