Friday 2 November 2018

Mutex Tables in SQL

A “mutex” table is a clever trick that allows joining tables while keeping them independent of each other in a query. This property allows interesting queries that are not otherwise possible. It is especially useful in earlier versions of MySQL, where it can be used to simulate some unsupported queries such as UNION and derived tables in the FROM clause.
My standard mutex table is as follows:
create table mutex(
    i int not null primary key
);
insert into mutex(i) values (0), (1);
I typically use the mutex table as the leftmost table of LEFT OUTER JOINqueries.

0 comments:

Post a Comment