Open uladkasach opened 3 years ago
note: we will not be supporting this soon, since it is an extreme optimization:
numeric()
vs numeric(p,s)
has no size difference
varchar(n)
vs varchar
, has no affect on storage size (the column is variable size anyway), it just specifies trimming/casting of values that get written to the column
select pg_column_size('80.1234567'::numeric(7, 5)); -- 12
select pg_column_size('80.1234567'::numeric); -- 12
select pg_column_size('80.1234'::numeric(7, 5)); -- 10 select pg_column_size('80.1234'::numeric); -- 10
- int vs numeric has huge size difference
- but this will only be really helpful for _large_ tables
```sql
select pg_column_size('821'::numeric); -- 8
select pg_column_size('821'::int); -- 4
select pg_column_size('821721'::numeric); -- 10
select pg_column_size('821721'::int); -- 4
for strings, varchar
is even explicitly specified to be used instead of varchar(n)
(since size is the same, and just limits what is put in the column)
datetime -vs- timestamp -vs- timestamptz
so from the above, it looks like the only cases we'd really need to change the type to optimize storage size is if its an integer.... that can be derived pretty easily from schema
(i.e., Joi.number().integer().min().max()
-> where .min().max()
tell us whether its a bigint, medint, smallint, etc)
folks can manually make the changes in these cases in the meantime, since this is such an easy optimization to do manually and would be a lot of lift automatically (i.e., domain-objects-metadata
would have to be able to introspect Joi/Yup schemas to figure this out)
for specifying the types of the generated entities / tables more granularly, we'll need to add supplemental info:
note: none of the above are critical for mvp, since:
however, we need to have an idea of how we could handle this long term
options:
@decorators
export type integer<Type = 'integer' extends 'smallint' | 'int' | 'bigint'> = number;
export type numeric<Precision, Scale> = number;
Joi.number().integer()
=>bigint
Joi.number().precision(5).min(-90).max(90).required()
=> numeric precision 7, scale 5, check "min -90 max 90".max()
is specified, in which case we can!!!Joi
andYup
to add more specific ways to define these constraints too:this will not be done for MVP, but is something to keep in mind for the future.
goals are: