T.index( n )

Read(1060) Label: memory table, hash index,

Description:

Create an index on the key of an in-memory table.

Syntax:

T.index(n)

Note:

The function creates an index whose length is n for the key of in-memory table T. Remove the index when parameter n is 0 or the in-memory table reset key; auto-select length of the index when parameter n is absent. The index facilitates data searching when we need to perform multiple searches according to the primary key.

 

To create an index table, we assume that the records’ primary key values are unique, otherwise error will be reported. Create HASH table only according to the basic key and arrange records having different time key values in the same HASH location.

Parameter:

T

An in-memory table with unique primary key values

n

The length of index

Option:

@m

Create the index with parallel processing

@n

Create index on the sequence number key

@s

Create a multilevel tree-structured index when the in-memory table T’s basic key is serial byte type, and ignore parameter n

Return value:

An in-memory table

Example:

Create index on the in-memory table’s primary key:

 

A

 

1

=file("ei.ctx")

 

2

=A1.create@y(#EID,NAME,DEPT)

Create the composite table’s base table and set EID as the key.

3

=demo.cursor("select EID,NAME,DEPT from employee")

 

4

=A2.append@i(A3)

Append cursor A3’s data to the composite table.

5

=A4.memory()

Generate an in-memory table from a composite table’s entity. table; the new table inherits the entity table’s key.

6

=A5.index(10)

Create an index of length 10 on in-memory table’s key.

Create multilevel tree-structured index on the in-memory table:

 

A

 

1

=3.new(k(~:2):id,~*~:num)

Create a table sequence.

2

=A1.keys(id)

Set id as the table sequence’s key.

3

=A2.memory()

Convert the table sequence into an in-memory table, which inherits the former’s key.

4

=A3.index@s()

As the in-memory table’s key is serial byte, use @s option to create multilevel tree-structured index for it.

Create ordinal-number-based index for the in-memory table:

 

A

 

1

=to(100).new(~*2:c1,rand():c2)

Create a table sequence.

2

=A1.memory()

Generate an in-memory table from the table sequence.

3

=A2.index@n()

Use @n option to create index on the in-memory table’s sequence number key; in this case the in-memory table only has the sequence number key without the basic key.

4

=A3.find(6)

Get the record whose key value is 6 from the in-memory table, which is the one whose sequence number key value is 6, and return the following result: