Tuple ranking


rank(operand: Relation, order: Ordering, as: AttrName) -> Relation


rank(suppliers, [:status], :ranking)
rank(suppliers, [:status, :sid], :ranking)


Extends tuples from operand with a new attribute (as) capturing the tuple position with respect to order.

The ranking of a tuple t is more precisely defined as the number of tuples from operand that would come strictly before t if they were all ordered according to order. 'Equal' tuples with respect to order are not counted in this ranking.

This means that, unless order is a total order, duplicate ranking may be observed. In contrast, if order covers a candidate key then the ranking attribute (as) is unique, and therefore defines an additional candidate key for the resulting relation.

Implementation notes

Note that this operator does not compile to SQL so far. The page and frame operators provide useful alternatives when the aim is to compute a subset of tuples based on a ranking.