275
SELECT Operation
SELECT is an important operation that is required by several methods. Many methods
that are implemented for the SELECT operation are also called from other methods. The
rnd_init() method is used to prepare for a table scan for non-indexed tables, resetting
counters and pointers to the start of the table. If the table is an indexed table, the
MariaDB server calls the index_init() method. As shown in Listing 13-14, the pointers
are initialized.
Listing 13-14. ha_pmdk.cc – rnd_init() is called when the system wants the
storage engine to do a table scan
869 int ha_pmdk::rnd_init(bool scan)
870 {
...
874
current=prev=NULL;
875
iter = proot->rows;
876
DBUG_RETURN(0);
877 }
When the table is initialized, the MariaDB server calls the rnd_next(), index_first(),
or index_read_map() method, depending on whether the table is indexed or not. These
methods populate the buffer with data from the current object and updates the iterator to
the next value. The methods are called once for every row to be scanned.
Listing 13-15 shows how the buffer passed to the function is populated with the
contents of the table row in the internal MariaDB format. If there are no more objects to
read, the return value must be HA_ERR_END_OF_FILE.
Listing 13-15. ha_pmdk.cc – rnd_init() is called when the system wants the
storage engine to do a table scan
902 int ha_pmdk::rnd_next(uchar *buf)
903 {
...
910
memcpy(buf, iter->buf, table->s->reclength);
911
if (current != NULL) {
912
prev = current;
913
}
Chapter 13 enabling persistenCe Using a real-World appliCation
Précédent

- 299/457

Suivant