Problem/Motivation
It is not possible to query on delta. This is a regression from Drupal 7 where we had fieldDeltaCondition since #1206200: Add support for field meta conditions in EntityFieldQuery (not 7.0 but long enough). Curiously enough I can't find https://www.drupal.org/core/beta-changeshttps://www.drupal.org/core/issue-priority any advice on the priority of such but given it's a regression it is allowed in beta.
Proposed resolution
Adopt a new syntax ->condition("fieldname.delta.columname")
. Like ->condition("field_image.0.alt", "foo")
Also support ->condition('fieldname.?.columname')->condition('fieldname.?', deltavalue, 'deltaoperator')
for the case when you need more complex delta operator(s). Yay, wildcards. I am reasonably sure we do not support the ? as a column name :)
Remaining tasks
Code it. Strike at the Tables::addField method:
$specifier = $specifiers[$key];
if ($key < $count && is_numeric($specifiers[$key + 1])) {
$delta = $specifiers[$key + 1];
$index_prefix .= ".$delta";
$key++;
}
then pass $delta 'round so that it ends up in addJoin, alongside of $langcode. I would replace $langcode with an associated array [langcode => $langcode, delta => $delta] and iterate it in addJoin making a minimal change there (beware that $delta can be 0 so an isset test is in order, $langcode defaults to NULL in the interface too).
In the if ($field_storage && $key < $count) {
part reset $delta to NULL.
Adjust the new tests to the new syntax. The patch, altogether could be quite small.
User interface changes
none
API changes
Some field schema columns might turn to reserved.