Avoid Using COUNT() in SQL When You Could Use EXISTS()
A while ago, I blogged about the importance of avoiding unnecessary COUNT(*) queries: SQL Tip of the Day: Be Wary of SELECT COUNT(*) … and how to replace them with equivalent EXISTS queries As I’m...
View ArticleWhen to Choose SQL and When to Choose NoSQL
Some people make architecture decisions purely based on the loudest consultant: @xeraa @lukaseder no, we base all our important architectural decisions on # of tweets. It's a Twitter Oriented...
View ArticleWhy You Should Design Your Database to Optimise for Statistics
In my SQL Masterclass, I frequently remind participants of the fact how important statistics are for a modern cost based optimiser. For instance, if you consider the fact that in an average E-Banking...
View ArticleDoes Your Database Really Use Your Index?
Adding the right index to speed up your queries is essential. But after a while, as your system grows, you may find yourself with tons of indexes, which all slow down writing to the database – as with...
View ArticleBe Careful When Emulating Parameterised Views with SYS_CONTEXT in Oracle
Everyone who writes complex SQL (or dare I say, move business logic into the database?) wishes for parameterised views from time to time. This hypothetical syntax would be terrific: CREATE VIEW...
View ArticleHow to Quickly Rename all Primary Keys in Oracle
Are you working with someone else’s schema and they haven’t declared nice names for all their constraints? Unfortunately, it is all too easy to create a table like this: CREATE TABLE order1 ( order_id...
View ArticleDon’t Even use COUNT(*) For Primary Key Existence Checks
In a recent blog post, I’ve advocated against the use of COUNT(*) in SQL, when a simple EXISTS() would suffice. This is important stuff. I keep tuning productive queries where a customer runs a...
View ArticleA Little Known SQL Feature: Use Logical Windowing to Aggregate Sliding Ranges
I’m frequently telling developers to put window functions almost everywhere, because they’re so awesome! One feature that I rarely see in the wild (even if it is extremely useful for reporting) is...
View ArticleWhy You Should (Sometimes) Avoid Expressions in SQL Predicates
I’ve recently discovered a rather significant performance issue on a productive Oracle 11g customer database. And I’m sure you have this issue too, which is why I’m documenting it here. This is a...
View ArticleApplying Queueing Theory to Dynamic Connection Pool Sizing with FlexyPool
I’m very happy to have another interesting blog post by Vlad Mihalcea on the jOOQ blog, this time about his Open Source library flexypool. Read his previous jOOQ Tuesdays post on Hibernate here. Vlad...
View ArticleUse jOOQ to Read / Write Oracle PL/SQL RECORD Types
Some of the biggest limitations when working with Oracle PL/SQL from Java is the lack of support for a variety of PL/SQL features through the JDBC interface. This lack of support is actually not...
View ArticleA Beginner’s Guide to the True Order of SQL Operations
The SQL language is very intuitive. Until it isn’t. Over the years, a lot of people have criticised the SQL language for a variety of reasons. For instance: IDEs cannot easily guess what auto...
View ArticleSQL, Streams, For Comprehension… It’s All the Same
Recently, at Devoxx, I’ve seen this beautiful slide in a talk by Kevlin Henney Absolutely beautiful! #Devoxx // @KevlinHenney pic.twitter.com/FRndrwxCnU — Lukas Eder (@lukaseder) November 10, 2016 In...
View ArticleA Probably Incomplete, Comprehensive Guide to the Many Different Ways to JOIN...
Perhaps the most powerful SQL feature is the JOIN operation. It is the envy of all non-relational databases, because the concept is so simple, yet so universally applicable, when you want to “combine”...
View ArticleHow to Emulate Partial Indexes in Oracle
A very interesting feature of the SQL Server and PostgreSQL databases (and some others, including SQLite) is the partial index (sometimes also called “filtered index”). That’s an index that contains...
View ArticleHow to Execute SQL Batches With JDBC and jOOQ
Some databases (in particular MySQL and T-SQL databases like SQL Server and Sybase) support a very nice feature: They allow for running a “batch” of statements in a single statement. For instance, in...
View ArticleBeautiful SQL: Lateral Unnesting of Array Columns
Sometimes, SQL can just be so beautiful. One of the less mainstream features in SQL is the array type (or nested collections). In fact, it’s so not mainstream that only 2 major databases actually...
View ArticlejOOQ Tuesdays: Brett Wooldridge Shows What it Takes to Write the Fastest Java...
Welcome to the jOOQ Tuesdays series. In this series, we’ll publish an article on the third Tuesday every other month where we interview someone we find exciting in our industry from a jOOQ perspective....
View ArticleImpress Your Coworkers With the Incredible NATURAL FULL OUTER JOIN!
There are already only very few real-world use-cases for FULL [ OUTER ] JOIN, but maybe, you have run into this beast in the past. But when was the last time you’ve seen a NATURAL JOIN? Right. A quick...
View ArticleMany SQL Performance Problems Stem from “Unnecessary, Mandatory Work”
Probably the most impactful thing you could learn about when writing efficient SQL is indexing. A very close runner-up, however, is the fact that a lot of SQL clients demand tons of “unnecessary,...
View Article