11 ms·
The internals of PostgreSQL
- combatentropy 10y agoI would like to read through this when I'm not so tired. Thank you! From what I can tell, PostgreSQL is sensibly structured. At least, it seems better than MySQL. The hackiest thing I have heard so far about MySQL is that if you run the exact same SQL text more than once, it will fetch the result from cache. If you run a differently worded query, it will skip the cache, even if the query were to bring back the exact same data. This is different than what I remember about PostgreSQL (correct me if I'm wrong). I remember reading in some book that PostgreSQL just let its rows become memory pages, and if a query resulted in data already in memory, then it got it from memory, otherwise it got it from disk. No need to make sure you didn't insert a space or something into your query the second time.
- znep 10y agoWhile that is true and the mysql query cache definitely became a scaling issue as machines got bigger with lock contention etc., postgres doesn't even have a similar feature period. Suppose you have a query that is doing a group by on a low cardinality field (eg. state) on a hundred million row table. Large amount of data in, small amount out. postgres has to actually look at all the rows to re-run the query. The mysql query cache only has to pull the tiny number of results out of the cache for that specific query. This is a dangerous feature because there is a super slippery slope as traffic increases... any change to any of the tables invalidates the cache when you need caching most, and hits all queries against those tables at the same time. But if used well in an environment with many copies of the data (replicated or otherwise) where you could manage when updates happened, it can be a lifesaver. InnoDB also has its own buffer pool that caches rows and is in general terms similar to the postgres buffer cache. It is fair to say that mysql has a lot more features like this that are "sometimes life-saving hacks that can bite you hard if you don't understand them" and postgres is much more restrained in ensuring the features are a little more general and thought through.
- brianwawok 10y agoMySQL needs the cache more often though with a limit of one index per query. Postgres seems like it more often can combine a few indexes and turn what scans 100k rows in MySQL into bitmasking two indexes and pulling 10 rows. Seems sensible, each has features to support the base design.
- znep 10y agoTrue point (disclaimer: don't know how mysql has evolved in the past 5 years). Fits with my general feeling of "if you want to optimize for a super specific use case, sometimes mysql can provide some cool tricks for that use case that can be amazing" but if you want a more general solution if you need more flexibility or don't have the knowledge or don't know your future needs, postgres shines.
- morgo 10y agoThe limit of one index per query was lifted in 2005, with mysql 5.0.
- brianwawok 10y agoIt's now one per table. Poor word choice by me, sorry.
- morgo 10y agohttps://dev.mysql.com/doc/refman/5.5/en/index-merge-optimization.html https://dev.mysql.com/doc/refman/5.5/en/index-merge-optimiza...
- jorgeleo 10y ago"While that is true and the mysql query cache definitely became a scaling issue as machines got bigger with lock contention etc., postgres doesn't even have a similar feature period." I am sorry, but I rather not have a feature than having a feature that is questionably implemented.
- 10y ago
- sqldba 10y agoSQL Server does all of these things (for comparison). It compiles queries and stores them in a cache. In many cases it can parameterise simple ones so even if the exact text changes it will pull back the matching plan (and it stores all this data so you can analyse later what plans were compiled, what was reused, which ones were similar, which were recompiled later - though hardly anyone deep dives into it because it's a tar pit of info and why bother instead of just focusing on worst cases). Also when the query pulls data into memory it stays there in the buffer. If the rows change the buffers aren't discarded, they're flushed to disk (along with the log records). So if your query pulls back the exact same data then it's from memory sure but it's not stale or anything. I don't consider any of these problems so I'm surprised how they could be interpreted as bad in other products. I don't understand enough about them to say but it's fun to discus.
- znep 10y agoFrom reading what you wrote, what I think you are talking about is statement caching where it can cache the "how do I run this" but still has to read each row (or indexed row) from the buffer cache. The mysql query cache actually caches the results of the query, see https://dev.mysql.com/doc/refman/8.0/en/query-cache.html https://dev.mysql.com/doc/refman/8.0/en/query-cache.html so it doesn't even need to look at the rows at all. SQL Server may have a similar thing now, I'm not up to date on it, but wanted to call out the distinction based on how you described it. No question, SQL Server has a lot of awesome qualities for the right use case and has come a long long way since the Sybase days.
- brightball 10y agoSQL Server does some great things for the data that's in it but if you ever want to get the data out (Elastic Search / Hadoop / Kafka / etc) you are in for a world of pain (and bills). The lock in alone is reason enough to steer clear of it for virtually all use cases. As you start running into scaling issues and need to search for solutions that are faster to implement you'll reach for Enterprise and then for more cores and before you know it you're stuck with a $16,000 / core scaling cost that you can't avoid because you can't get your data out to offload things easily. Dealing with SQL Server on a customer facing system is the stuff of nightmares.
- morgo 10y agoThis is only true for one specific kind of cache (query cache) which has been disabled by default for 4 years now. It works well at cheating benchmarks, and masking un-optimized queries. It is not something that I would recommend.
- elvinyung 10y agoA really cool paper to read is The Design of POSTGRES [1] by Stonebraker et al. It's dated by its mentions of things like POSTQUEL, but it's still really interesting to read about the early design of seminal features like the extensible ADT system, from a time when it was still innovative. 1: http://db.cs.berkeley.edu/papers/ERL-M85-95.pdf http://db.cs.berkeley.edu/papers/ERL-M85-95.pdf
- crudbug 10y agoI have been reading about Postgres architecture. The modular design enables - microkernel-like API where different languages can be integrated seamlessly. The only thing, I am missing are incremental materialized views.
- makoz 10y agoWhat resources have you been using to familiarize yourself with Postgres?
- crudbug 10y ago[0] Online documentation - Internals - https://www.postgresql.org/docs/9.6/static/internals.html https://www.postgresql.org/docs/9.6/static/internals.html [1] Wiki - https://en.wikibooks.org/wiki/PostgreSQL/Architecture https://en.wikibooks.org/wiki/PostgreSQL/Architecture
- qaq 10y agoI would highly recommend talks by Bruce Momjian https://momjian.us/ https://momjian.us/ he has separate talks on pretty much everything related to PG + All The Dirt On Vacuum talk by Jim Nasby https://www.youtube.com/watch?v=L8nErzxPJjQ https://www.youtube.com/watch?v=L8nErzxPJjQ
- algesten 10y agoyou mean you want the materialized view to refresh automatically? or what does "incremental" mean in this context? (sorry I'm no DB-person)
- Godel_unicode 10y agoI'm not OP, but I assume that phrase is in reference to the Oracle capability to not need to completely re-run the underlying query in order to refresh a materialized view. Here's the Oracle article about materialized view refresh, there are further details about the different schemes for incremental refresh within. Briefly, it's a method for refreshing by looking at the deltas since last refresh. https://docs.oracle.com/database/121/DWHSG/refresh.htm#DWHSG03003 https://docs.oracle.com/database/121/DWHSG/refresh.htm#DWHSG...
- sqldba 10y agoIt looks GREAT but... I always see these things posted while they're still being written and then I never go back to see them when they're completed. And nobody posts when it's completed. I'd prefer the posting not be done until it's finished, or, that there be an "email me when it's finished" button.
- snoman 10y agoIf you can't be bothered to set a reminder, subscribe to the RSS feed, create an ifttt trigger or anything like that... I don't know what to tell you. There's lots of solutions to this predicament. This one's on you.
- deleted 10y ago[deleted]
- hordeallergy 10y agoAs far as not having to read things twice, draft and final, I'd have to lean towards @sqldba's position.
- vog 10y agoThere is also an interesting middleground named Evolving Publication where the author publishes section by section, and the RSS feed informs you whenever a new section/chapter is added to the article: https://martinfowler.com/bliki/EvolvingPublication.html https://martinfowler.com/bliki/EvolvingPublication.html So the RSS feed is not per article, but per article part.
- karmacoda 10y agoThat is interesting, ta, although more work for the author.
- mickronome 10y agoI don't think a clearly expressed opinion does warrant the kind of response you gave here. There is little of substance in your comment except questioning the posters character by implying he/she is either lazy or to stupid. A tip on how to use IFTTT quickly and easily for this particular task would probably be a more constructive response. I for one don't know how to use IFTTT to reliably detect changes in any webpage, I thougt it was mostly for different api services and the like, as those are the only use-cases I've heard about.
- alexwebb2 10y agoThis is now returning a 403 Forbidden.
- justinclift 10y agoYep, same here. Guessing they're experiencing too much traffic or something, so this is their way to throttle it. ;)
- Jimmed 10y agoHug of death, methinks.
- etatoby 10y agoObligatory Archive.org link: http://web.archive.org/web/20170126103158/http://www.interdb.jp/pg/index.html http://web.archive.org/web/20170126103158/http://www.interdb... Also a reminder to everybody to give them a few $CURRENCY if you can. Archive.org offers a valuable service and are very underfunded.
- shx8 10y agoI'm the author of this document. Now, my hosting server denies accessing from foreign countries because of too many accesses. Please wait for a several hours.
- deleted 10y ago[deleted]