background image
C H A P T E R 1 1
Data Storage and Retrieval
Using Newton Data Storage Objects
A multiple-slot index solves this problem by sorting entries according to multiple
key values. The key values are extracted from up to six index paths specified by the
array of the index specification frame. For example, the following code
fragment specifies a multiple-slot index that sorts entries according to the values
each holds in its
, and
// multiple-slot index on data from three slots
myMultiSlotSpec :=
path: ['last,'first,'num],
type: ['string, 'string, 'int }
The first key in the
array is called the primary key; subsequent lower-order
keys, if they are present, are the secondary key, tertiary key, and so on, up to a total
of six keys per array.
The primary key specifies a minimum criterion for inclusion in the index and
provides a value used to sort the indexed entries initially. In the example, only
entries having a
slot are indexed, and the value of the
slot is used to
impose an initial ordering on the indexed entries. Thus, the multiple-slot index in
the previous example sorts the
entry before all of the
The secondary key, if it is present, is used to sort entries having identical primary
keys. In the previous example, the multiple-slot index imposes a secondary
ordering on all
entries, according to the value each holds in its
slot. Similarly, the tertiary key, if present, is used to sort further any entries having
identical secondary key values. Because none of the entries in the example have
identical secondary key values (none of the
slots hold identical values), the
value of each entry's
slot has no effect on how the index sorts the entries.
Thus, the multiple-slot index shown previously sorts the set of sample entries in the
following order:
{last: "Bates", first: "Carol", num: 5}
{last: "Perry", first: "Barbara", num: 3}
{last: "Perry", first: "Bruce", num: 1}
{last: "Perry", first: "Daphne", num: 7}
{last: "Perry", first: "John", num: 4}
{last: "Perry", first: "Ralph", num: 2}
Now that you're familiar with the manner in which multiple-slot indexes sort entries,
let's look at the way the
method uses a multiple-slot index to select entries.
Missing slots in a multiple-slot query spec are treated as
values, just as they
are when querying on single-slot indexes. For example, if the query spec is missing
slot, the upper end of the range of entries examined by the query is
unbounded, just as it would be for a query on a single-slot index.
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна