Since 2010


I stumbled upon this in Mozilla’s core source code:

This extracts the hostname from the URI and reverses it in the form that we use (always ending with a “.”). So “” becomes “moc.tfosorcim.”

The idea behind this is that we can create an index over the items in the reversed host name column, and then query for as much or as little of the host name as we feel like.

For example, the query “host >= ‘gro.allizom.’ AND host < ‘gro.allizom/’ Matches all host names ending in ‘’, including ‘’ and just ‘’ (since we define all reversed host names to end in a period, even ‘’ matches). The important thing is that this operation uses the index. Any substring calls in a select statement (even if it’s for the beginning of a string) will bypass any indices and will be slow).

Ingenious! Software is hard.