Hacker News new | ask | show | jobs
by davidpardo 3494 days ago
How do you deal with optional fields in documents? do you modify the table schema on the run?

If there's a larg-ish number of optional fields, but each document has only or a few of them, would it create a sparse table with lots of columns? Did you find any problem in these scenarios?

1 comments

So basically yes. ToroDB creates columns and tables on the fly. All the added columns are nullable, so the ALTER TABLE ADD COLUMN is an almost free operation in PostgreSQL.

Sure, sparse tables are created. This is not a problem since nulls in PostgreSQL are quite cheap (they require no or a few bytes of storage per record).

Even if there is a high cardinality of optional fields, we have not seen in real cases that the number of columns goes beyond a few hundred. And that's perfectly manageable by PostgreSQL :)

There might be some pathological, degraded use cases. But we have found none of them on real datasets.