Problem/Motivation
The $field
parameter for Drupal\Core\Database\Schema::addIndex
is not completely documented. There is hidden functionality in that it can additionally provide a maximum length for a given field.
The NodeStorageSchema
illustrates this:
$schema ['node_field_data']['indexes'] += array(
...
'node__title_type' => array('title', array('type', 4)),
);
That call results in the type
field being restricted to 4 characters in the index.
The code responsible is actually in each separate driver. This is the mysql version:
protected function createKeySql($fields) {
$return = array();
foreach ($fields as $field) {
if (is_array($field)) {
$return [] = '`' . $field [0] . '`(' . $field [1] . ')';
}
else {
$return [] = '`' . $field . '`';
}
}
return implode(', ', $return);
}
Proposed resolution
Document this behavior.
Remaining tasks
User interface changes
API changes
Beta phase evaluation
Issue category | Bug |
---|---|
Unfrozen changes | Unfrozen because it only changes documentation. |
Comment | File | Size | Author |
---|---|---|---|
#5 | addindex-docs-2462641-05.patch | 925 bytes | jhedstrom |
#3 | addindex-docs-2462641-03.patch | 150.79 KB | jhedstrom |
Comments
Comment #1
jhedstromComment #2
jhodgdonThanks for documenting this!
So... I think the docs could be clearer. How about:
An array of field names or field information; if field information is passed, it's an array whose first element is the field name and whose second is the maximum length in the index. For example [...]
Also the @code tags should be indented the same as the previous text.
Comment #3
jhedstromThanks! I realized as I was typing the docs for #1 that it felt extremely awkward :)
Comment #4
jhedstromComment #5
jhedstromWoah, that was the wrong patch :) Interdiff was still accurate though.
Comment #6
jhodgdonLooks good now, thanks!
Comment #7
alexpottCommitted 36b1c8b and pushed to 8.0.x. Thanks!