A <emphasis>tuple set<alt>There's a Wikipedia article about tuples: https://en.wikipedia.org/wiki/Tuple</alt></emphasis> -- 't0' in the example -- is a group of tuples.
</para>
<para>
There is always one tuple set in a space.
For the tarantool client, the identifier of a tuple set is <quote>t</quote> followed by the
space's number, for example <quote>t0</quote> refers to the tuple
set of space[0]. (The letter <quote>t</quote> stands for <quote>tuple set.</quote>)
</para>
<para>
A tuple fills
the same role as a <quote>row</quote> or a <quote>record</quote>, and the
components of a tuple (which we call <quote>fields</quote>)
fill the same role as a
<quote>row column</quote> or <quote>record field</quote>, except that: the
fields of a tuple don't need to have names.
That's why there was no need to pre-define the
tuple set in the configuration file, and that's
why each tuple can have a different number of
elements, and that's why we say that Tarantool has
a <quote>dynamic</quote> data model.
</para>
<para>
Any given tuple may have any number of fields and the
fields may have any of these three types:
NUM (32-bit unsigned integer between 0 and 2,147,483,647),
NUM64 (64-bit unsigned integer between 0 and 18,446,744,073,709,551,615),
or STR (string, any sequence of octets).
The identifier of a field is
<quote>k</quote> followed by the field's number, for example
<quote>k0</quote> refers to the first field of a tuple.
</para>
<note><para>This manual is following the tarantool client convention by
using tuple identifier = <quote>t</quote> followed by the space's number, and
using field identifier = <quote>k</quote> followed by the field's number.
The server knows nothing about such identifiers, it only cares
about the number. Other clients follow different conventions,
and may even have sophisticated ways of mapping meaningful names
to numbers.</para></note>
<para>
When the tarantool client displays a tuple, it surrounds
strings with single quotes, separates fields with commas,
and encloses the tuple inside square brackets. For example:
which can only be used with Lua stored procedures.
(Index iterators are for traversing indexes one key at a time,
taking advantage of features that are specific
to an index type, for example evaluating Boolean expressions
when traversing BITSET indexes, or going in descending order
when traversing TREE indexes.)
</para>
<para>
Five examples of basic operations:
<programlisting>
/* Add a new tuple to tuple set t0.
The first field, k0, will be 999 (type is NUM).
The second field, k1, will be 'Taranto' (type is STR). */
INSERT INTO t0 VALUES (999,'Taranto')
/* Update the tuple, changing field k1.
The clause "WHERE <replaceable>primary-key-field-identifier</replaceable> = <replaceable>value</replaceable> is mandatory
because UPDATE statements must always have a WHERE clause that
specifies the primary key, which in this case is k0. */
UPDATE t0 SET k1 = 'Tarantino' WHERE k0 = 999
/* Replace the tuple, adding a new field.
This is not possible with the UPDATE statement because
the SET clause of an UPDATE statement can only refer to
fields that already exist. */
REPLACE INTO t0 VALUES (999,'Tarantella',Tarantula')
/* Retrieve the tuple.
The WHERE clause is still mandatory, although it does not have to
mention the primary key. */
SELECT * FROM t0 WHERE k0 = 999
/* Delete the tuple.
Once again the clause "WHERE k0 = <replaceable>value</replaceable> is mandatory. */
DELETE FROM t0 WHERE k0 = 999
</programlisting>
</para>
<para>
How does Tarantool do a basic operation? Let's take this example:
<programlisting>
UPDATE t0 SET k1 = 'size', k2=0 WHERE k0 = 3
</programlisting>
</para>
<para>
STEP #1: the client parses the statement and changes it to a
binary-protocol instruction which has already been checked,
and which the server can understand without needing to parse
everything again. The client ships a packet to the server.
</para>
<para>
STEP #2: the server's <quote>transaction processor</quote> thread uses the
primary-key index on field k0 to find the location of the
tuple in memory. It determines that the tuple can be updated
(not much can go wrong when you're merely changing an unindexed
field value to something shorter).
</para>
<para>
STEP #3: the transaction processor thread sends a message to
the <emphasis>write-ahead logging<alt>There's a Wikipedia article about write-ahead logging: https://en.wikipedia.org/wiki/Write-ahead_logging</alt></emphasis> (WAL) thread.
</para>
<para>
At this point a <quote>yield</quote> takes place. To know
the significance of that -- and it's quite significant -- you
have to know a few facts and a few new words.
</para>
<para>
FACT #1: there is only one transaction processor thread.
Some people are used to the idea that there can be multiple
threads operating on the database, with (say) thread #1
reading row #x while thread#2 writes row#y. With Tarantool
no such thing ever happens. Only the transaction processor
thread can access the database, and there is only one
transaction processor thread for each instance of the server.
</para>
<para>
FACT #2: the transaction processor thread can handle many
<emphasis>fibers<alt>There's a Wikipedia article about fibers: https://en.wikipedia.org/wiki/Fiber_%28computer_science%29</alt></emphasis>.
A fiber is a set of computer instructions that may contain <quote>yield</quote> signals.
The transaction processor thread will execute all computer instructions
until a yield, then switch to execute the instructions of a different fiber.
Thus (say) the thread reads row#x for the sake of fiber#1,
then writes row#y for the sake of fiber#2.
</para>
<para>
FACT #3: yields must happen, otherwise the transaction processor thread
would stick permanently on the same fiber. There are implicit yields:
every data-change operation or network-access causes an implicit yield,
and every statement that goes through the tarantool client causes an
implicit yield. And there are explicit yields: in a Lua stored procedure
one can and should add <quote>yield</quote> statements to prevent hogging.
This is called <emphasis>cooperative multitasking<alt>There's a Wikipedia
article with a section about cooperative multitasking: