Implementing Basic Table Scanning - MySQL

The most basic storage engines implement read-only table scanning. Such engines might be used to support SQL queries of logs and other data files that are populated outside of MySQL.

The implementation of the methods in this section provide the first steps toward the creation of more advanced storage engines.

The following shows the method calls made during a nine-row table scan of the CSV engine:

method calls made during a nine-row table scan of the CSV engine

Implementing the store_lock() Method

The store_lock() method is called before any reading or writing is performed.

Before adding the lock into the table lock handler mysqld calls store lock with the requested locks.Store lock can modify the lock level, for example change blocking write lock to non-blocking, ignore the lock (if we don't want to use MySQL table locks at all) or add locks for many tables (like we do when we are using a MERGE handler).

When releasing locks, store_lock() is also called. In this case, one usually doesn't have to do any-thing.

If the argument of store_lock is TL_IGNORE, it means that MySQL requests the handler to store the same lock level as the last time.

The potential lock types are defined in includes/thr_lock.h and are copied here:

Implementing the store_lock() Method

Actual lock handling will vary depending on your locking implementation and you may choose to implement some or none of the requested lock types, substituting your own methods as appropriate. The following is the minimal implementation, for a storage engine that does not need to downgrade locks:

minimal implementation, for a storage engine

See also ha_myisammrg::store_lock() for a more complex implementation.

Implementing the external_lock() Method

The external_lock() method is called at the start of a statement or when a LOCK TABLES statement is issued.

Examples of using external_lock() can be found in the sql/ file, but most storage engines can simply return 0, as is the case with the EXAMPLE storage engine:

Implementing the rnd_init() Method

The method called before any table scan is the rnd_init() method. The rnd_init() method is used to prepare for a table scan, resetting counters and pointers to the start of the table.

The following example is from the CSV storage engine:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

MySQL Topics