Perhaps this is more of a DB/SQL question than Drupal. However, when defining large primary keys (multiple cols) how should I be indexing?
In my example below I am both setting a primary key -and- index on multiple cols. This is because I expect to use all of those cols in the WHERE part of queries. Is this correct?
$schema['tournament_stats_node'] = array(
'description' => 'Stores relations between tournament stats and node.',
'fields' => array(
'entity_type' => array(
'description' => 'Primary key: Entity type of participants, e.g. user/team.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'nid' => array(
'description' => 'Primary key: Related node ID',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'id' => array(
'description' => 'Primary key: Unique entity ID',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'stat' => array(
'description' => 'Tournament stat type',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('entity_type', 'nid', 'id'),
'indexes' => array(
'entity_type' => array('entity_type'),
'id' => array('id'),
'nid' => array('nid'),
'stat' => array('stat'),
),
);