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

It would surprise me to see the dispatch loop dominate in a DB? given that on the whole databases tend to block a lot on more expensive things like materialization, joins, etc?

I do think that a VM could mess up CPU branch prediction so I can see that as being a problem?

Some people have gone the route of emitting LLVM IR (or similar) for query plans, but this has a cost, too, so only makes sense for repeatedly used queries.




It really depends on the query. If there's a bunch of math in the select list, it's easy for that to be the biggest bottleneck, even if there are joins etc. Also you'll sometimes have to evaluate expressions to check join conditions depending on the join implementation and condition.

> I do think that a VM could mess up CPU branch prediction so I can see that as being a problem

It definitely happens. It can be partially addressed with things like computed gotos, but it's far from perfect. At least for postgres, it's just that the tree walk overhead was far higher.

The branch prediction handling for opcode dispatch loops definitely improved in CPUs - for Intel somewhere around Haswell (it's been a while, so this is a guess). I remember that, at the time, the gains of using computed goto on my aging workstation (nehalem) were far bigger than a few uarchs later, even when controlling for cache size etc.

Semi related anecdote: Both opcode dispatch switches and computed goto based dispatch are good for stressing compilers. I found newly introduced >= quadratic behavior in all the major c compilers in the years since.


clearly not in I/O bound cases, but in that world everything except the b-tree was done relationally, so yeah joins and view and the whole lot. we may have also had a really poorly though out VM. but direct instruction generation wasn't really a big deal and it helped quite a bit




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

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

Search: