Hacker News new | past | comments | ask | show | jobs | submit login

Most databases will allow you to collect statistics on every query run by users, e.g., pg_stat_statements: https://www.postgresql.org/docs/current/pgstatstatements.htm...

A relational database really shines when you have all sorts of queries on tables, so it’s hard to optimize your model for every potentially future desired query. Precalculating these, caching the results in separate tables is not very efficient, and requires you to predetermine every query you want to answer.

Indexing in this situation is often the better alternative.




Lots of apps however do the same N kind of queries, but the data under them can change over time without anyone noticing


So? Just make sure you regularly refresh the statistics...


Ideally yes, but sometimes your tables get so monstrously large that the auto-analyze is sampling thousandths of a percent of rows, and fiddling with sampling targets can throw off seemingly unconnected queries.

Planners are mysterious black boxes, which we can at best influence.


Yes, a bit like machine learning models.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: