Remix.run Logo
bob1029 8 days ago

> I don’t know yet if the implementations of this yet are good enough to use at scale. Maybe they’re slow or maybe the bugs aren’t ironed out yet.

This technique is very well supported in the big commercial engines. In MSSQL's Indexed View case, the views are synchronously updated when the underlying tables are modified. This has implications at insert/update/delete time, so if you are going to be doing a lot of these you might want to do it on a read replica to avoid impact to production writes.

https://learn.microsoft.com/en-us/sql/relational-databases/v...

https://learn.microsoft.com/en-us/sql/t-sql/statements/creat...

mike_hearn 7 days ago | parent | next [-]

Yes the idea it's newfangled is odd. It's only newfangled if you ignore the existence of database engines that are better than the open source ones.

Oracle's implementation scales horizontally and can do incremental view maintenance using commit logs:

https://oracle-base.com/articles/misc/materialized-views

But it may not even be necessary because Oracle also supports query caching both server and client side. By default you have to opt-in on the query level:

    SELECT /*+ RESULT_CACHE */ .... FROM .....
but if you do then queries might not even hit the database at all, the results are cached by the drivers. The main limitation of that feature is that it's meant for read-mostly tables and cache keys are invalidated on any write to the table. So for aggregating counts in a large multi-tenant table the hit rate would be low and a materialized view is more appropriate.

It's a bit unclear why the author of the article ignores triggers as not "in vogue" though. That's supported by every DB and will work fine for this use case. You do have to learn how to use these features but it can save a lot of work, especially when introducing non-consistent data sources like a Redis cache. Consistency is so valuable.

Disclosure: work for Oracle, opinions are my own (albeit in this case, presumably highly aligned).

sophiebits 8 days ago | parent | prev | next [-]

TIL, thanks! I know Postgres and MySQL don’t include an equivalent.

MangoToupe 8 days ago | parent | prev [-]

Can we inspect MSSQL's source or is it shipped as a blob? I can't find any serious information about how this works. I can't imagine who would want to spend money on this.