A method, computer system, and computer program are claimed for selecting
rows from first and second tables each having rows containing values in
columns. In at least the first table, the rows are divided into
partitions at least one of which is populated by one or more rows. The
method, computer system, and computer program include creating a
plurality of partition contexts, each partition context corresponding to
a populated partition and storing at least a first value associated with
a row. The lowest first value stored by the partition context is
determined. Rows with a particular first value are identified by reading
the partition contexts, creating a temporary file context corresponding
to one of the partition contexts, the temporary file context including
location data for a data block of rows in memory, and reading rows in
memory.