Skip to content

stevegrossi

Databases

Tended 2 years ago (6 times) Planted 3 years ago Mentioned 2 times

Contents

Know Your Options

Relational databases like PostgreSQL can take you really far, but it helps to know that no-SQL document databases exist when Postgres’ jsonb falls short, or how to use search-optimized databases like Elasticsearch when your needs grow beyond Postgres’ full-text search capabilities.

SQL Optimization

Prefixing a SQL query with EXPLAIN (or EXPLAIN ANALYZE to actually run it and get timing info) is the first step toward understanding (and then optimizing) the database’s plan for executing a query.

When it comes to optimizing data-querying and processing, experience has taught me that SQL is almost always going to be faster (and less memory-intensive) than performing that computation at the application level with e.g. Elixir or Ruby. But this TestDouble post adds a useful bit of nuance to that:

Specifically, very complex SQL queries with many conditions can still be pretty slow, and in those cases application logic can still have a role to play in determining whether some of those conditions don’t apply to a given query and can be skipped, ultimately resulting in a smaller, simpler SQL query. The example is of a search query parsing the search input and determining in Ruby which tables/columns actually need to be searched, then building a query across only those tables/columns and passing it to the database.

Schema Changes at Scale

Changing the structure of a database when it has a lot of data and/or is being frequently accessed brings new challenges, as I learned scaling up at Lessonly. Certain changes can take a long time and lock the database while they run, leading to downtime, but there are often strategies to mitigate these effects:

Forsaken Depths of SQL

I like this meme which depicts the progressively weirder aspects of SQL. I hope I never run into The Halloween Problem, but at least if I do I’ll recognize it.

increasingly weird concepts in SQL overlaid on an image of an iceberg with the weirder ones at the bottom

Resources

Mentions

  • Migrations

    …be renaming a column on a large and frequently-accessed [[Databases|database]] table over the course of a day. On the…