eXtremeSQL supports
asofjoins which are normally used withdate / timecolumns to select table rows within specified date or time ranges. The keywordasofcan be used forinnerjoins (returns only matched rows) andouterjoins (returns nulls for the inner table columns where no match is found). The syntax is as follows:outer_table o ASOF [OUTER] JOIN inner_table i ON (o.k1 = i.k1 AND o.k2 = i.k2 AND ... o.kN >= i.kN)The
asofjoin requires theonclause. Theonpredicate must consist of one or more conjuncts with equality comparisons for columns of the joined tables and exactly one greater-than-or-equal or less-than-or-equal comparison. The equality comparison specifies a normal (strict) join condition - the same as for a normal join.A single range comparison actually performs the
asofjoin where the value of the outer table corresponds to the interval of the inner table column values.For example if the outer table contains timestamps
tswith values:10:01, 10:03, 10:07, 10:08and the inner table contains timestamps:
10:02, 10:04, 10:06, 10:08then the
asofjoin with predicateouter.ts >= inner.tswould establish the following mapping:10:01 -> null 10:03 -> 10:02 10:07 -> 10:06 10:08 -> 10:08The
asofjoin is implemented using amergejoin; i.e. both tables are sorted and then merged. If there is a proper index, then instead of an explicit sort, an index scan is used.Note that a join condition
>=requires ascending sort order, and<=condition requires descending order.Examples of
asofjoin usage can be found in samples/xsql/scripts/asof_join.sql