Following a Select Statement Through Postgres Internals (2014)
patshaughnessy.net
patshaughnessy.net
Pat Shaughnessy has 3 other similar articles about Postgres internals. He does a great job of combining high level explanations, visual aids, and gritty details.
Discovering the Computer Science Behind Postgres Indexes http://patshaughnessy.net/2014/11/11/discovering-the-compute...
A Look at How Postgres Executes a Tiny Join http://patshaughnessy.net/2015/11/24/a-look-at-how-postgres-...
Is Your Postgres Query Starved for Memory? http://patshaughnessy.net/2016/1/22/is-your-postgres-query-s...
The whole process is quite clever, and this is what SQL engines are really about.
Because Postgres has not already found what we are looking for. The query is
select *
from users
where name = 'Capitain Nemo'
order by id asc
limit 1;
Only after Postgres has found all users with the name 'Capitain Nemo' it can sort them by their 'id' attribute and limit the result set to the first one in the sorted relation.Otherwise very nice post though.
[0] https://news.ycombinator.com/item?id=8449329 [1] http://api.rubyonrails.org/classes/ActiveRecord/FinderMethod...
I've wondered whether YouTube might be a good medium for this. Blog articles feel kind of "produced" -- I thought it might be cool to capture the exploratory nature of how this works.
You can add the investigative process you used to get there, and note what didn't work and why.
I can't say the same thing for ElasticSearch (or most large open-source projects). It's very difficult to get the high-level context without a well-written design doc explaining why things are the way they are. Some parts of ElasticSearch make sense, and other parts just seem hackneyed. Of course, I could pull together little bits and pieces of high-level insight from multiple disparate blog posts and forums and mailing lists here and there.
But what I would like is a design doc! If you were to produce something along the lines of that for open-source projects that need it, I wouldn't hesitate to pay a modest fee.
> If you were to produce something along the lines of that
> for open-source projects that need it, I wouldn't hesitate
> to pay a modest fee.
Try BountySource [1] maybe?There you can post a proposal for some improvement to an OSS project (a design doc, in your case) and pledge a bounty for it.
If other people have the same problem, they might chip in further, making it more visible/profitable to solve.
----
My comment was directed towards other projects. I wish they would follow Postgres's lead.
I found this paper "Architecture of a Database System" [1] to be an excellent starting point, it's written by database veterans James Hamilton and Micheal Stonebraker and references other much deeper works.
I've always liked Pat Shaughnessy's work, Ruby under a Microscope was a fantastic introduction to MRI 2.0. I really hope to see more works like these.
[1] http://db.cs.berkeley.edu/papers/fntdb07-architecture.pdf
Analyze & rewrite doesn't really use any complex algorithms.
Analyzing basically means that we resolve tables/objects/operators/databases/... in the parse-tree into what they mean in the current database with the current settings. The process of parsing itself (via a bison parser) doesn't do any object lookups and such. So errors about non-existant tables, operators and such will mostly happen during the analyze phase.
The rewrite phase, which often will do nothing, will resolve both explicitly (CREATE VIEW) and implicitly (row-level security) referenced views by their definition. It also processes rules in an equivalent manner, but you should never use those...
The actual optimization you're referring to will happen as part of planning.
EDIT: typos
Source: I'm a PostgreSQL Developer.
I just wish the author had gone closer to the nitty gritty details of _how_ the data is actually fetched from the disk. How does Postgres store the data? What do the data files look like, how is the parsing done?
In any case I appreciate the effort. I guess I might have to dive into the source code myself.
select * from users where name = 'Captain Nemo' and id = (select min(id) from users where name='Captain Nemo')
trying to forget bad memories of forcing the Oracle query planner into submission with more hints than actual sql