record_describer.rb

Path: lib/innodb/record_describer.rb
Last Update: Sat Feb 23 07:11:56 +0000 2019

A class to describe record layouts for InnoDB indexes. Designed to be usable in two different ways: statically built and dynamically built. Note that in both cases, the order that statements are encountered is critical. Columns must be added to the key and row structures in the correct order.

STATIC USAGE

Static building is useful for building a custom describer for any index and looks like the following:

To describe the SQL syntax:

  CREATE TABLE my_table (
    id BIGINT NOT NULL,
    name VARCHAR(100) NOT NULL,
    age INT UNSIGNED,
    PRIMARY KEY (id)
  );

The clustered key would require a class like:

  class MyTableClusteredDescriber < Innodb::RecordDescriber
    type :clustered
    key "id", :BIGINT, :UNSIGNED, :NOT_NULL
    row "name", "VARCHAR(100)", :NOT_NULL
    row "age", :INT, :UNSIGNED
  end

It can then be instantiated as usual:

  my_table_clustered = MyTableClusteredDescriber.new

All statically-defined type, key, and row information will be copied into the instance when it is initialized. Once initialized, the instance can be additionally used dynamically, as per below. (A dynamic class is just the same as a static class that is empty.)

Note that since InnoDB works in terms of indexes individually, a new class must be created for each index.

DYNAMIC USAGE

If a record describer needs to be built based on runtime information, such as index descriptions from a live data dictionary, instances can be built dynamically. For the same table above, this would require:

  my_table_clustered = Innodb::RecordDescriber.new
  my_table_clustered.type = :clustered
  my_table_clustered.key "id", :BIGINT, :UNSIGNED, :NOT_NULL
  my_table_clustered.row "name", "VARCHAR(100)", :NOT_NULL
  my_table_clustered.row "age", :INT, :UNSIGNED

[Validate]