Arrow of time
Arrow of time
How beautiful the PostgreSQL planner can be

Just wanted to share how beautiful the PostgreSQL query execution planner can be. Here is a query where I want ...

Just wanted to share how beautiful the PostgreSQL query execution planner can be. Here is a query where I want to find out both the minimum and the maximum of the id field, which is a sequential primary key:

explorer2=# explain analyze select min(id), max(id) from expl_iocombined;
                                                QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Result  (cost=1.21..1.22 rows=1 width=0) (actual time=0.028..0.028 rows=1 loops=1)
   InitPlan 1 (returns $0)
     ->  Limit  (cost=0.57..0.61 rows=1 width=8) (actual time=0.015..0.015 rows=1 loops=1)
       ->  Index Only Scan using expl_iocombined_pkey on expl_iocombined  (cost=0.57..25512595.31 rows=848505805 width=8) (actual time=0.015..0.015 rows=1 loops=1)
         Index Cond: (id IS NOT NULL)
         Heap Fetches: 0
   InitPlan 2 (returns $1)
     ->  Limit  (cost=0.57..0.61 rows=1 width=8) (actual time=0.011..0.011 rows=1 loops=1)
       ->  Index Only Scan Backward using expl_iocombined_pkey on expl_iocombined expl_iocombined_1  (cost=0.57..25512595.31 rows=848505805 width=8) (actual time=0.011..0.011 rows=1 loops=1)
         Index Cond: (id IS NOT NULL)
         Heap Fetches: 1
 Planning time: 0.084 ms
 Execution time: 0.040 ms
(13 rows)

So, it converted the min(x) and max(x) operations into ORDER BY x [DESC] LIMIT 1 and executed it from index-only scans. The index scans are slaved (deeper in execution hierachy) to the LIMIT operation, so the LIMIT operation just asks for a single fetch from the index lookup operation, and there it is. At most, one read operation is required (one for each min and max), and in reality, only one has happened here (the single heap fetch in the second operation).

Other databases have similar operations, just wanted to share this particular, elegant execution plan.


TIL: How do bicycles (and cars) turn?

It occured to me while driving a car that the act of turning direction is actually non-trivial. Reducing the case ...

It occured to me while driving a car that the act of turning direction is actually non-trivial. Reducing the case to a bicycle, consider this: You are pedaling your bike, and driving in the forward direction (of course). You now have certain speed and acceleration vectors pointing in front of you. You stop pedaling, and decide to turn left, 90 degrees to your current direction. You turn the wheel. Depending on the angle of the wheel and...

Read More
On (artificial) intelligence

Consider this armchair philosophising on the possibility of artificial intelligences. My stance on the existence of our biological intelligence is ...

Consider this armchair philosophising on the possibility of artificial intelligences. My stance on the existence of our biological intelligence is that it's a matter of accident, in the sense that all evolved traits are basically accidents: random mutations which get selected for over a large time span. It was very probably honed during that time, as individuals which had "more of it" had an advantage over the others. However, something singular must have happened some time ago, some...

Read More
Amazon's E-book Price-slashing Campaign and on Replacing One Evil with Another

Earlier today I have received a letter from Amazon, which I'm going to copy-paste below for completness and archival ...

Earlier today I have received a letter from Amazon, which I'm going to copy-paste below for completness and archival. It basically tries to invoke sympathy for Amazon in its "debate" with a publisher called Hachette. I don't follow the publishing world that closely and I admit to never hearing about Hachette until earlier today, but I am very aware of the problem at hand, which is pricing and distribution of digital goods...

Read More
How do you explain an OS kernel to a layperson? + an old text about The Matrix as an Operating System

Earlier this year I was a guest at a gathering of people who were mostly involved with social sciences and ...

Earlier this year I was a guest at a gathering of people who were mostly involved with social sciences and politics and a topic soon arised in which I had to explain some of the things I work with. In this group of 10-ish people there were one or two who had even a vague idea what a kernel is (they were engineering students, actually), and were suitably impressed, but the rest of the group simply offered...

Read More
A brief history of computing in error messages

Technologies and systems come and go but error messages stay. Of course, this is because errors are (or were, before ...

Technologies and systems come and go but error messages stay. Of course, this is because errors are (or were, before exceptions) signified by integer error codes and libraries maintain, among other things, dictionaries of human-readable messages to go with such codes. Most system programmers, or any other programmers which still dwell on C instead of using something less close to the metal, can remember a subset of those codes simply because they've seen them often enough. I first...

Read More
Switching my blog to Pelican

After using my own blog platform since 2008, I figured it's time to give up on maintaining yet another ...

After using my own blog platform since 2008, I figured it's time to give up on maintaining yet another piece of software just form my own use and switched this blog to Pelican. It's the popular static html site generator (the old blog system was also static) and I hope it will serve me well for years to come. I've imported old articles and comments, and new comments can be added by using Disqus. This makes my blog...

Read More
pkgng goes official in FreeBSD

As seen on the announcements list, pkgng is now officially up and running for FreeBSD! The infrastructure had some rough ...

As seen on the announcements list, pkgng is now officially up and running for FreeBSD! The infrastructure had some rough times before and the deployment was prolonged a bit, but now it's finally there and the old pkg_* tools can be put to rest. The preferred format for referencing repos has changed a bit, so if you have old config files, be sure to update them! Instead of specifying PACKAGESITE in the main pkg.conf, now each...

Read More
Why UFS in FreeBSD is great

ZFS is of course the rock-star file system in FreeBSD, with numerous features and new ones frequently coming in, but ...

ZFS is of course the rock-star file system in FreeBSD, with numerous features and new ones frequently coming in, but UFS is also a pretty solid deal which is perfectly usable for a wide number of tasks. Here are some of my favourite UFS features. #1: UFS is a pretty old file system which has been continually incrementally upgraded though the years. One of its best features is that its memory usage...

Read More
Apache 2.2 and Perfect Forward Secrecy (PFS)

Update: apparently (I haven't tested it yet), Apache 2.2.26 finally supports ECDH cipher suites! The remainder of ...

Update: apparently (I haven't tested it yet), Apache 2.2.26 finally supports ECDH cipher suites! The remainder of this blog post is not as usable any more and you can simply use some common SSLCipherSuite lines. Using modern Perfect Forward Secrecy (PFS) cipher suites with #Apache 2.2 and #OpenSSL is not really possible in the general case. The best you can do is enable some DHE suites instead of...

Read More
What I like about the Nimrod programming language

Nimrod is a relatively new programming language which I find very interesting mainly because it is a compiled language and ...

Nimrod is a relatively new programming language which I find very interesting mainly because it is a compiled language and has a syntax which is a combination of Python's and Pascal's syntax, the two languages I find most aesthetically pleasing, with a small sprinkling of other influences, like JavaScript. The language and its community are growing, there is an increasing number of available modules (like Jester, for web apps), and it's currently on the...

Read More
pgrep - another little known FreeBSD command

Have you ever wanted to perform an action on a large set of processes which are forked from one another ...

Have you ever wanted to perform an action on a large set of processes which are forked from one another (or started from the same binary in some other way) but were stopped by the need to use awk or something else to parse the PIDs from the output of ps or a similar utility? Pgrep allows you to do just that! The pgrep utility is actually not a program developed specifically for FreeBSD...

Read More
GEOM_SHSEC: A shared secret disk drive GEOM module

GEOM_SHSEC is one of the less frequently used GEOM modules from FreeBSD, but it is actually pretty interesting. It combines ...

GEOM_SHSEC is one of the less frequently used GEOM modules from FreeBSD, but it is actually pretty interesting. It combines several drives (or any other entities which are presentable as GEOM devices - including USB memory keys and files) into a single virtual drive which has the property that all its constituent devices must be present and available before its contents can be accessed. For example, you might have two USB keys which both need...

Read More
Viber voip+messaging app working on FreeBSD under Wine

A friend told me that Viber (a free VoIP + messaging application for smartphones, similar to Skype) now has a Windows ...

A friend told me that Viber (a free VoIP + messaging application for smartphones, similar to Skype) now has a Windows application and it works for him on Wine on Linux, so I just had to try it out on FreeBSD - and it works. Surprisingly easy. I guess even Wine is mature enough on Windows :) Viber has been a bit of a troublesome app for me on Android, with frequent lockups and...

Read More
People will be people

I am frequently amused by all the recent happenings around Snowden and the revelations of privacy breaches by various governments ...

I am frequently amused by all the recent happenings around Snowden and the revelations of privacy breaches by various governments. Before going on, I'd like to say that I don't offer any answers here in this text, just commentary, so it is probable you won't learn anything new from me. I'm writing this because I have an itch to scratch... Again, I feel the need to point out that I'm aware...

Read More
OpenVPN on FreeBSD

OpenVPN is probably the most popular semi-non-standard cross-platform VPN solution, with a large number of users and a pure userland ...

OpenVPN is probably the most popular semi-non-standard cross-platform VPN solution, with a large number of users and a pure userland implementation. It's pretty easy to set up, but I often forget certain steps so here's a tutorial for me to rememeber in the future :) I call OpenVPN semi-non-standard because it uses its own protocol instead of L2TP, IPSec or something other blessed by a RFC. OpenVPN takes care to be secure and offers some...

Read More
BSDCan and FreeBSD DevSummit 2013

It's that time of the year again - time for the biggest, bestest gathering of BSD geeks from around the ...

It's that time of the year again - time for the biggest, bestest gathering of BSD geeks from around the world - BSDCan 2013. It was great to see old friends and new faces, exchange ideas and talk about the bright future. The main event was traditionally precceded by two days of tutorial and the "Developers' summit", a sort of a general assembly of FreeBSD developers, used to exchange ideas and often also directly work...

Read More
FreeNAS vs NAS4free

I've (finally) tried both FreeNAS and NAS4free and I'd like to share some thoughts and experiences. Both of ...

I've (finally) tried both FreeNAS and NAS4free and I'd like to share some thoughts and experiences. Both of these are "NAS-in-a-box" products intended to be installed on computers with a large number of drives, which they will export to the world in a variety of protocols. Both are based on FreeBSD, both fully support ZFS and they even share a common history. The tl;dr of this post would be something like "yes, they...

Read More
FreeBSD 10 news

There's been a lot of maturing of technology for FreeBSD 10 - lots of new features which make this release ...

There's been a lot of maturing of technology for FreeBSD 10 - lots of new features which make this release the most exciting one in years. Here are some of my personal highlights. There's been a lot of development in the field of virtualization. FreeBSD has almost neglected "full" virtualization technology (relying on home-brewed jails/vnet), which made it a poor choice for modern deployments, but that is about to change. New stuff which will (probably, but...

Read More
Parallella on Kickstarter

Kickstarter is a great thing - it allows projects which limited appeal to be succesfully financed, which helps them succeed. One ...

Kickstarter is a great thing - it allows projects which limited appeal to be succesfully financed, which helps them succeed. One such project is the Parallela. It is basically an ARM-based highly-NUMA computer with 16-64 cores which can be used both to teach parallel programming and actually do some useful work with very little electrical power. The numbers cited as on the on the order of 45 GFLOPS/watt for the maximum configuration. As the...

Read More
  • 1
  • 2